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

yeoman-generator

Package Overview
Dependencies
Maintainers
1
Versions
167
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.10.5 to 0.11.0

lib/actions/spawn_command.js

4

changelog.md
# Changelog
## master
- `generator.prompt` replaced `read` with `prompt` as backend. If you were relying on specific `read` changes, you may need to adjust your code. [#213](https://github.com/yeoman/generator/pull/213)
## 0.10.5 - 2013-04-12

@@ -4,0 +8,0 @@

12

lib/actions/actions.js

@@ -43,3 +43,3 @@ var logger = process.logging || require('./utils/log');

if (!path.existsSync(root)) {
if (!fs.existsSync(root)) {
this.mkdir(root);

@@ -63,2 +63,3 @@ }

var body;
destination = destination || source;
source = this.isPathAbsolute(source) ? source : path.join(this.sourceRoot(), source);

@@ -68,3 +69,3 @@

if (!isBinaryFile(source)) {
encoding = 'utf-8'
encoding = 'utf-8';
}

@@ -241,5 +242,6 @@

// Returns the generator instance
actions.remote = function(username, repo, branch, cb) {
actions.remote = function (username, repo, branch, cb) {
if (!cb) {
cb = branch; branch = 'master';
cb = branch;
branch = 'master';
}

@@ -263,3 +265,3 @@

if (err) {
return cb( err );
return cb(err);
}

@@ -266,0 +268,0 @@

@@ -48,3 +48,3 @@ var fs = require('fs');

}).on('end', function () {
log.write().ok( ('Done in ' + (Date.now() - now) / 1000 + 's.') );
log.write().ok('Done in ' + (Date.now() - now) / 1000 + 's.');
});

@@ -51,0 +51,0 @@

var _ = require('lodash');
var spawn = require('child_process').spawn;
var win32 = process.platform === 'win32';
var dargs = require('dargs');
var install = module.exports;
function spawnCommand(command, args, cb) {
var winCommand = win32 ? 'cmd' : command;
var winArgs = win32 ? ['/c ' + command + ' ' + args.join(' ')] : args;
return spawn(winCommand, winArgs, { stdio: 'inherit' });
}
// Convert an object to an array of CLI arguments
function optsToArgs(options) {
var args = [];
Object.keys(options).forEach(function (flag) {
var val = options[flag];
flag = flag.replace(/[A-Z]/g, function (match) {
return '-' + match.toLowerCase();
});
if (val === true) {
args.push('--' + flag);
}
if (_.isString(val)) {
args.push('--' + flag, val);
}
if (_.isNumber(val)) {
args.push('--' + flag, '' + val);
}
if (_.isArray(val)) {
val.forEach(function (arrVal) {
args.push('--' + flag, arrVal);
});
}
});
return args;
}
function runInstall(generator, installer, paths, options, cb) {
if (!cb) {
// Combine package manager cmd line arguments and run the "install" command
//
// - installer - A String containing the name of the package manager to use
// - paths - A String or an Array of package name to install. Empty string for `npm install`
// - options - [optional] The Hash of options to invoke `npm install` with. See `npm help install`.
// - callback - [optional]
//
// Returns the generator instance.
install.runInstall = function (installer, paths, options, cb) {
if (!cb && _.isFunction(options)) {
cb = options;

@@ -56,14 +20,15 @@ options = {};

options = options || {};
cb = cb || function () {};
paths = Array.isArray(paths) ? paths : (paths && paths.split(' ') || []);
generator.emit(installer + 'Install', paths);
var args = ['install'].concat(paths).concat(optsToArgs(options));
this.emit(installer + 'Install', paths);
var args = ['install'].concat(paths).concat(dargs(options));
spawnCommand(installer, args, cb)
this.spawnCommand(installer, args, cb)
.on('err', cb)
.on('exit', generator.emit.bind(generator, installer + 'Install:end', paths))
.on('exit', this.emit.bind(this, installer + 'Install:end', paths))
.on('exit', function (err) {
if (err === 127) {
generator.log.error('Could not find ' + installer + '. Please install with ' +
this.log.error('Could not find ' + installer + '. Please install with ' +
'`npm install -g ' + installer + '`.');

@@ -74,4 +39,4 @@ }

return generator;
}
return this;
};

@@ -143,3 +108,3 @@

install.bowerInstall = function install(paths, options, cb) {
return runInstall(this, 'bower', paths, options, cb);
return this.runInstall('bower', paths, options, cb);
};

@@ -156,3 +121,3 @@

install.npmInstall = function install(paths, options, cb) {
return runInstall(this, 'npm', paths, options, cb);
return this.runInstall('npm', paths, options, cb);
};
var path = require('path');
var invoke = module.exports;
// Receives a `namespace`, and an Hash of `options` to invoke a given

@@ -16,3 +14,3 @@ // generator. The usual list of arguments can be set with `options.args`

// Returns the generator instance.
invoke.invoke = function invoke(namespace, options, cb) {
module.exports = function invoke(namespace, options, cb) {
cb = cb || function () {};

@@ -19,0 +17,0 @@ options = options || {};

@@ -1,5 +0,77 @@

var read = require('read');
'use strict';
var prompt = module.exports;
var prompt_ = require('prompt');
var _ = require('lodash');
var validate = require('revalidator').validate;
function evaluatePrompts(prompt) {
if (_.isFunction(prompt.default)) {
prompt.default = prompt.default();
} else if (typeof prompt.default === 'boolean') {
// Handle boolean defaults as confirmation prompts.
var defaultMsg = prompt.default ? 'Y/n' : 'y/N';
prompt.default = defaultMsg;
prompt.validator = function (value) {
return value.match(/^([yYnN]|(y\/N)|(Y\/n))$/);
};
prompt.required = true;
prompt.before = function (val) {
if (val === 'Y/n' || val.toLowerCase() === 'y') {
return true;
} else if (val === 'y/N' || val.toLowerCase() === 'n') {
return false;
}
return val;
};
}
return prompt;
}
// Monkey-patching prompt._performValidation to get rid of the overly verbose
// error message.
//
// Arguments:
// - name {Object} Variable name
// - prop {Object|string} Variable to get input for.
// - against {Object} Input
// - schema {Object} Validation schema
// - line {String|Boolean} Input line
// - callback {function} Continuation to pass control to when complete.
//
// Perfoms user input validation, print errors if needed and returns value
// according to validation
//
prompt_._performValidation = function (name, prop, against, schema, line, callback) {
var numericInput, valid, msg;
try {
valid = validate(against, schema);
} catch (err) {
return (line !== -1) ? callback(err) : false;
}
if (!valid.valid) {
msg = 'Invalid input';
if (prompt_.colors) {
prompt_.logger.error(msg);
} else {
prompt_.logger.error(msg);
}
if (prop.schema.message) {
prompt_.logger.error(prop.schema.message);
}
prompt_.emit('invalid', prop, line);
}
return valid.valid;
};
// Prompt for user input based on the given Array of `prompts` to perform in

@@ -9,3 +81,3 @@ // series, and call `done` callback on completion. `prompts` can be a single

//
// Options can be any read's option: https://github.com/isaacs/read#options
// Options can be any prompt's option: https://npmjs.org/package/prompt
//

@@ -16,7 +88,23 @@ // - prompts - A single or an Array of Hash options.

// Returns the generator instance.
prompt.prompt = function prompt(prompts, done) {
module.exports = function prompt(prompts, done) {
prompts = Array.isArray(prompts) ? prompts : [prompts];
prompts = prompts.map(evaluatePrompts);
prompt_.colors = false;
prompt_.message = '[' + '?'.green + ']';
prompt_.delimiter = ' ';
prompt_.start();
var results = {};
(function next(prompt) {
function handleResult(err, value) {
if (err) {
return done(err);
}
results[prompt.name] = value[prompt.name];
next(prompts.shift());
}
if (!prompt) {

@@ -26,15 +114,6 @@ return done(null, results);

if (!prompt.prompt) {
prompt.prompt = prompt.message;
}
prompt_.get(prompt, handleResult);
})(prompts.shift());
read(prompt, function (err, value) {
if (err) {
return done(err);
}
results[prompt.name] = value;
next(prompts.shift());
});
})(prompts.shift());
return this;
};

@@ -72,3 +72,4 @@ var util = require('util');

// injected into a usemin block.
// - searchPath - an alternate search path to look in for files
// - searchPath - either a single string, specifying an alternate search
// path to look in for files, or an array of strings.
//

@@ -81,2 +82,5 @@ // Returns the new block.

if (searchPath !== undefined) {
if (util.isArray(searchPath)) {
searchPath = '{' + searchPath.join(',') + '}';
}
blockSearchPath = '(' + searchPath + ')';

@@ -124,3 +128,3 @@ }

sourceFileList.forEach(function (el) {
files += ' <script ' + attrs + ' src="' + el + '"></script>\n';
files += ' <script ' + attrs + ' src="' + el + '"></script>\n';
});

@@ -130,4 +134,4 @@ blocks = this.generateBlock('js', optimizedPath, files, searchPath);

} else if (fileType === 'css') {
sourceFileList.forEach(function(el) {
files += ' <link ' + attrs + ' rel="stylesheet" href="' + el + '">\n';
sourceFileList.forEach(function (el) {
files += ' <link ' + attrs + ' rel="stylesheet" href="' + el + '">\n';
});

@@ -160,3 +164,3 @@ blocks = this.generateBlock('css', optimizedPath, files, searchPath);

wiring.removeScript = function removeScript(html, scriptPath) {
return this.domUpdate(html, 'script[src$="' + scriptPath + '"]' , '', 'd');
return this.domUpdate(html, 'script[src$="' + scriptPath + '"]', '', 'd');
};

@@ -169,3 +173,3 @@

wiring.removeStyle = function removeStyle(html, path) {
return this.domUpdate(html, 'link[href$="' + path + '"]' , '', 'd');
return this.domUpdate(html, 'link[href$="' + path + '"]', '', 'd');
};

@@ -190,3 +194,3 @@

wiring.writeFileFromString = function writeFileFromString(html, filePath) {
fs.writeFileSync(path.resolve(filePath), html, 'utf8');
fs.writeFileSync(path.resolve(filePath), html, 'utf8');
};

@@ -85,5 +85,11 @@ var fs = require('fs');

// "include" the actions modules
fs.readdirSync(actions).forEach(function (file) {
_.extend(Base.prototype, require(path.join(actions, file)));
});
_.extend(Base.prototype, require('./actions/actions'));
_.extend(Base.prototype, require('./actions/fetch'));
_.extend(Base.prototype, require('./actions/file'));
_.extend(Base.prototype, require('./actions/install'));
_.extend(Base.prototype, require('./actions/string'));
_.extend(Base.prototype, require('./actions/wiring'));
Base.prototype.prompt = require('./actions/prompt');
Base.prototype.invoke = require('./actions/invoke');
Base.prototype.spawnCommand = require('./actions/spawn_command');

@@ -189,2 +195,6 @@ // Adds an option to the set of generator expected options, only used to

if (config.required && value === undefined) {
return this.emit('error', new Error('Did not provide required argument ' + name.bold + '!'));
}
this[name] = value;

@@ -229,4 +239,5 @@ return this;

// us to perform test in a synchronous way -- i.e. without prompting user)
methods.push ( -1 );
methods.push(-1);
var waiter = 0;
(function next(method) {

@@ -252,3 +263,2 @@ if (!method) {

var waiter = 0;
self.async = function async() {

@@ -433,3 +443,3 @@ waiter++;

var filepath = path.join(this.sourceRoot(), '../USAGE');
var exists = path.existsSync(filepath);
var exists = fs.existsSync(filepath);

@@ -436,0 +446,0 @@ var out = [

@@ -10,8 +10,5 @@ var fs = require('fs');

var engines = require('./util/engines');
var eol = require('os').EOL;
var debug = require('debug')('generators:environment');
var exists = fs.existsSync || path.existsSync;
var Base = require('./base');

@@ -185,3 +182,3 @@

return out.join(eol)
return out.join('\n')
.replace(/:binary:/g, name);

@@ -469,3 +466,3 @@ };

this.register(filepath);
} catch(e) {
} catch (e) {
// silent fail unless not a loadpath error

@@ -498,3 +495,3 @@ if (e.message.indexOf(filepath) === -1) {

this.register(path.resolve(base, filename));
} catch(e) {
} catch (e) {
console.error('Unable to register %s (Error: %s)', filename, e.message);

@@ -683,3 +680,3 @@ }

if (exists(filepath)) {
if (fs.existsSync(filepath)) {
this.appendPath(filepath);

@@ -686,0 +683,0 @@ return this;

@@ -56,3 +56,3 @@ var fs = require('fs');

var out = [
'module.exports = function(grunt) {',
'module.exports = function (grunt) {',
config,

@@ -83,4 +83,4 @@ '};'

//
helpers.assertFiles = function(files) {
files.forEach(function(item) {
helpers.assertFiles = function (files) {
files.forEach(function (item) {
var file = item;

@@ -91,7 +91,7 @@ var rx;

rx = item[1];
};
}
helpers.assertFile(file, rx);
});
}
};

@@ -101,3 +101,3 @@ // Clean-up the test directory and ce into it.

//
helpers.testDirectory = function(dir, cb) {
helpers.testDirectory = function (dir, cb) {
if (!dir) {

@@ -124,9 +124,9 @@ throw new Error('Missing directory');

//
helpers.mockPrompt = function( generator, answers) {
var origPrompt = generator.prompt;
generator.prompt = function(prompts, done) {
done(null, answers);
};
generator.origPrompt = origPrompt;
}
helpers.mockPrompt = function (generator, answers) {
var origPrompt = generator.prompt;
generator.prompt = function (prompts, done) {
done(null, answers);
};
generator.origPrompt = origPrompt;
};

@@ -136,3 +136,3 @@ //

//
helpers.createDummyGenerator = function() {
helpers.createDummyGenerator = function () {
var dummy = function Dummy() {

@@ -149,3 +149,3 @@ generators.Base.apply(this, arguments);

return dummy;
}
};

@@ -161,12 +161,12 @@ // Create a generator, using the given dependencies and controller arguments

// [createDummyGenerator(), 'testacular:app']
// ];
// ];
// var angular = createGenerator('angular:app', deps);
//
helpers.createGenerator = function ( name, dependencies, args) {
helpers.createGenerator = function (name, dependencies, args) {
var env = generators();
dependencies.forEach(function(d) {
dependencies.forEach(function (d) {
if (d instanceof Array) {
env.register(d[0], d[1]);
} else {
env.register(d);
env.register(d);
}

@@ -189,4 +189,1 @@ });

};

@@ -7,4 +7,3 @@ var logger = process.logging || require('./log');

var diff = require('diff');
var prompt = require('../actions/prompt').prompt;
var exists = fs.existsSync || path.existsSync;
var prompt = require('../actions/prompt');
var log = logger('conflicter');

@@ -61,3 +60,3 @@

conflicter.emit('resolved:'+ conflict.file, status);
conflicter.emit('resolved:' + conflict.file, status);
next(conflicts.shift());

@@ -69,3 +68,6 @@ });

conflicter.collision = function collision(filepath, content, cb) {
conflicter._ask = function (filepath, content, cb) {
// for this particular use case, might use prompt module directly to avoid
// the additional "Are you sure?" prompt
var self = this;

@@ -81,3 +83,61 @@ var menu = [

if (!exists(filepath)) {
var config = {
message: ('Overwrite ' + filepath + '? (enter "h" for help) [Ynaqdh]?'),
name: 'overwrite',
default: 'h'
};
process.nextTick(function () {
self.emit('prompt', config);
self.emit('conflict', filepath);
});
prompt(config, function (err, result) {
if (err) {
return cb(err);
}
var answer = result.overwrite;
var ok = 'Yynaqdh'.split('').some(function (valid) {
return valid === answer;
});
if (answer === 'h' || !ok) {
console.log(menu);
return self._ask(filepath, content, cb);
}
if (answer === 'n') {
log.skip(filepath);
return cb(null, 'skip');
}
if (answer === 'q') {
log.writeln('Aborting...');
return process.exit(0);
}
if (/Y|a/i.test(answer)) {
log.force(filepath);
if (answer === 'a') {
self.force = true;
}
return cb(null, 'force');
}
if (answer === 'd') {
console.log(conflicter.diff(fs.readFileSync(filepath, 'utf8'), content));
return self._ask(filepath, content, cb);
}
// default, even though we should have handled every possible value
return cb();
});
};
conflicter.collision = function collision(filepath, content, cb) {
var self = this;
if (!fs.existsSync(filepath)) {
log.create(filepath);

@@ -101,62 +161,3 @@ return cb(null, 'create');

log.conflict(filepath);
log(menu);
// for this particular use case, might use prompt module directly to avoid
// the additional "Are you sure?" prompt
(function ask() {
var config = {
message: ('Overwrite ' + filepath + '? (enter "h" for help) [Ynaqdh]?'),
name: 'overwrite',
default: 'h'
};
process.nextTick(function () {
self.emit('prompt', config);
self.emit('conflict', filepath);
});
prompt(config, function (err, result) {
if (err) {
return cb(err);
}
var answer = result.overwrite;
var ok = 'Yynaqdh'.split('').some(function (valid) {
return valid === answer;
});
if (answer === 'h' || !ok) {
console.log(menu);
return ask();
}
if (answer === 'n') {
log.skip(filepath);
return cb(null, 'skip');
}
if (answer === 'q') {
log.writeln('Aborting...');
return process.exit(0);
}
if (/Y|a/i.test(answer)) {
log.force(filepath);
if (answer === 'a') {
self.force = true;
}
return cb(null, 'force');
}
if (answer === 'd') {
console.log(conflicter.diff(fs.readFileSync(filepath, 'utf8'), content));
return ask();
}
// default, even though we should have handled every possible value
return cb();
});
})();
conflicter._ask(filepath, content, cb);
};

@@ -163,0 +164,0 @@

@@ -26,3 +26,3 @@ var _ = require('lodash');

engines.underscore = function underscore(source, data) {
source = source.replace(matcher, function(m, content) {
source = source.replace(matcher, function (m, content) {
// let's add some funny markers to replace back when templating is done,

@@ -29,0 +29,0 @@ // should be fancy enough to reduce frictions with files using markers like

@@ -28,3 +28,3 @@ var util = require('util');

// borrowed to https://github.com/mikeal/logref/blob/master/main.js#L6-15
function formatter (msg, ctx) {
function formatter(msg, ctx) {
while (msg.indexOf('%') !== -1) {

@@ -38,3 +38,3 @@ var start = msg.indexOf('%');

msg = msg.slice(0, start) + ctx[msg.slice(start+1, end)] + msg.slice(end);
msg = msg.slice(0, start) + ctx[msg.slice(start + 1, end)] + msg.slice(end);
}

@@ -62,3 +62,3 @@ return msg;

// Retunrns the logger
function log (msg, ctx) {
function log(msg, ctx) {
msg = msg || '';

@@ -162,16 +162,16 @@ if (!ctx) {

var chars = {
top : '',
'top-mid' : '',
'top-left' : '',
'top-right' : '',
bottom : '',
'bottom-mid' : '',
'bottom-left' : '',
'bottom-right' : '',
left : '',
'left-mid' : '',
mid : '',
'mid-mid' : '',
right : '',
'right-mid' : ''
top : '',
'top-mid' : '',
'top-left' : '',
'top-right' : '',
bottom : '',
'bottom-mid' : '',
'bottom-left' : '',
'bottom-right' : '',
left : '',
'left-mid' : '',
mid : '',
'mid-mid' : '',
right : '',
'right-mid' : ''
};

@@ -178,0 +178,0 @@

{
"name": "yeoman-generator",
"version": "0.10.5",
"version": "0.11.0",
"description": "Rails-inspired generator system that provides scaffolding for your apps",

@@ -37,3 +37,2 @@ "keywords": [

"mkdirp": "~0.3.5",
"read": "~1.0.4",
"glob": "~3.1.21",

@@ -43,3 +42,6 @@ "nopt": "~2.1.1",

"debug": "~0.7.2",
"isbinaryfile": "~0.1.8"
"isbinaryfile": "~0.1.8",
"prompt": "~0.2.9",
"revalidator": "~0.1.5",
"dargs": "~0.1.0"
},

@@ -46,0 +48,0 @@ "devDependencies": {

@@ -1,2 +0,2 @@

/*global describe, before, it */
/*global describe, before, it, afterEach, beforeEach */
var fs = require('fs');

@@ -9,3 +9,4 @@ var path = require('path');

var generators = require('../');
var eol = require('os').EOL;
var EventEmitter = require('events').EventEmitter;
var win32 = process.platform === 'win32';

@@ -64,2 +65,3 @@

this.dummy.copy('foo.js', 'write/to/foo.js');
this.dummy.copy('foo-copy.js');
this.dummy.copy(path.join(__dirname, 'fixtures/lodash-copy.js'), 'write/to/lodash.js');

@@ -80,2 +82,6 @@ this.dummy.conflicter.resolve(done);

});
it('should default the destination to the source filepath value', function (done) {
fs.stat('foo-copy.js', done);
});
});

@@ -86,7 +92,7 @@

var body = this.dummy.read('foo.js');
assert.equal(body, 'var foo = \'foo\';' + eol);
assert.equal(body, 'var foo = \'foo\';' + '\n');
});
it('should allow absolute path, and prevent the relative paths join', function () {
var body = this.dummy.read(path.join(__dirname, 'fixtures/foo.js'));
assert.equal(body, 'var foo = \'foo\';' + eol);
assert.equal(body, 'var foo = \'foo\';' + '\n');
});

@@ -97,3 +103,3 @@ });

before(function (done) {
this.body = 'var bar = \'bar\';' + eol;
this.body = 'var bar = \'bar\';' + '\n';
this.dummy.write('write/to/foobar.js', this.body);

@@ -133,3 +139,3 @@ this.dummy.conflicter.resolve(done);

var body = fs.readFileSync('foo-template.js', 'utf8');
assert.equal(body, 'var fooooooo = \'fooooooo\';' + eol);
assert.equal(body, 'var fooooooo = \'fooooooo\';' + '\n');
});

@@ -139,3 +145,3 @@

var body = fs.readFileSync('write/to/from-template-bar.js', 'utf8');
assert.equal(body, 'var bar = \'bar\';' + eol);
assert.equal(body, 'var bar = \'bar\';' + '\n');
});

@@ -145,3 +151,3 @@

var body = fs.readFileSync('write/to/from-template.js', 'utf8');
assert.equal(body, 'var fooooooo = \'fooooooo\';' + eol);
assert.equal(body, 'var fooooooo = \'fooooooo\';' + '\n');
});

@@ -188,3 +194,3 @@ });

var foo = this.dummy.foo;
assert.equal(body, 'var ' + foo + ' = \'' + foo + '\';' + eol);
assert.equal(body, 'var ' + foo + ' = \'' + foo + '\';' + '\n');
});

@@ -204,40 +210,28 @@ });

describe('generator.bowerInstall', function () {
it('should spawn a bower process', function (done) {
var called = false;
function spawn(cmd, args) {
assert.equal(cmd, 'bower');
assert.deepEqual(args, ['install']);
called = true;
beforeEach(function () {
// Keep track of all commands executed by spawnCommand.
this.commandsRun = [];
this.dummy.spawnCommand = function spawnCommand(cmd, args) {
this.commandsRun.push([cmd, args]);
return asyncStub;
}
}.bind(this);
});
var install = proxyquire('../lib/actions/install', {
child_process: {spawn: spawn}
});
afterEach(function () {
// Restore the original function.
var spawn = require('../lib/actions/spawn_command');
this.dummy._.extend(this.dummy, spawn);
});
install.emit = function () {};
install.bowerInstall(null, done);
assert(called);
it('should spawn a bower process', function (done) {
this.dummy.bowerInstall(null, done);
assert(this.commandsRun.length, 1);
assert.deepEqual(this.commandsRun[0], ['bower', ['install']]);
});
it('should spawn a bower process with formatted options', function (done) {
var called = false;
function spawn(cmd, args) {
assert.equal(cmd, 'bower');
assert.deepEqual(args, ['install', 'jquery', '--save-dev']);
called = true;
return asyncStub;
}
var install = proxyquire('../lib/actions/install', {
child_process: {spawn: spawn}
});
install.emit = function () {};
install.bowerInstall('jquery', {saveDev: true}, done);
assert(called);
this.dummy.bowerInstall('jquery', { saveDev: true }, done);
assert(this.commandsRun.length, 1);
assert.deepEqual(this.commandsRun[0], ['bower', ['install', 'jquery', '--save-dev']]);
});

@@ -247,37 +241,34 @@ });

describe('generator.installDependencies', function () {
it('should spawn npm and bower', function () {
var commandsRun = [];
function spawn(cmd, args) {
commandsRun.push(cmd);
beforeEach(function () {
// Keep track of all commands executed by spawnCommand.
this.commandsRun = [];
this.dummy.spawnCommand = function spawnCommand(cmd, args) {
this.commandsRun.push(cmd);
return asyncStub;
}
}.bind(this);
});
var install = proxyquire('../lib/actions/install', {
child_process: {spawn: spawn}
});
afterEach(function () {
// Restore the original function.
var spawn = require('../lib/actions/spawn_command');
this.dummy._.extend(this.dummy, spawn);
});
install.emit = function () {};
install.installDependencies();
assert.deepEqual(commandsRun.sort(), ['bower', 'npm']);
it('should spawn npm and bower', function () {
this.dummy.installDependencies();
assert.deepEqual(this.commandsRun, ['bower', 'npm']);
});
it('should not spawn anything with skipInstall', function () {
var commandsRun = [];
this.dummy.installDependencies({ skipInstall: true });
assert.deepEqual(this.commandsRun.length, 0);
});
function spawn(cmd, args) {
commandsRun.push(cmd);
return asyncStub;
}
var install = proxyquire('../lib/actions/install', {
child_process: {spawn: spawn}
});
install.installDependencies.call(this.dummy, { skipInstall: true });
assert.deepEqual(commandsRun.length, 0);
it('npmInstall should run without callback', function () {
this.dummy.npmInstall('yo', { save: true });
assert.deepEqual(this.commandsRun.length, 1);
});
});
});
});

@@ -97,2 +97,15 @@ /*global describe, before, it */

});
it('should raise an error if required arguments are not provided', function (done) {
var dummy = new generators.Base([], {
env: this.env,
resolved: 'dummy:all'
}).on('error', function (ev) {
done();
});
dummy.argument('foo', {
required: true
});
});
});

@@ -99,0 +112,0 @@

@@ -5,2 +5,3 @@ /*global describe, before, it */

var assert = require('assert');
var proxyquire = require('proxyquire');
var conflicter = require('../lib/util/conflicter');

@@ -82,2 +83,37 @@

});
describe('conflicter#_ask', function () {
var promptMock = {
prompt: function (config, cb) {
cb(this.err, { overwrite: this.answer });
},
err: null,
answer: null
};
before(function () {
this.conflicter = proxyquire('../lib/util/conflicter', {
'../actions/prompt': promptMock.prompt.bind(promptMock)
});
});
it('skips on "n answer"', function (done) {
promptMock.answer = 'n';
this.conflicter._ask('/tmp/file', 'my file contents', function (err, result) {
assert.strictEqual(err, null);
assert(result, 'skip');
done();
});
});
it('enables force on "a" answer', function (done) {
promptMock.answer = 'a';
this.conflicter._ask('/tmp/file', 'my file contents', function (err, result) {
assert.strictEqual(err, null);
assert(result, 'force');
assert(this.conflicter.force);
done();
}.bind(this));
});
});
});

@@ -9,3 +9,2 @@ /*global it, describe, before */

var events = require('events');
var eol = require('os').EOL;

@@ -180,3 +179,3 @@ var Base = generators.Base;

assert.equal(fs.readFileSync(filename, 'utf8'), "var hey = 'hey';" + eol);
assert.equal(fs.readFileSync(filename, 'utf8'), "var hey = 'hey';" + '\n');
done();

@@ -183,0 +182,0 @@ });

@@ -1,2 +0,2 @@

module.exports = function(grunt) {
module.exports = function (grunt) {
grunt.initConfig({

@@ -3,0 +3,0 @@ "dummy": true

@@ -1,2 +0,2 @@

module.exports = function(grunt) {
module.exports = function (grunt) {
grunt.initConfig({

@@ -3,0 +3,0 @@ "dummy": true

@@ -1,2 +0,2 @@

/*global describe before it */
/*global describe, before, it */
var path = require('path');

@@ -31,2 +31,11 @@ var fs = require('fs');

it('should generate block with multiple search paths', function () {
var res = wiring.generateBlock('js', 'main.js', [
'path/file1.js',
'path/file2.js'
], ['.tmp/', 'dist/']);
assert.equal(res.trim(), '<!-- build:js({.tmp/,dist/}) main.js -->\npath/file1.js,path/file2.js <!-- endbuild -->');
});
it('should append js files to an html string', function () {

@@ -33,0 +42,0 @@ var html = '<html><body></body></html>';

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