Skip to content

Commit

Permalink
Fix some code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jan 6, 2015
1 parent f47c52d commit 7c4e1c8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 48 deletions.
6 changes: 4 additions & 2 deletions lib/actions/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ module.exports = function invoke(namespace, options, cb) {
this.log.invoke(namespace);
this.log.emit('up');

generator.on('end', this.log.emit.bind(this.log, 'down'));
generator.on('end', this.log.emit.bind(this.log, 'down'));
generator.once('end', function () {
this.log.emit('down');
this.log.emit('down');
}.bind(this));

return generator.run(cb);
};
49 changes: 20 additions & 29 deletions lib/actions/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,27 @@ remote.remote = function () {
url = 'https://github.com/' + [username, repo, 'archive', branch].join('/') + '.tar.gz';
}

var self = this;

var done = function (err) {
if (err) {
return cb(err);
}

self.remoteDir(cache, cb);
};
if (err) return cb(err);
this.remoteDir(cache, cb);
}.bind(this);

fs.stat(cache, function (err) {
// already cached
if (!err) {
// no refresh, so we can use this cache
if (!refresh) {
return done();
}

// otherwise, we need to remove it, to fetch it again
rimraf(cache, function (err) {
if (err) {
return cb(err);
}
self.extract(url, cache, { strip: 1 }, done);
});

} else {
self.extract(url, cache, { strip: 1 }, done);
if (err) {
return this.extract(url, cache, { strip: 1 }, done);
}
});

// no refresh, so we can use this cache
if (!refresh) return done();

// otherwise, we need to remove it, to fetch it again
rimraf(cache, function (err) {
if (err) return cb(err);
this.extract(url, cache, { strip: 1 }, done);
}.bind(this));

}.bind(this));

return this;
};
Expand Down Expand Up @@ -175,17 +166,17 @@ remote.remoteDir = function (cache, cb) {
// Set logger as a noop as logging is handled by the yeoman conflicter
remoteFs.src = fileUtils.createEnv({
base: cache,
dest: self.destinationRoot(),
dest: this.destinationRoot(),
logger: fileLogger
});
remoteFs.dest = fileUtils.createEnv({
base: self.destinationRoot(),
base: this.destinationRoot(),
dest: cache,
logger: fileLogger
});

remoteFs.dest.registerValidationFilter('collision', self.getCollisionFilter());
remoteFs.src.registerValidationFilter('collision', self.getCollisionFilter());
remoteFs.dest.registerValidationFilter('collision', this.getCollisionFilter());
remoteFs.src.registerValidationFilter('collision', this.getCollisionFilter());

cb(null, remoteFs, files);
};
1 change: 0 additions & 1 deletion lib/actions/spawn_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ var spawn = require('cross-spawn');
*/

module.exports = function spawnCommand(command, args, opt) {
opt = opt || {};
return spawn(command, args, _.defaults(opt, { stdio: 'inherit' }));
};
26 changes: 18 additions & 8 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ _.extend(Base.prototype, require('./actions/wiring'));
_.extend(Base.prototype, require('./actions/help'));
_.extend(Base.prototype, require('./util/common'));
Base.prototype.user = require('./actions/user');
Base.prototype.invoke = require('./actions/invoke');
Base.prototype.spawnCommand = require('./actions/spawn_command');

/**
* Prompt user to answer questions. The signature of this method is the same as {@link Inquirer.js}
*
* On top of Inquirer.js API, you can provide a `{cache: true}` property for every
* question descriptors. When true, Yeoman will store/reuser previous user answers as
* defaults.
*
* @param {array} questions Array of question descriptor objects. See {@link Inquirer.js Documentation}
* @param {Function} callback Receive a question object
* @return {this}
*/

Base.prototype.prompt = function (questions, callback) {
questions = promptSuggestion.prefillQuestions(this._globalConfig, questions);
Expand All @@ -208,9 +222,6 @@ Base.prototype.prompt = function (questions, callback) {
return this;
};

Base.prototype.invoke = require('./actions/invoke');
Base.prototype.spawnCommand = require('./actions/spawn_command');

/**
* Adds an option to the set of generator expected options, only used to
* generate generator usage. By default, generators get all the cli option
Expand Down Expand Up @@ -340,12 +351,11 @@ Base.prototype.checkRequiredArgs = function () {
};

/**
* Runs the generator, executing top-level methods in the order they
* were defined.
* Runs the generator, scheduling prototype methods on a run queue. Method names will
* determine in which order each method will be runned. Methods without special name will
* be runned in the default queue.
*
* Special named method like `constructor` and `initialize` are skipped
* (CoffeeScript and Backbone like inheritence), or any method prefixed by
* a `_`.
* Method named `constructor` and any methods prefixed by a `_` won't be scheduled.
*
* You can also supply the arguments for the method to be invoked, if
* none is given, the same values used to initialize the invoker are
Expand Down
8 changes: 0 additions & 8 deletions lib/util/engines.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
'use strict';
var _ = require('lodash');

// TODO(mklabs):
// - handle cache
// - implement adpaters for others engines (but do not add hard deps on them,
// should require manual install for anything that is not an underscore
// template)
// - put in multiple files, possibly other packages.

var engines = module.exports;

// Underscore
Expand Down

0 comments on commit 7c4e1c8

Please sign in to comment.