@@ -8,33 +8,44 @@ const cp = require("child_process");
88const path = require ( "path" ) ;
99const tc = require ( "./template-common" ) ;
1010const fs = require ( "fs" ) ;
11+ const async = require ( "async" ) ;
1112
1213const extraArgs = "" ;
1314
14- const hasConfiguration = fs . existsSync ( "webpack.config.js" ) ;
1515const targetArgs = global . NO_TARGET_ARGS ? "" : " ./example.js js/output.js " ;
1616const 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 ;
2925 }
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 ) => {
3230 if ( stderr )
3331 console . log ( stderr ) ;
3432 if ( error !== null )
3533 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 ( ) ;
3941 } ) ;
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 ( ) { } ) ;
4051} ) ;
0 commit comments