Skip to content

Commit a834492

Browse files
committed
feat: add support for the useGithub option in all the create-nx-* CLIs
1 parent 8989698 commit a834492

File tree

7 files changed

+196
-112
lines changed

7 files changed

+196
-112
lines changed

e2e/nx-flutter-e2e/tests/create-nx-flutter.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('create-nx-flutter', () => {
2323
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2424
projectDirectory = createCLITestProject(
2525
'create-nx-flutter',
26-
`--prjName=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`
26+
`--prjName=flutapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2727
);
2828

2929
// npm ls will fail if the package is not installed properly

e2e/nx-micronaut-e2e/tests/create-nx-micronaut.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('create-nx-micronaut', () => {
2323
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2424
projectDirectory = createCLITestProject(
2525
'create-nx-micronaut',
26-
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`
26+
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2727
);
2828

2929
// npm ls will fail if the package is not installed properly

e2e/nx-quarkus-e2e/tests/create-nx-quarkus.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ describe('create-nx-spring-boot', () => {
2222
${false}
2323
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2424
projectDirectory = createCLITestProject(
25-
'create-nx-spring-boot',
26-
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`
25+
'create-nx-quarkus',
26+
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2727
);
2828

2929
// npm ls will fail if the package is not installed properly

e2e/nx-quarkus-e2e/tests/nx-quarkus.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('nx-quarkus e2e', () => {
114114
expect(pomXml).toContain(`<artifactId>${artifactId}</artifactId>`);
115115
//expect(pomXml).toContain(`<version>${version}</version>`);
116116
expect(pomXml).toContain(
117-
`<maven.compiler.releasez>21</maven.compiler.release>`
117+
`<maven.compiler.release>21</maven.compiler.release>`
118118
);
119119

120120
// make sure the build wrapper file is executable (*nix only)

e2e/nx-spring-boot-e2e/tests/create-nx-spring-boot.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('create-nx-spring-boot', () => {
2323
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
2424
projectDirectory = createCLITestProject(
2525
'create-nx-spring-boot',
26-
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`
26+
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --useGitHub=false --no-interactive`
2727
);
2828

2929
// npm ls will fail if the package is not installed properly

packages/common-cli/src/lib/main.ts

+135-71
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,178 @@
1-
import { intro, text, confirm, spinner, note, outro, select } from '@clack/prompts';
1+
import {
2+
intro,
3+
text,
4+
confirm,
5+
spinner,
6+
note,
7+
outro,
8+
select,
9+
} from '@clack/prompts';
210
import { createWorkspace } from 'create-nx-workspace';
311
import * as yargs from 'yargs';
412
import * as terminalLink from 'terminal-link';
513

614
import { CLIArguments } from './models';
7-
import { createNxWorkspaceVersion, createWorkspaceWithNxWrapper, getNxCommand } from './utils';
15+
import {
16+
createNxWorkspaceVersion,
17+
createWorkspaceWithNxWrapper,
18+
getNxCommand,
19+
} from './utils';
820

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

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

1429
intro(createPkgName);
1530

16-
const options = (yargs
17-
.parserConfiguration({
18-
'strip-dashed': true,
19-
})
20-
.command(
21-
'$0 [name]',
22-
`Create a new Nx workspace with ${stackName} support`,
23-
(yargs) => yargs.option('name',
24-
{
25-
describe: 'Workspace name (e.g. org name)',
26-
type: 'string',
27-
}).
28-
option('useNxWrapper',
29-
{
30-
describe: 'Let Nx manages its own installation and updates',
31-
type: 'boolean',
32-
}).
33-
option('nxCloud',
34-
{
35-
describe: "Do you want Nx Cloud to make your CI fast?",
36-
choices: ['yes', 'github', 'circleci', 'skip'] as const
37-
}).
38-
option('verbose',
39-
{
40-
describe: "Enable more logging information",
41-
type: 'boolean',
42-
default: process.env['NX_VERBOSE_LOGGING'] === 'true',
43-
})
44-
)
45-
.help('help', 'Show help') as yargs.Argv<CLIArguments>).parseSync();
46-
47-
let { name, useNxWrapper, nxCloud } = options;
31+
const options = (
32+
yargs
33+
.parserConfiguration({
34+
'strip-dashed': true,
35+
})
36+
.command(
37+
'$0 [name]',
38+
`Create a new Nx workspace with ${stackName} support`,
39+
(yargs) =>
40+
yargs
41+
.option('name', {
42+
describe: 'Workspace Location (e.g. org name)',
43+
type: 'string',
44+
})
45+
.option('useNxWrapper', {
46+
describe: 'Let Nx manages its own installation and updates',
47+
type: 'boolean',
48+
})
49+
.option('nxCloud', {
50+
describe: 'Do you want Nx Cloud to make your CI fast?',
51+
choices: ['yes', 'github', 'circleci', 'skip'] as const,
52+
})
53+
.option('useGitHub', {
54+
describe:
55+
'Will you be using GitHub as your git hosting provider?',
56+
boolean: true,
57+
})
58+
.option('verbose', {
59+
describe: 'Enable more logging information',
60+
type: 'boolean',
61+
default: process.env['NX_VERBOSE_LOGGING'] === 'true',
62+
})
63+
)
64+
.help('help', 'Show help') as yargs.Argv<CLIArguments>
65+
).parseSync();
66+
67+
let { name, useNxWrapper, nxCloud, useGitHub } = options;
4868
const { _, $0, name: ignoredName, verbose, ...restArgs } = options;
4969

50-
name ||= await text({
51-
message: 'What is the name of your workspace (e.g. org name)?',
70+
name ||= (await text({
71+
message: 'Where would you like to create your workspace?',
5272
initialValue: 'myorg',
53-
validate: (value) => (value?.length === 0) ? 'You need to provide one' : void 0,
54-
}) as string;
55-
56-
useNxWrapper ??= await confirm({
57-
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')} ]`,
58-
initialValue: true
59-
}) as boolean;
60-
61-
nxCloud ??= await select({
62-
message: `Would you like Nx Cloud to make your CI faster? [ ${linkify('Nx Cloud', 'https://nx.app/?utm_source=' + createPkgName)} ]`,
73+
validate: (value) =>
74+
value?.length === 0 ? 'You need to provide one' : void 0,
75+
})) as string;
76+
77+
useNxWrapper ??= (await confirm({
78+
message: `Would you like to use Nx Wrapper? [ ${linkify(
79+
'Nx Wrapper',
80+
'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper'
81+
)} ]`,
82+
initialValue: true,
83+
})) as boolean;
84+
85+
nxCloud ??= (await select({
86+
message: `Would you like Nx Cloud to make your CI faster? [ ${linkify(
87+
'Nx Cloud',
88+
'https://nx.app/?utm_source=' + createPkgName
89+
)} ]`,
6390
options: [
64-
{ value: 'yes', label: 'Yes' },
65-
{ value: 'github', label: 'Github' },
91+
{ value: 'github', label: 'GitHub Actions' },
92+
//{ value: 'gitlab', label: 'Gitlab' },
93+
//{ value: 'azure', label: 'Azure DevOps' },
94+
//{ value: 'bitbucket-pipelines', label: 'BitBucket Pipelines' },
6695
{ value: 'circleci', label: 'Circle CI' },
67-
{ value: 'skip', label: 'Skip for now' },
96+
{ value: 'skip', label: '\nDo it later' },
6897
],
69-
initialValue: 'skip' as 'yes' | 'github' | 'circleci' | 'skip'
70-
}) as 'yes' | 'github' | 'circleci' | 'skip';
98+
initialValue: 'skip' as NxCloud,
99+
})) as NxCloud;
100+
101+
useGitHub ??=
102+
nxCloud === 'yes' ||
103+
nxCloud === 'github' ||
104+
((await confirm({
105+
message: `Will you be using GitHub as your git hosting provider?`,
106+
initialValue: false,
107+
})) as boolean);
71108

