@@ -8,7 +8,8 @@ import fs from "node:fs/promises"
88import { parseAppendData , parseConfigFile } from "./config"
99
1010export async function parseCliArgs ( args = process . argv . slice ( 2 ) ) {
11- const pkgFile = await fs . readFile ( path . join ( __dirname , "package.json" ) )
11+ const isProjectRoot = Boolean ( await fs . stat ( path . join ( __dirname , "package.json" ) ) . catch ( ( ) => false ) )
12+ const pkgFile = await fs . readFile ( path . resolve ( __dirname , isProjectRoot ? "." : ".." , "package.json" ) )
1213 const pkg = JSON . parse ( pkgFile . toString ( ) )
1314 const isConfigProvided =
1415 args . includes ( "--config" ) || args . includes ( "-c" ) || args . includes ( "--git" ) || args . includes ( "-g" )
@@ -56,7 +57,7 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
5657 name : "output" ,
5758 aliases : [ "o" ] ,
5859 description :
59- "Path to output to. If `--create-sub-folder ` is enabled, the subfolder will be created inside " +
60+ "Path to output to. If `--subdir ` is enabled, the subfolder will be created inside " +
6061 "this path. Default is current working directory." ,
6162 required : ! isConfigProvided ,
6263 } )
@@ -75,6 +76,7 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
7576 aliases : [ "w" ] ,
7677 defaultValue : false ,
7778 description : "Enable to override output files, even if they already exist." ,
79+ negatable : true ,
7880 } )
7981 . option ( {
8082 name : "data" ,
@@ -91,15 +93,17 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
9193 parse : parseAppendData ,
9294 } )
9395 . flag ( {
94- name : "create-sub-folder " ,
96+ name : "subdir " ,
9597 aliases : [ "s" ] ,
9698 defaultValue : false ,
97- description : "Create subfolder with the input name" ,
99+ description : "Create a parent directory with the input name (and possibly `--subdir-helper`" ,
100+ negatable : true ,
101+ negationName : "no-subdir" ,
98102 } )
99103 . option ( {
100- name : "sub-folder-name -helper" ,
101- aliases : [ "sh " ] ,
102- description : "Default helper to apply to subfolder name when using `--create-sub-folder true `." ,
104+ name : "subdir -helper" ,
105+ aliases : [ "H " ] ,
106+ description : "Default helper to apply to subfolder name when using `--subdir `." ,
103107 } )
104108 . flag ( {
105109 name : "quiet" ,
@@ -150,16 +154,17 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
150154 bindOption : true ,
151155 lineLength : 100 ,
152156 useGlobalTableColumns : true ,
153- // optionOptions: {
154- // displayNegations: true,
155- // },
157+ usageText : [ chalk . yellow `simple-scaffold` , chalk . gray `[options]` , chalk . cyan `<name>` ] . join ( " " ) ,
158+ optionOptions : {
159+ displayNegations : true ,
160+ } ,
156161 footerText : [
157162 `Version: ${ pkg . version } ` ,
158163 `Copyright © Chen Asraf 2017-${ new Date ( ) . getFullYear ( ) } ` ,
159164 `` ,
160- `Documentation:\n ${ chalk . underline `https://chenasraf.github.io/simple-scaffold` } ` ,
161- `NPM:\n ${ chalk . underline `https://npmjs.com/package/simple-scaffold` } ` ,
162- `GitHub:\n ${ chalk . underline `https://github.com/chenasraf/simple-scaffold` } ` ,
165+ `Documentation: ${ chalk . underline `https://chenasraf.github.io/simple-scaffold` } ` ,
166+ `NPM: ${ chalk . underline `https://npmjs.com/package/simple-scaffold` } ` ,
167+ `GitHub: ${ chalk . underline `https://github.com/chenasraf/simple-scaffold` } ` ,
163168 ] . join ( "\n" ) ,
164169 } )
165170 . parse ( args )
0 commit comments