Skip to content

Commit

Permalink
starting to emit events for different step completions
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Jul 9, 2013
1 parent dfd55e0 commit 32d562d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/new-config-given-partial-default-edit-step-sync.js
Expand Up @@ -32,4 +32,5 @@ configurate(
var conf = require(configDir + '/' + configFile);
console.log(conf);
}
);
)
.on('any', console.error);
28 changes: 25 additions & 3 deletions index.js
Expand Up @@ -5,6 +5,8 @@ var path = require('path')
, mkdirp = require('mkdirp')
, runnel = require('runnel')
, sinless = require('sinless')
, Emitter = require('events').EventEmitter
, format = require('util').format
, HOME = path.join(__dirname, 'test', 'fixtures', 'home') // process.env.HOME
;

Expand Down Expand Up @@ -94,6 +96,15 @@ function noop (config) {
var go = module.exports = function (opts, cb) {
opts = opts || {};

var events = new Emitter();

function emit (name, msg) {
return sinless(function (passthru) {
events.emit(name, msg || '');
return passthru;
});
}

var configDir = resolvePath(opts.configDir)
, configFile = path.join(configDir, opts.configFile)
;
Expand All @@ -106,13 +117,22 @@ var go = module.exports = function (opts, cb) {

var loadConfig = sinless(opts.loadConfig || defaultLoad);

var tasks = [ runnel.seed(configFile), mkconfigDir ];
var tasks = [
runnel.seed(configFile)
, mkconfigDir
, emit('any', format('Created config dir at: %s', configDir))
];

fs.exists(configFile, function (exists) {
if (!exists) {
if (defaultConfig) {
tasks.push(copyDefaultConfig.bind(null, defaultConfig));
tasks.push(loadConfig);
tasks = tasks.concat(
[ copyDefaultConfig.bind(null, defaultConfig)
, emit('any', format('Copied default config from %s to %s', defaultConfig, configDir))
, loadConfig
, emit('any', format('Loaded config'))
]
);
} else {
tasks.push(noConfigFound);
}
Expand All @@ -130,4 +150,6 @@ var go = module.exports = function (opts, cb) {

runnel(tasks);
});

return events;
};

0 comments on commit 32d562d

Please sign in to comment.