-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathhydrate-test-e2e.js
68 lines (61 loc) · 1.84 KB
/
hydrate-test-e2e.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
import chalk from "chalk";
import { $ } from "execa";
await $({
stdio: "inherit",
})`c8 -o ./coverage-hydrate -r html -r lcov node ./lib/hydrate/index.js`;
const { stdout: gitStatus } = await $`git status`;
console.log(`Stdout from running \`git status\`:\n${gitStatus}`);
const indexOfUnstagedFilesMessage = gitStatus.indexOf(
"Changes not staged for commit:"
);
if (indexOfUnstagedFilesMessage === -1) {
throw new Error(
`Looks like hydrate didn't cause any file changes? That's ...probably incorrect? 😬`
);
}
const filesExpectedToBeChanged = new Set([
".all-contributorsrc",
"README.md",
"knip.jsonc",
"package.json",
"pnpm-lock.yaml",
".eslintignore",
".eslintrc.cjs",
".github/DEVELOPMENT.md",
".github/workflows/release.yml",
".github/workflows/test.yml",
".gitignore",
".prettierignore",
".release-it.json",
"cspell.json",
]);
const unstagedModifiedFiles = gitStatus
.slice(indexOfUnstagedFilesMessage)
.match(/modified: {3}(\S+)\n/g)
.map((match) => match.split(/\s+/g)[1])
.filter((filePath) => !filesExpectedToBeChanged.has(filePath));
console.log("Unexpected modified files are:", unstagedModifiedFiles);
if (unstagedModifiedFiles.length) {
const gitDiffCommand = `git diff HEAD -- ${unstagedModifiedFiles.join(" ")}`;
console.log(
`Stdout from running \`${gitDiffCommand}\`:\n${
(await $(gitDiffCommand)).stdout
}`
);
console.error(
[
"",
"Oh no! Running the hydrate script modified some files:",
...unstagedModifiedFiles.map((filePath) => ` - ${filePath}`),
"",
"That likely indicates changes made to the repository without",
"corresponding updates to templates in src/hydrate/creation.",
"",
"Please search for those file(s)' name(s) under src/hydrate for",
"the corresponding template and update those as well.",
]
.map((line) => chalk.red(line))
.join("\n")
);
process.exitCode = 1;
}