Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
addWorkspaces:(stageName) => {
const stagePath = path.join(rootDir, stageName);
const packagesPath = path.join(rootDir, 'packages');
const packageJson = path.join(stagePath, 'package.json');
if (fs.existsSync(packageJson)) {
const dirs = fs.readdirSync(packagesPath, { withFileTypes:true })
.filter(dirent=>dirent.isDirectory()).map(dir=>dir.name);
let workspaces = [];
let packages = [];
for (const packageName of dirs) {
packages.push(packageName);
workspaces.push(path.join(packagesPath, packageName));
}
const packageJsonData = JSON.parse(fs.readFileSync(packageJson));
const newPackageJsonData = ["dependencies", "devDependencies"].reduce((acc, depType) => {
if (acc[depType]) {
acc[depType] = Object.keys(acc[depType]).reduce((depsAcc, dep) => {
if (packages.includes(dep)) {
delete depsAcc[dep];
}
return depsAcc;
}, acc[depType]);
}
return acc;
}, packageJsonData);
newPackageJsonData.workspaces = workspaces;
newPackageJsonData.private = true;
return fs.writeFileSync(packageJson, JSON.stringify(newPackageJsonData, null, ' '));
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.