Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update Nx workspace to v20.1.2 #240

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e" targets have been requested
- run: pnpm exec nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --stop-agents-after="e2e" --with-env-vars="ANDROID_SDK_VERSION,FLUTTER_VERSION,JDK_VERSION"
- run: pnpm exec nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --stop-agents-after="e2e-ci" --with-env-vars="ANDROID_SDK_VERSION,FLUTTER_VERSION,JDK_VERSION"

# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track develop origin/develop || exit 0
Expand All @@ -46,4 +46,4 @@ jobs:
main-branch-name: 'develop'

- run: pnpm exec nx-cloud record -- nx format:check
- run: pnpm exec nx affected -t lint test-ci build e2e --parallel=5 --exclude=smoke
- run: pnpm exec nx affected -t lint test-ci build e2e-ci --parallel=5 --exclude=smoke
1 change: 0 additions & 1 deletion .verdaccio/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ logs:
publish:
allow_offline: true # set offline to true to allow publish offline

listen: 0.0.0.0:4873 # listen on all addresses (INADDR_ANY)
5 changes: 2 additions & 3 deletions e2e/smoke/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/smoke/src",
"projectType": "application",
"tags": [],
"tags": ["e2e"],
"implicitDependencies": [
"nx-spring-boot",
"nx-quarkus",
"nx-micronaut",
"nx-flutter",
"nx-ktor",
"nx-melos"
"nx-ktor"
],
"targets": {}
}
7 changes: 4 additions & 3 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"passWithNoTests": true,
"runInBand": true
},
"dependsOn": ["^build"],
"dependsOn": ["nxrocks:populate-local-registry"],
"configurations": {
"ci": {
"ci": true,
Expand All @@ -69,7 +69,7 @@
"passWithNoTests": true,
"runInBand": true
},
"dependsOn": ["^build"],
"dependsOn": ["nxrocks:populate-local-registry"],
"configurations": {
"ci": {
"ci": true,
Expand Down Expand Up @@ -161,5 +161,6 @@
],
"sharedGlobals": ["{workspaceRoot}/.nx/workflows/**/**"]
},
"defaultBase": "develop"
"defaultBase": "develop",
"useLegacyCache": true
}
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"license": "MIT",
"scripts": {
"nx": "nx",
"build": "nx run-many --target build --parallel 4 --exclude smoke",
"build": "nx run-many --target build --parallel 4",
"test": "nx run-many --target test --parallel 4",
"e2e": "ts-node -P ./tools/tsconfig.tools.json ./tools/scripts/run-all-e2e-tests.ts",
"lint": "nx run-many --target lint --fix --parallel 4 --exclude smoke",
"affected:build": "nx affected --target build --exclude=smoke",
"lint": "nx run-many --target lint --fix --parallel 4",
"affected:build": "nx affected --target build",
"affected:e2e": "nx affected --target e2e --exclude=smoke",
"affected:test": "nx affected --target test",
"affected:lint": "nx affected --target lint --fix",
Expand All @@ -27,9 +27,9 @@
},
"private": true,
"dependencies": {
"@clack/prompts": "^0.7.0",
"@clack/prompts": "^0.8.1",
"@swc/helpers": "0.5.11",
"create-nx-workspace": "~18.1.3",
"create-nx-workspace": "20.1.2",
"enquirer": "^2.4.1",
"hpagent": "^1.2.0",
"js-yaml": "^4.1.0",
Expand All @@ -47,13 +47,13 @@
"@commitlint/cli": "^19.3.0",
"@commitlint/config-angular": "^19.3.0",
"@jest/globals": "29.7.0",
"@nx/devkit": "19.6.4",
"@nx/eslint-plugin": "19.6.4",
"@nx/jest": "19.6.4",
"@nx/js": "19.6.4",
"@nx/node": "19.6.4",
"@nx/plugin": "19.6.4",
"@nx/workspace": "19.6.4",
"@nx/devkit": "20.1.2",
"@nx/eslint-plugin": "20.1.2",
"@nx/jest": "20.1.2",
"@nx/js": "20.1.2",
"@nx/node": "20.1.2",
"@nx/plugin": "20.1.2",
"@nx/workspace": "20.1.2",
"@swc-node/register": "1.9.1",
"@swc/cli": "0.3.12",
"@swc/core": "1.5.7",
Expand All @@ -78,7 +78,7 @@
"jest-environment-node": "^29.4.1",
"jest-mock": "28.1.3",
"lint-staged": "^15.2.7",
"nx": "19.6.4",
"nx": "20.1.2",
"prettier": "2.6.2",
"ts-jest": "29.1.0",
"ts-node": "10.9.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/common-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"create-nx-ktor"
],
"dependencies": {
"create-nx-workspace": ">=18.0.0",
"create-nx-workspace": ">=20.0.0",
"@clack/prompts": "^0.7.0",
"yargs": "^17.7.2",
"tslib": "^2.6.1",
"@nx/devkit": ">=18.0.0",
"@nx/devkit": ">=20.0.0",
"fs-extra": "^10.1.0",
"terminal-link": "^2.1.1"
},
Expand Down
206 changes: 135 additions & 71 deletions packages/common-cli/src/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1,178 @@
import { intro, text, confirm, spinner, note, outro, select } from '@clack/prompts';
import {
intro,
text,
confirm,
spinner,
note,
outro,
select,
} from '@clack/prompts';
import { createWorkspace } from 'create-nx-workspace';
import * as yargs from 'yargs';
import * as terminalLink from 'terminal-link';

