Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Use Bestikk to do common build tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Oct 1, 2016
1 parent ac11235 commit 9662a14
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 129 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: node_js
node_js:
- "4.4.7"

jdk:
- oraclejdk8

before_script:
- npm install

script: "npm run dist"
sudo: false
83 changes: 8 additions & 75 deletions npm/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ var path = require('path');
var https = require('https');
var http = require('http');
var os = require('os');
var Uglify = require('./uglify.js');
var OpalCompiler = require('./opal-compiler.js');
var Log = require('./log.js');
var uglify = new Uglify();
var log = new Log();
var log = require('bestikk-log');

var stdout;

Expand All @@ -31,58 +28,6 @@ var deleteFolderRecursive = function(path) {
}
};

// https://github.com/jprichardson/node-fs-extra/blob/master/lib/mkdirs/mkdirs-sync.js
var mkdirsSync = function(p, made) {
p = path.resolve(p);
try {
fs.mkdirSync(p);
made = made || p;
} catch (err0) {
switch (err0.code) {
case 'ENOENT' :
made = mkdirsSync(path.dirname(p), made);
mkdirsSync(p, made);
break;

// In the case of any other error, just see if there's a dir
// there already. If so, then hooray! If not, then something
// is borked.
default:
var stat;
try {
stat = fs.statSync(p);
} catch (err1) {
throw err0;
}
if (!stat.isDirectory()) throw err0;
break;
}
}
return made;
}

var copyDir = function(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (exists && isDirectory) {
fs.readdirSync(src).forEach(function(childItemName) {
copyDir(path.join(src, childItemName), path.join(dest, childItemName));
});
} else {
mkdirsSync(path.dirname(dest));
var data = fs.readFileSync(src);
fs.writeFileSync(dest, data);
}
};

var javaVersionText = function() {
var result = child_process.execSync('java -version 2>&1', {encoding: 'utf8'});
var firstLine = result.split('\n')[0];
var javaVersion = firstLine.match(/"(.*?)"/i)[1];
return javaVersion.replace(/\./g, '').replace(/_/g, '');
};

function Builder() {
}

Expand All @@ -106,7 +51,7 @@ Builder.prototype.build = function(callback) {
};

Builder.prototype.clean = function(callback) {
log.title('clean');
log.task('clean');
this.deleteBuildFolder(); // delete build folder
callback();
};
Expand Down Expand Up @@ -141,14 +86,13 @@ Builder.prototype.release = function(releaseVersion) {
};

Builder.prototype.prepareRelease = function(releaseVersion, callback) {
log.title('Release version: ' + releaseVersion);
log.task('Release version: ' + releaseVersion);

if (process.env.DRY_RUN) {
log.warn('Dry run! To perform the release, run the command again without DRY_RUN environment variable');
}

this.replaceFileSync('package.json', /"version": "(.*?)"/g, '"version": "' + releaseVersion + '"');
this.replaceFileSync('bower.json', /"version": "(.*?)"/g, '"version": "' + releaseVersion + '"');
callback();
};

Expand Down Expand Up @@ -180,7 +124,7 @@ Builder.prototype.completeRelease = function(releaseVersion, callback) {
console.log('');
log.info('To complete the release, you need to:');
log.info("[ ] push changes upstream: 'git push origin master && git push origin v" + releaseVersion + "'");
log.info("[ ] publish a release page on GitHub: https://github.com/mogztter/asciidoctor-template.js/releases/new");
log.info("[ ] publish a release page on GitHub: https://github.com/asciidoctor/asciidoctor-template.js/releases/new");
callback();
};

Expand Down Expand Up @@ -221,19 +165,8 @@ Builder.prototype.uglify = function(callback) {
callback();
return;
}
// - Java7 or higher is available in PATH
try {
if (javaVersionText() < '170') {
log.warn('Closure Compiler requires Java7 or higher, skipping "minify" task');
callback();
return;
}
} catch (e) {
log.warn('\'java\' binary is not available in PATH, skipping "minify" task');
callback();
return;
}
log.title('uglify');
var uglify = require('bestikk-uglify');
log.task('uglify');
var files = [
{source: 'build/asciidoctor-backend-template.js', destination: 'build/asciidoctor-backend-template.min.js' }
];
Expand All @@ -251,7 +184,7 @@ Builder.prototype.uglify = function(callback) {
Builder.prototype.copyToDist = function(callback) {
var builder = this;

log.title('copy to dist/');
log.task('copy to dist/');
builder.deleteDistFolder();
builder.copy('build/asciidoctor-backend-template.js', 'dist/main.js');
builder.copy('build/asciidoctor-backend-template.min.js', 'dist/main.min.js');
Expand All @@ -277,7 +210,7 @@ Builder.prototype.compile = function(callback) {

this.mkdirSync('build');

log.title('compile template backend');
log.task('compile template backend');
opalCompiler.compile('asciidoctor/core_ext', 'build/asciidoctor-backend-template.js');

callback();
Expand Down
Binary file removed npm/compiler.jar
Binary file not shown.
36 changes: 0 additions & 36 deletions npm/log.js

This file was deleted.

5 changes: 1 addition & 4 deletions npm/opal-compiler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
var Log = require('./log.js');
var log = new Log();
var log = require('bestikk-log');

module.exports = OpalCompiler;

var Log = require('./log.js');
var log = new Log();
var Builder = require('opal-compiler').Builder;
var fs = require('fs');

Expand Down
3 changes: 1 addition & 2 deletions npm/release.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var Log = require('./log.js');
var Builder = require('./builder.js');
var builder = new Builder();
var log = new Log();
var log = require('bestikk-log');

var args = process.argv.slice(2);
var releaseVersion = args[0];
Expand Down
12 changes: 0 additions & 12 deletions npm/uglify.js

This file was deleted.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
},
"devDependencies": {
"async": "^1.5.0",
"bestikk-log": "^0.1.0",
"bestikk-uglify": "^0.1.1",
"colors": "1.1.2",
"cross-env": "^1.0.8",
"opal-compiler": "0.10.1-integration2"
Expand Down

0 comments on commit 9662a14

Please sign in to comment.