Skip to content

Commit

Permalink
chore: re-write bash to js.
Browse files Browse the repository at this point in the history
  • Loading branch information
h13i32maru committed May 9, 2015
1 parent d53c6bf commit edd09cb
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 5 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"url": "https://github.com/h13i32maru/esdoc"
},
"scripts": {
"build": "bash ./script/build.sh",
"test": "bash ./script/test.sh",
"test-es5": "bash ./script/test-es5.sh",
"esdoc": "bash ./script/esdoc.sh",
"start": "bash ./script/server.sh"
"build": "node ./script/build.js",
"test": "node ./script/test.js",
"test-es5": "node ./script/test-es5.js",
"esdoc": "node ./script/esdoc.js",
"start": "node ./script/server.js"
},
"dependencies": {
"babel": "~5.2.9",
Expand Down
13 changes: 13 additions & 0 deletions script/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node
var sh = require('./sh');

sh.rm('./out/src');
sh.mkdir('./out/src');
sh.exec('./node_modules/.bin/babel --out-dir out/src src');
sh.chmod('./out/src/ESDocCLI.js', '755');
sh.cp('./src/Publisher/Builder/template/', './out/src/Publisher/Builder/template/');

// build test
sh.rm('./out/test/src');
sh.mkdir('./out/test/src');
sh.exec('./node_modules/.bin/babel --out-dir out/test/src test/src');
9 changes: 9 additions & 0 deletions script/esdoc-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
var path = require('path');
var sh = require('./sh');

var esdoc = path.resolve(__dirname, '..', 'src', 'ESDocCLI.js');
var babel = path.resolve(__dirname, '..', 'node_modules', '.bin', 'babel-node');
var arg = [].concat(process.argv).splice(2);
var cmd = [babel, esdoc].concat(arg).join(' ');
sh.exec(cmd);
6 changes: 6 additions & 0 deletions script/esdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
var sh = require('./sh');

sh.rm('./doc/out/esdoc');
sh.mkdir('./doc/out/esdoc');
sh.exec('./node_modules/.bin/babel-node ./src/ESDocCLI.js -c esdoc.json');
4 changes: 4 additions & 0 deletions script/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
var sh = require('./sh');

sh.exec('./node_modules/.bin/http-server ./ -p 8080 -c -1');
30 changes: 30 additions & 0 deletions script/sh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var fs = require('fs-extra');
var path = require('path');
var child_process = require('child_process');

function rm(path) {
fs.removeSync(path);
}

function mkdir(path) {
fs.mkdirs(path);
}

function exec(cmd) {
cmd = cmd.replace(/\//g, path.sep);
child_process.execSync(cmd, {stdio: 'inherit'});
}

function chmod(path, mode) {
fs.chmodSync(path, mode);
}

function cp(src, dst) {
fs.copySync(src, dst);
}

module.exports.rm = rm;
module.exports.mkdir = mkdir;
module.exports.exec = exec;
module.exports.chmod = chmod;
module.exports.cp = cp;
17 changes: 17 additions & 0 deletions script/test-es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node
var sh = require('./sh');

// judge node or io because run test with node and io on TRAVIS.
// send coverage report with only node.
var isNodeJS = process.version.indexOf('v0.12.') === 0;
var mochaOption=" -t 10000 --recursive ./out/test/src -R spec";

sh.exec('node ./script/build.js');

if (process.env.TRAVIS && isNodeJS) {
sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- ' + mochaOption + ' && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js');
} else if(process.argv.indexOf('--coverage') !== -1) {
sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- ' + mochaOption);
} else {
sh.exec('./node_modules/.bin/mocha' + mochaOption);
}
15 changes: 15 additions & 0 deletions script/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
var sh = require('./sh');

// judge node or io because run test with node and io on TRAVIS.
// send coverage report with only node.
var isNodeJS = process.version.indexOf('v0.12.') === 0;
var mochaOption=" -t 10000 --require ./node_modules/babel/register.js --recursive ./test/src -R spec";

if (process.env.TRAVIS && isNodeJS) {
sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- ' + mochaOption + ' && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js');
} else if(process.argv.indexOf('--coverage') !== -1) {
sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- ' + mochaOption);
} else {
sh.exec('./node_modules/.bin/mocha' + mochaOption);
}

0 comments on commit edd09cb

Please sign in to comment.