From fa7d585f2c8bd1f9c52448948103532d9d2be26d Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Fri, 20 Oct 2017 20:54:29 -0500 Subject: [PATCH] Merge pull request #3 from pattern-lab/dev Dev --- .../patternengine-node-underscore/.eslintrc | 15 ++++++-- .../_meta/_00-head.html | 16 +++++++++ .../_meta/_01-foot.html | 6 ++++ .../lib/engine_underscore.js | 35 +++++++++++++++++-- .../package.json | 7 ++-- 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 packages/patternengine-node-underscore/_meta/_00-head.html create mode 100644 packages/patternengine-node-underscore/_meta/_01-foot.html diff --git a/packages/patternengine-node-underscore/.eslintrc b/packages/patternengine-node-underscore/.eslintrc index 6e83375f1..c445390a4 100644 --- a/packages/patternengine-node-underscore/.eslintrc +++ b/packages/patternengine-node-underscore/.eslintrc @@ -1,7 +1,12 @@ { "env": { "node": true, - "builtin": true + "builtin": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" }, "globals": {}, "rules": { @@ -67,7 +72,7 @@ "no-with": 2, "quotes": [0, "single"], "radix": 2, - "semi": [0, "never"], + "semi": [1, "always"], "strict": 0, "space-before-blocks": 1, "space-before-function-paren": [1, { @@ -78,6 +83,10 @@ "space-infix-ops": 1, "valid-typeof": 2, "vars-on-top": 0, - "wrap-iife": [2, "inside"] + "wrap-iife": [2, "inside"], + "prefer-const": ["error", { + "destructuring": "any", + "ignoreReadBeforeAssign": false + }] } } diff --git a/packages/patternengine-node-underscore/_meta/_00-head.html b/packages/patternengine-node-underscore/_meta/_00-head.html new file mode 100644 index 000000000..b1f5c1ce0 --- /dev/null +++ b/packages/patternengine-node-underscore/_meta/_00-head.html @@ -0,0 +1,16 @@ + + + + {{ title }} + + + + + + + + {{{ patternLabHead }}} + + + + diff --git a/packages/patternengine-node-underscore/_meta/_01-foot.html b/packages/patternengine-node-underscore/_meta/_01-foot.html new file mode 100644 index 000000000..797d9418d --- /dev/null +++ b/packages/patternengine-node-underscore/_meta/_01-foot.html @@ -0,0 +1,6 @@ + + +{{{ patternLabFoot }}} + + + diff --git a/packages/patternengine-node-underscore/lib/engine_underscore.js b/packages/patternengine-node-underscore/lib/engine_underscore.js index 764799690..b6688fade 100644 --- a/packages/patternengine-node-underscore/lib/engine_underscore.js +++ b/packages/patternengine-node-underscore/lib/engine_underscore.js @@ -1,3 +1,5 @@ +"use strict"; + /* * underscore pattern engine for patternlab-node - v0.15.1 - 2015 * @@ -17,8 +19,8 @@ * */ - -"use strict"; +const fs = require('fs-extra'); +const path = require('path'); var _ = require('underscore'); @@ -85,7 +87,7 @@ _.mixin({ var engine_underscore = { engine: _, engineName: 'underscore', - engineFileExtension: '.html', + engineFileExtension: ['.html', '.underscore'], // partial expansion is only necessary for Mustache templates that have // style modifiers or pattern parameters (I think) @@ -171,7 +173,34 @@ var engine_underscore = { var partialID = partialIDWithQuotes.replace(edgeQuotesMatcher, ''); return partialID; + }, + + spawnFile: function (config, fileName) { + const paths = config.paths; + const metaFilePath = path.resolve(paths.source.meta, fileName); + try { + fs.statSync(metaFilePath); + } catch (err) { + + //not a file, so spawn it from the included file + const localMetaFilePath = path.resolve(__dirname, '_meta/', fileName); + const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8'); + fs.outputFileSync(metaFilePath, metaFileContent); + } + }, + + /** + * Checks to see if the _meta directory has engine-specific head and foot files, + * spawning them if not found. + * + * @param {object} config - the global config object from core, since we won't + * assume it's already present + */ + spawnMeta: function (config) { + this.spawnFile(config, '_00-head.html'); + this.spawnFile(config, '_01-foot.html'); } + }; module.exports = engine_underscore; diff --git a/packages/patternengine-node-underscore/package.json b/packages/patternengine-node-underscore/package.json index 931197850..3537980dd 100644 --- a/packages/patternengine-node-underscore/package.json +++ b/packages/patternengine-node-underscore/package.json @@ -1,7 +1,7 @@ { - "name": "patternengine-node-underscore", + "name": "@pattern-lab/patternengine-node-underscore", "description": "The Underscore engine for Pattern Lab / Node", - "version": "1.2.0", + "version": "2.0.0-alpha.1", "main": "lib/engine_underscore.js", "dependencies": { "underscore": "^1.8.3" @@ -24,7 +24,8 @@ "author": "Brian Muenzenmeyer & Geoffrey Pursell", "license": "MIT", "scripts": { - "test": "grunt travis --verbose" + "test": "grunt travis --verbose", + "lint": "eslint **/*.js" }, "engines": { "node": ">=4.0"