Skip to content

Commit

Permalink
add build script
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Jun 27, 2018
1 parent 024d198 commit 4a2fb5a
Show file tree
Hide file tree
Showing 4 changed files with 3,109 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules

.DS_Store
out/
30 changes: 30 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const ssi = require('ssi');
const glob = require('glob');
const fs = require('fs')
const path = require('path');
const mkdirp = require('mkdirp');

const srcDir = './';
const outDir = 'out/';
const matcher = '/**/*.shtml';

const parser = new ssi(srcDir, outDir, matcher);

glob(srcDir + matcher, (err, match) => {
if (err) throw err;

match.filter(i => !i.match('node_modules') && !i.match('/inc/')).forEach(file => {
console.log('Reading:', file);

try {
const out = file.replace(srcDir, outDir).replace('.shtml', '.html');
const dir = path.dirname(out);

if (!fs.existsSync(dir)) mkdirp.sync(dir);

fs.writeFileSync(out, parser.parse(file, fs.readFileSync(file, {encoding: "utf8"})));
} catch (error) {
console.error(`Error '${file}' build failed:`, error);
}
});
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Mozilla Taiwan community web site",
"main": "index.html",
"scripts": {
"start": "browser-sync start --config bs-config.js"
"start": "browser-sync start --config bs-config.js",
"build": "node build.js"
},
"repository": {
"type": "git",
Expand All @@ -26,6 +27,7 @@
"grunt-update-submodules": "~0.4.1",
"gulp": "^3.9.0",
"load-grunt-tasks": "^3.4.0",
"mkdirp": "^0.5.1",
"ssi": "^0.3.0"
}
}
Loading

0 comments on commit 4a2fb5a

Please sign in to comment.