diff options
author | isaacs <i@izs.me> | 2020-07-23 23:37:25 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-29 21:55:03 +0300 |
commit | 40b6055658c1617b10c632a7b6e630ce64cc3915 (patch) | |
tree | 0ac9d7140274409179de44d0babd154d2457b7bf | |
parent | 8654c05e6e8cabf4642425b9e6373aeae9801c21 (diff) |
script to bundle and gitignore deps as appropriate
-rw-r--r-- | scripts/bundle-and-gitignore-deps.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/bundle-and-gitignore-deps.js b/scripts/bundle-and-gitignore-deps.js new file mode 100644 index 000000000..c264b1c3c --- /dev/null +++ b/scripts/bundle-and-gitignore-deps.js @@ -0,0 +1,32 @@ +const Arborist = require('@npmcli/arborist') +const { resolve } = require('path') +const ignore = resolve(__dirname, '../node_modules/.gitignore') +const { writeFileSync } = require('fs') +const pj = resolve(__dirname, '../package.json') +const pkg = require(pj) +const bundle = [] +const arb = new Arborist({ path: resolve(__dirname, '..') }) +const shouldIgnore = [] + +arb.loadVirtual().then(tree => { + for (const [name, node] of tree.children.entries()) { + if (node.dev) { + console.error('ignore', node.name) + shouldIgnore.push(node.name) + } else if (tree.edgesOut.has(node.name)) { + console.error('BUNDLE', node.name) + bundle.push(node.name) + } + } + pkg.bundleDependencies = bundle.sort((a, b) => a.localeCompare(b)) + + const ignores = shouldIgnore.sort((a, b) => a.localeCompare(b)) + .map(i => `/${i}`) + .join('\n') + const ignoreData = `# Automatically generated to ignore dev deps +/.package-lock.json +${ignores} +` + writeFileSync(ignore, ignoreData) + writeFileSync(pj, JSON.stringify(pkg, 0, 2) + '\n') +}) |