@@ -211,10 +211,17 @@ export async function main(argv: string[]): Promise<void> {
211
211
"init [name]" ,
212
212
"📥 Create a wrangler.toml configuration file" ,
213
213
( yargs ) => {
214
- return yargs . positional ( "name" , {
215
- describe : "The name of your worker." ,
216
- type : "string" ,
217
- } ) ;
214
+ return yargs
215
+ . positional ( "name" , {
216
+ describe : "The name of your worker." ,
217
+ type : "string" ,
218
+ } )
219
+ . option ( "yes" , {
220
+ describe :
221
+ "Skip confirmation prompt, automatic yes to prompts; assume 'yes' as answer to all prompts and run non-interactively." ,
222
+ type : "boolean" ,
223
+ alias : "y" ,
224
+ } ) ;
218
225
} ,
219
226
async ( args ) => {
220
227
if ( "type" in args ) {
@@ -259,11 +266,15 @@ export async function main(argv: string[]): Promise<void> {
259
266
260
267
let pathToPackageJson = await findUp ( "package.json" ) ;
261
268
let shouldCreatePackageJson = false ;
269
+ const yesFlag = args . yes ?? false ;
262
270
if ( ! pathToPackageJson ) {
263
271
// If no package.json exists, ask to create one
264
- shouldCreatePackageJson = await confirm (
265
- "No package.json found. Would you like to create one?"
266
- ) ;
272
+ shouldCreatePackageJson = yesFlag
273
+ ? yesFlag
274
+ : await confirm (
275
+ "No package.json found. Would you like to create one?"
276
+ ) ;
277
+
267
278
if ( shouldCreatePackageJson ) {
268
279
await writeFile (
269
280
"./package.json" ,
@@ -298,9 +309,11 @@ export async function main(argv: string[]): Promise<void> {
298
309
packageJson . dependencies ?. wrangler
299
310
)
300
311
) {
301
- const shouldInstall = await confirm (
302
- "Would you like to install wrangler into your package.json?"
303
- ) ;
312
+ const shouldInstall = yesFlag
313
+ ? yesFlag
314
+ : await confirm (
315
+ "Would you like to install wrangler into your package.json?"
316
+ ) ;
304
317
if ( shouldInstall ) {
305
318
await packageManager . addDevDeps ( `wrangler@${ wranglerVersion } ` ) ;
306
319
console . log ( `✨ Installed wrangler` ) ;
@@ -313,7 +326,7 @@ export async function main(argv: string[]): Promise<void> {
313
326
if ( ! pathToTSConfig ) {
314
327
// If there's no tsconfig, offer to create one
315
328
// and install @cloudflare /workers-types
316
- if ( await confirm ( "Would you like to use TypeScript?" ) ) {
329
+ if ( yesFlag || ( await confirm ( "Would you like to use TypeScript?" ) ) ) {
317
330
isTypescriptProject = true ;
318
331
await writeFile (
319
332
"./tsconfig.json" ,
@@ -418,9 +431,14 @@ export async function main(argv: string[]): Promise<void> {
418
431
}
419
432
if ( isTypescriptProject ) {
420
433
if ( ! fs . existsSync ( "./src/index.ts" ) ) {
421
- const shouldCreateSource = await confirm (
422
- `Would you like to create a Worker at src/index.ts?`
423
- ) ;
434
+ let shouldCreateSource = false ;
435
+
436
+ shouldCreateSource = yesFlag
437
+ ? yesFlag
438
+ : await confirm (
439
+ `Would you like to create a Worker at src/index.ts?`
440
+ ) ;
441
+
424
442
if ( shouldCreateSource ) {
425
443
await mkdir ( "./src" , { recursive : true } ) ;
426
444
await writeFile (
0 commit comments