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' ;
2
10
import { createWorkspace } from 'create-nx-workspace' ;
3
11
import * as yargs from 'yargs' ;
4
12
import * as terminalLink from 'terminal-link' ;
5
13
6
14
import { CLIArguments } from './models' ;
7
- import { createNxWorkspaceVersion , createWorkspaceWithNxWrapper , getNxCommand } from './utils' ;
15
+ import {
16
+ createNxWorkspaceVersion ,
17
+ createWorkspaceWithNxWrapper ,
18
+ getNxCommand ,
19
+ } from './utils' ;
8
20
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' ;
10
24
11
- const pkgFolderName = pkgName . replace ( '@nxrocks/' , '' )
25
+ export async function mainCLI ( pkgName : string , stackName : string ) {
26
+ const pkgFolderName = pkgName . replace ( '@nxrocks/' , '' ) ;
12
27
const createPkgName = `create-${ pkgFolderName } ` ;
13
28
14
29
intro ( createPkgName ) ;
15
30
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 ;
48
68
const { _, $0, name : ignoredName , verbose, ...restArgs } = options ;
49
69
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?' ,
52
72
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
+ ) } ]`,
63
90
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' },
66
95
{ value : 'circleci' , label : 'Circle CI' } ,
67
- { value : 'skip' , label : 'Skip for now ' } ,
96
+ { value : 'skip' , label : '\nDo it later ' } ,
68
97
] ,
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 ) ;
71
108
72
109
const presetVersion = 'latest' ;
73
-
110
+
74
111
let directory : string ;
75
112
76
113
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.`,
79
122
] ;
80
123
81
124
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
+ ) ;
83
131
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 ( ' ' ) ;
85
135
86
136
const s = spinner ( ) ;
87
137
s . start ( 'Initializing your workspace' ) ;
88
138
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
+ ) ;
90
149
91
150
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 } ` , {
97
154
...restArgs ,
98
155
name,
99
156
nxCloud,
100
- packageManager : 'npm'
101
- }
102
- ) ) ?. directory ;
157
+ useGitHub,
158
+ packageManager : 'npm' ,
159
+ } )
160
+ ) ?. directory ;
103
161
}
104
162
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
+ ) ;
106
166
107
- note ( notes . join ( '\n' ) , " Next steps" ) ;
167
+ note ( notes . join ( '\n' ) , ' Next steps' ) ;
108
168
109
169
outro ( `Your workspace in ${ directory } is all set 🎉. Let's goooooo! 🚀` ) ;
110
170
}
111
171
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
+ ) {
113
177
return terminalLink ( text , url , { fallback } ) ;
114
- }
178
+ }
0 commit comments