@@ -8,33 +8,44 @@ const cp = require("child_process");
8
8
const path = require ( "path" ) ;
9
9
const tc = require ( "./template-common" ) ;
10
10
const fs = require ( "fs" ) ;
11
+ const async = require ( "async" ) ;
11
12
12
13
const extraArgs = "" ;
13
14
14
- const hasConfiguration = fs . existsSync ( "webpack.config.js" ) ;
15
15
const targetArgs = global . NO_TARGET_ARGS ? "" : " ./example.js js/output.js " ;
16
16
const displayReasons = global . NO_REASONS ? "" : " --display-reasons --display-used-exports --display-provided-exports" ;
17
- const modeArgs = hasConfiguration ? "" : "--mode production" ;
18
- cp . exec ( `node ${ path . resolve ( __dirname , "../bin/webpack.js" ) } ${ modeArgs } ${ displayReasons } --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" -p ${ extraArgs } ${ targetArgs } ` , function ( error , stdout , stderr ) {
19
- if ( stderr )
20
- console . log ( stderr ) ;
21
- if ( error !== null )
22
- console . log ( error ) ;
23
- let readme ;
24
- try {
25
- readme = tc . replaceResults ( fs . readFileSync ( require ( "path" ) . join ( process . cwd ( ) , "template.md" ) , "utf-8" ) , process . cwd ( ) , stdout . replace ( / [ \r \n ] * $ / , "" ) , "min" ) ;
26
- } catch ( e ) {
27
- console . log ( stderr ) ;
28
- throw e ;
17
+ const commonArgs = `--display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" ${ extraArgs } ${ targetArgs } ` ;
18
+
19
+ let readme = fs . readFileSync ( require ( "path" ) . join ( process . cwd ( ) , "template.md" ) , "utf-8" ) ;
20
+
21
+ const doCompileAndReplace = ( args , prefix , callback ) => {
22
+ if ( ! tc . needResults ( readme , prefix ) ) {
23
+ callback ( ) ;
24
+ return ;
29
25
}
30
- cp . exec ( `node ${ path . resolve ( __dirname , "../bin/webpack.js" ) } ${ modeArgs } ${ displayReasons } --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" --output-pathinfo ${ extraArgs } ${ targetArgs } ` , function ( error , stdout , stderr ) {
31
- console . log ( stdout ) ;
26
+ if ( fs . existsSync ( "js" ) )
27
+ for ( const file of fs . readdirSync ( "js" ) )
28
+ fs . unlinkSync ( `js/${ file } ` ) ;
29
+ cp . exec ( `node ${ path . resolve ( __dirname , "../bin/webpack.js" ) } ${ args } ${ displayReasons } ${ commonArgs } ` , ( error , stdout , stderr ) => {
32
30
if ( stderr )
33
31
console . log ( stderr ) ;
34
32
if ( error !== null )
35
33
console . log ( error ) ;
36
- readme = tc . replaceResults ( readme , process . cwd ( ) , stdout . replace ( / [ \r \n ] * $ / , "" ) ) ;
37
- readme = tc . replaceBase ( readme ) ;
38
- fs . writeFile ( "README.md" , readme , "utf-8" , function ( ) { } ) ;
34
+ try {
35
+ readme = tc . replaceResults ( readme , process . cwd ( ) , stdout . replace ( / [ \r ? \n ] * $ / , "" ) , prefix ) ;
36
+ } catch ( e ) {
37
+ console . log ( stderr ) ;
38
+ throw e ;
39
+ }
40
+ callback ( ) ;
39
41
} ) ;
42
+ } ;
43
+
44
+ async . series ( [
45
+ callback => doCompileAndReplace ( "--mode production" , "production" , callback ) ,
46
+ callback => doCompileAndReplace ( "--mode development --devtool none" , "development" , callback ) ,
47
+ callback => doCompileAndReplace ( "--mode none --output-pathinfo" , "" , callback )
48
+ ] , ( ) => {
49
+ readme = tc . replaceBase ( readme ) ;
50
+ fs . writeFile ( "README.md" , readme , "utf-8" , function ( ) { } ) ;
40
51
} ) ;
0 commit comments