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

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Sep 14, 2016
1 parent d5363ea commit edd057b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 111 deletions.
28 changes: 28 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# Generic template backend for Asciidoctor.js
Guillaume Grossetie <https://github.com/mogztter[@mogztter]>

## Usage

In this example we are using the https://github.com/asciidoctor/asciidoctor-reveal.js[Reveal.js backend]:

```
npm install asciidoctor-reveal.js
```

```
var asciidoctor = require('asciidoctor.js')();
var Asciidoctor = asciidoctor.Asciidoctor();
var Opal = asciidoctor.Opal;
Opal.load('nodejs');
Opal.load('pathname');
require('asciidoctor-reveal.js');

var options = Opal.hash({'safe': 'safe',
'template_dir': 'node_modules/asciidoctor-reveal.js/dist/templates',
'backend': 'revealjs'});

var content = '= Title\n\n' +
'== Slide 1\n\n' +
'Content 1\n\n' +
'== Slide 2\n\n' +
'Content 2';
var result = Asciidoctor.$convert(content, options);
```
86 changes: 2 additions & 84 deletions npm/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ var path = require('path');
var https = require('https');
var http = require('http');
var os = require('os');
var zlib = require('zlib');
var tar = require('tar-fs');
var concat = require('./concat.js');
var Uglify = require('./uglify.js');
var OpalCompiler = require('./opal-compiler.js');
var Log = require('./log.js');
Expand All @@ -18,10 +15,6 @@ var log = new Log();

var stdout;

String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

var deleteFolderRecursive = function(path) {
var files = [];
if (fs.existsSync(path)) {
Expand Down Expand Up @@ -83,18 +76,6 @@ var copyDir = function(src, dest) {
}
};

var walk = function(currentDirPath, callback) {
fs.readdirSync(currentDirPath).forEach(function(name) {
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, stat);
} else if (stat.isDirectory()) {
walk(filePath, callback);
}
});
};

var javaVersionText = function() {
var result = child_process.execSync('java -version 2>&1', {encoding: 'utf8'});
var firstLine = result.split('\n')[0];
Expand All @@ -103,7 +84,6 @@ var javaVersionText = function() {
};

function Builder() {
this.templatesVersion = 'master';
}

Builder.prototype.build = function(callback) {
Expand All @@ -117,7 +97,6 @@ Builder.prototype.build = function(callback) {

async.series([
function(callback) { builder.clean(callback); }, // clean
function(callback) { builder.downloadDependencies(callback); }, // download dependencies
function(callback) { builder.compile(callback); }, // compile
function(callback) { builder.uglify(callback); } // uglify (optional)
], function() {
Expand All @@ -132,36 +111,6 @@ Builder.prototype.clean = function(callback) {
callback();
};

Builder.prototype.downloadDependencies = function(callback) {
log.title('download dependencies');

var builder = this;
async.series([
function(callback) { builder.getContentFromURL('https://codeload.github.com/asciidoctor/asciidoctor-reveal.js/tar.gz/' + builder.templatesVersion, 'build/templates-revealjs.tar.gz', callback); },
function(callback) { builder.untar('build/templates-revealjs.tar.gz', 'templates-revealjs', 'build', callback); }
], function() {
typeof callback === 'function' && callback();
});
}

Builder.prototype.untar = function(source, baseDirName, destinationDir, callback) {
var stream = fs.createReadStream(source).pipe(zlib.createGunzip()).pipe(tar.extract(destinationDir, {
map: function (header) {
// REMIND Do NOT user path.sep!
// In this case, even on Windows, the separator is '/'.
var paths = header.name.split('/');
// replace base directory with 'baseDirName'
paths.shift();
paths.unshift(baseDirName);
header.name = paths.join('/');
return header;
}
}));
stream.on('finish', function () {
callback();
});
}

Builder.prototype.dist = function(releaseVersion) {
var builder = this;
var start = process.hrtime();
Expand Down Expand Up @@ -231,15 +180,10 @@ 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.js-backend-template/releases/new");
log.info("[ ] publish a release page on GitHub: https://github.com/mogztter/asciidoctor-template.js/releases/new");
callback();
};

Builder.prototype.concat = function(message, files, destination) {
log.debug(message);
concat(files, destination);
};

Builder.prototype.deleteBuildFolder = function() {
log.debug('delete build directory');
deleteFolderRecursive('build');
Expand Down Expand Up @@ -311,15 +255,9 @@ Builder.prototype.copyToDist = function(callback) {
builder.deleteDistFolder();
builder.copy('build/asciidoctor-backend-template.js', 'dist/main.js');
builder.copy('build/asciidoctor-backend-template.min.js', 'dist/main.min.js');
copyDir('build/templates-revealjs/templates/jade', 'dist/templates/revealjs');
typeof callback === 'function' && callback();
};

Builder.prototype.copyToDir = function(from, toDir) {
var basename = path.basename(from);
this.copy(from, toDir + '/' + basename);
};

Builder.prototype.copy = function(from, to) {
log.transform('copy', from, to);
var data = fs.readFileSync(from);
Expand All @@ -332,34 +270,14 @@ Builder.prototype.mkdirSync = function(path) {
}
};

Builder.prototype.getContentFromURL = function(source, target, callback) {
log.transform('get', source, target);
var targetStream = fs.createWriteStream(target);
var downloadModule;
// startWith alternative
if (source.lastIndexOf('https', 0) === 0) {
downloadModule = https;
} else {
downloadModule = http;
}
downloadModule.get(source, function(response) {
response.pipe(targetStream);
targetStream.on('finish', function () {
targetStream.close(callback);
});
});
};

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

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

this.mkdirSync('build');

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

callback();
Expand Down
16 changes: 0 additions & 16 deletions npm/concat.js

This file was deleted.

20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asciidoctor.js-backend-template",
"version": "0.0.1",
"name": "asciidoctor-template.js",
"version": "1.5.5-2",
"description": "Generic template backend for Asciidoctor.js ",
"main": "dist/main.min.js",
"engines": {
Expand All @@ -9,7 +9,6 @@
"files": [
"dist/main.js",
"dist/main.min.js",
"dist/templates",
"LICENSE",
"README.adoc"
],
Expand All @@ -21,7 +20,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/mogztter/asciidoctor.js-backend-template.git"
"url": "https://github.com/mogztter/asciidoctor-template.js.git"
},
"keywords": [
"asciidoc",
Expand All @@ -30,26 +29,25 @@
"javascript",
"library",
"backend",
"template"
"template",
"jade"
],
"authors": [
"Guillaume Grossetie (https://github.com/mogztter)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/mogztter/asciidoctor.js-backend-template/issues"
"url": "https://github.com/mogztter/asciidoctor-template.js/issues"
},
"homepage": "https://github.com/mogztter/asciidoctor.js-backend-template",
"homepage": "https://github.com/mogztter/asciidoctor-template.js",
"dependencies": {
"jade": "1.11.0",
"opal-runtime": "0.10.1-integration2",
"reveal.js": "3.3.0"
"asciidoctor.js": "1.5.5-2"
},
"devDependencies": {
"async": "^1.5.0",
"colors": "1.1.2",
"cross-env": "^1.0.8",
"opal-compiler": "0.10.1-integration2",
"tar-fs": "1.11.1"
"opal-compiler": "0.10.1-integration2"
}
}

0 comments on commit edd057b

Please sign in to comment.