-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
64 lines (60 loc) · 2.09 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
const {ArgumentParser} = require('argparse');
const fs = require('fs');
const ParcelCore = require("@parcel/core");
const {default: Parcel} = ParcelCore;
const sites = ['main', 'maize', 'grapevine', 'sorghum', 'oryza', 'yeast'];
const parser = new ArgumentParser({
description: "build a gramene site"
});
parser.add_argument('site', {help: sites.join(', ')});
parser.add_argument('version', {help: 'site version'});
parser.add_argument('deploy', {help: 'dev or live?'});
parser.add_argument('-m', '--mode', {help: 'development or production?'});
const args = parser.parse_args();
const site = args.site;
const version = args.version;
const deploy = args.deploy;
if (!sites.includes(site)) {
console.error(`INVALID SITE NAME: "${site}"\nChoose one of these: ${sites.join(', ')}`);
}
const mode = args.mode || "production";
(async () => {
const dest = `${deploy}/${site}/${version}`;
let bundler = new Parcel({
entries: `html/${site}.html`,
defaultConfig: '@parcel/config-default',
mode: mode,
defaultTargetOptions: {
distDir: dest,
shouldScopeHoist: false,//mode === 'production',
publicUrl: deploy === 'dev' ? `/${site}/${version}` : '/'
},
env: {
NODE_ENV: mode,
SUBSITE: site,
VERSION: version,
DEPLOY: deploy
}
});
try {
console.log("await bundler.run()");
let {bundleGraph, buildTime} = await bundler.run();
console.log("bundleGraph.getBundles()");
let bundles = bundleGraph.getBundles();
console.log(`✨ Built ${bundles.length} bundles in ${buildTime}ms!`);
fs.rename(`${dest}/${site}.html`, `${dest}/index.html`, () => {
console.log(`Renamed ${dest}/${site}.html ${dest}/index.html`);
});
fs.copyFile('.htaccess', `${dest}/.htaccess`, () => {
console.log(`copied .htaccess into ${dest}/`)
});
fs.copyFile('robots.txt', `${dest}/robots.txt`, () => {
console.log(`copied robots.txt into ${dest}/`)
});
fs.symlink(`../../../src/static`, `./${dest}/static`, () => {
console.log('symlinked static content');
})
} catch (err) {
console.log(err.diagnostics);
}
})();