feat(toggle-scripts): supports npm < 7
This commit is contained in:
parent
ce17ee2ae6
commit
dafdedef9a
@ -10,8 +10,8 @@ const mapKeys = (object, iteratee) => {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
const pkgPath = process.env.npm_package_json
|
const args = process.argv.slice(2)
|
||||||
if (pkgPath === undefined) {
|
if (args.length === 0) {
|
||||||
const { description, name, version } = require('./package.json')
|
const { description, name, version } = require('./package.json')
|
||||||
const bin = 'toggle-scripts'
|
const bin = 'toggle-scripts'
|
||||||
process.stdout.write(`Usage: ${bin} options...
|
process.stdout.write(`Usage: ${bin} options...
|
||||||
@ -32,7 +32,7 @@ ${name} v${version}
|
|||||||
}
|
}
|
||||||
|
|
||||||
const plan = { __proto__: null }
|
const plan = { __proto__: null }
|
||||||
for (const arg of process.argv.slice(2)) {
|
for (const arg of args) {
|
||||||
const action = arg[0]
|
const action = arg[0]
|
||||||
const script = arg.slice(1)
|
const script = arg.slice(1)
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ for (const arg of process.argv.slice(2)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pkgPath = process.env.npm_package_json || './package.json'
|
||||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
||||||
pkg.scripts = mapKeys(pkg.scripts, (name, scripts) => {
|
pkg.scripts = mapKeys(pkg.scripts, (name, scripts) => {
|
||||||
const newName = plan[name]
|
const newName = plan[name]
|
||||||
|
Loading…
Reference in New Issue
Block a user