Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed Jul 10, 2014
1 parent 2d2716a commit 6292bfd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
55 changes: 21 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var events = require('events').EventEmitter;
var util = require('util');
var async = require('async');
var jf = require('jsonfile');
var neuron_tree = require('neuron-tree');


function compiler (options){
Expand All @@ -20,8 +21,6 @@ function compiler (options){

function Compiler (options) {
this.cwd = options.cwd || process.cwd();
this.js_ext = options.js_ext || '.js';
this.css_ext = options.css_ext || '.css';
this.href_root = options.href_root || '';
this.jsons = {};
}
Expand Down Expand Up @@ -52,7 +51,7 @@ Compiler.prototype.compile = function() {


Compiler.prototype._render = function(path, template, callback) {
this._gather_info(function (err, pkg, shrinkWrap) {
this._gather_info(function (err, pkg, tree) {
if (err) {
return callback(err);
}
Expand All @@ -61,11 +60,9 @@ Compiler.prototype._render = function(path, template, callback) {
try {
compiled = compiler({
pkg: pkg,
shrinkWrap: shrinkWrap,
tree: tree,
cwd: this.cwd,
path: path,
js_ext: this.js_ext,
css_ext: this.css_ext,
href_root: this.href_root
}).compile(template);

Expand All @@ -81,31 +78,21 @@ Compiler.prototype._render = function(path, template, callback) {


Compiler.prototype._gather_info = function(callback) {
var pkg;
var shrinkWrap;
var self = this;

async.parallel([
function (done) {
self._read_pkg(function (err, json) {
pkg = json;
done(err);
});
},

function (done) {
self._read_shrinkwrap(function (err, json) {
shrinkWrap = json;
done(err);
});
}
if (this.pkg || this.tree) {
return callback(null, this.pkg, this.tree);
}

], function (err) {
if (err) {
return callback(err);
}
var self = this;
this._read_pkg(function (err, pkg) {
self._read_tree(pkg, function (err, tree) {
if (err) {
return callback(err);
}

callback(null, pkg, shrinkWrap);
self.pkg = pkg;
self.tree = tree;
callback(null, self.pkg, self.tree);
});
});
};

Expand All @@ -117,11 +104,11 @@ Compiler.prototype._read_pkg = function (callback) {
};


Compiler.prototype._read_shrinkwrap = function(callback) {
var shrinkwrap_json = node_path.join(this.cwd, 'cortex-shrinkwrap.json');

this._read_json(shrinkwrap_json, function (path, done) {
jf.readFile(path, done);
Compiler.prototype._read_tree = function(callback) {
neuron_tree(pkg, {
cwd: this.cwd,
built_root: built_root,
dependencyKeys: ['dependencies', 'asyncDependencies']
}, callback);
};

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
"chai": "*"
},
"dependencies": {
"async": "^0.9.0",
"cortex-handlebars-compiler": "^0.2.0",
"gulp-util": "^2.2.14",
"jsonfile": "^1.1.1",
"neuron-tree": "^2.0.4",
"read-cortex-json": "^2.0.0",
"gulp-util": "^2.2.14",
"through2": "^0.4.2",
"async": "^0.9.0"
"through2": "^0.4.2"
}
}

0 comments on commit 6292bfd

Please sign in to comment.