2021-11-17 19:04:16 +01:00
|
|
|
const fs = require("fs")
|
|
|
|
const { join } = require("path")
|
|
|
|
const { spawnSync } =require("child_process")
|
|
|
|
|
2021-11-17 20:12:54 +01:00
|
|
|
const DONT_RUN_PKG = ["bbui"]
|
2021-11-17 19:04:16 +01:00
|
|
|
const PACKAGES_PATH = join(__dirname, "..", "packages")
|
|
|
|
|
|
|
|
function getPackages() {
|
|
|
|
return fs.readdirSync(PACKAGES_PATH)
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteFile(path) {
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(path)
|
|
|
|
} catch (err) {
|
|
|
|
// don't error, it just doesn't exist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeModules(path) {
|
|
|
|
if (fs.existsSync(path)) {
|
|
|
|
fs.rmdirSync(path, { recursive: true })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function executeInPackage(packageName) {
|
2021-11-17 20:12:54 +01:00
|
|
|
if (DONT_RUN_PKG.includes(packageName)) {
|
|
|
|
return
|
|
|
|
}
|
2021-11-17 19:04:16 +01:00
|
|
|
const dir = join(PACKAGES_PATH, packageName)
|
|
|
|
if (!fs.existsSync(join(dir, "package.json"))) {
|
|
|
|
console.error(`SKIPPING ${packageName} directory, no package.json`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const packageLockLoc = join(dir, "package-lock.json")
|
|
|
|
const modulesLoc = join(dir, "node_modules")
|
|
|
|
deleteFile(join(dir, "yarn.lock"))
|
|
|
|
deleteFile(packageLockLoc)
|
|
|
|
removeModules(modulesLoc)
|
|
|
|
const opts = { cwd: dir, stdio: "inherit", shell: true }
|
|
|
|
spawnSync("npm", ["i", "--package-lock-only"], opts)
|
|
|
|
spawnSync("npm", ["audit", "fix"], opts)
|
|
|
|
spawnSync("yarn", ["import"], opts)
|
|
|
|
deleteFile(packageLockLoc)
|
|
|
|
removeModules(modulesLoc)
|
|
|
|
}
|
|
|
|
|
|
|
|
const packages = getPackages()
|
|
|
|
for (let pkg of packages) {
|
|
|
|
executeInPackage(pkg)
|
|
|
|
}
|
|
|
|
|
|
|
|
spawnSync("yarn", ["bootstrap"], { cwd: join(__dirname, ".."), stdio: "inherit", shell: true })
|
|
|
|
|