Skip to content

Commit 690a447

Browse files
authored
chore(): replace colors module with chalk and update all usages. (#1605)
1 parent 26486d2 commit 690a447

30 files changed

+197
-241
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ module.exports = {
33
node: true,
44
commonjs: true
55
},
6+
plugins: [
7+
'no-use-extend-native'
8+
],
69
extends: 'eslint:recommended',
710
rules: {
11+
'no-use-extend-native/no-use-extend-native': 2,
812
eqeqeq: [
913
"error",
1014
"smart"

lib/cli.js

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require('colors');
2-
31
var Cli = {};
42
var IonicAppLib = require('ionic-app-lib');
53
var IonicStats = require('./utils/stats');
@@ -19,6 +17,7 @@ var log = Logging.logger;
1917
var Q = require('q');
2018
var helpUtil = require('./utils/help');
2119
var EOL = require('os').EOL;
20+
var chalk = require('chalk');
2221

2322
Cli.ALL_TASKS = Tasks;
2423
Cli.IONIC_DASH = 'https://apps.ionic.io';
@@ -154,7 +153,7 @@ Cli.run = function run(processArgv) {
154153
// For v2, print a warning as this is most likely not what they want
155154
if (!fs.existsSync('node_modules')) {
156155
if (argv.v2) {
157-
log.warn('WARN: No node_modules directory found, do you need to run npm install?'.yellow);
156+
log.warn(chalk.yellow('WARN: No node_modules directory found, do you need to run npm install?'));
158157
}
159158
log.debug('node_modules directory not found, not running gulp hooks');
160159

@@ -173,7 +172,7 @@ Cli.run = function run(processArgv) {
173172
log.info('\nDo you need to run `npm install`?\n');
174173
process.exit(1);
175174
}
176-
log.error('\nThere is an error in your gulpfile: '.red);
175+
log.error(chalk.red('\nThere is an error in your gulpfile: '));
177176
log.error(e.stack + '\n');
178177
process.exit(1);
179178
}
@@ -188,6 +187,7 @@ Cli.run = function run(processArgv) {
188187
}
189188

190189
if (!gulpLoaded) {
190+
191191
// warn if no build file and it's a command that requires a build step
192192
// but still run the command with no hooks
193193
if (Cli.isBuildCommand(taskName) && argv.v2 && !npmScripts) {
@@ -216,8 +216,8 @@ Cli.runWithGulp = function runWithGulp(argv, taskInstance, rawCliArguments) {
216216
} catch (e) {
217217

218218
// Empty gulpfile (or one that doesn't require gulp?), and no gulp
219-
log.error('\nGulpfile detected, but gulp is not installed'.red);
220-
log.error('Do you need to run `npm install`?\n'.red);
219+
log.error(chalk.red('\nGulpfile detected, but gulp is not installed'));
220+
log.error(chalk.red('Do you need to run `npm install`?\n'));
221221
return process.exit(1);
222222
}
223223

@@ -231,9 +231,9 @@ Cli.runWithGulp = function runWithGulp(argv, taskInstance, rawCliArguments) {
231231
beforeHookPromise = Cli.runGulpHook(gulp, beforeHook);
232232

233233
} else if (Cli.isBuildCommand(cmdName) && argv.v2) {
234-
log.warn(('WARN: No \'' + beforeHook + '\' gulp task found!').yellow);
235-
log.warn(('If your app requires a build step, you may want to ensure it runs before ' +
236-
cmdName + '.\n').yellow);
234+
log.warn(chalk.yellow('WARN: No \'' + beforeHook + '\' gulp task found!'));
235+
log.warn(chalk.yellow('If your app requires a build step, you may want to ensure it runs before ' +
236+
cmdName + '.\n'));
237237
}
238238

239239
// run beforeHook
@@ -333,7 +333,7 @@ Cli.runNpmHook = function runNpmHook(hook) {
333333
spawned.stdout.pipe(process.stdout);
334334
spawned.stdout.on('data', function(data) {
335335
var dataLines = data.toString().split(EOL);
336-
for (var i = 0; i < dataLines.length; i++) {
336+
for (var i = 0; i < dataLines.length; i += 1) {
337337
if (dataLines[i].length) {
338338
if (dataLines[i].indexOf('watch ready') > -1) {
339339
return q.resolve();
@@ -348,7 +348,7 @@ Cli.runNpmHook = function runNpmHook(hook) {
348348
}
349349
return q.resolve();
350350
});
351-
351+
352352
// If this process ends ensure that we killed the spawned child
353353
process.on('exit', function() {
354354
spawned.kill();
@@ -367,8 +367,6 @@ Cli.loadNpmScripts = function loadNpmScripts() {
367367
} catch (e) {
368368
throw e;
369369
}
370-
371-
return undefined;
372370
};
373371

374372
Cli.logEvents = function logEvents(gulpInst, finalTaskNames) {
@@ -379,14 +377,14 @@ Cli.logEvents = function logEvents(gulpInst, finalTaskNames) {
379377

380378
// TODO: batch these
381379
// so when 5 tasks start at once it only logs one time with all 5
382-
gutil.log('Starting', '\'' + e.task.cyan + '\'...');
380+
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
383381
});
384382

385383
gulpInst.on('task_stop', function(e) {
386384
var time = prettyTime(e.hrDuration);
387385
gutil.log(
388-
'Finished', '\'' + e.task.cyan + '\'',
389-
'after', time.magenta
386+
'Finished', '\'' + chalk.cyan(e.task) + '\'',
387+
'after', chalk.magenta(time)
390388
);
391389
if (finalTaskNames.indexOf(e.task) > -1) {
392390
log.info();
@@ -397,20 +395,12 @@ Cli.logEvents = function logEvents(gulpInst, finalTaskNames) {
397395
var msg = Cli.formatGulpError(e);
398396
var time = prettyTime(e.hrDuration);
399397
gutil.log(
400-
'\'' + e.task.cyan + '\'',
401-
'errored after'.red,
402-
time.magenta
398+
'\'' + chalk.cyan(e.task) + '\'',
399+
chalk.red('errored after'),
400+
chalk.magenta(time)
403401
);
404402
gutil.log(msg);
405403
});
406-
407-
// gulpInst.on('task_not_found', function(err) {
408-
// gutil.log(
409-
// ('Task \'' + err.task + '\' is not in your gulpfile').red
410-
// );
411-
// gutil.log('Please check the documentation for proper gulpfile formatting');
412-
// process.exit(1);
413-
// });
414404
};
415405

416406
// Format orchestrator errors
@@ -472,13 +462,13 @@ Cli.printVersionWarning = function printVersionWarning(version, npmVersion) {
472462
}
473463

474464
if (npmVersion && npmVersion !== version.trim()) {
475-
log.warn('\n------------------------------------\n'.red);
476-
log.warn('Ionic CLI is out of date:\n'.bold.yellow);
477-
log.warn((' * Locally installed version: ' + version + '\n').yellow);
478-
log.warn((' * Latest version: ' + npmVersion + '\n').yellow);
479-
log.warn((' * https://github.com/driftyco/ionic-cli/blob/master/CHANGELOG.md\n').yellow);
480-
log.warn(' * Run '.yellow + 'npm install -g ionic'.bold + ' to update\n'.yellow);
481-
log.warn('------------------------------------\n\n'.red);
465+
log.warn(chalk.red('\n------------------------------------\n'));
466+
log.warn(chalk.yellow.bold('Ionic CLI is out of date:\n'));
467+
log.warn(chalk.yellow(' * Locally installed version: ' + version + '\n'));
468+
log.warn(chalk.yellow(' * Latest version: ' + npmVersion + '\n'));
469+
log.warn(chalk.yellow(' * https://github.com/driftyco/ionic-cli/blob/master/CHANGELOG.md\n'));
470+
log.warn(chalk.yellow(' * Run ') + chalk.bold('npm install -g ionic') + chalk.yellow(' to update\n'));
471+
log.warn(chalk.red('------------------------------------\n\n'));
482472
}
483473
};
484474

@@ -614,10 +604,10 @@ Cli.printNewsUpdates = function printNewsUpdates(skipNewsCheck) {
614604

615605
for (var i = 0, j = messagesJson.list.length; i < j; i += 1) {
616606
var entry = messagesJson.list[i];
617-
var entryMessage = ['+ ', entry.name, '\n', '+ ', entry.action.blue.bold, '\n+\n'].join('');
607+
var entryMessage = ['+ ', entry.name, '\n', '+ ', chalk.blue.bold(entry.action), '\n+\n'].join('');
618608
log.info(entryMessage);
619609
}
620-
log.info('+---------------------------------------------------------+\n'.green);
610+
log.info(chalk.green('+---------------------------------------------------------+\n'));
621611
} catch (ex) {
622612
q.reject('Error occurred in downloading the CLI messages:', ex);
623613
appLibUtils.fail(ex);
@@ -639,7 +629,7 @@ Cli.gatherInfo = function gatherInfo() {
639629
};
640630

641631
Cli.handleUncaughtExceptions = function handleUncaughtExceptions(err) {
642-
log.error('An uncaught exception occurred and has been reported to Ionic'.red.bold);
632+
log.error(chalk.red.bold('An uncaught exception occurred and has been reported to Ionic'));
643633
var errorMessage = typeof err === 'string' ? err : err.message;
644634
appLibUtils.errorHandler(errorMessage);
645635
process.exit(1);
@@ -655,10 +645,10 @@ Cli.attachErrorHandling = function attachErrorHandling() {
655645
var info = Cli.gatherInfo();
656646
var ionicCliVersion = info.ionic_cli;
657647
if (stack && stack.length > 0) {
658-
process.stderr.write('\n' + stack.bold + '\n\n');
648+
process.stderr.write('\n' + chalk.bold(stack) + '\n\n');
659649
}
660-
process.stderr.write('\n' + errorMessage.bold);
661-
process.stderr.write((' (CLI v' + ionicCliVersion + ')').bold + '\n');
650+
process.stderr.write('\n' + chalk.bold(errorMessage));
651+
process.stderr.write(chalk.bold(' (CLI v' + ionicCliVersion + ')') + '\n');
662652

663653
Info.printInfo(info);
664654
}

lib/ionic/add.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

3-
require('colors');
4-
3+
var chalk = require('chalk');
54
var extend = require('../utils/extend');
65
var childProcess = require('child_process');
76
var IonicAppLib = require('ionic-app-lib');
@@ -31,8 +30,8 @@ function installBowerComponent(componentName) {
3130
} catch (e) {} // eslint-disable-line no-empty
3231

3332
// Error happened, report it.
34-
var errorMessage = 'Bower error, check that "'.red.bold + componentName + '"'.red.bold +
35-
' exists,'.red.bold + '\nor try running "'.red.bold + bowerInstallCommand + '" for more info.'.red.bold;
33+
var errorMessage = chalk.red.bold('Bower error, check that "') + componentName +
34+
chalk.red.bold('" exists,\nor try running "') + bowerInstallCommand + chalk.red.bold('" for more info.');
3635
appLibUtils.fail(errorMessage, 'add');
3736
}
3837

@@ -45,10 +44,10 @@ function installBowerComponent(componentName) {
4544
function run(ionic, argv) {
4645

4746
// This command will be deprecated in the future.
48-
var deprecationMsg = 'This command has been ' + 'deprecated'.red + '. All ' +
47+
var deprecationMsg = 'This command has been ' + chalk.red('deprecated') + '. All ' +
4948
'resources are currently available in NPM and we recommend that you use NPM to manage these.\n' +
5049
'More information is available here: https://github.com/driftyco/ionic-cli/wiki/Migrating-to-NPM-from-bower\n';
51-
log.info(deprecationMsg.bold);
50+
log.info(chalk.bold(deprecationMsg));
5251

5352
if (!bower.checkForBower()) {
5453
appLibUtils.fail(bower.installMessage, 'add');

lib/ionic/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var chalk = require('chalk');
34
var extend = require('../utils/extend');
45
var IonicAppLib = require('ionic-app-lib');
56
var ioLib = IonicAppLib.ioConfig;
@@ -11,7 +12,8 @@ var settings = {
1112
name: 'config',
1213
summary: 'Set configuration variables for your ionic app',
1314
args: {
14-
'<command>': 'set'.yellow + ', ' + 'unset'.yellow + ', ' + 'build'.yellow + ', or ' + 'info'.yellow,
15+
'<command>': chalk.yellow('set') + ', ' +
16+
chalk.yellow('unset') + ', ' + chalk.yellow('build') + ', or ' + chalk.yellow('info'),
1517
'[key]': 'The key to set',
1618
'[value]': 'The value to set'
1719
},

lib/ionic/docs.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var chalk = require('chalk');
34
var prompt = require('prompt');
45
var _ = require('underscore');
56
var extend = require('../utils/extend');
@@ -28,7 +29,7 @@ function list() {
2829
var docsList = IonicDocs.api;
2930

3031
// var i = 0;
31-
log.info('Help Topics'.yellow);
32+
log.info(chalk.yellow('Help Topics'));
3233
_.each(docsList, function(doc) {
3334
var table = new Table({ head: [doc.id] });
3435
var count = 0;
@@ -50,7 +51,7 @@ function list() {
5051
} catch (ex) {
5152
log.error('Error listing docs:', ex);
5253
}
53-
log.info('Type "ionic docs <docname>" to open the help document for that doc.'.blue.bold);
54+
log.info(chalk.blue.bold('Type "ionic docs <docname>" to open the help document for that doc.'));
5455
}
5556

5657
function openDefault() {
@@ -150,7 +151,7 @@ function lookUpCommand(helpDoc) {
150151

151152
function openDoc(topic, doc) {
152153
var url = sanitizeUrl('http://ionicframework.com/docs/api/' + topic + '/' + doc);
153-
log.info('Opening Ionic document:'.green.bold, url.green.bold);
154+
log.info(chalk.green.bold('Opening Ionic document:'), chalk.green.bold(url));
154155
return require('open')(url);
155156
}
156157
}

lib/ionic/emulate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var chalk = require('chalk');
34
var extend = require('../utils/extend');
45
var npmScripts = require('../utils/npmScripts');
56
var os = require('os');
@@ -10,7 +11,7 @@ var log = IonicAppLib.logging.logger;
1011
var cordovaUtils = require('../utils/cordova');
1112

1213
var cordovaRunEmulateOptions = {
13-
'--livereload|-l': 'Live reload app dev files from the device' + ' (beta)'.yellow,
14+
'--livereload|-l': 'Live reload app dev files from the device' + chalk.yellow(' (beta)'),
1415
'--address': 'Use specific address (livereload req.)',
1516
'--port|-p': 'Dev server HTTP port (8100 default, livereload req.)',
1617
'--livereload-port|-r': 'Live Reload port (35729 default, livereload req.)',

lib/ionic/generate.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var path = require('path');
55
var ionicAppLib = require('ionic-app-lib');
66
var appGenerator = require('@ionic/app-generators');
77
var log = ionicAppLib.logging.logger;
8-
var Project = ionicAppLib.project;
98
var fail = ionicAppLib.utils.fail;
109

1110
var settings = {
@@ -34,16 +33,8 @@ function run(ionic, argv) {
3433
return fail('Generators are only available for Ionic 2 projects');
3534
}
3635

37-
var project;
38-
try {
39-
project = Project.load(process.cwd());
40-
} catch (err) {
41-
return fail(err);
42-
}
43-
4436
var generator = argv._[1];
4537
var name = argv._[2]; // TODO support multiple names
46-
var isTS = project.get('typescript') || argv.ts;
4738

4839
if (argv.list) {
4940
appGenerator.printAvailableGenerators();
@@ -117,45 +108,6 @@ function run(ionic, argv) {
117108
}
118109
}
119110

120-
function loadToolingModule() {
121-
122-
// First try node_modules/ionic-angular/tooling
123-
var toolingPath;
124-
var ionicModule;
125-
126-
try {
127-
toolingPath = path.join(process.cwd(), 'node_modules', 'ionic-angular', 'tooling');
128-
ionicModule = require(toolingPath);
129-
} catch (err) {
130-
131-
// if this isn't found, that's fine, check for ionic-framework
132-
if (err.code !== 'MODULE_NOT_FOUND') {
133-
fail('Error when requiring ' + toolingPath + ':\n ' + err);
134-
}
135-
}
136-
137-
// Then try node_modules/ionic-framework/tooling
138-
if (!ionicModule) {
139-
try {
140-
ionicModule = require(path.join(process.cwd(), 'node_modules', 'ionic-framework', 'tooling'));
141-
} catch (err) {
142-
if (err.code === 'MODULE_NOT_FOUND') {
143-
fail('No ionic-angular package found, do you have Ionic installed?');
144-
}
145-
}
146-
}
147-
148-
// Last, try node_modules/ionic-framework (beta.1 and below)
149-
if (!ionicModule) {
150-
try {
151-
ionicModule = require(path.join(process.cwd(), 'node_modules', 'ionic-framework'));
152-
} catch (err) {
153-
fail(err);
154-
}
155-
}
156-
return ionicModule;
157-
}
158-
159111
module.exports = extend(settings, {
160112
run: run
161113
});

lib/ionic/help.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var chalk = require('chalk');
34
var extend = require('../utils/extend');
45
var helpUtil = require('../utils/help');
56

@@ -28,7 +29,7 @@ function run(ionic, argv) {
2829
return helpUtil.printTaskUsage(task, ionic.VERSION);
2930
}
3031

31-
return console.log('Command not found.'.red.bold);
32+
return console.log(chalk.red.bold('Command not found.'));
3233
}
3334

3435
module.exports = extend(settings, {

0 commit comments

Comments
 (0)