-
Notifications
You must be signed in to change notification settings - Fork 45
/
build.js
107 lines (87 loc) · 2.89 KB
/
build.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
#!/usr/bin/env node
//@ts-check
const insertBanner = () => {
const fs = require('fs');
const index = fs.readFileSync("exports/public/index.html", "utf-8")
if(index.indexOf("<div class=\"banner-container\"") < 0){
const banner = fs.readFileSync("static/banner.html", "utf-8")
const editedIndex = index.replace(/(<body.*?\n)/, "$1"+banner)
fs.writeFileSync("exports/public/index.html", editedIndex)
console.log("Updated index.html")
}
else{
console.log("index.html already has banner")
}
}
const removeZipFiles = () => {
const fs = require('fs')
fs.readdirSync('exports/public').forEach(file => {
const extension = require('path').extname(file).toLowerCase()
if(extension === '.zip') {
const filePath = require('path').join('exports/public', file)
fs.unlinkSync(filePath)
}
})
console.log("deleted exports/public/*.zip")
}
const build = () => {
return exec('gwee',
`build`,
`-b rc6`,
`. `,
`-g`,
`-p x11,win,osx`
)
}
const pushReleases = async () => {
console.log("Pushing releases... This takes time and there's no update monitor, please be patient")
await exec(`gh`, `release`, `create`, `test`, `public/*.zip`, `--generate-notes`)
console.log("Releases pushed")
}
const pushToGHPages = async () => {
const scriptText = `#!/usr/bin/env bash
export BUILD_DIR="exports/public"
export RELEASE_BRANCH="gh-pages"
git fetch origin $RELEASE_BRANCH || git checkout -b $RELEASE_BRANCH
git add -f $BUILD_DIR
tree=$(git write-tree --prefix=$BUILD_DIR)
git reset -- $BUILD_DIR
export identifier=$(git describe --dirty --always)
git push -u origin $RELEASE_BRANCH
export commit=$(git commit-tree -p refs/remotes/origin/$RELEASE_BRANCH -m "Deploy $identifier" $tree)
git update-ref refs/heads/$RELEASE_BRANCH $commit
git push origin refs/heads/$RELEASE_BRANCH
git checkout main`
const fs = require('fs')
const scriptDir = fs.mkdtempSync('gh-pages')
const scriptPath = require('path').join(scriptDir, 'gh-pages.sh')
fs.writeFileSync(scriptPath, scriptText, "utf-8")
console.log("Writing to gh-pages")
exec(`bash`, scriptPath)
console.log("Written to gh-pages")
}
const exec = (command, ...args) => /** @type {Promise<void>} */(new Promise((resolve, reject) => {
const spawn = require('child_process').spawn;
console.log(`Executing:\n${command} ${args.join(' ')}`);
const stream = spawn(command, args, { shell: true });
stream.stdout.on('data', (data) => {
process.stdout.write(data.toString());
});
stream.stderr.on('data', (data) => {
process.stderr.write(data.toString());
});
stream.on('error', reject)
stream.on('close', (code) => {
if(code !== 0){
return reject(new Error(`${command} exited with code ${code}`));
}
resolve()
});
}));
(async function doTheThing(){
await build()
await insertBanner()
await removeZipFiles()
await pushReleases()
//await pushToGHPages()
})()