-
Notifications
You must be signed in to change notification settings - Fork 83
/
buildArchive.js
71 lines (64 loc) · 3.43 KB
/
buildArchive.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
/******************************************************************************
Copyright:: 2024- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
const { exec } = require("child_process");
const { readFileSync, writeFileSync } = require("fs");
function myExec(cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(error.message);
return;
}
if (stderr) {
console.error(stderr);
return;
}
resolve(stdout);
});
});
}
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
const now = new Date();
const paddedDate = (""+now.getDate()).padStart(2,'0');
const monthStr = monthNames[now.getMonth()];
const archiveDir = `${now.getFullYear()}.${(""+(now.getMonth()+1)).padStart(2,'0')}.${paddedDate}`;
const archiveId = `${paddedDate}${monthStr}${now.getFullYear()}`;
(async () => {
// **Pull from Git**: Ensure we have the latest from Git
await myExec("git pull");
// **Install**: In `accessibility-checker-engine` and `rule-server` run `npm install`
await myExec("pushd accessibility-checker-engine && npm install && popd");
await myExec("pushd rule-server && npm install && popd");
// **Build**: Delete `rule-server/dist`. In `rule-server`, `npm run build`
await myExec("pushd rule-server && npx shx rm -rf ./dist && npm run build && popd");
// **Deploy**: The new archive will be found in `rule-server/dist/static/archives/preview`. Copy and rename `preview` to the archive directory (e.g., `rule-server/src/static/archives/yyyy.mm.dd`)
await myExec(`npx shx rm -rf rule-server/src/static/archives/${archiveDir}`);
await myExec(`npx shx mv rule-server/dist/static/archives/preview rule-server/src/static/archives/${archiveDir}`);
// **Metadata**: Add an entry to `rule-server/src/static/archives.json`. See other entries for examples. Ensure that you move the `latest` property to the new archive.
const archives = JSON.parse(readFileSync("rule-server/src/static/archives.json"));
let existArchiveIdx = archives.findIndex(archive => archive.id === archiveId);
if (existArchiveIdx !== -1) {
archives.splice(existArchiveIdx, 1);
}
let lastVersion = archives[1].version.split(".");
lastVersion[lastVersion.length-1] = parseInt(lastVersion[lastVersion.length-1])+1;
archives.splice(1, 0, {
"id": `${paddedDate}${monthStr}${now.getFullYear()}`,
"name": `${paddedDate} ${monthStr} ${now.getFullYear()} Deployment (IBM 7.3)`,
"version": lastVersion.join("."),
"path": `/archives/${archiveDir}`
})
writeFileSync("rule-server/src/static/archives.json", JSON.stringify(archives, null, 4));
})();