diff --git a/.eslintrc b/.eslintrc index 6e83375..c445390 100644 --- a/.eslintrc +++ b/.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/_meta/_00-head.html b/_meta/_00-head.html new file mode 100644 index 0000000..b1f5c1c --- /dev/null +++ b/_meta/_00-head.html @@ -0,0 +1,16 @@ + + + + {{ title }} + + + + + + + + {{{ patternLabHead }}} + + + + diff --git a/_meta/_01-foot.html b/_meta/_01-foot.html new file mode 100644 index 0000000..797d941 --- /dev/null +++ b/_meta/_01-foot.html @@ -0,0 +1,6 @@ + + +{{{ patternLabFoot }}} + + + diff --git a/lib/engine_underscore.js b/lib/engine_underscore.js index 7647996..b6688fa 100644 --- a/lib/engine_underscore.js +++ b/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/package.json b/package.json index 9311978..3537980 100644 --- a/package.json +++ b/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"