2019-02-22 14:36:10 -08:00
|
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
2019-08-13 21:59:07 -07:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2019-08-13 17:58:03 -07:00
|
|
|
|
const {exec, execSync} = require('child_process');
|
|
|
|
|
|
const {readFileSync, writeFileSync} = require('fs');
|
|
|
|
|
|
const {join} = require('path');
|
2019-02-22 14:36:10 -08:00
|
|
|
|
|
|
|
|
|
|
const main = async buildId => {
|
2019-08-13 22:15:38 -07:00
|
|
|
|
const root = join(__dirname, buildId);
|
2019-02-22 14:36:10 -08:00
|
|
|
|
const buildPath = join(root, 'build');
|
|
|
|
|
|
|
2019-04-18 14:45:24 -07:00
|
|
|
|
execSync(`node ${join(root, './build')}`, {
|
|
|
|
|
|
cwd: __dirname,
|
2019-04-21 09:05:55 -07:00
|
|
|
|
env: {
|
|
|
|
|
|
...process.env,
|
|
|
|
|
|
NODE_ENV: 'production',
|
|
|
|
|
|
},
|
2019-04-18 14:45:24 -07:00
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
|
});
|
2019-02-22 14:36:10 -08:00
|
|
|
|
|
|
|
|
|
|
await exec(`cp ${join(root, 'now.json')} ${join(buildPath, 'now.json')}`, {
|
|
|
|
|
|
cwd: root,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const file = readFileSync(join(root, 'now.json'));
|
|
|
|
|
|
const json = JSON.parse(file);
|
|
|
|
|
|
const alias = json.alias[0];
|
|
|
|
|
|
|
|
|
|
|
|
const commit = execSync('git rev-parse HEAD')
|
|
|
|
|
|
.toString()
|
|
|
|
|
|
.trim()
|
|
|
|
|
|
.substr(0, 7);
|
2019-02-23 08:59:21 -08:00
|
|
|
|
|
|
|
|
|
|
let date = new Date();
|
|
|
|
|
|
date = `${date.toLocaleDateString()} – ${date.toLocaleTimeString()}`;
|
|
|
|
|
|
|
|
|
|
|
|
const installationInstructions =
|
|
|
|
|
|
buildId === 'chrome'
|
|
|
|
|
|
? readFileSync(join(__dirname, 'deploy.chrome.html'))
|
|
|
|
|
|
: readFileSync(join(__dirname, 'deploy.firefox.html'));
|
|
|
|
|
|
|
|
|
|
|
|
let html = readFileSync(join(__dirname, 'deploy.html')).toString();
|
|
|
|
|
|
html = html.replace(/%commit%/g, commit);
|
|
|
|
|
|
html = html.replace(/%date%/g, date);
|
|
|
|
|
|
html = html.replace(/%installation%/, installationInstructions);
|
|
|
|
|
|
|
|
|
|
|
|
writeFileSync(join(buildPath, 'index.html'), html);
|
2019-02-22 14:36:10 -08:00
|
|
|
|
|
|
|
|
|
|
await exec(`now deploy && now alias ${alias}`, {
|
|
|
|
|
|
cwd: buildPath,
|
|
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Deployed to https://${alias}.now.sh`);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = main;
|