1
-
2
1
import chalk from "chalk" ;
3
2
import * as logSymbols from "log-symbols" ;
4
3
import * as Generator from "yeoman-generator" ;
@@ -11,7 +10,7 @@ import { Confirm, Input, List } from "@webpack-cli/webpack-scaffold";
11
10
import { WebpackOptions } from "./types" ;
12
11
import entryQuestions from "./utils/entry" ;
13
12
import langQuestionHandler from "./utils/language" ;
14
- import styleQuestionHandler , { ILoader , StylingType } from "./utils/style" ;
13
+ import styleQuestionHandler , { Loader , StylingType } from "./utils/style" ;
15
14
import tooltip from "./utils/tooltip" ;
16
15
17
16
/**
@@ -55,8 +54,6 @@ export default class InitGenerator extends Generator {
55
54
config : {
56
55
configName : this . isProd ? "prod" : "config" ,
57
56
topScope : [ ] ,
58
- // TODO migrate tslint
59
- // tslint:disable: object-literal-sort-keys
60
57
webpackOptions : {
61
58
mode : this . isProd ? "'production'" : "'development'" ,
62
59
entry : undefined ,
@@ -66,7 +63,6 @@ export default class InitGenerator extends Generator {
66
63
rules : [ ] ,
67
64
} ,
68
65
} ,
69
- // tslint:enable: object-literal-sort-keys
70
66
} ,
71
67
} ;
72
68
@@ -87,7 +83,7 @@ export default class InitGenerator extends Generator {
87
83
) ;
88
84
}
89
85
90
- this . configuration . config . webpackOptions . plugins . push (
86
+ ( this . configuration . config . webpackOptions . plugins as string [ ] ) . push (
91
87
"new webpack.ProgressPlugin()" ,
92
88
) ;
93
89
@@ -134,7 +130,7 @@ export default class InitGenerator extends Generator {
134
130
const done : ( ) => { } = this . async ( ) ;
135
131
const self : this = this ;
136
132
let regExpForStyles : string ;
137
- let ExtractUseProps : ILoader [ ] ;
133
+ let ExtractUseProps : Loader [ ] ;
138
134
139
135
process . stdout . write (
140
136
`\n${ logSymbols . info } ${ chalk . blue ( " INFO " ) } ` +
@@ -151,17 +147,17 @@ export default class InitGenerator extends Generator {
151
147
] )
152
148
. then ( ( multiEntriesAnswer : {
153
149
multiEntries : boolean ,
154
- } ) =>
150
+ } ) : Promise < { } > =>
155
151
entryQuestions ( self , multiEntriesAnswer . multiEntries ) ,
156
152
)
157
- . then ( ( entryOption : object | string ) => {
153
+ . then ( ( entryOption : object | string ) : void => {
158
154
if ( typeof entryOption === "string" && entryOption . length > 0 ) {
159
155
this . configuration . config . webpackOptions . entry = `${ entryOption } ` ;
160
156
} else if ( typeof entryOption === "object" ) {
161
157
this . configuration . config . webpackOptions . entry = entryOption ;
162
158
}
163
159
} )
164
- . then ( ( ) =>
160
+ . then ( ( ) : Promise < { } > =>
165
161
this . prompt ( [
166
162
Input (
167
163
"outputDir" ,
@@ -172,7 +168,7 @@ export default class InitGenerator extends Generator {
172
168
)
173
169
. then ( ( outputDirAnswer : {
174
170
outputDir : string ;
175
- } ) => {
171
+ } ) : void => {
176
172
// As entry is not required anymore and we dont set it to be an empty string or """""
177
173
// it can be undefined so falsy check is enough (vs entry.length);
178
174
if (
@@ -193,7 +189,7 @@ export default class InitGenerator extends Generator {
193
189
`path.resolve(__dirname, '${ outputDirAnswer . outputDir } ')` ;
194
190
}
195
191
} )
196
- . then ( ( ) =>
192
+ . then ( ( ) : Promise < { } > =>
197
193
this . prompt ( [
198
194
List ( "langType" , "Will you use one of the below JS solutions?" , [
199
195
"ES6" ,
@@ -203,11 +199,11 @@ export default class InitGenerator extends Generator {
203
199
] ) ,
204
200
)
205
201
. then ( ( langTypeAnswer : {
206
- langType : boolean ;
207
- } ) => {
202
+ langType : string ;
203
+ } ) : void => {
208
204
langQuestionHandler ( this , langTypeAnswer . langType ) ;
209
205
} )
210
- . then ( ( ) =>
206
+ . then ( ( ) : Promise < { } > =>
211
207
this . prompt ( [
212
208
List ( "stylingType" , "Will you use one of the below CSS solutions?" , [
213
209
"No" ,
@@ -219,10 +215,10 @@ export default class InitGenerator extends Generator {
219
215
] ) )
220
216
. then ( ( stylingTypeAnswer : {
221
217
stylingType : string ;
222
- } ) =>
223
- ( { ExtractUseProps, regExpForStyles } = styleQuestionHandler ( self , stylingTypeAnswer . stylingType ) ) ,
224
- )
225
- . then ( ( ) : Promise < Inquirer . Answers > => {
218
+ } ) : void => {
219
+ ( { ExtractUseProps, regExpForStyles } = styleQuestionHandler ( self , stylingTypeAnswer . stylingType ) ) ;
220
+ } )
221
+ . then ( ( ) : Promise < { } > | void => {
226
222
if ( this . isProd ) {
227
223
// Ask if the user wants to use extractPlugin
228
224
return this . prompt ( [
@@ -235,7 +231,7 @@ export default class InitGenerator extends Generator {
235
231
} )
236
232
. then ( ( useExtractPluginAnswer : {
237
233
useExtractPlugin : string ;
238
- } ) => {
234
+ } ) : void => {
239
235
if ( regExpForStyles ) {
240
236
if ( this . isProd ) {
241
237
const cssBundleName : string = useExtractPluginAnswer . useExtractPlugin ;
@@ -246,12 +242,12 @@ export default class InitGenerator extends Generator {
246
242
"\n" ,
247
243
) ;
248
244
if ( cssBundleName . length !== 0 ) {
249
- this . configuration . config . webpackOptions . plugins . push (
245
+ ( this . configuration . config . webpackOptions . plugins as string [ ] ) . push (
250
246
// TODO: use [contenthash] after it is supported
251
247
`new MiniCssExtractPlugin({ filename:'${ cssBundleName } .[chunkhash].css' })` ,
252
248
) ;
253
249
} else {
254
- this . configuration . config . webpackOptions . plugins . push (
250
+ ( this . configuration . config . webpackOptions . plugins as string [ ] ) . push (
255
251
"new MiniCssExtractPlugin({ filename:'style.css' })" ,
256
252
) ;
257
253
}
@@ -273,7 +269,7 @@ export default class InitGenerator extends Generator {
273
269
} ) ;
274
270
}
275
271
276
- public installPlugins ( ) {
272
+ public installPlugins ( ) : void {
277
273
const packager = getPackageManager ( ) ;
278
274
const opts : {
279
275
dev ?: boolean ,
@@ -292,7 +288,7 @@ export default class InitGenerator extends Generator {
292
288
this . fs . extendJSON ( this . destinationPath ( "package.json" ) , require ( packageJsonTemplatePath ) ( this . isProd ) ) ;
293
289
294
290
const entry = this . configuration . config . webpackOptions . entry ;
295
- const generateEntryFile = ( entryPath : string , name : string ) => {
291
+ const generateEntryFile = ( entryPath : string , name : string ) : void => {
296
292
entryPath = entryPath . replace ( / ' / g, "" ) ;
297
293
this . fs . copyTpl (
298
294
path . resolve ( __dirname , "./templates/index.js" ) ,
@@ -304,7 +300,7 @@ export default class InitGenerator extends Generator {
304
300
if ( typeof entry === "string" ) {
305
301
generateEntryFile ( entry , "your main file!" ) ;
306
302
} else if ( typeof entry === "object" ) {
307
- Object . keys ( entry ) . forEach ( ( name ) =>
303
+ Object . keys ( entry ) . forEach ( ( name : string ) : void =>
308
304
generateEntryFile ( entry [ name ] , `${ name } main file!` ) ,
309
305
) ;
310
306
}
0 commit comments