Skip to content

Commit

Permalink
Update travis config and release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dashdashzako committed Oct 10, 2019
1 parent 83f5be8 commit 92c7f18
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: node_js
env:
- INLINE_RUNTIME_CHUNK=false
before_install:
- sudo apt-get update
- sudo apt-get install -y zip
Expand Down
51 changes: 36 additions & 15 deletions scripts/extract-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,52 @@ const Parser = require('htmlparser2').Parser;
const fs = require('fs');
const util = require('util');
const path = require('path');
const pwd = require('pwd');

const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);

const releaseDirname = process.argv.slice(2)[0];

const currentDir = pwd.currentDir();
const currentDir = process.cwd();
const releaseDir = path.join(currentDir, releaseDirname);

const parser = new Parser({
onopentag(name, attribs) {
if (name === 'script' && /\/static\/js/.test(attribs.src)) {
const fp = path.join(__dirname, 'build', attribs.src);
const filename = path.basename(fp);
fs.rename(fp, path.join(releaseDir, filename), (err) => {
throw err;
});
}
}
});

readFile('build/index.html')
.then((content) => {
const filenames = [];

const parser = new Parser({
onopentag(name, attribs) {
if (name === 'script' && /\/static\/js/.test(attribs.src)) {
const fp = path.join(currentDir, 'build', attribs.src);
const filename = path.basename(attribs.src);
filenames.push(filename);

console.log(`Moving ${filename} to release directory...`);

fs.rename(fp, path.join(releaseDir, filename), (err) => {
if (err) {
throw err;
}

console.log(`Successfully moved ${filename} to release directory.`);
});
}
}
});

parser.write(content);

return filenames;
})
.then((filenames) => {
const manifestPath = path.join(releaseDir, 'manifest.yml');
const manifestContent = filenames.reduce((filename) => `- ${filename}\n`);

return writeFile(manifestPath, manifestContent);
})
.then(() => {
console.log('Manifest written to release directory.\nAll done.');
})
.catch((err) => {
console.log('OOOPS', err);
throw err;
});

0 comments on commit 92c7f18

Please sign in to comment.