Created
September 18, 2020 16:04
-
-
Save fivethreeo/3fdc7dadc15d2fd2cf96b0dc8465227c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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