11#!/usr/bin/env node
2- 'use strict' ;
32import fs from 'node:fs' ;
43import path from 'node:path' ;
4+ import process from 'node:process' ;
55import chalk from 'chalk' ;
66import updateNotifier from 'update-notifier' ;
77import yosay from 'yosay' ;
88import stringLength from 'string-length' ;
99import rootCheck from 'root-check' ;
1010import meow from 'meow' ;
1111import list from 'cli-list' ;
12+ import { bootstrap } from 'global-agent' ;
1213import tabtab from './completion/tabtab.cjs' ;
1314import pkg from './utils/project-package.js' ;
1415import Router from './router.js' ;
15- import { bootstrap } from 'global-agent' ;
1616import * as routes from './routes/index.js' ;
1717import { getDirname } from './utils/node-shims.js' ;
1818
1919const __dirname = getDirname ( import . meta. url ) ;
20- const gens = list ( process . argv . slice ( 2 ) ) ;
20+ const generators = list ( process . argv . slice ( 2 ) ) ;
2121
2222bootstrap ( ) ;
2323
24- const cli = gens . map ( gen => {
25- const minicli = meow ( { autoHelp : false , autoVersion : true , pkg, argv : gen , importMeta : import . meta} ) ;
24+ const cli = generators . map ( generator => {
25+ const minicli = meow ( {
26+ autoHelp : false , autoVersion : true , pkg, argv : generator , importMeta : import . meta,
27+ } ) ;
2628 const options = minicli . flags ;
27- const args = minicli . input ;
29+ const arguments_ = minicli . input ;
2830
2931 // Add un-camelized options too, for legacy
3032 // TODO: Remove some time in the future when generators have upgraded
3133 for ( const key of Object . keys ( options ) ) {
32- const legacyKey = key . replace ( / [ A - Z ] / g, m => `-${ m . toLowerCase ( ) } ` ) ;
34+ const legacyKey = key . replaceAll ( / [ A - Z ] / g, m => `-${ m . toLowerCase ( ) } ` ) ;
3335 options [ legacyKey ] = options [ key ] ;
3436 }
3537
36- return { opts : options , args} ;
38+ return { opts : options , args : arguments_ } ;
3739} ) ;
3840
3941const firstCmd = cli [ 0 ] || { opts : { } , args : { } } ;
@@ -46,7 +48,7 @@ function updateCheck() {
4648 if ( notifier . update ) {
4749 message . push (
4850 'Update available: ' + chalk . green . bold ( notifier . update . latest ) + chalk . gray ( ' (current: ' + notifier . update . current + ')' ) ,
49- 'Run ' + chalk . magenta ( 'npm install -g ' + pkg . name ) + ' to update.'
51+ 'Run ' + chalk . magenta ( 'npm install -g ' + pkg . name ) + ' to update.' ,
5052 ) ;
5153 console . log ( yosay ( message . join ( ' ' ) , { maxLength : stringLength ( message [ 0 ] ) } ) ) ;
5254 }
@@ -55,8 +57,7 @@ function updateCheck() {
5557async function pre ( ) {
5658 // Debugging helper
5759 if ( cmd === 'doctor' ) {
58- // eslint-disable-next-line node/no-unsupported-features/es-syntax
59- const yeomanDoctor = ( await import ( 'yeoman-doctor' ) ) . default ;
60+ const { default : yeomanDoctor } = await import ( 'yeoman-doctor' ) ;
6061 yeomanDoctor ( ) ;
6162 return ;
6263 }
@@ -67,8 +68,7 @@ async function pre() {
6768
6869 // Easteregg
6970 if ( cmd === 'yeoman' || cmd === 'yo' ) {
70- // eslint-disable-next-line node/no-unsupported-features/es-syntax
71- const yeomanCharacter = ( await import ( 'yeoman-character' ) ) . default ;
71+ const { default : yeomanCharacter } = await import ( 'yeoman-character' ) ;
7272 console . log ( yeomanCharacter ) ;
7373 return ;
7474 }
@@ -82,9 +82,7 @@ function createGeneratorList(env) {
8282 const generatorName = parts . shift ( ) ;
8383
8484 // If first time we found this generator, prepare to save all its sub-generators
85- if ( ! namesByGenerator [ generatorName ] ) {
86- namesByGenerator [ generatorName ] = [ ] ;
87- }
85+ namesByGenerator [ generatorName ] ||= [ ] ;
8886
8987 // If sub-generator (!== app), save it
9088 if ( parts [ 0 ] !== 'app' ) {
@@ -111,7 +109,6 @@ const onError = error => {
111109} ;
112110
113111async function init ( ) {
114- // eslint-disable-next-line node/no-unsupported-features/es-syntax
115112 const { createEnv} = await import ( 'yeoman-environment' ) ;
116113 const env = createEnv ( ) ;
117114
@@ -156,9 +153,9 @@ async function init() {
156153 // Note: at some point, nopt needs to know about the generator options, the
157154 // one that will be triggered by the below args. Maybe the nopt parsing
158155 // should be done internally, from the args.
159- for ( const gen of cli ) {
156+ for ( const generator of cli ) {
160157 // eslint-disable-next-line no-await-in-loop
161- await env . run ( gen . args , gen . opts ) . catch ( error => onError ( error ) ) ;
158+ await env . run ( generator . args , generator . opts ) . catch ( error => onError ( error ) ) ;
162159 }
163160}
164161
@@ -182,6 +179,7 @@ rootCheck('\n' + chalk.red('Easy with the `sudo`. Yeoman is the master around he
182179
183180updateCheck ( ) ;
184181
182+ // eslint-disable-next-line unicorn/prefer-top-level-await
185183( async function ( ) {
186184 await pre ( ) ;
187185} ) ( ) ;
0 commit comments