@@ -66,7 +66,8 @@ export const initCommand = cli('init', {
66
66
args . output ??= join ( process . cwd ( ) , args . cliName ) ;
67
67
ensureDirSync ( args . output ) ;
68
68
const packageJsonPath = join ( args . output , 'package.json' ) ;
69
- const cliPath = join ( args . output , 'bin' , `${ args . cliName } .${ args . format } ` ) ;
69
+ const cliPathWithoutExtension = join ( args . output , 'bin' , `${ args . cliName } ` ) ;
70
+ const cliPath = [ cliPathWithoutExtension , args . format ] . join ( '.' ) ;
70
71
71
72
let packageJsonContent : PackageJson = readJsonOr ( packageJsonPath , {
72
73
name : args . cliName ,
@@ -76,7 +77,7 @@ export const initCommand = cli('init', {
76
77
name : args . cliName ,
77
78
version : args . initialVersion ,
78
79
bin : {
79
- [ args . cliName ] : relative ( args . output , cliPath ) ,
80
+ [ args . cliName ] : relative ( args . output , cliPathWithoutExtension ) ,
80
81
} ,
81
82
dependencies : {
82
83
'cli-forge' : CLI_FORGE_VERSION ,
@@ -131,7 +132,21 @@ cpSync('package.json', 'dist/package.json');
131
132
)
132
133
) ;
133
134
}
134
- writeFileSync ( packageJsonPath , JSON . stringify ( packageJsonContent , null , 2 ) ) ;
135
+ writeFileSync (
136
+ packageJsonPath ,
137
+ JSON . stringify (
138
+ orderKeysInJson ( packageJsonContent , [
139
+ 'name' ,
140
+ 'version' ,
141
+ 'scripts' ,
142
+ 'bin' ,
143
+ 'dependencies' ,
144
+ 'devDependencies' ,
145
+ ] ) ,
146
+ null ,
147
+ 2
148
+ )
149
+ ) ;
135
150
ensureDirSync ( dirname ( cliPath ) ) ;
136
151
writeFileSync (
137
152
cliPath ,
@@ -273,3 +288,26 @@ function mergePackageJsonContents(
273
288
274
289
return merged ;
275
290
}
291
+
292
+ function orderKeysInJson < T extends Record < string , unknown > > (
293
+ obj : T ,
294
+ order : Array < keyof T & string >
295
+ ) : T {
296
+ const values = new Map ( Object . entries ( obj ) ) ;
297
+ const keys = new Set ( Object . keys ( obj ) ) ;
298
+ const returnObj = { } as T ;
299
+
300
+ for ( const key of order ) {
301
+ const value = values . get ( key ) ;
302
+ if ( value !== undefined ) {
303
+ returnObj [ key ] = value as T [ typeof key ] ;
304
+ keys . delete ( key ) ;
305
+ }
306
+ }
307
+
308
+ for ( const key of keys ) {
309
+ ( returnObj as any ) [ key ] = values . get ( key ) as T [ typeof key ] ;
310
+ }
311
+
312
+ return returnObj ;
313
+ }
0 commit comments