Skip to content

Commit

Permalink
Setup Prettier + bump dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jun 30, 2018
1 parent 91b297c commit 5fca282
Show file tree
Hide file tree
Showing 24 changed files with 2,756 additions and 2,741 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output
test/fixtures
30 changes: 9 additions & 21 deletions lib/actions/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,20 @@ const help = module.exports;
* Tries to get the description from a USAGE file one folder above the
* source root otherwise uses a default description
*/
help.help = function () {
help.help = function() {
const filepath = path.resolve(this.sourceRoot(), '../USAGE');
const exists = fs.existsSync(filepath);

let out = [
'Usage:',
' ' + this.usage(),
''
];
let out = ['Usage:', ' ' + this.usage(), ''];

// Build options
if (Object.keys(this._options).length > 0) {
out = out.concat([
'Options:',
this.optionsHelp(),
''
]);
out = out.concat(['Options:', this.optionsHelp(), '']);
}

// Build arguments
if (this._arguments.length > 0) {
out = out.concat([
'Arguments:',
this.argumentsHelp(),
''
]);
out = out.concat(['Arguments:', this.argumentsHelp(), '']);
}

// Append USAGE file is any
Expand All @@ -64,7 +52,7 @@ function formatArg(config) {
* Output usage information for this given generator, depending on its arguments
* or options
*/
help.usage = function () {
help.usage = function() {
const options = Object.keys(this._options).length ? '[options]' : '';
let name = this.options.namespace;
let args = '';
Expand All @@ -89,7 +77,7 @@ help.usage = function () {
* @param {String} description
*/

help.desc = function (description) {
help.desc = function(description) {
this.description = description || '';
return this;
};
Expand All @@ -98,7 +86,7 @@ help.desc = function (description) {
* Get help text for arguments
* @returns {String} Text of options in formatted table
*/
help.argumentsHelp = function () {
help.argumentsHelp = function() {
const rows = this._arguments.map(config => {
return [
'',
Expand All @@ -116,7 +104,7 @@ help.argumentsHelp = function () {
* Get help text for options
* @returns {String} Text of options in formatted table
*/
help.optionsHelp = function () {
help.optionsHelp = function() {
const options = _.reject(this._options, x => x.hide);

const rows = options.map(opt => {
Expand All @@ -125,7 +113,7 @@ help.optionsHelp = function () {
opt.alias ? `-${opt.alias}, ` : '',
`--${opt.name}`,
opt.description ? `# ${opt.description}` : '',
(opt.default !== undefined && opt.default !== '') ? 'Default: ' + opt.default : ''
opt.default !== undefined && opt.default !== '' ? 'Default: ' + opt.default : ''
];
});

Expand Down
111 changes: 62 additions & 49 deletions lib/actions/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const install = module.exports;
* @return {Promise} Resolved on installation success, rejected otherwise
*/

install.runInstall = function (installer, paths, options, spawnOptions) {
install.runInstall = function(installer, paths, options, spawnOptions) {
return new Promise((resolve, reject) => {
options = options || {};
spawnOptions = spawnOptions || {};
Expand All @@ -46,31 +46,44 @@ install.runInstall = function (installer, paths, options, spawnOptions) {

// Return early if we're skipping installation
if (this.options.skipInstall) {
this.log('Skipping install command: ' + chalk.yellow(installer + ' ' + args.join(' ')));
this.log(
'Skipping install command: ' + chalk.yellow(installer + ' ' + args.join(' '))
);
return resolve();
}

this.env.runLoop.add('install', done => {
this.emit(`${installer}Install`, paths);
this.spawnCommand(installer, args, spawnOptions)
.on('error', err => {
this.log(chalk.red('Could not finish installation. \n') +
'Please install ' + installer + ' with ' +
chalk.yellow('npm install -g ' + installer) + ' and try again. \n' +
'If ' + installer + ' is already installed, try running the following command manually: ' + chalk.yellow(installer + ' ' + args.join(' '))
);
reject(err);
done();
})
.on('exit', () => {
this.emit(`${installer}Install:end`, paths);
resolve();
done();
});
}, {
once: installer + ' ' + args.join(' '),
run: false
});
this.env.runLoop.add(
'install',
done => {
this.emit(`${installer}Install`, paths);
this.spawnCommand(installer, args, spawnOptions)
.on('error', err => {
this.log(
chalk.red('Could not finish installation. \n') +
'Please install ' +
installer +
' with ' +
chalk.yellow('npm install -g ' + installer) +
' and try again. \n' +
'If ' +
installer +
' is already installed, try running the following command manually: ' +
chalk.yellow(installer + ' ' + args.join(' '))
);
reject(err);
done();
})
.on('exit', () => {
this.emit(`${installer}Install:end`, paths);
resolve();
done();
});
},
{
once: installer + ' ' + args.join(' '),
run: false
}
);
});
};

Expand All @@ -97,15 +110,17 @@ install.runInstall = function (installer, paths, options, spawnOptions) {
* @param {Boolean} [options.skipMessage=false] - whether to log the used commands
* @return {Promise} Resolved once done, rejected if errors
*/
install.installDependencies = function (options) {
install.installDependencies = function(options) {
options = options || {};
const commands = [];
const msg = {
commands: [],
template: _.template('\n\nI\'m all done. ' +
'<%= skipInstall ? "Just run" : "Running" %> <%= commands %> ' +
'<%= skipInstall ? "" : "for you " %>to install the required dependencies.' +
'<% if (!skipInstall) { %> If this fails, try running the command yourself.<% } %>\n\n')
template: _.template(
"\n\nI'm all done. " +
'<%= skipInstall ? "Just run" : "Running" %> <%= commands %> ' +
'<%= skipInstall ? "" : "for you " %>to install the required dependencies.' +
'<% if (!skipInstall) { %> If this fails, try running the command yourself.<% } %>\n\n'
)
};

const getOptions = options => {
Expand All @@ -115,41 +130,39 @@ install.installDependencies = function (options) {
if (options.npm !== false) {
msg.commands.push('npm install');
commands.push(cb => {
this.npmInstall(null, getOptions(options.npm)).then(
val => cb(null, val),
cb
);
this.npmInstall(null, getOptions(options.npm)).then(val => cb(null, val), cb);
});
}

if (options.yarn) {
msg.commands.push('yarn install');
commands.push(cb => {
this.yarnInstall(null, getOptions(options.yarn)).then(
val => cb(null, val),
cb
);
this.yarnInstall(null, getOptions(options.yarn)).then(val => cb(null, val), cb);
});
}

if (options.bower !== false) {
msg.commands.push('bower install');
commands.push(cb => {
this.bowerInstall(null, getOptions(options.bower)).then(
val => cb(null, val),
cb
);
this.bowerInstall(null, getOptions(options.bower)).then(val => cb(null, val), cb);
});
}

assert(msg.commands.length, 'installDependencies needs at least one of `npm`, `bower` or `yarn` to run.');
assert(
msg.commands.length,
'installDependencies needs at least one of `npm`, `bower` or `yarn` to run.'
);

if (!options.skipMessage) {
const tplValues = _.extend({
skipInstall: false
}, this.options, {
commands: chalk.yellow.bold(msg.commands.join(' && '))
});
const tplValues = _.extend(
{
skipInstall: false
},
this.options,
{
commands: chalk.yellow.bold(msg.commands.join(' && '))
}
);
this.log(msg.template(tplValues));
}

Expand All @@ -173,7 +186,7 @@ install.installDependencies = function (options) {
* @param {Object} [spawnOptions] Options to pass `child_process.spawn`.
* @return {Promise} Resolved if install successful, rejected otherwise
*/
install.bowerInstall = function (cmpnt, options, spawnOptions) {
install.bowerInstall = function(cmpnt, options, spawnOptions) {
return this.runInstall('bower', cmpnt, options, spawnOptions);
};

Expand All @@ -187,7 +200,7 @@ install.bowerInstall = function (cmpnt, options, spawnOptions) {
* @param {Object} [spawnOptions] Options to pass `child_process.spawn`.
* @return {Promise} Resolved if install successful, rejected otherwise
*/
install.npmInstall = function (pkgs, options, spawnOptions) {
install.npmInstall = function(pkgs, options, spawnOptions) {
return this.runInstall('npm', pkgs, options, spawnOptions);
};

Expand All @@ -201,6 +214,6 @@ install.npmInstall = function (pkgs, options, spawnOptions) {
* @param {Object} [spawnOptions] Options to pass `child_process.spawn`.
* @return {Promise} Resolved if install successful, rejected otherwise
*/
install.yarnInstall = function (pkgs, options, spawnOptions) {
install.yarnInstall = function(pkgs, options, spawnOptions) {
return this.runInstall('yarn', pkgs, options, spawnOptions);
};
4 changes: 2 additions & 2 deletions lib/actions/spawn-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const spawnCommand = module.exports;
*/
spawnCommand.spawnCommand = (command, args, opt) => {
opt = opt || {};
return spawn(command, args, _.defaults(opt, {stdio: 'inherit'}));
return spawn(command, args, _.defaults(opt, { stdio: 'inherit' }));
};

/**
Expand All @@ -29,5 +29,5 @@ spawnCommand.spawnCommand = (command, args, opt) => {
*/
spawnCommand.spawnCommandSync = (command, args, opt) => {
opt = opt || {};
return spawn.sync(command, args, _.defaults(opt, {stdio: 'inherit'}));
return spawn.sync(command, args, _.defaults(opt, { stdio: 'inherit' }));
};
4 changes: 2 additions & 2 deletions lib/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ user.git.name = () => {
}

if (shell.which('git')) {
name = shell.exec('git config --get user.name', {silent: true}).stdout.trim();
name = shell.exec('git config --get user.name', { silent: true }).stdout.trim();
nameCache.set(process.cwd(), name);
}

Expand All @@ -47,7 +47,7 @@ user.git.email = () => {
}

if (shell.which('git')) {
email = shell.exec('git config --get user.email', {silent: true}).stdout.trim();
email = shell.exec('git config --get user.email', { silent: true }).stdout.trim();
emailCache.set(process.cwd(), email);
}

Expand Down
Loading

0 comments on commit 5fca282

Please sign in to comment.