|
20 | 20 |
|
21 | 21 | "use strict";
|
22 | 22 |
|
23 |
| -var path = require('path'), |
| 23 | +var fs = require('fs-extra'), |
| 24 | + path = require('path'), |
24 | 25 | plPath = process.cwd(),
|
25 | 26 | plConfig = require(path.join(plPath, 'patternlab-config.json')),
|
26 | 27 | nunjucks = require('nunjucks'),
|
|
36 | 37 | if (typeof nunjucksConfig == 'function') {
|
37 | 38 | nunjucksConfig(nunjucks, env);
|
38 | 39 | }
|
39 |
| -} |
40 |
| -catch (err) { |
41 |
| - console.log('Cannot find module \'patternlab-nunjucks-config.js\''); |
42 |
| -} |
| 40 | +} catch (err) { } |
43 | 41 |
|
44 | 42 |
|
45 | 43 | ////////////////////////////
|
@@ -76,7 +74,7 @@ var engine_nunjucks = {
|
76 | 74 | // replace pattern names with their full path so Nunjucks can find them.
|
77 | 75 | pattern.extendedTemplate = this.replacePartials(pattern);
|
78 | 76 | var result = nunjucks.renderString(pattern.extendedTemplate, data);
|
79 |
| - return result; |
| 77 | + return Promise.resolve(result); |
80 | 78 | }
|
81 | 79 | catch (err) {
|
82 | 80 | console.error('Failed to render pattern: ' + pattern.name);
|
@@ -141,6 +139,32 @@ var engine_nunjucks = {
|
141 | 139 | // handled by nunjucks. This is here to keep PL from erroring
|
142 | 140 | findPartialsWithPatternParameters: function () {
|
143 | 141 | return null;
|
| 142 | + }, |
| 143 | + |
| 144 | + spawnFile: function (config, fileName) { |
| 145 | + const paths = config.paths; |
| 146 | + const metaFilePath = path.resolve(paths.source.meta, fileName); |
| 147 | + try { |
| 148 | + fs.statSync(metaFilePath); |
| 149 | + } catch (err) { |
| 150 | + |
| 151 | + //not a file, so spawn it from the included file |
| 152 | + const localMetaFilePath = path.resolve(__dirname, '_meta/', fileName); |
| 153 | + const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8'); |
| 154 | + fs.outputFileSync(metaFilePath, metaFileContent); |
| 155 | + } |
| 156 | + }, |
| 157 | + |
| 158 | + /** |
| 159 | + * Checks to see if the _meta directory has engine-specific head and foot files, |
| 160 | + * spawning them if not found. |
| 161 | + * |
| 162 | + * @param {object} config - the global config object from core, since we won't |
| 163 | + * assume it's already present |
| 164 | + */ |
| 165 | + spawnMeta: function (config) { |
| 166 | + this.spawnFile(config, '_00-head.njk'); |
| 167 | + this.spawnFile(config, '_01-foot.njk'); |
144 | 168 | }
|
145 | 169 | };
|
146 | 170 |
|
|
0 commit comments