1
- 'use strict'
2
- const create = require ( '@pkgjs/create' )
3
- const fs = require ( 'fs-extra' )
4
- const path = require ( 'path' )
5
- const parseList = require ( 'safe-parse-list' )
6
- const scopeAndName = require ( './lib/scope-and-name' )
7
- const npm = require ( './lib/npm' )
8
- const git = require ( './lib/git' )
1
+ 'use strict' ;
2
+ const create = require ( '@pkgjs/create' ) ;
3
+ const fs = require ( 'fs-extra' ) ;
4
+ const path = require ( 'path' ) ;
5
+ const parseList = require ( 'safe-parse-list' ) ;
6
+ const scopeAndName = require ( './lib/scope-and-name' ) ;
7
+ const npm = require ( './lib/npm' ) ;
8
+ const git = require ( './lib/git' ) ;
9
9
10
10
// @TODO https://docs.npmjs.com/files/package.json
11
11
// exports
@@ -236,31 +236,31 @@ module.exports = create({
236
236
}
237
237
} ,
238
238
initOptions : async ( input ) => {
239
- const directory = input . directory || process . cwd ( )
240
- const pkgPath = path . resolve ( directory , input . pkgPath || 'package.json' )
239
+ const directory = input . directory || process . cwd ( ) ;
240
+ const pkgPath = path . resolve ( directory , input . pkgPath || 'package.json' ) ;
241
241
242
242
// Read existing package.json
243
- const pkg = input . ignoreExisting ? { } : await readPackageJson ( pkgPath )
243
+ const pkg = input . ignoreExisting ? { } : await readPackageJson ( pkgPath ) ;
244
244
245
245
// Derive defaults from input and existing package.json
246
- const version = input . version || pkg . version || '1.0.0'
247
- const name = scopeAndName ( input . scope , input . name || pkg . name , directory )
248
- const type = input . type || pkg . type || 'commonjs'
249
- const author = input . author || pkg . author || await git . author ( )
250
- const description = input . description || pkg . description
251
- const repository = input . repository || ( pkg . repository && pkg . repository . url ) || await git . remote ( input )
252
- const keywords = parseList ( input . keywords || pkg . keywords )
246
+ const version = input . version || pkg . version || '1.0.0' ;
247
+ const name = scopeAndName ( input . scope , input . name || pkg . name , directory ) ;
248
+ const type = input . type || pkg . type || 'commonjs' ;
249
+ const author = input . author || pkg . author || await git . author ( ) ;
250
+ const description = input . description || pkg . description ;
251
+ const repository = input . repository || ( pkg . repository && pkg . repository . url ) || await git . remote ( input ) ;
252
+ const keywords = parseList ( input . keywords || pkg . keywords ) ;
253
253
254
254
// Dependencies
255
- const dependencies = parseList ( input . dependencies )
256
- const devDependencies = parseList ( input . devDependencies )
257
- const peerDependencies = parseList ( input . peerDependencies )
255
+ const dependencies = parseList ( input . dependencies ) ;
256
+ const devDependencies = parseList ( input . devDependencies ) ;
257
+ const peerDependencies = parseList ( input . peerDependencies ) ;
258
258
259
259
// Derive standard scripts
260
- const scriptsTest = input . scriptsTest || ( pkg . scripts && pkg . scripts . test ) || 'echo "Error: no test specified" && exit 1'
261
- const scriptsPrepare = input . scriptsPrepare || ( pkg . scripts && pkg . scripts . prepare )
262
- const scriptsPreVersion = input . scriptsPreVersion || ( pkg . scripts && pkg . scripts . preversion )
263
- const scriptsPostPublish = input . scriptsPostPublish || ( pkg . scripts && pkg . scripts . postpublish )
260
+ const scriptsTest = input . scriptsTest || ( pkg . scripts && pkg . scripts . test ) || 'echo "Error: no test specified" && exit 1' ;
261
+ const scriptsPrepare = input . scriptsPrepare || ( pkg . scripts && pkg . scripts . prepare ) ;
262
+ const scriptsPreVersion = input . scriptsPreVersion || ( pkg . scripts && pkg . scripts . preversion ) ;
263
+ const scriptsPostPublish = input . scriptsPostPublish || ( pkg . scripts && pkg . scripts . postpublish ) ;
264
264
265
265
return {
266
266
pkg,
@@ -280,39 +280,39 @@ module.exports = create({
280
280
scriptsPrepare,
281
281
scriptsPreVersion,
282
282
scriptsPostPublish
283
- }
283
+ } ;
284
284
}
285
285
} , async ( initOpts ) => {
286
286
// Process options & prompt for input
287
- const opts = await initOpts ( )
287
+ const opts = await initOpts ( ) ;
288
288
289
289
// Format the json and write it out
290
- return write ( opts . pkgPath , opts , await format ( opts , opts . pkg ) )
291
- } )
290
+ return write ( opts . pkgPath , opts , await format ( opts , opts . pkg ) ) ;
291
+ } ) ;
292
292
293
- module . exports . readPackageJson = readPackageJson
293
+ module . exports . readPackageJson = readPackageJson ;
294
294
async function readPackageJson ( pkgPath , opts = { } ) {
295
- let pkg = { }
295
+ let pkg = { } ;
296
296
try {
297
- pkg = await fs . readJSON ( pkgPath )
297
+ pkg = await fs . readJSON ( pkgPath ) ;
298
298
} catch ( e ) {
299
299
// @TODO log this?
300
300
// ignore if missing or unreadable
301
301
}
302
- return pkg
302
+ return pkg ;
303
303
}
304
304
305
- module . exports . format = format
305
+ module . exports . format = format ;
306
306
async function format ( opts , pkg = { } ) {
307
307
// The order here matters
308
- pkg . name = opts . name
309
- pkg . version = opts . version
310
- pkg . description = opts . description || ''
311
- pkg . main = opts . main
312
- pkg . type = opts . type || 'commonjs'
308
+ pkg . name = opts . name ;
309
+ pkg . version = opts . version ;
310
+ pkg . description = opts . description || '' ;
311
+ pkg . main = opts . main ;
312
+ pkg . type = opts . type || 'commonjs' ;
313
313
314
314
if ( opts . keywords && opts . keywords . length ) {
315
- pkg . keywords = opts . keywords
315
+ pkg . keywords = opts . keywords ;
316
316
}
317
317
318
318
// Scripts
@@ -321,68 +321,68 @@ async function format (opts, pkg = {}) {
321
321
prepare : opts . scriptsPrepare ,
322
322
preversion : opts . scriptsPreVersion ,
323
323
postpublish : opts . scriptsPostPublish
324
- } , opts . scripts )
324
+ } , opts . scripts ) ;
325
325
326
- pkg . author = opts . author || ''
327
- pkg . license = opts . license
326
+ pkg . author = opts . author || '' ;
327
+ pkg . license = opts . license ;
328
328
329
329
if ( opts . repository ) {
330
330
pkg . repository = {
331
331
type : 'git' ,
332
332
url : opts . repository
333
- }
333
+ } ;
334
334
}
335
335
336
336
if ( opts . private === true ) {
337
- pkg . private = true
337
+ pkg . private = true ;
338
338
}
339
339
340
340
if ( opts . man && opts . man . length ) {
341
- pkg . man = Array . isArray ( opts . man ) && ! opts . man [ 1 ] ? opts . man [ 0 ] : opts . man
341
+ pkg . man = Array . isArray ( opts . man ) && ! opts . man [ 1 ] ? opts . man [ 0 ] : opts . man ;
342
342
}
343
343
344
344
// Format peer deps
345
345
if ( opts . peerDependencies && opts . peerDependencies . length ) {
346
- pkg . peerDependencies = { }
346
+ pkg . peerDependencies = { } ;
347
347
348
348
await Promise . all ( opts . peerDependencies . map ( async ( name ) => {
349
- const spec = await npm . normalizePackageName ( name )
350
- let ver
349
+ const spec = await npm . normalizePackageName ( name ) ;
350
+ let ver ;
351
351
switch ( spec . type ) {
352
352
case 'range' :
353
353
case 'version' :
354
- ver = spec . fetchSpec
355
- break
354
+ ver = spec . fetchSpec ;
355
+ break ;
356
356
default :
357
- ver = '*'
357
+ ver = '*' ;
358
358
}
359
- pkg . peerDependencies [ spec . name ] = ver
360
- } ) )
359
+ pkg . peerDependencies [ spec . name ] = ver ;
360
+ } ) ) ;
361
361
}
362
- return pkg
362
+ return pkg ;
363
363
}
364
364
365
- module . exports . write = write
365
+ module . exports . write = write ;
366
366
async function write ( pkgPath , opts , pkg ) {
367
367
// Write package json
368
368
await fs . outputJSON ( pkgPath , pkg , {
369
369
spaces : opts . spacer || 2
370
- } )
370
+ } ) ;
371
371
372
372
// Run installs
373
373
await npm . install ( opts . dependencies , {
374
374
save : 'prod' ,
375
375
directory : opts . directory ,
376
376
silent : opts . silent ,
377
377
exact : opts . saveExact
378
- } )
378
+ } ) ;
379
379
await npm . install ( opts . devDependencies , {
380
380
save : 'dev' ,
381
381
directory : opts . directory ,
382
382
silent : opts . silent ,
383
383
exact : opts . saveExact
384
- } )
384
+ } ) ;
385
385
386
386
// Read full package back to return
387
- return fs . readJSON ( pkgPath )
387
+ return fs . readJSON ( pkgPath ) ;
388
388
}
0 commit comments