Skip to content

Commit

Permalink
Re-installed watcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
nporteschaikin committed Oct 22, 2014
1 parent 7340df5 commit 7377dcc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
13 changes: 5 additions & 8 deletions lib/compiler/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ var Project = function (peak, context, options) {
this.context = context;
this.options = options || {};

var ignore_paths = ignore_paths || [];
ignore_paths.push(this.options.output_path);

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

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

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

Expand All @@ -39,13 +36,13 @@ 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.out_path(paths[x])));
compilers.push(file.save(this.output_path(paths[x])));
}

return when.all(compilers);
},

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

if (typeof source_path === 'string')
Expand Down
11 changes: 6 additions & 5 deletions lib/compiler/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ var fs = require('fs')
, minimatch = require('minimatch');

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

Tree.prototype = {

parse: function () {
this.parse_folder(this.source);
this.parse_folder(this.source_path);
},

parse_folder: function (folder) {
Expand All @@ -35,9 +35,10 @@ Tree.prototype = {
}
},

is_ignore_path: function (source_path) {
is_ignore_path: function (p) {
p = p.replace(this.source_path, '').slice(1);
for (var x=0; x<this.ignore_paths.length; x++) {
if (minimatch(path.basename(source_path), this.ignore_paths[x])) return true;
if (minimatch(p, this.ignore_paths[x], { dot: true })) return true;
}
return false;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ Config.prototype = {

options: function (action) {
var config = this.config
, options = {};
, options = {}
, output_path_minimatch;

for (option in config) {
options[option] = config[option];
}

if (typeof config[action] === 'object') {
for (option in config[action]) options[option] = config[action][option];
}

if (!(options.ignore_paths instanceof Array)) options.ignore_paths = [];
if (options.ignore_paths.indexOf(options.output_path) == -1) options.ignore_paths.push(options.output_path);

return options;
}

Expand Down
34 changes: 24 additions & 10 deletions lib/watcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var Server = require('../server')
, when = require('when')
, request = require('request')
, chokidar = require('chokidar')
, minimatch = require('minimatch')
, path = require('path');

var Watcher = function (peak, options) {
Expand All @@ -15,41 +16,54 @@ var Watcher = function (peak, options) {
this.compiler = new Compiler(this.peak, this.options);
this.server = new Server(this.peak, this.options);
this.tumblr = new Tumblr(this.peak, this.options);
this.watcher = chokidar.watch(this.peak.path, { ignored: /\.peak$/ });

this.path = path.join(this.peak.path, '.peak');
this.path = path.join(this.peak.path, this.options.output_path);
this.emitter.on('exit', this.stop.bind(this));
}

Watcher.prototype = {

start: function () {
return this.fetch_tumblr()
return this.fetch_tumblr_demo_content()
.with(this)
.then(this.handle_demo_content)
.then(this.compile)
.then(this.serve)
.then(this.watch);
.then(this.watch)
.then(this.serve);
},

stop: function () {
this.watcher.close();
if (this.watcher) this.watcher.close();
this.server.stop();
},

fetch_tumblr: function () {
fetch_tumblr_demo_content: function () {
return this.tumblr.fetch_demo_content();
},

compile: function (context) {
return this.compiler.compile_project(context);
handle_demo_content: function (context) {
return this.context = context || {};
},

compile: function (file) {
return this.compiler.compile_project(this.context);
},

serve: function () {
return this.server.start();
},

watch: function () {
// this.watcher.on('change', this.compile.bind(this));
if (!this.watcher) this.watcher = chokidar.watch(this.peak.path, { ignored: this.is_ignore_path.bind(this), ignoreInitial: true });
this.watcher.on('change', this.compile.bind(this));
},

is_ignore_path: function (p) {
p = p.replace(this.peak.path, '').slice(1);
for (var x=0; x<this.options.ignore_paths.length; x++) {
if (minimatch(p, this.options.ignore_paths[x], { dot: true })) return true;
}
return false;
}

}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"argparse": "0.x",
"cheerio": "0.12.x",
"chokidar": "0.x",
"chokidar": "0.8.2",
"colors": "0.x",
"connect": "2.x",
"js-yaml": "3.x",
Expand Down

0 comments on commit 7377dcc

Please sign in to comment.