-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathmigrate-test-e2e.js
76 lines (67 loc) · 2.37 KB
/
migrate-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
69
70
71
72
73
74
75
76
import chalk from "chalk";
import { $, execaCommand } from "execa";
import packageData from "../package.json" assert { type: "json" };
const { description, name: repository } = packageData;
const emailGithub = "[email protected]";
const emailNpm = "[email protected]";
const owner = "JoshuaKGoldberg";
const title = "Create TypeScript App";
await $({
stdio: "inherit",
})`c8 -o ./coverage-migrate -r html -r lcov --src src node ./bin/index.js --base everything --mode migrate --description ${description} --email-github ${emailGithub} --email-npm ${emailNpm} --owner ${owner} --title ${title} --repository ${repository} --skip-all-contributors-api --skip-github-api --skip-install`;
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 migrate didn't cause any file changes? That's ...probably incorrect? 😬`,
);
}
const filesExpectedToBeChanged = new Set([
".all-contributorsrc",
"bin/index.js",
"README.md",
"knip.jsonc",
"package.json",
"pnpm-lock.yaml",
".eslintignore",
".eslintrc.cjs",
".github/DEVELOPMENT.md",
".github/workflows/lint-knip.yml",
".github/workflows/test.yml",
".gitignore",
".prettierignore",
"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 execaCommand(gitDiffCommand)).stdout
}`,
);
console.error(
[
"",
"Oh no! Running the migrate script modified some files:",
...unstagedModifiedFiles.map((filePath) => ` - ${filePath}`),
"",
"That likely indicates changes made to the repository without",
"corresponding updates to templates in src/.",
"",
"Please search for those file(s)' name(s) under src/migrate for",
"the corresponding template and update those as well.",
]
.map((line) => chalk.red(line))
.join("\n"),
);
process.exitCode = 1;
}