-
Notifications
You must be signed in to change notification settings - Fork 22
/
fill-with-old-docs-win-compat.js
111 lines (95 loc) · 2.87 KB
/
fill-with-old-docs-win-compat.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const shell = require("shelljs");
const currVerStr = require("../package.json").version;
const currVerMajor = parseInt(currVerStr.split(".")[0], 10);
const currVerMinor = parseInt(currVerStr.split(".")[1], 10);
shell.rm("-r", "src/docs/old-docs");
shell.mkdir("src/docs/old-docs");
shell.touch("src/docs/old-docs/.gitkeep");
const fillLegacyDocs = (verMajor, verMinor) => {
const nextCommitHash = shell
.exec(
`git log -S "\\"version\\": \\"${verMajor}.${verMinor}" --oneline -n 1 --branches HEAD -- package.json`,
{
silent: true,
}
)
.stdout.split(" ")[0];
const verStr = JSON.parse(
shell.exec(`git show "${nextCommitHash}^:./package.json"`, { silent: true })
.stdout
)["version"];
const fileContent = shell.exec(
`git show "${nextCommitHash}^:./src/views/docs.mdx"`,
{ silent: true }
).stdout;
const pkgFileContent = shell.exec(
`git show "${nextCommitHash}^:./package.json"`,
{ silent: true }
).stdout;
if (fileContent !== "") {
shell.mkdir("-p", `src/docs/old-docs/${verStr}/src/docs`);
shell
.ShellString(fileContent)
.to(`src/docs/old-docs/${verStr}/src/docs/docs.mdx`);
shell
.ShellString(pkgFileContent)
.to(`src/docs/old-docs/${verStr}/package.json`);
shell.cp(
"scripts/legacy-app-routes.tsx",
`src/docs/old-docs/${verStr}/src/docs/app-routes.tsx`
);
}
};
const fillDocs = (verMajor, verMinor) => {
if (verMajor === 0 && verMinor <= 3) {
if (verMinor < 3) return;
fillLegacyDocs(verMajor, verMinor);
return;
}
const nextCommitHash = shell
.exec(
`git log -S "\\"version\\": \\"${verMajor}.${verMinor}" --oneline -n 1 --branches HEAD -- package.json`,
{
silent: true,
}
)
.stdout.split(" ")[0];
const verStr = JSON.parse(
shell.exec(`git show "${nextCommitHash}^:./package.json"`, { silent: true })
.stdout
)["version"];
shell.exec(
`git worktree add -f "src/docs/old-docs/${verStr}" "${nextCommitHash}^"`,
{ silent: true }
);
shell.rm(
"-r",
`src/docs/old-docs/${verStr}/vite*`,
`src/docs/old-docs/${verStr}/src/docs/typings`
);
};
for (let i = currVerMajor; i >= Math.max(0, currVerMajor - 2); i--) {
if (i === currVerMajor) {
for (let j = currVerMinor - 1; j >= Math.max(0, currVerMinor - 2); j--) {
fillDocs(i, j);
}
} else {
const nextCommitHash = shell
.exec(
`git log -S "\\"version\\": \\"${i}." --oneline -n 1 --branches HEAD -- package.json`,
{
silent: true,
}
)
.stdout.split(" ")[0];
const verStr = JSON.parse(
shell.exec(`git show "${nextCommitHash}^:./package.json"`, {
silent: true,
}).stdout
)["version"];
const verMinor = parseInt(verStr.split(".")[1], 10);
for (let j = verMinor; j >= Math.max(0, verMinor - 2); j--) {
fillDocs(i, j);
}
}
}