11const shell = require ( "child_process" ) ;
2+ const fs = require ( "fs" ) ;
23
34// Load cli
45let cli = require ( "./lib/cli" ) ( ) ;
@@ -27,6 +28,12 @@ if (cli.force && config.output && config.output.directory) {
2728
2829// Start the engine
2930
31+ // Run the precmd
32+ if ( config . precmd && config . precmd . length ) {
33+ console . log ( "Pre-cmd:" , config . precmd ) ;
34+ shell . execSync ( config . precmd ) ;
35+ }
36+
3037/// Check for input server command
3138let server = false ;
3239let serverStarted = false ;
@@ -108,6 +115,34 @@ function download() {
108115
109116 try {
110117 shell . execSync ( wgetcmd ) ;
118+
119+ // Run the post command
120+ if ( config . postcmd && config . postcmd . length ) {
121+ console . log ( "Post-cmd:" , config . postcmd ) ;
122+ shell . execSync ( config . postcmd ) ;
123+ }
124+
125+ // Fix dot ones
126+ if ( config . output && config . output . fixDotOnes ) {
127+
128+ // Scan the directory
129+ fs . readdirSync ( config . output . directory ) . forEach ( file => {
130+ if ( file . includes ( ".1.html" ) ) {
131+
132+ file = config . output . directory + '/' + file ;
133+ let newfile = file . replace ( ".1.html" , ".html" ) ;
134+
135+ try {
136+ fs . renameSync ( file , newfile ) ;
137+ }
138+ catch ( ex ) {
139+ throw "Could not move file " + file ;
140+ }
141+ }
142+ } ) ;
143+
144+ }
145+
111146 console . log ( "Done." ) ;
112147 }
113148 catch ( ex ) {
@@ -125,4 +160,4 @@ function download() {
125160 }
126161 process . exit ( ) ;
127162
128- }
163+ }
0 commit comments