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

Commit

Permalink
Use bestikk-fs
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Oct 2, 2016
1 parent 7858085 commit a7619a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 51 deletions.
66 changes: 15 additions & 51 deletions npm/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,10 @@ var http = require('http');
var os = require('os');
var OpalCompiler = require('./opal-compiler.js');
var log = require('bestikk-log');
var bfs = require('bestikk-fs');

var stdout;

var deleteFolderRecursive = function(path) {
var files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function(file){
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};

function Builder() {
}

Expand All @@ -52,7 +37,7 @@ Builder.prototype.build = function(callback) {

Builder.prototype.clean = function(callback) {
log.task('clean');
this.deleteBuildFolder(); // delete build folder
this.removeBuildDirSync(); // remove build directory
callback();
};

Expand Down Expand Up @@ -104,7 +89,7 @@ Builder.prototype.commit = function(releaseVersion, callback) {
};

Builder.prototype.prepareNextIteration = function(callback) {
this.deleteDistFolder();
this.removeDistDirSync();
this.execSync('git add -A .');
this.execSync('git commit -m "Prepare for next development iteration"');
callback();
Expand All @@ -128,25 +113,16 @@ Builder.prototype.completeRelease = function(releaseVersion, callback) {
callback();
};

Builder.prototype.deleteBuildFolder = function() {
log.debug('delete build directory');
deleteFolderRecursive('build');
fs.mkdirSync('build');
Builder.prototype.removeBuildDirSync = function() {
log.debug('remove build directory');
bfs.removeSync('build');
bfs.mkdirsSync('build');
};

Builder.prototype.deleteDistFolder = function() {
log.debug('delete dist directory');
deleteFolderRecursive('dist');
fs.mkdirSync('dist');
};

Builder.prototype.replaceFileSync = function(file, regexp, newSubString) {
log.debug('update ' + file);
if (!process.env.DRY_RUN) {
var data = fs.readFileSync(file, 'utf8');
var dataUpdated = data.replace(regexp, newSubString);
fs.writeFileSync(file, dataUpdated, 'utf8');
}
Builder.prototype.removeDistDirSync = function() {
log.debug('remove dist directory');
bfs.removeSync('dist');
bfs.mkdirsSync('dist');
};

Builder.prototype.execSync = function(command) {
Expand Down Expand Up @@ -185,30 +161,18 @@ Builder.prototype.copyToDist = function(callback) {
var builder = this;

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');
builder.removeDistDirSync();
bfs.copySync('build/asciidoctor-backend-template.js', 'dist/main.js');
bfs.copySync('build/asciidoctor-backend-template.min.js', 'dist/main.min.js');
typeof callback === 'function' && callback();
};

Builder.prototype.copy = function(from, to) {
log.transform('copy', from, to);
var data = fs.readFileSync(from);
fs.writeFileSync(to, data);
};

Builder.prototype.mkdirSync = function(path) {
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
}
};

Builder.prototype.compile = function(callback) {
var builder = this;

var opalCompiler = new OpalCompiler({dynamicRequireLevel: 'ignore'});

this.mkdirSync('build');
bfs.mkdirsSync('build');

log.task('compile template backend');
opalCompiler.compile('asciidoctor/core_ext', 'build/asciidoctor-backend-template.js');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
},
"devDependencies": {
"async": "^1.5.0",
"bestikk-fs": "^0.1.0",
"bestikk-log": "^0.1.0",
"bestikk-uglify": "^0.1.1",
"colors": "1.1.2",
Expand Down

0 comments on commit a7619a9

Please sign in to comment.