diff --git a/src/bin/vtex-login.js b/src/bin/vtex-login.js index 7630e155a..98c1352fe 100644 --- a/src/bin/vtex-login.js +++ b/src/bin/vtex-login.js @@ -1,15 +1,16 @@ #!/usr/bin/env node import { login } from '../lib/auth'; +import chalk from 'chalk'; function showSuccessMessage(data) { - console.log('\n', ('Logged in as ' + data.email).green); + console.log('\n', chalk.green('Logged in as ' + data.email)); } function handleError(err) { let error = err && err.message ? err.message : err; console.log(''); - console.error(error.red); + console.error(chalk.red(error)); process.exit(1); } diff --git a/src/bin/vtex-publish.js b/src/bin/vtex-publish.js index ccc1e8c94..3738b5b7e 100644 --- a/src/bin/vtex-publish.js +++ b/src/bin/vtex-publish.js @@ -16,7 +16,7 @@ function showSuccessMessage(app) { } function handleError(error) { - console.error('\nFailed to publish app\n'.bold.red); + console.error(chalk.bold.red('\nFailed to publish app\n')); const errorObj = JSON.parse(error.body); if (errorObj.message) { diff --git a/src/bin/vtex-watch.js b/src/bin/vtex-watch.js index d41b3b27a..69fe37496 100644 --- a/src/bin/vtex-watch.js +++ b/src/bin/vtex-watch.js @@ -39,9 +39,9 @@ function runWebpack() { } function handleError(error) { - console.error('\nFailed to start watch'.red); + console.error(chalk.red('\nFailed to start watch')); if (error.code === 'ENOTFOUND') { - console.log((`Address ${error.hostname} not found`).red + '\nAre you online?'.yellow); + console.log(chalk.red(`Address ${error.hostname} not found`) + chalk.yellow('\nAre you online?')); } else { console.log(error); } diff --git a/src/lib/auth/login.js b/src/lib/auth/login.js index 72794fdfe..b6b810188 100644 --- a/src/lib/auth/login.js +++ b/src/lib/auth/login.js @@ -5,6 +5,7 @@ import fs from 'fs'; import prompt from 'prompt'; import { getErrorMessage } from './utils'; import { getCredentialsPath } from './credentials'; +import chalk from 'chalk'; export function askAccountAndLogin() { let deferred = Q.defer(); @@ -26,7 +27,7 @@ export function askAccountAndLogin() { prompt.delimiter = ''; prompt.start(); - console.log('Please log in with your VTEX credentials:\n'.green + + console.log(chalk.green('Please log in with your VTEX credentials:\n') + 'account - The store account you want to be developing on\n' + 'login - Your VTEX registered email\n' + 'password - Your VTEX registered password\n'); @@ -155,11 +156,11 @@ function getAuthenticationToken(email, password) { try { let auth = JSON.parse(body); if (auth.authStatus !== 'Success') { - deferred.reject(('Authentication has failed with status ' + auth.authStatus).red); + deferred.reject(chalk.red('Authentication has failed with status ' + auth.authStatus)); } deferred.resolve(auth.authCookie.Value); } catch (_error) { - deferred.reject('Invalid JSON while authenticating with VTEX ID'.red); + deferred.reject(chalk.red('Invalid JSON while authenticating with VTEX ID')); } }); }); @@ -237,11 +238,11 @@ function getEmailAuthenticationToken(email, token, code) { try { let auth = JSON.parse(body); if (auth.authStatus !== 'Success') { - deferred.reject(('Authentication has failed with status ' + auth.authStatus).red); + deferred.reject(chalk.red('Authentication has failed with status ' + auth.authStatus)); } return deferred.resolve(auth.authCookie.Value); } catch (_error) { - return deferred.reject('Invalid JSON while authenticating with VTEX ID'.red); + return deferred.reject(chalk.red('Invalid JSON while authenticating with VTEX ID')); } }); diff --git a/src/lib/auth/utils.js b/src/lib/auth/utils.js index 72ff1c003..803bfdb69 100644 --- a/src/lib/auth/utils.js +++ b/src/lib/auth/utils.js @@ -1,9 +1,10 @@ import httpStatusName from 'http-status-name'; +import chalk from 'chalk'; export function getErrorMessage(error, response, action) { if (error) { if (error.code === 'ENOTFOUND') { - return ('Address ' + error.hostname + ' not found').red + '\nAre you online?'.yellow; + return (chalk.red('Address ' + error.hostname + ' not found') + chalk.yellow('\nAre you online?'); } return error; } diff --git a/src/lib/meta.js b/src/lib/meta.js index 507dc283e..a2318cda8 100644 --- a/src/lib/meta.js +++ b/src/lib/meta.js @@ -1,6 +1,7 @@ import path from 'path'; import fs from 'fs'; import Q from 'q'; +import chalk from 'chalk'; function readAppMetadata() { const metaPath = path.resolve(process.cwd(), 'meta.json'); @@ -34,6 +35,6 @@ export function getAppMetadata() { .then(JSON.parse) .then(validateMetadata) .catch(function(error) { - throw new Error(error.message.red); + throw new Error(chalk.red(error.message)); }); } diff --git a/src/lib/publish.js b/src/lib/publish.js index 054cc7c5a..79c84df6c 100644 --- a/src/lib/publish.js +++ b/src/lib/publish.js @@ -2,9 +2,10 @@ import Q from 'q'; import request from 'request'; import fs from 'fs'; import { compressFiles, getRequestConfig, getZipFilePath, removeZipFile } from './file-manager'; +import chalk from 'chalk'; function pushApp(app, version, vendor, credentials) { - console.log('Compressing files...'.grey); + console.log(chalk.grey('Compressing files...')); return compressFiles(app, version).then(() => { return getRequestConfig().then((config) => { @@ -26,7 +27,7 @@ function pushApp(app, version, vendor, credentials) { } }; - console.log('Sending files...'.grey); + console.log(chalk.grey('Sending files...')); request(options, (error, response) => { if (error) return deferred.reject(error); diff --git a/src/lib/watch.js b/src/lib/watch.js index 383f66e32..160f67ad6 100644 --- a/src/lib/watch.js +++ b/src/lib/watch.js @@ -7,6 +7,7 @@ import { listFiles } from './file-manager'; import tinylr from 'tiny-lr'; import crypto from 'crypto'; import net from 'net'; +import chalk from 'chalk'; class Watcher { constructor(app, vendor, credentials, isServerSet) { @@ -189,9 +190,9 @@ class Watcher { if (refresh) options.url += '?resync=true'; if (refresh) { - console.log('Synchronizing...'.blue); + console.log(chalk.blue('Synchronizing...')); } else { - console.log('Changes detected, uploading...'.blue); + console.log(chalk.blue('Changes detected, uploading...')); } return request(options, (error, response) => { @@ -208,21 +209,21 @@ class Watcher { return change.path; }); - let linkMsg = 'Your URL: '.green; + let linkMsg = chalk.green('Your URL: '); if (paths.length > 0) { - console.log('\n... files uploaded\n'.green); + console.log(chalk.green('\n... files uploaded\n')); } else { - console.log('\nEverything is up to date\n'.green); + console.log(chalk.green('\nEverything is up to date\n')); } if (this.isServerSet === 'true') { - linkMsg += ('http://' + this.credentials.account + '.local.myvtex.com:3000/').blue.underline; + linkMsg += chalk.blue.underline('http://' + this.credentials.account + '.local.myvtex.com:3000/'); } else { - linkMsg += ('http://' + this.credentials.account + '.beta.myvtex.com/').blue.underline; + linkMsg += chalk.blue.underline('http://' + this.credentials.account + '.beta.myvtex.com/'); } - linkMsg += ('?workspace=sb_' + this.sandbox + '\n').blue.underline; + linkMsg += chalk.blue.underline('?workspace=sb_' + this.sandbox + '\n'); console.log(linkMsg); let options = { @@ -244,16 +245,16 @@ class Watcher { batchChanges.forEach((change) => { if (change.action === 'save') { - console.log('U'.yellow + (' ' + change.path)); + console.log(chalk.yellow('U') + (' ' + change.path)); } else if (change.action === 'remove') { - console.log('D'.red + (' ' + change.path)); + console.log(chalk.red('D') + (' ' + change.path)); } else { - console.log(change.action.grey + ' ' + change.path); + console.log(chalk.grey(change.action) + ' ' + change.path); } if (change.warnings) { change.warnings.forEach((warning) => { - results.push(console.log(' ' + warning.yellow)); + results.push(console.log(' ' + chalk.yellow(warning))); }); } else { results.push(void 0); @@ -264,7 +265,7 @@ class Watcher { } changeSendError = (error, response) => { - console.error('Error sending files'.red); + console.error(chalk.red('Error sending files')); if (error) console.error(error); if (response) { diff --git a/src/lib/webpack.js b/src/lib/webpack.js index a14bbdeb5..bed5bc1f8 100644 --- a/src/lib/webpack.js +++ b/src/lib/webpack.js @@ -1,6 +1,7 @@ import webpack from 'webpack'; import express from 'express'; import httpProxy from 'http-proxy'; +import chalk from 'chalk'; class WebpackRunner { constructor() { @@ -10,10 +11,10 @@ class WebpackRunner { if (err.code === 'MODULE_NOT_FOUND') { let pkgName = err.toString().match(/'(.*)'/)[1]; if (pkgName.indexOf('webpack.config.js') !== -1) { - console.log('webpack.config.js not found'.bold.yellow); + console.log(chalk.bold.yellow('webpack.config.js not found')); } else { - console.log(err.toString().bold.red); - console.log('Did you install ' + pkgName.yellow + '?'); + console.log(chalk.bold.red(err.toString())); + console.log('Did you install ' + chalk.yellow(pkgName) + '?'); } } else { console.error('Error while trying to read ' + process.cwd() + '/webpack.config.js'); @@ -88,8 +89,8 @@ class WebpackRunner { }) .on('error', (err) => { if (err.code === 'EADDRINUSE') { - console.log(('Server port ' + port + ' already in use').red); - console.log('(maybe another `vtex watch -s` is running?)'.yellow); + console.log(chalk.red('Server port ' + port + ' already in use')); + console.log(chalk.yellow('(maybe another `vtex watch -s` is running?)')); return process.exit(1); } else if (err) { console.log('Error while trying to start a server');