72109
const presetVersion = 'latest';
73-
110+
74111
let directory: string;
75112

76113
const notes = [
77-
`- Go to [ ${linkify(pkgName, 'https://github.com/tinesoft/nxrocks/tree/develop/packages/' + pkgFolderName)} ] to get started with Nx and ${stackName} plugin.`,
78-
`- Run [ ${getNxCommand(useNxWrapper)} g ${pkgName}:project ] to add more projects.`
114+
`- Go to [ ${linkify(
115+
pkgName,
116+
'https://github.com/tinesoft/nxrocks/tree/develop/packages/' +
117+
pkgFolderName
118+
)} ] to get started with Nx and ${stackName} plugin.`,
119+
`- Run [ ${getNxCommand(
120+
useNxWrapper
121+
)} g ${pkgName}:project ] to add more projects.`,
79122
];
80123

81124
if (useNxWrapper) {
82-
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.`);
125+
notes.push(
126+
`- Go to [ ${linkify(
127+
'Nx Wrapper',
128+
'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper'
129+
)} ] to get started with Nx Wrapper.`
130+
);
83131

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

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

89-
directory = createWorkspaceWithNxWrapper(name, pkgName, allArgs, nxCloud, presetVersion, createNxWorkspaceVersion, !verbose);
139+
directory = createWorkspaceWithNxWrapper(
140+
name,
141+
pkgName,
142+
allArgs,
143+
nxCloud,
144+
useGitHub,
145+
presetVersion,
146+
createNxWorkspaceVersion,
147+
!verbose
148+
);
90149

91150
s.stop(`Successfully created the workspace: ${name}`);
92-
}
93-
else {
94-
directory = (await createWorkspace(
95-
`${pkgName}@${presetVersion}`,
96-
{
151+
} else {
152+
directory = (
153+
await createWorkspace(`${pkgName}@${presetVersion}`, {
97154
...restArgs,
98155
name,
99156
nxCloud,
100-
packageManager: 'npm'
101-
}
102-
))?.directory;
157+
useGitHub,
158+
packageManager: 'npm',
159+
})
160+
)?.directory;
103161
}
104162

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

107-
note(notes.join('\n'), "Next steps");
167+
note(notes.join('\n'), 'Next steps');
108168

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

112-
function linkify(text: string, url: string, fallback = (text: string, url: string) => url) {
172+
function linkify(
173+
text: string,
174+
url: string,
175+
fallback = (text: string, url: string) => url
176+
) {
113177
return terminalLink(text, url, { fallback });
114-
}
178+
}

0 commit comments

Comments
 (0)