Permalink
Browse files

modifications to error handling and file watching

  • Loading branch information...
1 parent 01c4c93 commit b348a9540d02f2521221bd9093c5afbbf9c81017 @chrisfjones chrisfjones committed Jan 3, 2013
Showing with 91 additions and 56 deletions.
  1. +25 −14 lib/build.js
  2. +8 −3 lib/cli.js
  3. +21 −14 lib/index.js
  4. +13 −5 src/build.iced
  5. +4 −4 src/cli.iced
  6. +20 −16 src/index.iced
View
39 lib/build.js
@@ -1,6 +1,6 @@
// Generated by IcedCoffeeScript 1.3.3g
(function() {
- var buildOutputTemplateFilePath, cc, ccupOptions, colors, compileLayout, compilePage, compilePages, cs, error, exec, fs, fsextra, iced, makeReleaseDir, path, vm, _, __iced_k, __iced_k_noop,
+ var buildOutputTemplateFilePath, cc, ccupOptions, colors, compileLayout, compilePage, compilePages, cs, error, exec, fs, fsextra, handleProcessOutput, iced, makeReleaseDir, path, vm, _, __iced_k, __iced_k_noop,
__slice = [].slice;
iced = {
@@ -63,8 +63,16 @@
compilePages = [null][0];
+ handleProcessOutput = function(command, err, stdout, stderr) {
+ if (stdout != null) console.log(stdout);
+ if (stderr != null) console.error(stderr);
+ if (err != null) {
+ return console.error("the " + command + " command exited with an error, check the output above for more details");
+ }
+ };
+
module.exports = function(callback) {
- var copyErr, csErr, pagesErr, sassErr, stderr, stdout, ___iced_passed_deferral, __iced_deferrals, __iced_k,
+ var copyErr, csErr, csStderr, csStdout, pagesErr, sassErr, sassStderr, sassStdout, ___iced_passed_deferral, __iced_deferrals, __iced_k,
_this = this;
__iced_k = __iced_k_noop;
___iced_passed_deferral = iced.findDeferral(arguments);
@@ -77,7 +85,7 @@
funcname: "exports"
});
exec('rm -rf release/', __iced_deferrals.defer({
- lineno: 14
+ lineno: 20
}));
__iced_deferrals._fulfill();
})(function() {
@@ -94,39 +102,42 @@
return copyErr = arguments[0];
};
})(),
- lineno: 18
+ lineno: 24
}));
exec('sass --scss -t expanded --update -f scss:release/css', __iced_deferrals.defer({
assign_fn: (function() {
return function() {
- return sassErr = arguments[0];
+ sassErr = arguments[0];
+ sassStdout = arguments[1];
+ return sassStderr = arguments[2];
};
})(),
- lineno: 19
+ lineno: 24
}));
exec('coffee -c -o release/lib/ src/', __iced_deferrals.defer({
assign_fn: (function() {
return function() {
csErr = arguments[0];
- stdout = arguments[1];
- return stderr = arguments[2];
+ csStdout = arguments[1];
+ return csStderr = arguments[2];
};
})(),
- lineno: 19
+ lineno: 25
}));
compilePages(__iced_deferrals.defer({
assign_fn: (function() {
return function() {
return pagesErr = arguments[0];
};
})(),
- lineno: 21
+ lineno: 26
}));
__iced_deferrals._fulfill();
})(function() {
- if (copyErr || sassErr || csErr || pagesErr) {
- throw copyErr || sassErr || csErr || pagesErr;
- }
+ handleProcessOutput('copy', copyErr);
+ handleProcessOutput('sass', sassErr, sassStdout, sassStderr);
+ handleProcessOutput('coffee', csErr, csStdout, csStderr);
+ return handleProcessOutput('compilePages', pagesErr);
});
});
} catch (e) {
@@ -224,7 +235,7 @@
return layoutTemplate = arguments[0];
};
})(),
- lineno: 82
+ lineno: 90
}));
__iced_deferrals._fulfill();
})(function() {
View
11 lib/cli.js
@@ -1,6 +1,6 @@
// Generated by IcedCoffeeScript 1.3.3g
(function() {
- var colors, iced, program, star, starman, __iced_k, __iced_k_noop,
+ var colors, fs, iced, path, pjson, program, star, starman, __iced_k, __iced_k_noop,
__slice = [].slice;
iced = {
@@ -51,7 +51,13 @@
star = '\u2606'.red;
- program.version('0.0.1');
+ path = require('path');
+
+ fs = require('fs');
+
+ pjson = require(path.join(path.dirname(fs.realpathSync(__filename)), '../package.json'));
+
+ program.version(pjson.version);
program.command('init').description('Set up a new project with the appropriate directory structure. Run this within your new project\'s root directory.').action(function(options) {
return starman.init();
@@ -83,7 +89,6 @@
__iced_k = __iced_k_noop;
___iced_passed_deferral = iced.findDeferral(arguments);
port = options.port || 8080;
- starman.build();
starman.watch();
starman.serve(port);
(function(__iced_k) {
View
35 lib/index.js
@@ -1,6 +1,6 @@
// Generated by IcedCoffeeScript 1.3.3g
(function() {
- var colors, exec, fs, iced, star, watch, _, __iced_k, __iced_k_noop,
+ var colors, exec, fs, iced, path, star, w, _, __iced_k, __iced_k_noop,
__slice = [].slice;
iced = {
@@ -43,7 +43,9 @@
};
__iced_k = __iced_k_noop = function() {};
- watch = require('watch');
+ w = require('watch');
+
+ path = require('path');
fs = require('fs');
@@ -73,7 +75,7 @@
funcname: "clean"
});
exec('rm -rf release/', __iced_deferrals.defer({
- lineno: 12
+ lineno: 13
}));
__iced_deferrals._fulfill();
})(function() {
@@ -99,7 +101,7 @@
return err = arguments[0];
};
})(),
- lineno: 17
+ lineno: 18
}));
__iced_deferrals._fulfill();
})(function() {
@@ -108,31 +110,36 @@
};
module.exports.watch = function(callback) {
- var buildWrapper, dir, dirs, fileChangeCallback, lazyBuild, opts, _i, _len;
+ var buildWrapper, dir, dirs, fileChangeCallback, lazyBuild, opts, watchDir, _i, _len;
buildWrapper = function() {
process.stdout.write("" + star + " ");
return module.exports.build();
};
lazyBuild = _.debounce(buildWrapper, 500);
- fileChangeCallback = function(f, curr, prev) {
- if (!curr && !prev) return;
+ fileChangeCallback = function(f) {
+ console.log("detected change: " + f);
return lazyBuild();
};
+ dirs = ['pages', 'src', 'static', 'scss'];
opts = {
- ignoreDotFiles: true,
- filter: function(f) {
- return !(f.match(/~$/) != null);
- },
persistent: true,
interval: 511
};
- dirs = ['pages', 'src', 'static', 'scss'];
+ console.log('watching for changes...');
+ watchDir = function(dir) {
+ var dirPath;
+ dirPath = path.join(process.cwd(), dir);
+ return w.createMonitor(dirPath, function(monitor) {
+ monitor.on('created', fileChangeCallback);
+ monitor.on('changed', fileChangeCallback);
+ return monitor.on('removed', fileChangeCallback);
+ });
+ };
for (_i = 0, _len = dirs.length; _i < _len; _i++) {
dir = dirs[_i];
- watch.watchTree(dir, opts, fileChangeCallback);
+ watchDir(dir);
}
fs.watchFile('layout.html.coffee', opts, lazyBuild);
- console.log('watching for changes...');
return typeof callback === "function" ? callback() : void 0;
};
View
18 src/build.iced
@@ -10,17 +10,25 @@ _ = require 'underscore'
[compilePages] = [null]
+handleProcessOutput = (command, err, stdout, stderr) ->
+ console.log stdout if stdout?
+ console.error stderr if stderr?
+ if err?
+ console.error "the #{command} command exited with an error, check the output above for more details"
+
module.exports = (callback) ->
try
await exec 'rm -rf release/', defer()
fsextra.mkdirRecursiveSync 'release'
await
fsextra.copyRecursive './static', './release', defer copyErr
- exec 'sass --scss -t expanded --update -f scss:release/css', defer sassErr
- exec 'coffee -c -o release/lib/ src/', defer(csErr, stdout, stderr)
- compilePages defer pagesErr
- if copyErr or sassErr or csErr or pagesErr
- throw copyErr or sassErr or csErr or pagesErr
+ exec 'sass --scss -t expanded --update -f scss:release/css', defer(sassErr, sassStdout, sassStderr)
+ exec 'coffee -c -o release/lib/ src/', defer(csErr, csStdout, csStderr)
+ compilePages defer(pagesErr)
+ handleProcessOutput 'copy', copyErr
+ handleProcessOutput 'sass', sassErr, sassStdout, sassStderr
+ handleProcessOutput 'coffee', csErr, csStdout, csStderr
+ handleProcessOutput 'compilePages', pagesErr
catch e
console.error e
callback?()
View
8 src/cli.iced
@@ -2,9 +2,11 @@ program = require 'commander'
colors = require 'colors'
starman = require './index'
star = '\u2606'.red
-
+path = require 'path'
+fs = require 'fs'
+pjson = require path.join(path.dirname(fs.realpathSync(__filename)), '../package.json')
program
- .version('0.0.1')
+ .version pjson.version
program
.command('init')
@@ -58,8 +60,6 @@ program
# custom help
).action((options) ->
port = options.port or 8080
-
- starman.build()
starman.watch()
starman.serve port
await setTimeout defer(), 1000
View
36 src/index.iced
@@ -1,9 +1,10 @@
-watch = require 'watch'
-fs = require 'fs'
-{exec} = require 'child_process'
-_ = require 'underscore'
-colors = require 'colors'
-star = '\u2606'.red
+w = require 'watch'
+path = require 'path'
+fs = require 'fs'
+{exec} = require 'child_process'
+_ = require 'underscore'
+colors = require 'colors'
+star = '\u2606'.red
module.exports.init = require './init'
module.exports.serve = require './serve'
@@ -25,20 +26,23 @@ module.exports.watch = (callback) ->
lazyBuild = _.debounce buildWrapper, 500
- fileChangeCallback = (f, curr, prev) ->
- if not curr and not prev
- return
+ fileChangeCallback = (f) ->
+ console.log "detected change: #{f}"
lazyBuild()
-
+
+ dirs = ['pages', 'src', 'static', 'scss']
opts =
- ignoreDotFiles : true
- filter : (f) -> not f.match(/~$/)?
persistent: true
interval: 511
-
- dirs = ['pages', 'src', 'static', 'scss']
- watch.watchTree dir, opts, fileChangeCallback for dir in dirs
- fs.watchFile 'layout.html.coffee', opts, lazyBuild
console.log 'watching for changes...'
+ watchDir = (dir) ->
+ dirPath = path.join(process.cwd(), dir)
+ w.createMonitor dirPath, (monitor) ->
+ monitor.on 'created', fileChangeCallback
+ monitor.on 'changed', fileChangeCallback
+ monitor.on 'removed', fileChangeCallback
+ watchDir dir for dir in dirs
+ fs.watchFile 'layout.html.coffee', opts, lazyBuild
+
callback?()

0 comments on commit b348a95

Please sign in to comment.