Move logWithTime function to utils
This commit is contained in:
parent
56d48758d3
commit
87d157b805
@ -10,7 +10,6 @@ import {
|
|||||||
URLResolver,
|
URLResolver,
|
||||||
} from '@0x/sol-resolver';
|
} from '@0x/sol-resolver';
|
||||||
import { logUtils } from '@0x/utils';
|
import { logUtils } from '@0x/utils';
|
||||||
import chalk from 'chalk';
|
|
||||||
import * as chokidar from 'chokidar';
|
import * as chokidar from 'chokidar';
|
||||||
import { CompilerOptions, ContractArtifact, ContractVersionData, StandardOutput } from 'ethereum-types';
|
import { CompilerOptions, ContractArtifact, ContractVersionData, StandardOutput } from 'ethereum-types';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
@ -136,18 +135,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
|
||||||
logWithTime('Starting compilation in watch mode...');
|
utils.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();
|
||||||
logWithTime('Found 0 errors. Watching for file changes.');
|
utils.logWithTime('Found 0 errors. Watching for file changes.');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.typeName === 'CompilationError') {
|
if (err.typeName === 'CompilationError') {
|
||||||
logWithTime(`Found ${err.errorsCount} ${pluralize('error', err.errorsCount)}. Watching for file changes.`);
|
utils.logWithTime(`Found ${err.errorsCount} ${pluralize('error', err.errorsCount)}. Watching for file changes.`);
|
||||||
} else {
|
} else {
|
||||||
logWithTime('Found errors. Watching for file changes.');
|
utils.logWithTime('Found errors. Watching for file changes.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +156,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
|
||||||
logWithTime('File change detected. Starting incremental compilation...');
|
utils.logWithTime('File change detected. Starting incremental compilation...');
|
||||||
onFileChangedAsync();
|
onFileChangedAsync();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -340,7 +339,3 @@ export class Compiler {
|
|||||||
logUtils.warn(`${contractName} artifact saved!`);
|
logUtils.warn(`${contractName} artifact saved!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logWithTime(arg: string): void {
|
|
||||||
logUtils.log(`[${chalk.gray(new Date().toLocaleTimeString())}] ${arg}`);
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
|
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}`);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user