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' ) ;
99
1010// @TODO https://docs.npmjs.com/files/package.json
1111// exports
@@ -236,31 +236,31 @@ module.exports = create({
236236 }
237237 } ,
238238 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' ) ;
241241
242242 // Read existing package.json
243- const pkg = input . ignoreExisting ? { } : await readPackageJson ( pkgPath )
243+ const pkg = input . ignoreExisting ? { } : await readPackageJson ( pkgPath ) ;
244244
245245 // 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 ) ;
253253
254254 // 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 ) ;
258258
259259 // 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 ) ;
264264
265265 return {
266266 pkg,
@@ -280,39 +280,39 @@ module.exports = create({
280280 scriptsPrepare,
281281 scriptsPreVersion,
282282 scriptsPostPublish
283- }
283+ } ;
284284 }
285285} , async ( initOpts ) => {
286286 // Process options & prompt for input
287- const opts = await initOpts ( )
287+ const opts = await initOpts ( ) ;
288288
289289 // 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+ } ) ;
292292
293- module . exports . readPackageJson = readPackageJson
293+ module . exports . readPackageJson = readPackageJson ;
294294async function readPackageJson ( pkgPath , opts = { } ) {
295- let pkg = { }
295+ let pkg = { } ;
296296 try {
297- pkg = await fs . readJSON ( pkgPath )
297+ pkg = await fs . readJSON ( pkgPath ) ;
298298 } catch ( e ) {
299299 // @TODO log this?
300300 // ignore if missing or unreadable
301301 }
302- return pkg
302+ return pkg ;
303303}
304304
305- module . exports . format = format
305+ module . exports . format = format ;
306306async function format ( opts , pkg = { } ) {
307307 // 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' ;
313313
314314 if ( opts . keywords && opts . keywords . length ) {
315- pkg . keywords = opts . keywords
315+ pkg . keywords = opts . keywords ;
316316 }
317317
318318 // Scripts
@@ -321,68 +321,68 @@ async function format (opts, pkg = {}) {
321321 prepare : opts . scriptsPrepare ,
322322 preversion : opts . scriptsPreVersion ,
323323 postpublish : opts . scriptsPostPublish
324- } , opts . scripts )
324+ } , opts . scripts ) ;
325325
326- pkg . author = opts . author || ''
327- pkg . license = opts . license
326+ pkg . author = opts . author || '' ;
327+ pkg . license = opts . license ;
328328
329329 if ( opts . repository ) {
330330 pkg . repository = {
331331 type : 'git' ,
332332 url : opts . repository
333- }
333+ } ;
334334 }
335335
336336 if ( opts . private === true ) {
337- pkg . private = true
337+ pkg . private = true ;
338338 }
339339
340340 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 ;
342342 }
343343
344344 // Format peer deps
345345 if ( opts . peerDependencies && opts . peerDependencies . length ) {
346- pkg . peerDependencies = { }
346+ pkg . peerDependencies = { } ;
347347
348348 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 ;
351351 switch ( spec . type ) {
352352 case 'range' :
353353 case 'version' :
354- ver = spec . fetchSpec
355- break
354+ ver = spec . fetchSpec ;
355+ break ;
356356 default :
357- ver = '*'
357+ ver = '*' ;
358358 }
359- pkg . peerDependencies [ spec . name ] = ver
360- } ) )
359+ pkg . peerDependencies [ spec . name ] = ver ;
360+ } ) ) ;
361361 }
362- return pkg
362+ return pkg ;
363363}
364364
365- module . exports . write = write
365+ module . exports . write = write ;
366366async function write ( pkgPath , opts , pkg ) {
367367 // Write package json
368368 await fs . outputJSON ( pkgPath , pkg , {
369369 spaces : opts . spacer || 2
370- } )
370+ } ) ;
371371
372372 // Run installs
373373 await npm . install ( opts . dependencies , {
374374 save : 'prod' ,
375375 directory : opts . directory ,
376376 silent : opts . silent ,
377377 exact : opts . saveExact
378- } )
378+ } ) ;
379379 await npm . install ( opts . devDependencies , {
380380 save : 'dev' ,
381381 directory : opts . directory ,
382382 silent : opts . silent ,
383383 exact : opts . saveExact
384- } )
384+ } ) ;
385385
386386 // Read full package back to return
387- return fs . readJSON ( pkgPath )
387+ return fs . readJSON ( pkgPath ) ;
388388}
0 commit comments