Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yeoman-generator

Package Overview
Dependencies
Maintainers
6
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yeoman-generator - npm Package Compare versions

Comparing version 0.17.0 to 0.17.1

8

.jscs.json

@@ -13,6 +13,6 @@ {

"disallowQuotedKeysInObjects": true,
"disallowLeftStickedOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"requireRightStickedOperators": ["!"],
"disallowRightStickedOperators": ["?", ",", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"requireLeftStickedOperators": [","],
"requireSpaceBeforeBinaryOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowSpaceAfterBinaryOperators": ["!"],
"requireSpaceAfterBinaryOperators": ["?", ",", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowSpaceBeforeBinaryOperators": [","],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],

@@ -19,0 +19,0 @@ "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],

'use strict';
var _ = require('underscore.string');
var fs = require('fs');

@@ -390,6 +391,6 @@ var path = require('path');

/**
* Remotely fetch a package on github, store this into a _cache folder, and
* provide a "remote" object as a facade API to ourself (part of genrator API,
* copy, template, directory). It's possible to remove local cache, and force
* a new remote fetch of the package on Github.
* Remotely fetch a package from github (or an archive), store this into a _cache
* folder, and provide a "remote" object as a facade API to ourself (part of
* genrator API, copy, template, directory). It's possible to remove local cache,
* and force a new remote fetch of the package.
*

@@ -402,2 +403,11 @@ * ### Examples:

*
* this.remote('user', 'repo', 'branch', function(err, remote) {
* remote.copy('.', 'vendors/user-repo');
* });
*
* this.remote('http://foo.com/bar.zip', function(err, remote) {
* remote.copy('.', 'vendors/user-repo');
* });
*
* When fetching from Github
* @param {String} username

@@ -408,14 +418,50 @@ * @param {String} repo

* @param {Boolean} refresh
*
* @also
* When fetching an archive
* @param {String} url
* @param {Function} cb
* @param {Boolean} refresh
*/
actions.remote = function (username, repo, branch, cb, refresh) {
if (!cb) {
cb = branch;
branch = 'master';
actions.remote = function () {
var username;
var repo;
var branch;
var cb;
var refresh;
var url;
var cache;
if (arguments.length <= 3 && typeof arguments[2] !== 'function') {
url = arguments[0];
cb = arguments[1];
refresh = arguments[2];
cache = path.join(this.cacheRoot(), _.slugify(url));
} else {
username = arguments[0];
repo = arguments[1];
branch = arguments[2];
cb = arguments[3];
refresh = arguments[4];
if (!cb) {
cb = branch;
branch = 'master';
}
cache = path.join(this.cacheRoot(), username, repo, branch);
url = 'http://github.com/' + [username, repo, 'archive', branch].join('/') + '.tar.gz';
}
var self = this;
var cache = path.join(this.cacheRoot(), username, repo, branch);
var url = 'http://github.com/' + [username, repo, 'archive', branch].join('/') + '.tar.gz';
var done = function (err) {
if (err) {
return cb(err);
}
self.remoteDir(cache, cb);
};
fs.stat(cache, function (err) {

@@ -442,75 +488,85 @@ // already cached

function done(err) {
if (err) {
return cb(err);
}
return this;
};
var files = self.expandFiles('**', { cwd: cache, dot: true });
/**
* Retrive a stored directory and use as a remote reference. This is handy if
* you have files you want to move that may have been downloaded differently to
* using `this.remove()` (eg such as `node_modules` installed via `package.json`)
*
* ### Examples:
*
* this.remote('foo/bar', function(err, remote) {
* remote.copy('.', 'vendors/user-repo');
* });
*
* @param {String} cache
*/
actions.remoteDir = function (cache, cb) {
var self = this;
var files = this.expandFiles('**', { cwd: cache, dot: true });
var remote = {};
remote.cachePath = cache;
var remote = {};
remote.cachePath = cache;
// simple proxy to `.copy(source, destination)`
remote.copy = function copy(source, destination) {
source = path.join(cache, source);
self.copy(source, destination);
return this;
};
// simple proxy to `.copy(source, destination)`
remote.copy = function copy(source, destination) {
source = path.join(cache, source);
self.copy(source, destination);
return this;
};
// simple proxy to `.bulkCopy(source, destination)`
remote.bulkCopy = function copy(source, destination) {
source = path.join(cache, source);
self.bulkCopy(source, destination);
return this;
};
// simple proxy to `.bulkCopy(source, destination)`
remote.bulkCopy = function copy(source, destination) {
source = path.join(cache, source);
self.bulkCopy(source, destination);
return this;
};
// same as `.template(source, destination, data)`
remote.template = function template(source, destination, data) {
data = data || self;
destination = destination || source;
source = path.join(cache, source);
// same as `.template(source, destination, data)`
remote.template = function template(source, destination, data) {
data = data || self;
destination = destination || source;
source = path.join(cache, source);
var body = self.engine(self.read(source), data);
self.write(destination, body);
};
var body = self.engine(self.read(source), data);
self.write(destination, body);
};
// same as `.template(source, destination)`
remote.directory = function directory(source, destination) {
var root = self.sourceRoot();
self.sourceRoot(cache);
self.directory(source, destination);
self.sourceRoot(root);
};
// same as `.template(source, destination)`
remote.directory = function directory(source, destination) {
var root = self.sourceRoot();
self.sourceRoot(cache);
self.directory(source, destination);
self.sourceRoot(root);
};
// simple proxy to `.bulkDirectory(source, destination)`
remote.bulkDirectory = function directory(source, destination) {
var root = self.sourceRoot();
self.sourceRoot(cache);
self.bulkDirectory(source, destination);
self.sourceRoot(root);
};
// simple proxy to `.bulkDirectory(source, destination)`
remote.bulkDirectory = function directory(source, destination) {
var root = self.sourceRoot();
self.sourceRoot(cache);
self.bulkDirectory(source, destination);
self.sourceRoot(root);
};
var noop = function () {};
var fileLogger = { write: noop, warn: noop };
var noop = function () {};
var fileLogger = { write: noop, warn: noop };
// Set the file-utils environments
// Set logger as a noop as logging is handled by the yeoman conflicter
remote.src = file.createEnv({
base: cache,
dest: self.destinationRoot(),
logger: fileLogger
});
remote.dest = file.createEnv({
base: self.destinationRoot(),
dest: cache,
logger: fileLogger
});
// Set the file-utils environments
// Set logger as a noop as logging is handled by the yeoman conflicter
remote.src = file.createEnv({
base: cache,
dest: self.destinationRoot(),
logger: fileLogger
});
remote.dest = file.createEnv({
base: self.destinationRoot(),
dest: cache,
logger: fileLogger
});
remote.dest.registerValidationFilter('collision', self.getCollisionFilter());
remote.src.registerValidationFilter('collision', self.getCollisionFilter());
remote.dest.registerValidationFilter('collision', self.getCollisionFilter());
remote.src.registerValidationFilter('collision', self.getCollisionFilter());
cb(err, remote, files);
}
return this;
cb(null, remote, files);
};

@@ -145,3 +145,3 @@ 'use strict';

opt.desc ? '# ' + opt.desc : '',
defaults === null || defaults === '' ? '' : 'Default: ' + opt.defaults
defaults == null || defaults === '' ? '' : 'Default: ' + defaults
];

@@ -148,0 +148,0 @@ });

'use strict';
var _ = require('lodash');
var shell = require('shelljs');
var githubUsername = require('github-username');
var nameCache = {};
var emailCache = {};
var usernameCache = {};

@@ -13,40 +16,53 @@ /**

user.git = {};
user.github = {};
/**
* Git related properties
*
* The value will come from the global scope or the project scope (it'll take
* what git will use in the current context)
* @prop name {String|undefined} - Current git name
* @prop email {String|undefined} - Current git email
* Retrieves user's name from Git in the global scope or the project scope
* (it'll take what Git will use in the current context)
*/
user.git = {
get name() {
var name = nameCache[process.cwd()];
if (name) {
return name;
}
user.git.name = function () {
var name = nameCache[process.cwd()];
if (shell.which('git')) {
name = shell.exec('git config --get user.name', { silent: true }).output.trim();
nameCache[process.cwd()] = name;
}
if (name) {
return name;
},
}
get email() {
var email = emailCache[process.cwd()];
if (shell.which('git')) {
name = shell.exec('git config --get user.name', { silent: true }).output.trim();
nameCache[process.cwd()] = name;
}
if (email) {
return email;
}
return name;
};
if (shell.which('git')) {
email = shell.exec('git config --get user.email', { silent: true }).output.trim();
emailCache[process.cwd()] = email;
}
/**
* Retrieves user's email from Git in the global scope or the project scope
* (it'll take what Git will use in the current context)
*/
user.git.email = function () {
var email = emailCache[process.cwd()];
if (email) {
return email;
}
if (shell.which('git')) {
email = shell.exec('git config --get user.email', { silent: true }).output.trim();
emailCache[process.cwd()] = email;
}
return email;
};
/**
* Retrieves GitHub's username from the GitHub API.
*/
user.github.username = function () {
var args = _.toArray(arguments);
args.unshift(user.git.email());
return githubUsername.apply(null, args);
};

@@ -91,3 +91,2 @@ 'use strict';

assert(this.options.resolved, 'You must provide the resolved path value. Use env#create() to create a new generator.');
this.env = this.options.env;

@@ -280,3 +279,3 @@ this.resolved = this.options.resolved;

set: function (value) {
this[name] = value;
this.args[position] = value;
}

@@ -356,9 +355,16 @@ });

assert(methods.length, 'This Generator is empty. Add at least one method for it to be runned.');
assert(methods.length, 'This Generator is empty. Add at least one method for it to run.');
this.env.runLoop.once('end', function () {
self.emit('end');
var endProcess = function () {
this.emit('end');
cb();
});
}.bind(this);
this.env.runLoop.once('end', function () {
if (this.config.pending) {
return this.config.on('save', endProcess);
}
endProcess();
}.bind(this));
// Ensure a prototype method is candidate to be run by default

@@ -406,3 +412,3 @@ function methodIsValid(name) {

_.each(item, function (method, methodName) {
if (!_.isFunction(method)) return;
if (!_.isFunction(method) || !methodIsValid(methodName)) return;
addMethod(method, methodName, queueName);

@@ -409,0 +415,0 @@ });

@@ -193,3 +193,7 @@ /**

if (!(prompt.name in answers)) {
answers[prompt.name] = prompt.default;
if (_.isFunction(prompt.default)) {
answers[prompt.name] = prompt.default(answers);
} else {
answers[prompt.name] = prompt.default;
}
}

@@ -248,10 +252,5 @@

var env = generators();
dependencies.forEach(function (d) {
if (d instanceof Array) {
env.registerStub(d[0], d[1]);
} else {
env.register(d);
}
});
this.registerDependencies(env, dependencies);
var generator = env.create(name, { arguments: args, options: options });

@@ -273,2 +272,19 @@

/**
* Register a list of dependent generators into the provided env.
* Dependecies can be path (autodiscovery) or an array [<generator>, <name>]
*
* @param {Array} dependencies - paths to the generators dependencies
*/
exports.registerDependencies = function (env, dependencies) {
dependencies.forEach(function (d) {
if (_.isArray(d)) {
env.registerStub(d[0], d[1]);
} else {
env.register(d);
}
});
};
/**
* Run the provided Generator

@@ -275,0 +291,0 @@ * @param {String|Function} Generator - Generator constructor or namespace

'use strict';
var path = require('path');
var assert = require('assert');
var _ = require('lodash');

@@ -10,7 +12,7 @@ var yeoman = require('../..');

* This class provide a run context object to façade the complexity involved in setting
* up a generator for testing.
* up a generator for testing
* @constructor
* @param {String|Function} Generator - Namespace or generator constructor. If the later
* is provided, then namespace is assumed to be
* 'gen:test' in all cases.
* 'gen:test' in all cases
* @return {this}

@@ -20,24 +22,10 @@ */

var RunContext = module.exports = function RunContext(Generator) {
var namespace;
this._asyncHolds = 0;
this.runned = false;
this.env = yeoman();
this.args = [];
this.options = {};
this._dependencies = [];
this.Generator = Generator;
if (_.isString(Generator)) {
namespace = this.env.namespace(Generator);
this.env.register(Generator);
} else {
namespace = 'gen:test';
this.env.registerStub(Generator, namespace);
}
this.generator = this.env.create(namespace);
// Mock prompt by default
this.withPrompt();
setTimeout(this._onReady.bind(this), 0);
setTimeout(this._run.bind(this), 0);
};

@@ -49,11 +37,10 @@

* Hold the execution until the returned callback is triggered
* @private
* @return {Function} Callback to notify the normal execution can resume
*/
RunContext.prototype._holdExec = function () {
RunContext.prototype.async = function () {
this._asyncHolds++;
return function () {
this._asyncHolds--;
this._onReady();
this._run();
}.bind(this);

@@ -63,14 +50,33 @@ };

/**
* Method called when the context is ready to run the generator.
* Method called when the context is ready to run the generator
* @private
*/
RunContext.prototype._onReady = function () {
RunContext.prototype._run = function () {
if (this._asyncHolds !== 0 || this.runned) return;
this.runned = true;
this.generator.args = this.args;
this.generator.arguments = this.args;
this.generator.options = _.extend({
'skip-install': true
}, this.options);
var namespace;
this.env = yeoman();
helpers.registerDependencies(this.env, this._dependencies);
if (_.isString(this.Generator)) {
namespace = this.env.namespace(this.Generator);
this.env.register(this.Generator);
} else {
namespace = 'gen:test';
this.env.registerStub(this.Generator, namespace);
}
this.generator = this.env.create(namespace, {
arguments: this.args,
options: _.extend({
'skip-install': true
}, this.options)
});
helpers.mockPrompt(this.generator, this._answers);
this.generator.once('end', this.emit.bind(this, 'end'));
this.emit('ready', this.generator);
this.generator.run();

@@ -80,11 +86,12 @@ };

/**
* Clean the provided directory, then change directory into it.
* Clean the provided directory, then change directory into it
* @param {String} dirPath - Directory path (relative to CWD). Prefer passing an absolute
* file path for predictable results.
* file path for predictable results
* @return {this}
*/
RunContext.prototype.inDir = function (dirPath) {
var release = this._holdExec();
helpers.testDirectory(dirPath, release);
RunContext.prototype.inDir = function (dirPath, cb) {
var release = this.async();
var callBackThenRelease = _.compose(release, (cb || _.noop).bind(this, path.resolve(dirPath)));
helpers.testDirectory(dirPath, callBackThenRelease);
return this;

@@ -121,4 +128,4 @@ };

RunContext.prototype.withPrompt = function (answers) {
helpers.mockPrompt(this.generator, answers);
RunContext.prototype.withPrompts = function (answers) {
this._answers = answers;
return this;

@@ -128,3 +135,38 @@ };

/**
* Add a callback to be called after the generator has runned.
* @alias RunContext.prototype.withPrompts
* @deprecated
*/
RunContext.prototype.withPrompt = RunContext.prototype.withPrompts;
/**
* Provide dependent generators
* @param {Array} dependencies - paths to the generators dependencies
* @return {this}
* @example
* var deps = ['../../common',
* '../../controller',
* '../../main',
* [helpers.createDummyGenerator(), 'testacular:app']
* ];
* var angular = new RunContext('../../app');
* angular.withGenerator(deps);
* angular.withPrompt({
* compass: true,
* bootstrap: true
* });
* angular.onEnd(function () {
* // assert something
* });
*/
RunContext.prototype.withGenerators = function (dependencies) {
assert(_.isArray(dependencies), 'dependencies should be an array');
this._dependencies = this._dependencies.concat(dependencies);
return this;
};
/**
* Add a callback to be called after the generator has ran
* @deprecated `onEnd` is deprecated, use .on('end', onEndHandler) instead.
* @param {Function} callback

@@ -135,4 +177,4 @@ * @return {this}

RunContext.prototype.onEnd = function (cb) {
this.generator.once('end', cb);
return this;
console.log('`onEnd` is deprecated, use .on(\'end\', onEndHandler) instead.');
return this.on('end', cb);
};

@@ -64,3 +64,3 @@ 'use strict';

msg = msg || '';
if (!ctx) {
if (ctx == null) {
ctx = {};

@@ -67,0 +67,0 @@ }

@@ -34,7 +34,8 @@ 'use strict';

this.name = name;
this.existed = false;
this.pending = false;
this.save = _.debounce(_.bind(this.forceSave, this), 5);
this._throttledSave = _.debounce(_.bind(this.forceSave, this), 5);
this.loadConfig();
this._store = readJSON(this.path)[this.name] || {};
this.existed = Object.keys(this._store).length > 0;
};

@@ -44,26 +45,2 @@ util.inherits(Storage, EventEmitter);

/**
* Get the previous configs or setup a new one.
* note: it won't actually create any file before save is called.
* @return {Object} Key-value object store
*/
Storage.prototype.loadConfig = function () {
if (fs.existsSync(this.path)) {
var content = fs.readFileSync(this.path, 'utf8');
this._fullStore = JSON.parse(content);
this.existed = true;
} else {
this._fullStore = {};
}
if (!this._fullStore[this.name]) {
this._fullStore[this.name] = {};
}
this._store = this._fullStore[this.name];
return this._store;
};
/**
* Schedule a save to happen sometime on a future tick.

@@ -74,3 +51,6 @@ * Note: This method is actually defined at runtime in the constructor function.

Storage.prototype.save = function () {};
Storage.prototype.save = function () {
this.pending = true;
this._throttledSave();
};

@@ -83,3 +63,6 @@ /**

Storage.prototype.forceSave = function () {
fs.writeFileSync(this.path, JSON.stringify(this._fullStore, null, ' '));
this.pending = false;
var fullStore = readJSON(this.path);
fullStore[this.name] = this._store;
fs.writeFileSync(this.path, JSON.stringify(fullStore, null, ' '));
this.emit('save');

@@ -109,4 +92,5 @@ };

* Assign a key to a value and schedule a save.
* @param {String} key
* @param {*} val Any valid JSON type value (String, Number, Array, Object)
* @param {String} key The key under which the value is stored
* @param {*} val Any valid JSON type value (String, Number, Array, Object).
* @return {*} val Whatever was passed in as val.
*/

@@ -118,3 +102,3 @@

if (_.isObject(key)) {
_.extend(this._store, key);
val = _.extend(this._store, key);
} else {

@@ -124,2 +108,3 @@ this._store[key] = val;

this.save();
return val;
};

@@ -129,3 +114,3 @@

* Delete a key from the store and schedule a save.
* @param {String} key
* @param {String} key The key under which the value is stored.
* @return {null}

@@ -142,4 +127,4 @@ */

* If keys already exist, the initial value is kept.
* @param {Object} defaults Key-value object to store.
* @return {null}
* @param {Object} defaults Key-value object to store.
* @return {*} val Returns the merged options.
*/

@@ -151,2 +136,10 @@

this.set(val);
return val;
};
function readJSON(path) {
if (fs.existsSync(path)) {
return JSON.parse(fs.readFileSync(path, 'utf8'));
}
return {};
}
{
"name": "yeoman-generator",
"version": "0.17.0",
"version": "0.17.1",
"description": "Rails-inspired generator system that provides scaffolding for your apps",

@@ -33,6 +33,6 @@ "license": "BSD",

"chalk": "^0.4.0",
"cheerio": "^0.16.0",
"cheerio": "^0.17.0",
"class-extend": "^0.1.0",
"dargs": "^0.1.0",
"debug": "^0.8.0",
"debug": "^1.0.1",
"diff": "^1.0.4",

@@ -42,5 +42,6 @@ "download": "^0.1.6",

"findup-sync": "^0.1.2",
"glob": "^3.2.0",
"grouped-queue": "^0.2.1",
"gruntfile-editor": "^0.1.0",
"github-username": "~0.1.1",
"glob": "^4.0.2",
"grouped-queue": "^0.3.0",
"gruntfile-editor": "^0.1.1",
"iconv-lite": "^0.2.10",

@@ -52,3 +53,3 @@ "inquirer": "^0.5.0",

"mkdirp": "^0.5.0",
"nopt": "^2.2.1",
"nopt": "^3.0.0",
"request": "^2.34.0",

@@ -55,0 +56,0 @@ "rimraf": "^2.2.0",

@@ -6,3 +6,3 @@ # Generator [![Build Status](https://secure.travis-ci.org/yeoman/generator.svg?branch=master)](http://travis-ci.org/yeoman/generator) [![Coverage Status](https://coveralls.io/repos/yeoman/generator/badge.png)](https://coveralls.io/r/yeoman/generator)

### [Getting Started](http://yeoman.io/generators.html)&nbsp;&nbsp;&nbsp;[API Documentation](http://yeoman.github.io/generator/)
### [Getting Started](http://yeoman.io/authoring/getting-started.html)&nbsp;&nbsp;&nbsp;[API Documentation](http://yeoman.github.io/generator/)

@@ -17,3 +17,3 @@

If you're interested in writing your own Yeoman generator we recommend reading [the official getting started guide](http://yeoman.io/generators.html).
If you're interested in writing your own Yeoman generator we recommend reading [the official getting started guide](http://yeoman.io/authoring/).

@@ -20,0 +20,0 @@ There are typically two types of generators - simple boilerplate 'copiers' and more advanced generators which can use custom prompts, remote dependencies, wiring and much more.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc