Skip to content

Commit 09488de

Browse files
committed
feat: composibility support via initOptions
1 parent 3b340e2 commit 09488de

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed

index.js

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -234,55 +234,60 @@ module.exports = create({
234234
message: 'Save exact versions:'
235235
}
236236
}
237-
}
238-
}, async (initOpts, input) => {
239-
const directory = input.directory || process.cwd()
240-
const pkgPath = path.resolve(directory, input.pkgPath || 'package.json')
237+
},
238+
initOptions: async (input) => {
239+
const directory = input.directory || process.cwd()
240+
const pkgPath = path.resolve(directory, input.pkgPath || 'package.json')
241241

242-
// Read existing package.json
243-
const pkg = input.ignoreExisting ? {} : await readPackageJson(pkgPath)
242+
// Read existing package.json
243+
const pkg = input.ignoreExisting ? {} : await readPackageJson(pkgPath)
244244

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)
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)
253253

254-
// Dependencies
255-
const dependencies = parseList(input.dependencies)
256-
const devDependencies = parseList(input.devDependencies)
257-
const peerDependencies = parseList(input.peerDependencies)
254+
// Dependencies
255+
const dependencies = parseList(input.dependencies)
256+
const devDependencies = parseList(input.devDependencies)
257+
const peerDependencies = parseList(input.peerDependencies)
258258

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)
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)
264264

265+
return {
266+
pkg,
267+
directory,
268+
pkgPath,
269+
version,
270+
name,
271+
type,
272+
description,
273+
author,
274+
repository,
275+
keywords,
276+
dependencies,
277+
devDependencies,
278+
peerDependencies,
279+
scriptsTest,
280+
scriptsPrepare,
281+
scriptsPreVersion,
282+
scriptsPostPublish
283+
}
284+
}
285+
}, async (initOpts) => {
265286
// Process options & prompt for input
266-
const opts = await initOpts({
267-
directory,
268-
version,
269-
name,
270-
type,
271-
description,
272-
author,
273-
repository,
274-
keywords,
275-
dependencies,
276-
devDependencies,
277-
peerDependencies,
278-
scriptsTest,
279-
scriptsPrepare,
280-
scriptsPreVersion,
281-
scriptsPostPublish
282-
})
287+
const opts = await initOpts()
283288

284289
// Format the json and write it out
285-
return write(pkgPath, opts, await format(opts, pkg))
290+
return write(opts.pkgPath, opts, await format(opts, opts.pkg))
286291
})
287292

288293
module.exports.readPackageJson = readPackageJson

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"license": "ICS",
3333
"dependencies": {
34-
"@pkgjs/create": "^0.1.0",
34+
"@pkgjs/create": "^0.2.0",
3535
"execa": "^3.4.0",
3636
"fs-extra": "^6.0.1",
3737
"inquirer": "^5.2.0",

0 commit comments

Comments
 (0)