@@ -3,47 +3,49 @@ import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin/lib";
33import { Options as TsconfigPathsPluginOptions } from "tsconfig-paths-webpack-plugin/lib/options" ;
44import { loadTsconfig , Tsconfig } from "tsconfig-paths/lib/tsconfig-loader" ;
55import upath from "upath" ;
6- import * as fs from "fs-extra" ;
76import { Plugin } from "@reactway/webpack-builder" ;
87import { ForkTsCheckerWebpackPluginOptions } from "./plugin-options" ;
98import TerserPlugin , { TerserPluginOptions } from "terser-webpack-plugin" ;
109
1110import "ts-loader" ;
11+ import { TS_CONFIG_NAME , checkTsConfig , TSLINT_CONFIG_NAME , checkTslintConfig } from "./checkers" ;
12+
13+ const enum Linter {
14+ TsLint = "tslint" ,
15+ EsLint = "eslint"
16+ }
1217
1318// Extensions.
1419const TS_EXTENSION : string = ".ts" ;
1520const TSX_EXTENSION : string = ".tsx" ;
1621const JS_EXTENSION : string = ".js" ;
1722const JSX_EXTENSION : string = ".jsx" ;
1823
19- // Tsconfig.
20- export const TS_CONFIG_NAME : string = "tsconfig.json" ;
21- const DEFAULT_TS_CONFIG_LOCATION : string = upath . resolve ( __dirname , `../assets/${ TS_CONFIG_NAME } ` ) ;
22-
23- // TsLint.
24- export const TSLINT_CONFIG_NAME : string = "tslint.json" ;
25- const DEFAULT_TSLINT_CONFIG_LOCATION : string = upath . resolve ( __dirname , `../assets/${ TSLINT_CONFIG_NAME } ` ) ;
26-
2724interface TypeScriptPluginOptions {
2825 forkTsCheckerOptions ?: Partial < ForkTsCheckerWebpackPluginOptions > ;
2926 tsconfigPathsPluginOptions ?: Partial < TsconfigPathsPluginOptions > ;
3027 terserPluginOptions ?: TerserPluginOptions ;
28+ linter ?: Linter ;
3129}
3230
3331export const TypeScriptPlugin : Plugin < TypeScriptPluginOptions > = ( config , projectDirectory ) => {
3432 const fullTsconfigLocation = upath . resolve ( projectDirectory , TS_CONFIG_NAME ) ;
3533 let baseURLExist : boolean = false ;
3634
35+ const linter = config != null && config . linter != null ? config . linter : Linter . EsLint ;
36+
3737 try {
3838 checkTsConfig ( projectDirectory ) ;
3939 } catch ( error ) {
4040 console . error ( `Failed while initiating "${ TS_CONFIG_NAME } ".` , error ) ;
4141 }
4242
43- try {
44- checkTslintConfig ( projectDirectory ) ;
45- } catch ( error ) {
46- console . error ( `Failed while initiating "${ TSLINT_CONFIG_NAME } ".` , error ) ;
43+ if ( linter === Linter . TsLint ) {
44+ try {
45+ checkTslintConfig ( projectDirectory ) ;
46+ } catch ( error ) {
47+ console . error ( `Failed while initiating "${ TSLINT_CONFIG_NAME } ".` , error ) ;
48+ }
4749 }
4850
4951 const tsConfig : Tsconfig | undefined = loadTsconfig ( fullTsconfigLocation ) ;
@@ -63,7 +65,8 @@ export const TypeScriptPlugin: Plugin<TypeScriptPluginOptions> = (config, projec
6365 webpack . plugins . push (
6466 new ForkTsCheckerWebpackPlugin ( {
6567 checkSyntacticErrors : true ,
66- tslint : true ,
68+ tslint : linter === Linter . TsLint ? true : undefined ,
69+ eslint : linter === Linter . EsLint ? true : undefined ,
6770 ...forkTsConfig
6871 } )
6972 ) ;
@@ -144,7 +147,7 @@ export const TypeScriptPlugin: Plugin<TypeScriptPluginOptions> = (config, projec
144147 }
145148
146149 if ( ! baseURLExist && config != null && config . tsconfigPathsPluginOptions != null ) {
147- throw new Error ( `Cannot add tsconfigPathsPluginOptions because baseUrl do not exist at ${ TS_CONFIG_NAME } ` ) ;
150+ throw new Error ( `Cannot add tsconfigPathsPluginOptions because baseUrl does not exist at ${ TS_CONFIG_NAME } ` ) ;
148151 }
149152
150153 if ( webpack . resolve . extensions == null ) {
@@ -209,23 +212,3 @@ export const TypeScriptPlugin: Plugin<TypeScriptPluginOptions> = (config, projec
209212 return webpack ;
210213 } ;
211214} ;
212-
213- export function checkTsConfig ( projectDirectory : string ) : void {
214- const configLocation = upath . resolve ( projectDirectory , TS_CONFIG_NAME ) ;
215-
216- if ( ! fs . pathExistsSync ( configLocation ) ) {
217- console . info ( `File "${ TS_CONFIG_NAME } " not found at ${ configLocation } . Creating...` ) ;
218- fs . copySync ( DEFAULT_TS_CONFIG_LOCATION , configLocation ) ;
219- console . info ( "Created." ) ;
220- }
221- }
222-
223- export function checkTslintConfig ( projectDirectory : string ) : void {
224- const configLocation = upath . resolve ( projectDirectory , TSLINT_CONFIG_NAME ) ;
225-
226- if ( ! fs . pathExistsSync ( configLocation ) ) {
227- console . info ( `File "${ TSLINT_CONFIG_NAME } " not found at ${ configLocation } . Creating...` ) ;
228- fs . copySync ( DEFAULT_TSLINT_CONFIG_LOCATION , configLocation ) ;
229- console . info ( "Created." ) ;
230- }
231- }
0 commit comments