Skip to content

Instantly share code, notes, and snippets.

@stukennedy
Created July 20, 2020 10:24
Show Gist options
  • Save stukennedy/dbbb73187b475eaaa363b5b6782ffb1e to your computer and use it in GitHub Desktop.
Save stukennedy/dbbb73187b475eaaa363b5b6782ffb1e to your computer and use it in GitHub Desktop.
/* eslint-disable no-console */
const { readdirSync } = require('fs')
const packageJson = require('./package.json');
const fs = require('fs');
const { exec } = require('child_process');
require('colors');
const args = process.argv.slice(2);
const getDirectories = source =>
readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
/* get all ./submodules */
const submodules = getDirectories('./submodules');
if (args.includes('--bootstrap')) {
console.log(`bootstrapping ${submodules.length} submodules`.underline.blue);
console.log(submodules);
for (const key in packageJson.dependencies) {
if (submodules.includes(key)) {
packageJson.dependencies[key] = `file:submodules/${key}`;
}
}
/* update package.json to point dependencies at submodules */
fs.writeFile(
'./package.json',
JSON.stringify(packageJson, null, 2) + '\n',
() => {
console.log('completed bootstrapping'.blue);
console.log('package.json updated'.yellow);
}
);
}
if (args.includes('--install')) {
console.log(`installing in ${submodules.length} submodules`.underline.blue);
(submodules || []).map((submodule) => {
console.log(`installing ${submodule}`.green);
exec(`cd submodules/${submodule}; npm i`, (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr.red);
if (err) {
console.error('exec error :', err);
}
})
})
}
if (args.includes('--build')) {
console.log('building all submodules'.underline.blue);
(submodules || []).map((submodule) => {
console.log(`building ${submodule}`.green);
exec(`cd submodules/${submodule}; npm run build`, (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr.red);
if (err) {
console.error('exec error :', err);
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment