forked from cyberconnecthq/cyberconnect-docs-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.js
72 lines (62 loc) · 1.77 KB
/
version.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
// Command: yarn update-version x.x.x
const fs = require("fs");
const path = require("path");
const os = require("os");
const child_process = require("child_process");
const version = process.argv[2];
const dirPaths = [
`/i18n/zh/docusaurus-plugin-content-docs/version-${version}`,
`/versioned_docs/version-${version}`,
`/versioned_sidebars/version-${version}-sidebars.json`,
];
const getPreVersionNum = () => {
try {
const jsonString = fs.readFileSync("./package.json");
const json = JSON.parse(jsonString);
return json.version;
} catch (e) {
console.error(
"\x1b[33m%s\x1b[0m",
`Error while getting previous version.\n`,
e
);
}
};
const deleteDir = (dir) => {
try {
fs.rmSync(dir, { recursive: true });
console.log("\x1b[33m%s\x1b[0m", `${dir} is deleted\n`);
} catch (e) {
console.error("\x1b[33m%s\x1b[0m", `Error while deleting ${dir}.\n`, e);
}
};
const updateVersion = () => {
try {
// Revert version in version.json first
fs.writeFileSync("./versions.json", '["V1"]');
console.log("\x1b[33m%s\x1b[0m", `version is reverted to V1\n`);
// Update version using docusaurus
const result = child_process
.execFileSync(`${os.platform() === "win32" ? "yarn.cmd" : "yarn"}`, [
"run",
"docusaurus",
"docs:version",
version,
])
.toString()
.trim();
console.log(result);
} catch (e) {
console.error("\x1b[33m%s\x1b[0m", `Error while update version.\n`, e);
}
};
const main = () => {
console.log("\x1b[33m%s\x1b[0m", `Start to delete files\n`);
dirPaths.forEach((dirPath) => {
const dir = path.join(__dirname, dirPath);
deleteDir(dir);
});
console.log("\x1b[33m%s\x1b[0m", `Start to update version\n`);
updateVersion();
};
main();