UNPKG

obj-chain-core

Version:

fluent chaining for obj with dot-prop access

128 lines (111 loc) 3.44 kB
function pkgPlugin(pkg) { // needs a `string-to-fn` // script chain would be cool too // for things like this script runs other scripts and it builds npm run... // should also have presets to use in the ObjChain for defaults like MIT/ISC // https://docs.npmjs.com/misc/config#onload-script // https://docs.npmjs.com/misc/config#tag const keys = Object.keys({ name: 'string', version: 'string', description: 'string', main: 'string', bin: 'string|obj', files: 'arr', keywords: 'arr', engines: 'obj', author: 'string|obj', homepage: 'string', license: 'enum', private: 'bool', tag: 'string', }) const nestKeys = Object.keys({ optionalDependencies: 'obj', bundledDependencies: 'obj', peerDependencies: 'obj', devDependencies: 'obj', dependencies: 'obj', config: 'obj', directories: 'obj', scripts: 'obj', repository: 'obj', bugs: 'obj', contributors: 'obj', }) // .exports({ // "main": "dist/preact.js", // "jsnext:main": "src/preact.js", // "dev:main": "dist/preact.dev.js", // "minified:main": "dist/preact.min.js", // "typings": "./dist/preact.d.ts", // "module": "dist/obj-str.es.js", // }) // pkg.extendZip(obj) pkg.extend(keys) pkg.repo = str => { str = 'https://github.com/' + str pkg .set('bugs.url', str) .set('homepage', str) .set('repository.type', 'git') .set('repository.url', 'git+' + str + '.git') return pkg } pkg.meta = (repo, author, license = 'MIT') => { return pkg.author(author).repo(repo).license(license) } // when using these, they should auto add the dependencies // "autofix": "babel-node ./node_modules/.bin/eslint src/** --fix", // "flow": "flow; test $? -eq 0 -o $? -eq 2", // "clean": "rimraf packages/ds--solver/mocks/d4/** packages/ds--solver/mocks/nj/** packages/ds--solver/output/nj/sites** packages/ds--solver/output/d4/sites**", pkg.script = (scriptName, data) => pkg.set('scripts.' + scriptName, data) pkg.pretest = script => pkg.script('pretest', script) pkg.prepublish = script => pkg.script('prepublish', script) pkg.postpublish = script => pkg.script('postpublish', script) pkg.posttest = script => pkg.script('posttest', script) pkg.dependency = (name, version, type = null) => { const arglen = [name, version, type].filter(arg => arg).length if (arglen === 3) { pkg.set(type + 'Dependencies.' + name, version) } else if (arglen === 1) { pkg.set('dependencies.' + name.split('@').shift(), name.split('@').pop()) } else if (arglen === 2 && ['dev', 'optional', 'bundle'].includes(version)) { pkg.set( 'dependencies.' + name.split('@').shift(), name.split('@').pop(), version ) } else { pkg.set('dependencies.' + name, version) } return pkg } pkg.dep = pkg.dependency pkg.deps = requiredDeps => { requiredDeps.forEach(dep => pkg.dep(dep)) return pkg } pkg.devDep = (dep, version) => pkg.dep(dep, version) pkg.devDeps = devDeps => { devDeps.forEach(dep => pkg.devDep(dep)) return pkg } // @HACK: @FIXME: hardcoded in deps pkg.extendKebab([ 'neutrino', 'jsdocs', 'babel', 'preCommit', 'postCommit', 'fliplog', 'main', 'module', // 'scripts.prepublish', ]) } const PkgPlugin = pkgPlugin module.exports = PkgPlugin