1
+ "use strict" ;
2
+
1
3
/*
2
4
* mustache pattern engine for patternlab-node - v2.X.X - 2016
3
5
*
17
19
*
18
20
*/
19
21
20
- "use strict" ;
21
-
22
- var Mustache = require ( 'mustache' ) ;
23
- var utilMustache = require ( './util_mustache' ) ;
22
+ const fs = require ( 'fs-extra' ) ;
23
+ const path = require ( 'path' ) ;
24
+ const Mustache = require ( 'mustache' ) ;
25
+ const utilMustache = require ( './util_mustache' ) ;
24
26
25
27
// This holds the config from from core. The core has to call
26
28
// usePatternLabConfig() at load time for this to be populated, which
@@ -73,6 +75,20 @@ var engine_mustache = {
73
75
return matches ;
74
76
} ,
75
77
78
+ spawnFile : function ( config , fileName ) {
79
+ const paths = config . paths ;
80
+ const metaFilePath = path . resolve ( paths . source . meta , fileName ) ;
81
+ try {
82
+ fs . statSync ( metaFilePath ) ;
83
+ } catch ( err ) {
84
+
85
+ //not a file, so spawn it from the included file
86
+ const localMetaFilePath = path . resolve ( __dirname , '_meta/' , fileName ) ;
87
+ const metaFileContent = fs . readFileSync ( path . resolve ( __dirname , '..' , '_meta/' , fileName ) , 'utf8' ) ;
88
+ fs . outputFileSync ( metaFilePath , metaFileContent ) ;
89
+ }
90
+ } ,
91
+
76
92
/**
77
93
* Checks to see if the _meta directory has engine-specific head and foot files,
78
94
* spawning them if not found.
@@ -81,7 +97,8 @@ var engine_mustache = {
81
97
* assume it's already present
82
98
*/
83
99
spawnMeta : function ( config ) {
84
-
100
+ this . spawnFile ( config , '_00-head.mustache' ) ;
101
+ this . spawnFile ( config , '_01-foot.mustache' ) ;
85
102
} ,
86
103
87
104
// find and return any {{> template-name }} within pattern
0 commit comments