Skip to content

Commit

Permalink
Initial ES2015ification
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus authored and SBoudrias committed Mar 5, 2017
1 parent 80863b0 commit d535bac
Show file tree
Hide file tree
Showing 23 changed files with 641 additions and 638 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
sudo: false
language: node_js
node_js:
- 0.10
- 0.12
- 4
- 6
- node
Expand Down
4 changes: 2 additions & 2 deletions benchmark/module.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global suite, bench */
'use strict';

suite('yeoman-generator module', function () {
bench('require', function () {
suite('yeoman-generator module', () => {
bench('require', () => {
require('..'); // eslint-disable-line import/no-unassigned-import
delete require.cache[require.resolve('..')];
});
Expand Down
28 changes: 14 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
'use strict';
var path = require('path');
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');
var coveralls = require('gulp-coveralls');
const path = require('path');
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const nsp = require('gulp-nsp');
const plumber = require('gulp-plumber');
const coveralls = require('gulp-coveralls');

gulp.task('nsp', function (cb) {
gulp.task('nsp', cb => {
nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('pre-test', function () {
gulp.task('pre-test', () => {
return gulp.src([
'lib/**/*.js'
])
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire());
});

gulp.task('test', ['pre-test'], function (cb) {
var mochaErr;
gulp.task('test', ['pre-test'], cb => {
let mochaErr;

gulp.src('test/*.js')
.pipe(plumber())
.pipe(mocha({reporter: 'spec', timeout: 3000}))
.on('error', function (err) {
.on('error', err => {
mochaErr = err;
})
.pipe(istanbul.writeReports())
.on('end', function () {
.on('end', () => {
cb(mochaErr);
});
});

gulp.task('coveralls', ['test'], function () {
gulp.task('coveralls', ['test'], () => {
if (!process.env.CI) {
return;
}
Expand Down
34 changes: 17 additions & 17 deletions lib/actions/help.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
'use strict';
var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var table = require('text-table');
var pathExists = require('path-exists');
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const table = require('text-table');
const pathExists = require('path-exists');

/**
* @mixin
* @alias actions/help
*/
var help = module.exports;
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 () {
var filepath = path.join(this.sourceRoot(), '../USAGE');
var exists = pathExists.sync(filepath);
var out = [
const filepath = path.join(this.sourceRoot(), '../USAGE');
const exists = pathExists.sync(filepath);
let out = [
'Usage:',
' ' + this.usage(),
''
Expand Down Expand Up @@ -52,7 +52,7 @@ help.help = function () {
};

function formatArg(config) {
var arg = '<' + config.name + '>';
let arg = '<' + config.name + '>';

if (!config.required) {
arg = '[' + arg + ']';
Expand All @@ -67,16 +67,16 @@ function formatArg(config) {
*/

help.usage = function () {
var options = Object.keys(this._options).length ? '[options]' : '';
var name = ' ' + this.options.namespace;
var args = '';
const options = Object.keys(this._options).length ? '[options]' : '';
let name = ' ' + this.options.namespace;
let args = '';

if (this._arguments.length > 0) {
args = this._arguments.map(formatArg).join(' ');
}

name = name.replace(/^yeoman:/, '');
var out = 'yo' + name + ' ' + options + ' ' + args;
let out = 'yo' + name + ' ' + options + ' ' + args;

if (this.description) {
out += '\n\n' + this.description;
Expand All @@ -101,7 +101,7 @@ help.desc = function (description) {
* @returns {String} Text of options in formatted table
*/
help.argumentsHelp = function () {
var rows = this._arguments.map(function (config) {
const rows = this._arguments.map(config => {
return [
'',
config.name ? config.name : '',
Expand All @@ -119,11 +119,11 @@ help.argumentsHelp = function () {
* @returns {String} Text of options in formatted table
*/
help.optionsHelp = function () {
var options = _.reject(this._options, function (el) {
const options = _.reject(this._options, el => {
return el.hide;
});

var rows = options.map(function (opt) {
const rows = options.map(opt => {
return [
'',
opt.alias ? '-' + opt.alias + ', ' : '',
Expand Down
42 changes: 21 additions & 21 deletions lib/actions/install.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';
var assert = require('assert');
var _ = require('lodash');
var dargs = require('dargs');
var async = require('async');
var chalk = require('chalk');
const assert = require('assert');
const _ = require('lodash');
const dargs = require('dargs');
const async = require('async');
const chalk = require('chalk');

/**
* @mixin
* @alias actions/install
*/
var install = module.exports;
const install = module.exports;

/**
* Combine package manager cmd line arguments and run the `install` command.
Expand All @@ -36,7 +36,7 @@ install.runInstall = function (installer, paths, options, cb, spawnOptions) {
cb = cb || function () {};
paths = Array.isArray(paths) ? paths : (paths && paths.split(' ')) || [];

var args = ['install'].concat(paths).concat(dargs(options));
let args = ['install'].concat(paths).concat(dargs(options));

// Yarn uses the `add` command to specifically add a package to a project.
if (installer === 'yarn' && paths.length > 0) {
Expand All @@ -54,22 +54,22 @@ install.runInstall = function (installer, paths, options, cb, spawnOptions) {
return this;
}

this.env.runLoop.add('install', function (done) {
this.env.runLoop.add('install', done => {
this.emit(installer + 'Install', paths);
this.spawnCommand(installer, args, spawnOptions)
.on('error', function (err) {
.on('error', err => {
console.log(chalk.red('Could not finish installation. \n') +
'Please install ' + installer + ' with ' +
chalk.yellow('npm install -g ' + installer) + ' and try again.'
);
cb(err);
})
.on('exit', function (err) {
.on('exit', err => {
this.emit(installer + 'Install:end', paths);
cb(err);
done();
}.bind(this));
}.bind(this), {once: installer + ' ' + args.join(' '), run: false});
});
}, {once: installer + ' ' + args.join(' '), run: false});

return this;
};
Expand Down Expand Up @@ -97,8 +97,8 @@ install.runInstall = function (installer, paths, options, cb, spawnOptions) {

install.installDependencies = function (options) {
options = options || {};
var commands = [];
var msg = {
const commands = [];
const msg = {
commands: [],
template: _.template('\n\nI\'m all done. ' +
'<%= skipInstall ? "Just run" : "Running" %> <%= commands %> ' +
Expand All @@ -114,29 +114,29 @@ install.installDependencies = function (options) {

if (options.npm !== false) {
msg.commands.push('npm install');
commands.push(function (cb) {
commands.push(cb => {
this.npmInstall(null, null, cb);
}.bind(this));
});
}

if (options.yarn === true) {
msg.commands.push('yarn install');
commands.push(function (cb) {
commands.push(cb => {
this.yarnInstall(null, null, cb);
}.bind(this));
});
}

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

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

if (!options.skipMessage) {
var tplValues = _.extend({
const tplValues = _.extend({
skipInstall: false
}, this.options, {
commands: chalk.yellow.bold(msg.commands.join(' && '))
Expand Down
6 changes: 3 additions & 3 deletions lib/actions/spawn-command.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
var _ = require('lodash');
var spawn = require('cross-spawn');
const _ = require('lodash');
const spawn = require('cross-spawn');

/**
* @mixin
* @alias actions/spawn-command
*/
var spawnCommand = module.exports;
const spawnCommand = module.exports;

/**
* Normalize a command across OS and spawn it (asynchronously).
Expand Down
16 changes: 8 additions & 8 deletions lib/actions/user.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';
var shell = require('shelljs');
var githubUsername = require('github-username');
const shell = require('shelljs');
const githubUsername = require('github-username');

var nameCache = {};
var emailCache = {};
const nameCache = {};
const emailCache = {};

/**
* @mixin
* @alias actions/user
*/
var user = module.exports;
const user = module.exports;

user.git = {};
user.github = {};
Expand All @@ -20,7 +20,7 @@ user.github = {};
*/

user.git.name = function () {
var name = nameCache[process.cwd()];
let name = nameCache[process.cwd()];

if (name) {
return name;
Expand All @@ -40,7 +40,7 @@ user.git.name = function () {
*/

user.git.email = function () {
var email = emailCache[process.cwd()];
let email = emailCache[process.cwd()];

if (email) {
return email;
Expand All @@ -59,7 +59,7 @@ user.git.email = function () {
*/

user.github.username = function (cb) {
var promise = githubUsername(user.git.email());
const promise = githubUsername(user.git.email());

if (cb) {
promise.then(
Expand Down
Loading

0 comments on commit d535bac

Please sign in to comment.