Skip to content

Commit

Permalink
Merge branch 'fix/chalk'
Browse files Browse the repository at this point in the history
  • Loading branch information
tamorim committed Mar 1, 2016
2 parents c8eb3a9 + b4a51f0 commit fb974d3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 32 deletions.
5 changes: 3 additions & 2 deletions src/bin/vtex-login.js
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bin/vtex-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/bin/vtex-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions src/lib/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
Expand Down Expand Up @@ -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'));
}
});
});
Expand Down Expand Up @@ -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'));
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/lib/auth/utils.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/meta.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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));
});
}
5 changes: 3 additions & 2 deletions src/lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);

Expand Down
27 changes: 14 additions & 13 deletions src/lib/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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 = {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions src/lib/webpack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import webpack from 'webpack';
import express from 'express';
import httpProxy from 'http-proxy';
import chalk from 'chalk';

class WebpackRunner {
constructor() {
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit fb974d3

Please sign in to comment.