1- /**
2- * The purpose of this file structure is to force commander to
3- * use the shebang, which is necessary to provide flags to Node. If
4- * the files do not have an extension, TypeScript won't check them, while
5- * if they have an extension, Commander executes them with Node to accommodate
6- * Windows users.
7- */
8-
91import * as module from 'node:module' ;
2+ import * as path from 'node:path' ;
103import * as process from 'node:process' ;
114
125import { Command , InvalidArgumentError } from 'commander' ;
136
14- import { resolveAbsoluteImportPath } from '../meta/resolve.js' ;
7+ module . register ( '@swc-node/register/esm' , import . meta. url ) ;
8+
9+ const { resolveAbsoluteImportPath } = await import ( '../meta/resolve.js' ) ;
1510
1611const require = module . createRequire ( import . meta. url ) ;
1712
18- const { name, version } = require ( '../../package.json' ) as { name : string ; version : string } ;
13+ const { name, version } = require ( '../../package.json' ) ;
1914
2015const program = new Command ( ) ;
2116program . name ( name ) ;
2217program . version ( version ) ;
2318program . allowExcessArguments ( false ) ;
24- program . allowUnknownOption ( false ) ;
19+ program . allowUnknownOption ( true ) ;
2520program . requiredOption ( '-c, --config-file <path>' , 'path to the config file' , ( filename ) => {
2621 const result = resolveAbsoluteImportPath ( filename , process . cwd ( ) ) ;
2722 if ( result . isErr ( ) ) {
@@ -30,11 +25,15 @@ program.requiredOption('-c, --config-file <path>', 'path to the config file', (f
3025 return result . value ;
3126} ) ;
3227
33- program . command ( 'build' , 'build application for production' ) ;
34- program . command ( 'dev' , 'run application in development mode' ) ;
28+ program . command ( 'build' , 'build application for production' , {
29+ executableFile : path . resolve ( import . meta. dirname , 'bin/libnest-build' )
30+ } ) ;
31+ program . command ( 'dev' , 'run application in development mode' , {
32+ executableFile : path . resolve ( import . meta. dirname , 'bin/libnest-dev' )
33+ } ) ;
3534
3635program . hook ( 'preSubcommand' , ( command ) => {
37- const configFile = command . getOptionValue ( 'configFile' ) as string ;
36+ const configFile = command . getOptionValue ( 'configFile' ) ;
3837 process . env . LIBNEST_CONFIG_FILEPATH = configFile ;
3938} ) ;
4039
0 commit comments