import { CLIArguments } from './models';
import { createNxWorkspaceVersion, createWorkspaceWithNxWrapper, getNxCommand } from './utils';
import {
createNxWorkspaceVersion,
createWorkspaceWithNxWrapper,
getNxCommand,
} from './utils';

export async function mainCLI(pkgName: string, stackName: string) {
// change type to ('yes' | 'github' | 'gitlab' | 'azure' | 'bitbucket-pipelines' | 'circleci' | 'skip');
// and uncomment below prompt options, once https://github.com/nrwl/nx/pull/29008 is merged
export type NxCloud = 'yes' | 'github' | 'circleci' | 'skip';

const pkgFolderName = pkgName.replace('@nxrocks/', '')
export async function mainCLI(pkgName: string, stackName: string) {
const pkgFolderName = pkgName.replace('@nxrocks/', '');
const createPkgName = `create-${pkgFolderName}`;

intro(createPkgName);

const options = (yargs
.parserConfiguration({
'strip-dashed': true,
})
.command(
'$0 [name]',
`Create a new Nx workspace with ${stackName} support`,
(yargs) => yargs.option('name',
{
describe: 'Workspace name (e.g. org name)',
type: 'string',
}).
option('useNxWrapper',
{
describe: 'Let Nx manages its own installation and updates',
type: 'boolean',
}).
option('nxCloud',
{
describe: "Do you want Nx Cloud to make your CI fast?",
choices: ['yes', 'github', 'circleci', 'skip'] as const
}).
option('verbose',
{
describe: "Enable more logging information",
type: 'boolean',
default: process.env['NX_VERBOSE_LOGGING'] === 'true',
})
)
.help('help', 'Show help') as yargs.Argv<CLIArguments>).parseSync();

let { name, useNxWrapper, nxCloud } = options;
const options = (
yargs
.parserConfiguration({
'strip-dashed': true,
})
.command(
'$0 [name]',
`Create a new Nx workspace with ${stackName} support`,
(yargs) =>
yargs
.option('name', {
describe: 'Workspace Location (e.g. org name)',
type: 'string',
})
.option('useNxWrapper', {
describe: 'Let Nx manages its own installation and updates',
type: 'boolean',
})
.option('nxCloud', {
describe: 'Do you want Nx Cloud to make your CI fast?',
choices: ['yes', 'github', 'circleci', 'skip'] as const,
})
.option('useGitHub', {
describe:
'Will you be using GitHub as your git hosting provider?',
boolean: true,
})
.option('verbose', {
describe: 'Enable more logging information',
type: 'boolean',
default: process.env['NX_VERBOSE_LOGGING'] === 'true',
})
)
.help('help', 'Show help') as yargs.Argv<CLIArguments>
).parseSync();

let { name, useNxWrapper, nxCloud, useGitHub } = options;
const { _, $0, name: ignoredName, verbose, ...restArgs } = options;

name ||= await text({
message: 'What is the name of your workspace (e.g. org name)?',
name ||= (await text({
message: 'Where would you like to create your workspace?',
initialValue: 'myorg',
validate: (value) => (value?.length === 0) ? 'You need to provide one' : void 0,
}) as string;

useNxWrapper ??= await confirm({
message: `Would you like to use Nx Wrapper? [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ]`,
initialValue: true
}) as boolean;

nxCloud ??= await select({
message: `Would you like Nx Cloud to make your CI faster? [ ${linkify('Nx Cloud', 'https://nx.app/?utm_source=' + createPkgName)} ]`,
validate: (value) =>
value?.length === 0 ? 'You need to provide one' : void 0,
})) as string;

useNxWrapper ??= (await confirm({
message: `Would you like to use Nx Wrapper? [ ${linkify(
'Nx Wrapper',
'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper'
)} ]`,
initialValue: true,
})) as boolean;

nxCloud ??= (await select({
message: `Would you like Nx Cloud to make your CI faster? [ ${linkify(
'Nx Cloud',
'https://nx.app/?utm_source=' + createPkgName
)} ]`,
options: [
{ value: 'yes', label: 'Yes' },
{ value: 'github', label: 'Github' },
{ value: 'github', label: 'GitHub Actions' },
//{ value: 'gitlab', label: 'Gitlab' },
//{ value: 'azure', label: 'Azure DevOps' },
//{ value: 'bitbucket-pipelines', label: 'BitBucket Pipelines' },
{ value: 'circleci', label: 'Circle CI' },
{ value: 'skip', label: 'Skip for now' },
{ value: 'skip', label: '\nDo it later' },
],
initialValue: 'skip' as 'yes' | 'github' | 'circleci' | 'skip'
}) as 'yes' | 'github' | 'circleci' | 'skip';
initialValue: 'skip' as NxCloud,
})) as NxCloud;

useGitHub ??=
nxCloud === 'yes' ||
nxCloud === 'github' ||
((await confirm({
message: `Will you be using GitHub as your git hosting provider?`,
initialValue: false,
})) as boolean);

const presetVersion = 'latest';

let directory: string;

const notes = [
`- Go to [ ${linkify(pkgName, 'https://github.com/tinesoft/nxrocks/tree/develop/packages/' + pkgFolderName)} ] to get started with Nx and ${stackName} plugin.`,
`- Run [ ${getNxCommand(useNxWrapper)} g ${pkgName}:project ] to add more projects.`
`- Go to [ ${linkify(
pkgName,
'https://github.com/tinesoft/nxrocks/tree/develop/packages/' +
pkgFolderName
)} ] to get started with Nx and ${stackName} plugin.`,
`- Run [ ${getNxCommand(
useNxWrapper
)} g ${pkgName}:project ] to add more projects.`,
];

if (useNxWrapper) {
notes.push(`- Go to [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ] to get started with Nx Wrapper.`);
notes.push(
`- Go to [ ${linkify(
'Nx Wrapper',
'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper'
)} ] to get started with Nx Wrapper.`
);

const allArgs = Object.entries(restArgs).map(([key, value]) => `--${key}=${value}`).join(' ');
const allArgs = Object.entries(restArgs)
.map(([key, value]) => `--${key}=${value}`)
.join(' ');

const s = spinner();
s.start('Initializing your workspace');

directory = createWorkspaceWithNxWrapper(name, pkgName, allArgs, nxCloud, presetVersion, createNxWorkspaceVersion, !verbose);
directory = createWorkspaceWithNxWrapper(
name,
pkgName,
allArgs,
nxCloud,
useGitHub,
presetVersion,
createNxWorkspaceVersion,
!verbose
);

s.stop(`Successfully created the workspace: ${name}`);
}
else {
directory = (await createWorkspace(
`${pkgName}@${presetVersion}`,
{
} else {
directory = (
await createWorkspace(`${pkgName}@${presetVersion}`, {
...restArgs,
name,
nxCloud,
packageManager: 'npm'
}
))?.directory;
useGitHub,
packageManager: 'npm',
})
)?.directory;
}

notes.push(`- Go to [ ${linkify('Nx.dev', 'https://nx.dev')} ] to get started with Nx.`);
notes.push(
`- Go to [ ${linkify('Nx.dev', 'https://nx.dev')} ] to get started with Nx.`
);

note(notes.join('\n'), "Next steps");
note(notes.join('\n'), 'Next steps');

outro(`Your workspace in ${directory} is all set 🎉. Let's goooooo! 🚀`);
}

function linkify(text: string, url: string, fallback = (text: string, url: string) => url) {
function linkify(
text: string,
url: string,
fallback = (text: string, url: string) => url
) {
return terminalLink(text, url, { fallback });
}
}
Loading
Loading