Skip to content

Commit

Permalink
Use template strings for diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion committed Mar 17, 2017
1 parent f4eac4d commit 91ef319
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@angular/platform-browser-dynamic": "^2.3.0",
"@angular/platform-server": "^2.3.0",
"@angular/router": "^3.3.0",
"@types/chalk": "^0.4.31",
"@types/fs-extra": "0.0.37",
"@types/glob": "^5.0.30",
"@types/gulp": "^3.8.32",
Expand All @@ -53,6 +54,7 @@
"@types/rx": "2.5.33",
"axe-core": "^2.1.7",
"axe-webdriverjs": "^0.5.0",
"chalk": "^1.1.3",
"conventional-changelog": "^1.1.0",
"dgeni": "^0.4.7",
"dgeni-packages": "^0.16.5",
Expand Down
14 changes: 7 additions & 7 deletions tools/gulp/util/ts-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as ts from 'typescript';
import * as path from 'path';
import * as chalk from 'chalk';

/** Compiles a TypeScript project with possible extra options. */
export function compileProject(project: string, options: ts.CompilerOptions) {
Expand All @@ -10,9 +11,8 @@ export function compileProject(project: string, options: ts.CompilerOptions) {
checkDiagnostics(program.getOptionsDiagnostics());

let emitResult = program.emit();
let emitDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);

checkDiagnostics(emitDiagnostics);
checkDiagnostics(emitResult.diagnostics);
}

/** Parses a TypeScript project configuration. */
Expand All @@ -38,11 +38,9 @@ export function formatDiagnostics(diagnostics: ts.Diagnostic[]): string {
if (diagnostic.file) {
let {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);

res += ' at ' + diagnostic.file.fileName + ':';
res += (line + 1) + ':' + (character + 1) + ':';
res += ` at ${diagnostic.file.fileName}(${line + 1},${character + 1}):`;
}

res += ' ' + ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
res += ` ${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}`;

return res;
}).join('\n');
Expand All @@ -51,6 +49,8 @@ export function formatDiagnostics(diagnostics: ts.Diagnostic[]): string {
/** Checks diagnostics and throws errors if present. */
export function checkDiagnostics(diagnostics: ts.Diagnostic[]) {
if (diagnostics && diagnostics.length && diagnostics[0]) {
throw new Error(formatDiagnostics(diagnostics));
console.error(formatDiagnostics(diagnostics));
console.error(chalk.red('TypeScript compilation failed. Exiting process.'));
process.exit(1);
}
}

0 comments on commit 91ef319

Please sign in to comment.