-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathmigrate.js
63 lines (58 loc) · 1.79 KB
/
migrate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { execSync } = require("child_process");
const { readdirSync, existsSync } = require("fs");
const BROKEN_RECIPES = [];
function isRecipe(file) {
const cwd = `./${file.name}`;
return file.isDirectory() &&
!file.name.startsWith(".") &&
!BROKEN_RECIPES.includes(file.name) &&
existsSync(`${cwd}/nx.json`) &&
// TODO(caleb): this might not be true for nx wrapper repos?
existsSync(`${cwd}/package.json`)
}
function installPackages(cwd) {
console.log("Installing packages for " + cwd);
const files = readdirSync(cwd);
if (files.includes("pnpm-lock.yaml")) {
execSync("pnpm i", { cwd, stdio: [0, 1, 2] });
} else if (files.includes("yarn.lock")) {
execSync("yarn", { cwd, stdio: [0, 1, 2] });
} else {
execSync("npm i ---peer-deps", { cwd, stdio: [0, 1, 2] });
}
}
function migrateToLatest(cwd) {
console.log(`Migrating ${cwd}...`);
execSync("CI=true npx nx migrate latest", { cwd, stdio: [0, 1, 2] });
installPackages(cwd);
execSync("CI=true npx nx migrate --run-migrations --no-interactive --if-exists", {
cwd,
stdio: [0, 1, 2],
timeout: 60000,
});
execSync("rm -rf migrations.json", { cwd, stdio: [0, 1, 2] });
console.log(`Done migrating ${cwd}.`);
}
function processAllExamples() {
const files = readdirSync(".", { withFileTypes: true });
let failedMigrations = [];
files.forEach((file) => {
if (isRecipe(file)) {
const cwd = `./${file.name}`;
try {
installPackages(cwd);
migrateToLatest(cwd);
} catch (ex) {
console.log(ex);
console.log("Continuing to next example...");
failedMigrations.push(cwd);
}
}
});
if (failedMigrations.length > 0) {
console.log(
"The following migrations failed: " + failedMigrations.join(", ")
);
}
}
processAllExamples();