@@ -15,65 +15,16 @@ function appendGATrackCode(content) {
1515 return content . slice ( 0 , content . lastIndexOf ( pageEnds ) ) + gaCode + pageEnds ;
1616}
1717
18- //invalidate cached files to enable auto-recompile then reload
19- //http://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate
20- /**
21- * Removes a module from the cache
22- */
23- function purgeCache ( moduleName ) {
24- // Traverse the cache looking for the files
25- // loaded by the specified module name
26- searchCache ( moduleName , function ( mod ) {
27- delete require . cache [ mod . id ] ;
28- } ) ;
29-
30- // Remove cached paths to the module.
31- // Thanks to @bentael for pointing this out.
32- Object . keys ( module . constructor . _pathCache ) . forEach ( function ( cacheKey ) {
33- if ( cacheKey . indexOf ( moduleName ) > 0 ) {
34- delete module . constructor . _pathCache [ cacheKey ] ;
35- }
36- } ) ;
37- }
38-
39- /**
40- * Traverses the cache to search for all the cached
41- * files of the specified module name
42- */
43- function searchCache ( moduleName , callback ) {
44- // Resolve the module identified by the specified name
45- var mod = require . resolve ( moduleName ) ;
46-
47- // Check if the module has been resolved and found within
48- // the cache
49- if ( mod && ( ( mod = require . cache [ mod ] ) !== undefined ) ) {
50- // Recursively go over the results
51- ( function traverse ( mod ) {
52- // Go over each of the module's children and
53- // traverse them
54- mod . children . forEach ( function ( child ) {
55- traverse ( child ) ;
56- } ) ;
57-
58- // Call the specified callback providing the
59- // found cached module
60- callback ( mod ) ;
61- } ( mod ) ) ;
62- }
63- }
64- //end of invalidate cached files
65-
66-
6718function outputOnePage ( content , destFolder ) {
6819 mkdirp ( destFolder , err => {
6920 if ( err ) {
70- console . log ( '✗ Error: outputOnePage' . underline . maroon , err ) ;
21+ console . log ( '✗ Error: outputOnePage' ) ;
7122 }
7223 else {
73- let outPath = path . join ( destFolder , "index.html" ) ;
74- let outStream = fs . createWriteStream ( outPath ) ;
24+ const outPath = path . join ( destFolder , "index.html" ) ;
25+ const outStream = fs . createWriteStream ( outPath ) ;
7526 outStream . once ( 'open' , ( ) => {
76- outStream . write ( '<!doctype html>\r\n ' ) ;
27+ outStream . write ( '<!doctype html>' ) ;
7728 outStream . write ( appendGATrackCode ( content ) ) ;
7829 outStream . end ( ) ;
7930 } ) ;
@@ -102,8 +53,6 @@ function transformOnePage(pageFile, propFile, srcFolder, destFolder) {
10253
10354 const file = path . join ( srcFolder , pageFile ) ;
10455 let Component = require ( file ) ;
105- //delete require.cache[require.resolve(file)]; //force to invalidate the cache for changed file
106- purgeCache ( file ) ;
10756
10857 if ( ! Component ) {
10958 console . log ( `✗ Error: No component found at ${ file } ` ) ;
0 commit comments