Skip to content

Commit

Permalink
0.3.2: Fixes #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
nporteschaikin committed Oct 16, 2014
1 parent efab358 commit 044dfc4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 48 deletions.
3 changes: 1 addition & 2 deletions lib/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ Commands.prototype = {
this.intro();
this.bind();
}
return this.exec()
.catch(this.error.bind(this));
return this.exec();
},

exec: function () {
Expand Down
20 changes: 16 additions & 4 deletions lib/compiler/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ var Project = function (peak, context, options) {
this.context = context;
this.options = options || {};

this.tree = new Tree(this.peak.path, this.options.is_ignored);
var ignore_paths = ignore_paths || [];
ignore_paths.push(this.options.output_path);

this.tree = new Tree(this.peak.path, ignore_paths);
this.tree.parse();
}

Expand All @@ -24,9 +27,9 @@ Project.prototype = {

create_folders: function () {
var paths = this.tree.folders;
if (!fs.existsSync(this.options.out_path())) fs.mkdirSync(this.options.out_path());
if (!fs.existsSync(this.out_path())) fs.mkdirSync(this.out_path());
for (var x=0; x<paths.length; x++) {
if (!fs.existsSync(this.options.out_path(paths[x]))) fs.mkdirSync(this.options.out_path(paths[x]));
if (!fs.existsSync(this.out_path(paths[x]))) fs.mkdirSync(this.out_path(paths[x]));
}
},

Expand All @@ -36,10 +39,19 @@ Project.prototype = {

for (var x=0; x<paths.length; x++) {
var file = new File(paths[x], this.context, this.options.compiler);
compilers.push(file.save(this.options.out_path(paths[x])));
compilers.push(file.save(this.out_path(paths[x])));
}

return when.all(compilers);
},

out_path: function (source_path) {
var output_path = path.resolve(this.peak.path, this.options.output_path);

if (typeof source_path === 'string')
return path.join(output_path, path.relative(this.peak.path, source_path));

return output_path;
}

}
Expand Down
18 changes: 11 additions & 7 deletions lib/compiler/tree.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
var fs = require('fs')
, path = require('path')
, minimatch = require('minimatch');

, readdir = fs.readdirSync
, lstat = fs.lstatSync
, join = path.join;

var Tree = function (source_path, is_ignored_fn) {
var Tree = function (source_path, ignore_paths) {
this.source = source_path;
this.folders = [];
this.files = [];
this.is_ignored_path = is_ignored_fn;
this.ignore_paths = ignore_paths || [];
}

Tree.prototype = {
Expand All @@ -27,7 +24,7 @@ Tree.prototype = {

for (var x=0; x<paths.length; x++) {
source_path = path.join(folder, paths[x]);
if (!this.is_ignored_path(paths[x])) {
if (!this.is_ignore_path(source_path)) {
lstat = fs.lstatSync(source_path);
if (lstat.isDirectory()) {
this.parse_folder(source_path);
Expand All @@ -36,6 +33,13 @@ Tree.prototype = {
}
}
}
},

is_ignore_path: function (source_path) {
for (var x=0; x<this.ignore_paths.length; x++) {
if (minimatch(path.basename(source_path), this.ignore_paths[x])) return true;
}
return false;
}

}
Expand Down
33 changes: 0 additions & 33 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,6 @@ Config.prototype = {
if (typeof config[action] === 'object') {
for (option in config[action]) options[option] = config[action][option];
}
return this.init_options(options);
},

init_options: function (options) {
var __this = this;

options.out_path = function (source_path) {
var output_path = path.resolve(__this.peak.path, options.output_path);

if (typeof source_path === 'string')
return path.join(output_path, path.relative(__this.peak.path, source_path));

return output_path;
};

options.is_ignored = function (basename) {
var ignore = (options.ignore instanceof Array) ? options.ignore : [];
ignore.push(options.out_path());

for (var x=0; x<ignore.length; x++) {
if (basename == ignore[x]) return true;
};
};

options.toYaml = function () {
var opts = {};

for (var option in options)
if (!(typeof options[option] === 'function')) opts[option] = options[option];

return yaml.safeDump(opts);
};

return options;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var path = require('path')
, fs = require('fs')
, path = require('path')
, when = require('when')
, yaml = require('js-yaml');

var Generator = function (peak) {
this.peak = peak;
Expand Down Expand Up @@ -34,7 +35,7 @@ Generator.prototype = {
},

create_configuration_file: function () {
fs.writeFileSync(this.peak.config.file_path, this.options.toYaml());
fs.writeFileSync(this.peak.config.file_path, yaml.safeDump(this.options));
},

emit: function () {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "peak",
"version": "0.3.1",
"version": "0.3.2",
"author": "Noah Portes Chaikin <[email protected]>",
"description": "Tumblr development framework.",
"license": "MIT",
Expand All @@ -26,6 +26,7 @@
"colors": "0.x",
"connect": "2.x",
"js-yaml": "3.x",
"minimatch": "1.x",
"request": "2.x",
"socket.io": "1.x",
"when": "3.2.x"
Expand Down

0 comments on commit 044dfc4

Please sign in to comment.