Files
xen-orchestra/scripts/normalize-packages
2019-05-09 09:23:49 +02:00

96 lines
2.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
const isEmpty = require('lodash/isEmpty')
const sortedObject = require('sorted-object')
const { getPackages, writeFile, unlink } = require('./utils')
const deleteProperties = (object, property, properties) => {
const nestedObject = object[property]
if (nestedObject === undefined) {
return
}
properties.forEach(property => {
delete nestedObject[property]
})
if (isEmpty(object[property])) {
delete object[property]
}
}
require('exec-promise')(() =>
getPackages(true).map(({ dir, name, package: pkg, relativeDir }) => {
pkg.name = name
pkg.homepage = `https://github.com/vatesfr/xen-orchestra/tree/master/${relativeDir}`
pkg.bugs = `https://github.com/vatesfr/xen-orchestra/issues`
pkg.repository = {
directory: relativeDir,
type: 'git',
url: 'https://github.com/vatesfr/xen-orchestra.git',
}
if (!('version' in pkg)) {
pkg.version = '0.0.0'
}
delete pkg.standard
deleteProperties(pkg, 'config', ['commitizen'])
deleteProperties(pkg, 'devDependencies', [
'babel-7-jest',
'babel-eslint',
'babel-jest',
'commitizen',
'cz-conventional-changelog',
'dependency-check',
'eslint',
'eslint-config-standard',
'eslint-plugin-import',
'eslint-plugin-node',
'eslint-plugin-promise',
'eslint-plugin-standard',
'flow-bin',
'ghooks',
'husky',
'jest',
'lint-staged',
'prettier',
'standard',
])
deleteProperties(pkg, 'scripts', ['commitmsg', 'cz'])
let { scripts = {} } = pkg
const originalScripts = scripts
if (!pkg.private && !('postversion' in scripts)) {
scripts = { ...scripts, postversion: 'npm publish' }
}
const prepublish = scripts.prepublish
if (prepublish !== undefined && !('prepublishOnly' in scripts)) {
scripts = {
...scripts,
prepublishOnly: prepublish,
prepublish: undefined,
}
}
if (scripts !== originalScripts) {
pkg.scripts = sortedObject(scripts)
}
return Promise.all([
writeFile(`${dir}/package.json`, JSON.stringify(pkg, null, 2) + '\n'),
unlink(`${dir}/.editorconfig`),
unlink(`${dir}/.eslintrc.js`),
unlink(`${dir}/.flowconfig`),
unlink(`${dir}/.gitignore`),
unlink(`${dir}/.jshintrc`),
unlink(`${dir}/.prettierrc.js`),
unlink(`${dir}/.travis.yml`),
unlink(`${dir}/ISSUE_TEMPLATE.lock`),
unlink(`${dir}/package-lock.json`),
unlink(`${dir}/yarn.lock`),
])
})
)