Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit fc67592

Browse files
committed
spawn mustache meta patterns if not found
part of pattern-lab/patternlab-node#611
1 parent cfae4d2 commit fc67592

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

_meta/_00-head.mustache

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html class="{{ htmlClass }}">
3+
<head>
4+
<title>{{ title }}</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width" />
7+
8+
<link rel="stylesheet" href="../../css/style.css?{{ cacheBuster }}" media="all" />
9+
<link rel="stylesheet" href="../../css/pattern-scaffolding.css?{{ cacheBuster }}" media="all" />
10+
11+
<!-- Begin Pattern Lab (Required for Pattern Lab to run properly) -->
12+
{{{ patternLabHead }}}
13+
<!-- End Pattern Lab -->
14+
15+
</head>
16+
<body class="{{ bodyClass }}">
17+

_meta/_01-foot.mustache

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
<!--DO NOT REMOVE-->
3+
{{{ patternLabFoot }}}
4+
5+
</body>
6+
</html>

lib/engine_mustache.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
/*
24
* mustache pattern engine for patternlab-node - v2.X.X - 2016
35
*
@@ -17,10 +19,10 @@
1719
*
1820
*/
1921

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');
2426

2527
// This holds the config from from core. The core has to call
2628
// usePatternLabConfig() at load time for this to be populated, which
@@ -73,6 +75,20 @@ var engine_mustache = {
7375
return matches;
7476
},
7577

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+
7692
/**
7793
* Checks to see if the _meta directory has engine-specific head and foot files,
7894
* spawning them if not found.
@@ -81,7 +97,8 @@ var engine_mustache = {
8197
* assume it's already present
8298
*/
8399
spawnMeta: function (config) {
84-
100+
this.spawnFile(config, '_00-head.mustache');
101+
this.spawnFile(config, '_01-foot.mustache');
85102
},
86103

87104
// find and return any {{> template-name }} within pattern

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.0.2",
55
"main": "lib/engine_mustache.js",
66
"dependencies": {
7+
"fs-extra": "^0.30.0",
78
"mustache": "^2.2.0"
89
},
910
"devDependencies": {

0 commit comments

Comments
 (0)