chore: format all code (#2632)
This commit is contained in:
@@ -29,7 +29,7 @@ require('exec-promise')(() =>
|
||||
|
||||
delete pkg.standard
|
||||
|
||||
deleteProperties(pkg, 'config', [ 'commitizen' ])
|
||||
deleteProperties(pkg, 'config', ['commitizen'])
|
||||
deleteProperties(pkg, 'devDependencies', [
|
||||
'babel-7-jest',
|
||||
'babel-eslint',
|
||||
@@ -51,15 +51,12 @@ require('exec-promise')(() =>
|
||||
'prettier',
|
||||
'standard',
|
||||
])
|
||||
deleteProperties(pkg, 'scripts', [ 'commitmsg', 'cz' ])
|
||||
deleteProperties(pkg, 'scripts', ['commitmsg', 'cz'])
|
||||
|
||||
const { scripts } = pkg
|
||||
if (scripts !== undefined) {
|
||||
const prepublish = scripts.prepublish
|
||||
if (
|
||||
prepublish !== undefined &&
|
||||
!('prepublishOnly' in scripts)
|
||||
) {
|
||||
if (prepublish !== undefined && !('prepublishOnly' in scripts)) {
|
||||
delete scripts.prepublish
|
||||
scripts.prepublishOnly = prepublish
|
||||
pkg.scripts = sortedObject(scripts)
|
||||
@@ -67,10 +64,7 @@ require('exec-promise')(() =>
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
writeFile(
|
||||
`${dir}/package.json`,
|
||||
JSON.stringify(pkg, null, 2) + '\n'
|
||||
),
|
||||
writeFile(`${dir}/package.json`, JSON.stringify(pkg, null, 2) + '\n'),
|
||||
unlink(`${dir}/.editorconfig`),
|
||||
unlink(`${dir}/.eslintrc.js`),
|
||||
unlink(`${dir}/.flowconfig`),
|
||||
|
||||
13
scripts/run
13
scripts/run
@@ -5,13 +5,16 @@ const { spawn } = require('child_process')
|
||||
|
||||
const { getPackages } = require('./utils')
|
||||
|
||||
require('exec-promise')(([ command, ...args ]) =>
|
||||
require('exec-promise')(([command, ...args]) =>
|
||||
getPackages().forEach(({ dir, name }) => {
|
||||
console.log('*', name)
|
||||
return fromEvent(spawn(command, args, {
|
||||
cwd: dir,
|
||||
stdio: 'inherit',
|
||||
}), 'exit').then(code => {
|
||||
return fromEvent(
|
||||
spawn(command, args, {
|
||||
cwd: dir,
|
||||
stdio: 'inherit',
|
||||
}),
|
||||
'exit'
|
||||
).then(code => {
|
||||
if (code !== 0) {
|
||||
throw code
|
||||
}
|
||||
|
||||
@@ -13,25 +13,24 @@ const { env } = process
|
||||
// TODO: https://docs.npmjs.com/misc/scripts#environment
|
||||
require('exec-promise')(args => {
|
||||
const parallel = args[0] === '--parallel'
|
||||
let script = args[parallel ? 1 : 0]
|
||||
const script = args[parallel ? 1 : 0]
|
||||
|
||||
let errors = 0
|
||||
return getPackages(true)[parallel ? 'map' : 'forEach'](({ dir, name, package: { scripts } }) => {
|
||||
if (scripts == null) {
|
||||
return
|
||||
}
|
||||
return getPackages(true)
|
||||
[parallel ? 'map' : 'forEach'](({ dir, name, package: { scripts } }) => {
|
||||
if (scripts == null) {
|
||||
return
|
||||
}
|
||||
|
||||
const spawnOpts = {
|
||||
cwd: dir,
|
||||
env: Object.assign({}, env, {
|
||||
PATH: `${dir}/node_modules/.bin${delimiter}${env.PATH}`,
|
||||
}),
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
}
|
||||
return forEach.call(
|
||||
[ `pre${script}`, script, `post${script}` ],
|
||||
script => {
|
||||
const spawnOpts = {
|
||||
cwd: dir,
|
||||
env: Object.assign({}, env, {
|
||||
PATH: `${dir}/node_modules/.bin${delimiter}${env.PATH}`,
|
||||
}),
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
}
|
||||
return forEach.call([`pre${script}`, script, `post${script}`], script => {
|
||||
const command = scripts[script]
|
||||
if (command !== undefined) {
|
||||
console.log(`* ${name}:${script} −`, command)
|
||||
@@ -42,11 +41,11 @@ require('exec-promise')(args => {
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
if (errors !== 0) {
|
||||
throw errors
|
||||
}
|
||||
)
|
||||
}).then(() => {
|
||||
if (errors !== 0) {
|
||||
throw errors
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -15,39 +15,37 @@ const _getPackages = scope => {
|
||||
}
|
||||
|
||||
exports.getPackages = (readPackageJson = false) => {
|
||||
const p = Promise.all([
|
||||
_getPackages(),
|
||||
_getPackages('@xen-orchestra'),
|
||||
]).then(pkgs => {
|
||||
pkgs = [].concat(...pkgs) // flatten
|
||||
return readPackageJson
|
||||
? Promise.all(pkgs.map(pkg =>
|
||||
readFile(`${pkg.dir}/package.json`).then(data => {
|
||||
pkg.package = JSON.parse(data)
|
||||
return pkg
|
||||
}, noop)
|
||||
)).then(pkgs => pkgs.filter(pkg => pkg !== undefined))
|
||||
: pkgs
|
||||
})
|
||||
const p = Promise.all([_getPackages(), _getPackages('@xen-orchestra')]).then(
|
||||
pkgs => {
|
||||
pkgs = [].concat(...pkgs) // flatten
|
||||
return readPackageJson
|
||||
? Promise.all(
|
||||
pkgs.map(pkg =>
|
||||
readFile(`${pkg.dir}/package.json`).then(data => {
|
||||
pkg.package = JSON.parse(data)
|
||||
return pkg
|
||||
}, noop)
|
||||
)
|
||||
).then(pkgs => pkgs.filter(pkg => pkg !== undefined))
|
||||
: pkgs
|
||||
}
|
||||
)
|
||||
p.forEach = fn => p.then(pkgs => forEach.call(pkgs, fn))
|
||||
p.map = fn => p.then(pkgs => Promise.all(pkgs.map(fn))).then(noop)
|
||||
return p
|
||||
}
|
||||
|
||||
const noop = exports.noop = () => {}
|
||||
const noop = (exports.noop = () => {})
|
||||
|
||||
const readFile = exports.readFile = file => fromCallback(cb =>
|
||||
fs.readFile(file, 'utf8', cb)
|
||||
)
|
||||
const readFile = (exports.readFile = file =>
|
||||
fromCallback(cb => fs.readFile(file, 'utf8', cb)))
|
||||
|
||||
exports.unlink = path => fromCallback(cb =>
|
||||
fs.unlink(path, cb)
|
||||
).catch(error => {
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error
|
||||
}
|
||||
})
|
||||
exports.unlink = path =>
|
||||
fromCallback(cb => fs.unlink(path, cb)).catch(error => {
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error
|
||||
}
|
||||
})
|
||||
|
||||
exports.writeFile = (file, data) => fromCallback(cb =>
|
||||
fs.writeFile(file, data, cb)
|
||||
)
|
||||
exports.writeFile = (file, data) =>
|
||||
fromCallback(cb => fs.writeFile(file, data, cb))
|
||||
|
||||
Reference in New Issue
Block a user