Move logWithTime to logUtils

This commit is contained in:
Leonid Logvinov 2018-12-19 15:32:04 +01:00
parent 69de1d05ef
commit 85be2fbf19
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4
5 changed files with 20 additions and 11 deletions

View File

@ -134,18 +134,18 @@ export class Compiler {
} }
public async watchAsync(): Promise<void> { public async watchAsync(): Promise<void> {
console.clear(); // tslint:disable-line:no-console console.clear(); // tslint:disable-line:no-console
utils.logWithTime('Starting compilation in watch mode...'); logUtils.logWithTime('Starting compilation in watch mode...');
const watcher = chokidar.watch('^$', { ignored: /(^|[\/\\])\../ }); const watcher = chokidar.watch('^$', { ignored: /(^|[\/\\])\../ });
const onFileChangedAsync = async () => { const onFileChangedAsync = async () => {
watcher.unwatch('*'); // Stop watching watcher.unwatch('*'); // Stop watching
try { try {
await this.compileAsync(); await this.compileAsync();
utils.logWithTime('Found 0 errors. Watching for file changes.'); logUtils.logWithTime('Found 0 errors. Watching for file changes.');
} catch (err) { } catch (err) {
if (err.typeName === 'CompilationError') { if (err.typeName === 'CompilationError') {
utils.logWithTime(`Found ${err.errorsCount} ${pluralize('error', err.errorsCount)}. Watching for file changes.`); logUtils.logWithTime(`Found ${err.errorsCount} ${pluralize('error', err.errorsCount)}. Watching for file changes.`);
} else { } else {
utils.logWithTime('Found errors. Watching for file changes.'); logUtils.logWithTime('Found errors. Watching for file changes.');
} }
} }
@ -155,7 +155,7 @@ export class Compiler {
await onFileChangedAsync(); await onFileChangedAsync();
watcher.on('change', (changedFilePath: string) => { watcher.on('change', (changedFilePath: string) => {
console.clear(); // tslint:disable-line:no-console console.clear(); // tslint:disable-line:no-console
utils.logWithTime('File change detected. Starting incremental compilation...'); logUtils.logWithTime('File change detected. Starting incremental compilation...');
// NOTE: We can't await it here because that's a callback. // NOTE: We can't await it here because that's a callback.
// Instead we stop watching inside of it and start it again when we're finished. // Instead we stop watching inside of it and start it again when we're finished.
onFileChangedAsync(); // tslint:disable-line no-floating-promises onFileChangedAsync(); // tslint:disable-line no-floating-promises

View File

@ -1,12 +1,6 @@
import { logUtils } from '@0x/utils';
import chalk from 'chalk';
export const utils = { export const utils = {
stringifyWithFormatting(obj: any): string { stringifyWithFormatting(obj: any): string {
const stringifiedObj = JSON.stringify(obj, null, '\t'); const stringifiedObj = JSON.stringify(obj, null, '\t');
return stringifiedObj; return stringifiedObj;
}, },
logWithTime(arg: string): void {
logUtils.log(`[${chalk.gray(new Date().toLocaleTimeString())}] ${arg}`);
},
}; };

View File

@ -1,4 +1,13 @@
[ [
{
"version": "2.1.0",
"changes": [
{
"note": "Add `logWithTime` to `logUtils`",
"pr": 1461
}
]
},
{ {
"version": "2.0.8", "version": "2.0.8",
"changes": [ "changes": [

View File

@ -49,6 +49,7 @@
"@types/node": "*", "@types/node": "*",
"abortcontroller-polyfill": "^1.1.9", "abortcontroller-polyfill": "^1.1.9",
"bignumber.js": "~4.1.0", "bignumber.js": "~4.1.0",
"chalk": "^2.4.1",
"detect-node": "2.0.3", "detect-node": "2.0.3",
"ethereum-types": "^1.1.4", "ethereum-types": "^1.1.4",
"ethereumjs-util": "^5.1.1", "ethereumjs-util": "^5.1.1",

View File

@ -1,3 +1,5 @@
import chalk from 'chalk';
export const logUtils = { export const logUtils = {
log(...args: any[]): void { log(...args: any[]): void {
console.log(...args); // tslint:disable-line:no-console console.log(...args); // tslint:disable-line:no-console
@ -5,4 +7,7 @@ export const logUtils = {
warn(...args: any[]): void { warn(...args: any[]): void {
console.warn(...args); // tslint:disable-line:no-console console.warn(...args); // tslint:disable-line:no-console
}, },
logWithTime(arg: string): void {
logUtils.log(`[${chalk.gray(new Date().toLocaleTimeString())}] ${arg}`);
},
}; };