Skip to content

Commit

Permalink
feat: add ci script
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondYuan committed Jun 20, 2020
1 parent a14263f commit f9b5da1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dll/
webclipper.zip

.now
release
16 changes: 15 additions & 1 deletion script/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
const webpack = require('webpack');
const prodConfig = require('../webpack/webpack.prod');
const compiler = webpack(prodConfig);
compiler.run();

function send(data) {
if (!process.send) {
return;
}
return new Promise(r => {
process.send(data, null, {}, r);
});
}

compiler.run(() => {
send({
type: 'Success',
});
});
48 changes: 48 additions & 0 deletions script/ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { fork } = require('child_process');
const path = require('path');
const compressing = require('compressing');
const fs = require('fs');
const pump = require('pump');

const releaseDir = path.join(__dirname, '../release');
if (!fs.existsSync(releaseDir)) {
fs.mkdirSync(releaseDir);
}

function build(targetBrowser) {
const buildScript = require.resolve('./build');
const buildEnv = Object.create(process.env);
buildEnv.NODE_ENV = 'production';
buildEnv.TARGET_BROWSER = targetBrowser;
const cp = fork(buildScript, [], {
env: buildEnv,
silent: true,
});
return new Promise(r => {
cp.on('message', r);
});
}
function pack(targetBrowser) {
const dist = path.resolve(__dirname, `../dist`);
const { version } = JSON.parse(fs.readFileSync(path.join(dist, 'manifest.json'), 'utf-8'));
const zipStream = new compressing.zip.Stream();
fs.readdirSync(dist).forEach(o => {
if (o.match(/^\./)) {
return;
}
zipStream.addEntry(path.join(dist, o));
});
const dest = path.join(releaseDir, `web_clipper_${version}_${targetBrowser}.zip`);
const destStream = fs.createWriteStream(dest);
return new Promise(r => {
pump(zipStream, destStream, r);
});
}

(async () => {
const browserList = ['Firefox', 'Chrome'];
for (const browser of browserList) {
await build(browser);
await pack(browser);
}
})();
1 change: 0 additions & 1 deletion script/release_ff.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const homedir = require('os').homedir();
const dest = path.resolve(homedir, `${name}_${version}_firefox.zip`);
const source = path.resolve(__dirname, `../dist`);
const zipStream = new compressing.zip.Stream();

fs.readdirSync(source).forEach(o => {
zipStream.addEntry(path.join(source, o));
});
Expand Down

0 comments on commit f9b5da1

Please sign in to comment.