@@ -2,6 +2,7 @@ import * as ts from 'typescript';
22import chalk from 'chalk' ;
33import * as tslint from 'tslint' ;
44import * as path from 'path' ;
5+ import * as fs from 'fs' ;
56
67import { IInternalTypeCheckerOptions , END_LINE , ITSLintError , ITSError } from './interfaces' ;
78
@@ -291,11 +292,66 @@ export class Checker {
291292 ( `└── TsLint: ${ tsLintErrors } ${ END_LINE } ${ END_LINE } ` )
292293 ) ;
293294
295+ if ( options . emit ) {
296+ print (
297+ chalk . grey ( `Skipping emit file${ END_LINE } ` )
298+ ) ;
299+ }
300+
294301 } else {
295302 // if there no errors, then also give some feedback about this, so they know its working
296303 print (
297304 chalk . grey ( `All good, no errors :-)${ END_LINE } ` )
298305 ) ;
306+
307+ if ( options . emit ) {
308+ print (
309+ chalk . grey ( `Getting ready to emit files${ END_LINE } ` )
310+ ) ;
311+ try {
312+ if ( options . clearOnEmit ) {
313+ let outputFolder : any = program . getCompilerOptions ( ) . outDir ;
314+ let deleteFolder = function ( folder : string ) {
315+ folder = path . join ( folder ) ;
316+ if ( fs . existsSync ( folder ) ) {
317+ fs . readdirSync ( folder ) . forEach ( function ( file : string ) {
318+ let curPath = folder + '/' + file ;
319+ if ( fs . lstatSync ( curPath ) . isDirectory ( ) ) { // recurse
320+ deleteFolder ( curPath ) ;
321+ } else { // delete file
322+ fs . unlinkSync ( curPath ) ;
323+ }
324+ } ) ;
325+ fs . rmdirSync ( folder ) ;
326+ }
327+ } ;
328+ if ( ! outputFolder ) {
329+ console . warn ( 'output filder missing' ) ;
330+ } else {
331+ print (
332+ chalk . grey ( `clearing output folder${ END_LINE } ` )
333+ ) ;
334+ deleteFolder ( outputFolder ) ;
335+ print (
336+ chalk . grey ( `Output folder cleared${ END_LINE } ` )
337+ ) ;
338+ program . emit ( ) ;
339+ print (
340+ chalk . grey ( `Files emittet${ END_LINE } ` )
341+ ) ;
342+ }
343+ } else {
344+ program . emit ( ) ;
345+ print (
346+ chalk . grey ( `Files emittet${ END_LINE } ` )
347+ ) ;
348+ }
349+ } catch ( error ) {
350+ print (
351+ chalk . red ( `emitting files failed${ END_LINE } ` )
352+ ) ;
353+ }
354+ }
299355 }
300356
301357 print (
0 commit comments