forked from vercel/turborepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathignore-examples.js
77 lines (60 loc) · 2.04 KB
/
ignore-examples.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
This script is used to determine when examples should be built on Vercel.
We use a custom script for this situation instead of `npx turbo-ignore` because
the examples are not workspaces within this repository, and we want to rebuild them
only when:
1. The examples themselves have changed
2. The turbo version has changed
3. We force a build on vercel
We recommend using `npx turbo-ignore` in your own projects.
*/
const childProcess = require("child_process");
// https://vercel.com/support/articles/how-do-i-use-the-ignored-build-step-field-on-vercel
const ABORT_BUILD_CODE = 0;
const CONTINUE_BUILD_CODE = 1;
const continueBuild = () => process.exit(CONTINUE_BUILD_CODE);
const abortBuild = () => process.exit(ABORT_BUILD_CODE);
const example = process.argv[2];
const ignoreCheck = () => {
if (process.env.TURBO_FORCE === "true") {
console.log("\u226B `TURBO_FORCE` detected");
continueBuild();
}
// no app name (directory) was passed in via args
if (!example) {
console.log(
`\u226B Could not determine example to check - continuing build...`
);
continueBuild();
}
console.log(
`\u226B Checking for changes to "examples/${example}" or "turbo" version...`
);
// get all file names changed in last commit
const fileNameList = childProcess
.execSync("git diff --name-only HEAD~1")
.toString()
.trim()
.split("\n");
// check if any files in the example have changed,
const exampleChanged = fileNameList.some((file) =>
file.startsWith(`examples/${example}`)
);
// or if a new version of turbo has been released.
const turboVersionChanged = fileNameList.some(
(file) => file === "version.txt"
);
if (exampleChanged) {
console.log(
`\u226B Detected changes to examples/${example} - continuing build...`
);
continueBuild();
}
if (turboVersionChanged) {
console.log(`\u226B New version of "turbo" detected - continuing build...`);
continueBuild();
}
console.log(`\u226B No relevant changes detected, skipping build.`);
abortBuild();
};
ignoreCheck();