2019-02-23 06:36:10 +08:00
|
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
|
|
const { exec, execSync } = require('child_process');
|
|
|
|
|
|
const { readFileSync, writeFileSync } = require('fs');
|
|
|
|
|
|
const { join } = require('path');
|
2019-04-13 05:42:34 +08:00
|
|
|
|
const convert = require('xml-js');
|
2019-02-23 06:36:10 +08:00
|
|
|
|
|
|
|
|
|
|
const main = async buildId => {
|
|
|
|
|
|
const root = join(__dirname, '..', buildId);
|
|
|
|
|
|
const buildPath = join(root, 'build');
|
|
|
|
|
|
|
2019-04-19 05:45:24 +08:00
|
|
|
|
execSync(`node ${join(root, './build')}`, {
|
|
|
|
|
|
cwd: __dirname,
|
2019-04-22 00:05:55 +08:00
|
|
|
|
env: {
|
|
|
|
|
|
...process.env,
|
|
|
|
|
|
NODE_ENV: 'production',
|
|
|
|
|
|
},
|
2019-04-19 05:45:24 +08:00
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
|
});
|
2019-02-23 06:36:10 +08:00
|
|
|
|
|
|
|
|
|
|
await exec(`cp ${join(root, 'now.json')} ${join(buildPath, 'now.json')}`, {
|
|
|
|
|
|
cwd: root,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-04-13 04:46:05 +08:00
|
|
|
|
if (buildId === 'chrome') {
|
2019-04-13 05:42:34 +08:00
|
|
|
|
const file = readFileSync(join(buildPath, 'unpacked', 'manifest.json'));
|
|
|
|
|
|
const json = JSON.parse(file);
|
|
|
|
|
|
const { version } = json;
|
|
|
|
|
|
|
|
|
|
|
|
const xmlString = readFileSync(join(root, 'updates.xml'), 'utf8');
|
|
|
|
|
|
const parsedXML = convert.xml2js(xmlString);
|
|
|
|
|
|
parsedXML.elements[0].elements[0].elements[0].attributes.version = version;
|
|
|
|
|
|
|
|
|
|
|
|
writeFileSync(join(buildPath, 'updates.xml'), convert.js2xml(parsedXML));
|
2019-04-13 04:46:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-23 06:36:10 +08:00
|
|
|
|
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-24 00: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-23 06: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;
|