@@ -7,7 +7,7 @@ import path from 'path';
77import yargsInteractive , { OptionData } from 'yargs-interactive' ;
88import { exists , isOccupied } from './fs' ;
99import { getGitUser , initGit } from './git' ;
10- import { addDeps , installDeps } from './npm' ;
10+ import { addDeps , installDeps , whichPm } from './npm' ;
1111import { copy , getAvailableTemplates } from './template' ;
1212
1313export interface Option {
@@ -17,6 +17,10 @@ export interface Option {
1717export interface Options {
1818 templateRoot : string ;
1919 promptForTemplate ?: boolean ;
20+ promptForLicense ?: boolean ;
21+ promptForNodePM ?: boolean ;
22+ skipGitInit ?: boolean ;
23+ skipNpmInstall ?: boolean ;
2024 modifyName ?: ( name : string ) => string | Promise < string > ;
2125 extra ?: Option ;
2226 caveat ?:
@@ -73,6 +77,8 @@ function getContact(author: string, email?: string) {
7377async function getYargsOptions (
7478 templateRoot : string ,
7579 promptForTemplate : boolean ,
80+ promptForLicense : boolean ,
81+ promptForNodePM : boolean ,
7682 extraOptions : Option = { }
7783) {
7884 const gitUser = await getGitUser ( ) ;
@@ -110,16 +116,16 @@ async function getYargsOptions(
110116 type : 'list' ,
111117 describe : 'license' ,
112118 choices : [ ...availableLicenses ( ) , 'UNLICENSED' ] ,
113- default : 'MIT' ,
114- prompt : 'if-no-arg' ,
119+ default : promptForLicense ? 'MIT' : 'UNLICENSED ',
120+ prompt : promptForLicense ? 'if-no-arg' : 'never ',
115121 } ,
116122 'node-pm' : {
117123 type : 'list' ,
118124 describe :
119125 'select package manager to use for installing packages from npm' ,
120126 choices : [ 'npm' , 'yarn' , 'pnpm' ] ,
121- default : 'npm' ,
122- prompt : 'never' ,
127+ default : undefined , // undefined by default, we'll try to guess pm manager later
128+ prompt : promptForNodePM ? 'if-no-arg' : 'never' ,
123129 } ,
124130 ...extraOptions ,
125131 } ;
@@ -149,13 +155,21 @@ export async function create(appName: string, options: Options) {
149155 throw new CLIError ( `${ packageDir } is not empty directory.` ) ;
150156 }
151157
152- const { templateRoot, promptForTemplate = false } = options ;
158+ const {
159+ templateRoot,
160+ promptForTemplate = false ,
161+ promptForLicense = true ,
162+ promptForNodePM = false ,
163+ } = options ;
153164
154165 const yargsOption = await getYargsOptions (
155166 templateRoot ,
156167 promptForTemplate ,
168+ promptForLicense ,
169+ promptForNodePM ,
157170 options . extra
158171 ) ;
172+
159173 const args = await yargsInteractive ( )
160174 . usage ( '$0 <name> [args]' )
161175 . interactive ( yargsOption as any ) ;
@@ -212,12 +226,17 @@ export async function create(appName: string, options: Options) {
212226 }
213227
214228 // init git
215- try {
216- console . log ( '\nInitializing a git repository' ) ;
217- await initGit ( packageDir ) ;
218- } catch ( err : any ) {
219- if ( err ?. exitCode == 127 ) return ; // no git available
220- throw err ;
229+ const skipGit = args [ 'skip-git' ] ;
230+
231+ // init git if option skipGitInit or arg --skip-git are not set
232+ if ( ! ( options . skipGitInit || skipGit ) ) {
233+ try {
234+ console . log ( '\nInitializing a git repository' ) ;
235+ await initGit ( packageDir ) ;
236+ } catch ( err : any ) {
237+ if ( err ?. exitCode == 127 ) return ; // no git available
238+ throw err ;
239+ }
221240 }
222241
223242 const run = ( command : string , options : CommonOptions < string > = { } ) => {
@@ -233,10 +252,16 @@ export async function create(appName: string, options: Options) {
233252 let installNpmPackage = async ( packageName : string ) : Promise < void > => { } ;
234253
235254 if ( exists ( 'package.json' , packageDir ) ) {
236- const packageManager = args [ 'node-pm' ] ;
255+ const nodePMArg = args [ 'node-pm' ] ;
256+ const skipInstallArg = args [ 'skip-install' ] ;
257+
258+ // guess which package manager to use
259+ const packageManager = whichPm ( nodePMArg ) ;
237260
238- console . log ( `Installing dependencies using ${ packageManager } ` ) ;
239- await installDeps ( packageDir , packageManager ) ;
261+ // install deps only if skipNpmInstall is not falsy
262+ if ( ! ( options . skipNpmInstall || skipInstallArg ) ) {
263+ await installDeps ( packageDir , packageManager ) ;
264+ }
240265
241266 installNpmPackage = async (
242267 pkg : string | string [ ] ,
0 commit comments