diff --git a/src/lib/compiler/typescript-compiler.ts b/src/lib/compiler/typescript-compiler.ts index 91524d8..cc3f057 100644 --- a/src/lib/compiler/typescript-compiler.ts +++ b/src/lib/compiler/typescript-compiler.ts @@ -1,31 +1,7 @@ import * as ts from 'typescript'; -import { error, info } from '../helpers/log-helper'; - -const compile = (filePaths: string[], compilerOptions: ts.CompilerOptions): void => { - let program = ts.createProgram(filePaths, compilerOptions); - let emitResult = program.emit(); - if (emitResult.emitSkipped) { - error('Error during compilation of Typesript files'); - reportDiagnostics(ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)); - } else { - info('Typescript files successfully compiled'); - } -}; - -const reportDiagnostics = (diagnostics: ts.Diagnostic[]): void => { - diagnostics.forEach(diagnostic => { - let message = 'Error'; - if (diagnostic.file) { - let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); - message += ` ${diagnostic.file.fileName} (${line + 1},${character + 1})`; - } - message += ': ' + ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - info(message); - }); -}; export const compileSources = (filePaths: string[]): void => { - const tsOptions = { + const compilerOptions = { noEmitOnError: true, noImplicitAny: true, declaration: true, @@ -33,5 +9,5 @@ export const compileSources = (filePaths: string[]): void => { target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext }; - compile(filePaths, tsOptions); + ts.createProgram(filePaths, compilerOptions); };