-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.js
More file actions
100 lines (77 loc) · 2.95 KB
/
build.js
File metadata and controls
100 lines (77 loc) · 2.95 KB
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
/******************************************************************************\
This file is part of FoldingAtHome/fah-node
The fah-node enables secure remote access to Folding@home clients.
Copyright (c) 2023-2026, foldingathome.org
All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
For information regarding this software email:
Joseph Coffland
joseph@cauldrondevelopment.com
\******************************************************************************/
const esbuild = require('esbuild')
const pluginVue = require('esbuild-plugin-vue3')
const fs = require('fs-extra')
const path = require('path')
const pug = require('pug')
const chokidar = require('chokidar')
const pkg = require('./package.json')
const outdir = 'build/res'
const watchPaths = [
'src/index.pug',
'src/admin.pug',
'src/login.pug',
'src/vue'
]
// Parse args
const args = process.argv.slice(2)
let watch = false
for (let arg of args)
if (arg == '--watch') watch = true
async function build() {
console.log('Building...')
await fs.remove(outdir)
await fs.copy('src/resources', outdir)
let result = await esbuild.build({
entryPoints: ['src/vue/main.js'],
bundle: true,
minify: true,
sourcemap: true,
outdir: outdir + '/http',
entryNames: '[name]-[hash]',
metafile: true,
plugins: [pluginVue()]
})
let vars = {version: pkg.version}
let outputs = Object.keys(result.metafile.outputs)
for (let output of outputs) {
let href = '/' + path.basename(output)
if (output.endsWith('.js')) vars.js = href
if (output.endsWith('.css')) vars.css = href
}
for (let name of ['index', 'admin', 'login']) {
let html = pug.compileFile('src/' + name + '.pug')(vars)
await fs.writeFile(outdir + '/http/' + name + '.html', html)
}
}
async function main() {
await build()
if (watch) {
console.log('Watching...')
chokidar.watch(watchPaths)
.on('change', async (path, stats) => {
console.log('Change detected in', path)
await build()
})
}
}
main().catch(e => console.log(e))