Skip to content

Commit 6fdcad9

Browse files
committed
feat(emit): emit files and clear output dir
1 parent 8edd479 commit 6fdcad9

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ interface ITypeCheckerOptionsInterface {
183183
yellowOnSemantic?: boolean; // use yellow color instead of red on Semantic errors
184184
yellowOnSyntactic?: boolean; // use yellow color instead of red on Syntactic errors
185185
shortenFilenames?: boolean; // use shortened filenames in order to make output less noisy
186+
187+
// when not using with fusebox or just typechecking (remember to install typescript and tslint)
188+
emit?: boolean;// emit files according to tsconfig file
189+
clearOnEmit? : boolean // output folder on emit
186190
}
187191

188192

src/checker.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as ts from 'typescript';
22
import chalk from 'chalk';
33
import * as tslint from 'tslint';
44
import * as path from 'path';
5+
import * as fs from 'fs';
56

67
import { 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(

src/interfaces.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ export interface ITypeCheckerOptions {
3333

3434
// use shortened filenames in order to make output less cluttered
3535
shortenFilenames?: boolean;
36+
37+
// emit files according to tsconfig file
38+
emit?: boolean;
39+
40+
// output folder on emit
41+
clearOnEmit?: boolean;
3642
}
3743

3844
// lint options,this is the same as tsLint uses all paths will be from basepath

0 commit comments

Comments
 (0)