@@ -27,11 +27,10 @@ class Project {
27
27
this . middlewares = [ ] ;
28
28
this . packCallbacks = [ ] ;
29
29
this . eslintConfig = require ( '../config/eslint.json' ) ;
30
- this . configFile = globby . sync ( [ 'ykit.*.js' , 'ykit.js' ] , { cwd : this . cwd } ) [ 0 ] || '' ;
31
- this . extendConfig = this . configFile &&
32
- this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) &&
33
- this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) [ 1 ] &&
34
- this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) [ 1 ] . replace ( / \. / g, '-' ) ;
30
+ this . configFile = globby . sync ( [
31
+ 'ykit.*.js' , 'ykit.js'
32
+ ] , { cwd : this . cwd } ) [ 0 ] || '' ;
33
+ this . extendConfig = this . configFile && this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) && this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) [ 1 ] && this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) [ 1 ] . replace ( / \. / g, '-' ) ;
35
34
this . ignores = [ 'node_modules/**/*' , 'bower_components/**/*' , 'dev/**/*' , 'prd/**/*' , '.ykit_cache/**/*' ] ;
36
35
this . cachePath = this . _isCacheDirExists ( cwd ) || '' ;
37
36
@@ -189,7 +188,9 @@ class Project {
189
188
190
189
for ( let key in entries ) {
191
190
const entryItem = entries [ key ] ,
192
- entry = Array . isArray ( entryItem ) ? entryItem [ entryItem . length - 1 ] : entryItem ,
191
+ entry = Array . isArray ( entryItem )
192
+ ? entryItem [ entryItem . length - 1 ]
193
+ : entryItem ,
193
194
extName = sysPath . extname ( entry ) ;
194
195
195
196
// 放在cache目录下
@@ -215,20 +216,12 @@ class Project {
215
216
entryItem . forEach ( ( cssPath ) => {
216
217
const originCssPath = sysPath . join ( config . context , cssPath ) ;
217
218
const requiredPath = UtilPath . normalize ( sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) ) ;
218
- fs . appendFileSync (
219
- cacheFilePath ,
220
- 'require("' + requiredPath + '");' ,
221
- 'utf-8'
222
- ) ;
219
+ fs . appendFileSync ( cacheFilePath , 'require("' + requiredPath + '");' , 'utf-8' ) ;
223
220
} ) ;
224
221
} else {
225
222
const originCssPath = sysPath . join ( config . context , entry ) ;
226
223
const requiredPath = UtilPath . normalize ( sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) ) ;
227
- fs . writeFileSync (
228
- cacheFilePath ,
229
- 'require("' + requiredPath + '");' ,
230
- 'utf-8'
231
- ) ;
224
+ fs . writeFileSync ( cacheFilePath , 'require("' + requiredPath + '");' , 'utf-8' ) ;
232
225
}
233
226
234
227
fps . push ( cacheFilePath ) ;
@@ -272,11 +265,13 @@ class Project {
272
265
}
273
266
274
267
pack ( opt , callback ) {
275
- let config = this . config . getConfig ( ) ;
268
+ let self = this ,
269
+ config = this . config . getConfig ( ) ;
270
+
276
271
UtilFs . deleteFolderRecursive ( this . cachePath ) ;
277
272
278
273
if ( ! config . beforePack ) {
279
- config . beforePack = function ( done ) {
274
+ config . beforePack = function ( done ) {
280
275
done ( ) ;
281
276
} ;
282
277
}
@@ -320,58 +315,60 @@ class Project {
320
315
}
321
316
322
317
webpack ( config , ( err , stats ) => {
323
- globby . sync ( '**/*.cache' , {
324
- cwd : config . output . path
325
- } )
326
- . map ( ( p ) => sysPath . join ( config . output . path , p ) )
327
- . forEach ( ( fp ) => fs . unlinkSync ( fp ) ) ;
318
+ globby . sync ( '**/*.cache' , { cwd : config . output . path } ) . map ( ( p ) => {
319
+ sysPath . join ( config . output . path , p ) ;
320
+ } ) . forEach ( ( fp ) => {
321
+ fs . unlinkSync ( fp ) ;
322
+ } ) ;
328
323
329
324
if ( ! err ) {
330
- let statsInfo = stats . toJson ( {
331
- errorDetails : false
332
- } ) ;
325
+ async . series ( this . packCallbacks . map ( ( packCallback ) => {
326
+ return function ( callback ) {
327
+ packCallback ( opt , stats ) ;
328
+ callback ( null ) ;
329
+ } ;
330
+ } ) , ( err ) => {
331
+
332
+ let statsInfo = stats . toJson ( { errorDetails : false } ) ;
333
+
334
+ process . stdout . write ( '\n' +
335
+ '\x1b[90m' +
336
+ '-------------------------- YKIT PACKED ASSETS -------------------------- ' +
337
+ '\x1b[0m \n\n' ) ;
338
+
339
+ if ( statsInfo . errors . length > 0 ) {
340
+ statsInfo . errors . map ( ( err ) => {
341
+ error ( err . red ) ;
342
+ info ( ) ;
343
+ } ) ;
344
+ }
345
+ if ( statsInfo . warnings . length > 0 ) {
346
+ statsInfo . warnings . map ( ( warning ) => {
347
+ warn ( warning . yellow ) ;
348
+ info ( ) ;
349
+ } ) ;
350
+ }
333
351
334
- process . stdout . write (
335
- // clear bundle log
336
- ' \n'
337
- + '\x1b[90m'
338
- + '-------------------------- YKIT PACKED ASSETS -------------------------- '
339
- + '\x1b[0m \n\n'
340
- ) ;
341
-
342
- if ( statsInfo . errors . length > 0 ) {
343
- statsInfo . errors . map ( ( err ) => {
344
- error ( err . red ) ;
345
- info ( ) ;
346
- } ) ;
347
- }
348
- if ( statsInfo . warnings . length > 0 ) {
349
- statsInfo . warnings . map ( ( warning ) => {
350
- warn ( warning . yellow ) ;
351
- info ( ) ;
352
+ const assetsInfo = self . config . _config . assetsInfo || statsInfo . assets ;
353
+ assetsInfo . map ( ( asset ) => {
354
+ const size = asset . size > 1024
355
+ ? ( asset . size / 1024 ) . toFixed ( 2 ) + ' kB'
356
+ : asset . size + ' bytes' ;
357
+ if ( ! / \. c a c h e $ / . test ( asset . name ) ) {
358
+ log ( '- ' . gray + asset . name + ' - ' + size ) ;
359
+ }
352
360
} ) ;
353
- }
354
- statsInfo . assets . map ( ( asset ) => {
355
- const size = asset . size > 1024 ?
356
- ( asset . size / 1024 ) . toFixed ( 2 ) + ' kB' :
357
- asset . size + ' bytes' ;
358
- if ( ! / \. c a c h e $ / . test ( asset . name ) ) {
359
- log ( '- ' . gray + asset . name + ' - ' + size ) ;
360
- }
361
+
362
+ info ( ) ;
363
+ callback ( err , stats ) ;
361
364
} ) ;
362
- info ( ) ;
363
- this . packCallbacks . forEach ( cb => cb ( opt , stats ) ) ;
364
365
}
365
-
366
- callback ( err , stats ) ;
367
366
} ) ;
368
367
} ;
369
368
370
369
config . beforePack ( ( ) => {
371
370
if ( opt . lint ) {
372
- async . series ( [
373
- ( callback ) => this . lint ( callback )
374
- ] , ( err , results ) => {
371
+ async . series ( [ ( callback ) => this . lint ( callback ) ] , ( err , results ) => {
375
372
if ( ! err ) {
376
373
if ( results [ 0 ] && results [ 1 ] ) {
377
374
compilerProcess ( ) ;
@@ -414,7 +411,9 @@ class Project {
414
411
if ( dir ) {
415
412
dir = sysPath . resolve ( this . cwd , dir ) ;
416
413
try {
417
- fs . statSync ( dir ) . isDirectory ( ) ? context = dir : lintPath = sysPath . relative ( context , dir ) ;
414
+ fs . statSync ( dir ) . isDirectory ( )
415
+ ? context = dir
416
+ : lintPath = sysPath . relative ( context , dir ) ;
418
417
} catch ( e ) {
419
418
error ( e ) ;
420
419
process . exit ( 1 ) ;
0 commit comments