diff --git a/.github/gitgraph/patternlab-flow.js b/.github/gitgraph/patternlab-flow.js index 79872b09a..a68910cee 100644 --- a/.github/gitgraph/patternlab-flow.js +++ b/.github/gitgraph/patternlab-flow.js @@ -1,58 +1,65 @@ var graphConfig = new GitGraph.Template({ - colors: [ "#9993FF", "#47E8D4", "#6BDB52", "#F85BB5", "#FFA657", "#FFCCAA", "#F85BB5" ], + colors: [ + '#9993FF', + '#47E8D4', + '#6BDB52', + '#F85BB5', + '#FFA657', + '#FFCCAA', + '#F85BB5', + ], branch: { lineWidth: 3, spacingX: 60, - mergeStyle: "straight", + mergeStyle: 'straight', showLabel: true, // display branch names on graph - labelFont: "normal 10pt Arial", + labelFont: 'normal 10pt Arial', labelRotation: 0, - color: "black" + color: 'black', }, commit: { spacingY: -30, dot: { size: 8, - strokeColor: "#000000", - strokeWidth: 4 + strokeColor: '#000000', + strokeWidth: 4, }, tag: { - font: "normal 10pt Arial", - color: "yellow" + font: 'normal 10pt Arial', + color: 'yellow', }, message: { - color: "black", - font: "normal 12pt Arial", + color: 'black', + font: 'normal 12pt Arial', displayAuthor: false, displayBranch: false, displayHash: false, - } + }, }, arrow: { size: 8, offset: 3, - - } + }, }); var config = { template: graphConfig, - mode: "extended", - orientation: "horizontal" + mode: 'extended', + orientation: 'horizontal', }; var bugFixCommit = { messageAuthorDisplay: false, messageBranchDisplay: false, messageHashDisplay: false, - message: "Bug fix commit(s)" + message: 'Bug fix commit(s)', }; var stabilizationCommit = { messageAuthorDisplay: false, messageBranchDisplay: false, messageHashDisplay: false, - message: "Release stabilization commit(s)" + message: 'Release stabilization commit(s)', }; // You can manually fix columns to control the display. @@ -68,109 +75,104 @@ var masterCol = i++; var gitgraph = new GitGraph(config); var master = gitgraph.branch({ - name: "master", - column: masterCol + name: 'master', + column: masterCol, }); -master.commit("Initial commit"); +master.commit('Initial commit'); var develop = gitgraph.branch({ parentBranch: master, - name: "dev", - column: developCol + name: 'dev', + column: developCol, }); var developV3 = gitgraph.branch({ parentBranch: master, - name: "dev-3.0", - column: developV3Col + name: 'dev-3.0', + column: developV3Col, }); - var longRunning = gitgraph.branch({ parentBranch: master, - name: "long-running-improvement", - column: longRunningCol + name: 'long-running-improvement', + column: longRunningCol, }); develop.commit({ - messageDisplay: false + messageDisplay: false, }); developV3.commit({ - messageDisplay: false + messageDisplay: false, }); longRunning.commit({ - messageDisplay: false + messageDisplay: false, }); longRunning.merge(developV3); var feature1 = gitgraph.branch({ parentBranch: develop, - name: "feature/1-description", - column: featureCol + name: 'feature/1-description', + column: featureCol, }); -feature1.commit("#1 A feature to go into v2.8.0").commit({ - messageDisplay: false +feature1.commit('#1 A feature to go into v2.8.0').commit({ + messageDisplay: false, }); develop.merge(feature1); -feature1.commit("Small Bugfix").commit({ - messageDisplay: false +feature1.commit('Small Bugfix').commit({ + messageDisplay: false, }); feature1.merge(develop); - var feature3X = gitgraph.branch({ parentBranch: developV3, - name: "feature/42-feature-for-3-x-only", - column: featureV3Col + name: 'feature/42-feature-for-3-x-only', + column: featureV3Col, }); -feature3X.commit("#42 A feature to go into v3.X").commit({ - messageDisplay: false +feature3X.commit('#42 A feature to go into v3.X').commit({ + messageDisplay: false, }); feature3X.merge(developV3); - var feature2 = gitgraph.branch({ parentBranch: develop, - name: "feature/2-description", - column: featureCol + name: 'feature/2-description', + column: featureCol, }); -feature2.commit("#2 Another feature to go into v2.8.0").commit({ - messageDisplay: false +feature2.commit('#2 Another feature to go into v2.8.0').commit({ + messageDisplay: false, }); feature2.merge(develop); feature2.merge(developV3); -develop.merge(master,{ +develop.merge(master, { dotStrokeWidth: 10, - message: "Release v2.8.1 tagged", - tag: "v2.8.1" + message: 'Release v2.8.1 tagged', + tag: 'v2.8.1', }); - develop.commit({ - messageDisplay: false + messageDisplay: false, }); - longRunning.commit({ - messageDisplay: false + messageDisplay: false, }); developV3.merge(longRunning); longRunning.commit({ - messageDisplay: false + messageDisplay: false, }); var feature3 = gitgraph.branch({ parentBranch: develop, - name: "bugfix/3-description", - column: featureCol + name: 'bugfix/3-description', + column: featureCol, }); -feature3.commit("A feature to go into v2.8.0").commit({ - messageDisplay: false +feature3.commit('A feature to go into v2.8.0').commit({ + messageDisplay: false, }); feature3.merge(develop); @@ -178,27 +180,26 @@ longRunning.merge(developV3); developV3.commit({ messageDisplay: false, - dotStrokeWidth: 10 + dotStrokeWidth: 10, }); - develop.commit({ - messageDisplay: false + messageDisplay: false, }); develop.commit({ - messageDisplay: false + messageDisplay: false, }); develop.merge(master, { dotStrokeWidth: 10, - message: "Release v2.9.0 tagged", - tag: "v2.9.0" + message: 'Release v2.9.0 tagged', + tag: 'v2.9.0', }); develop.commit({ messageDisplay: false, - dotStrokeWidth: 10 + dotStrokeWidth: 10, }); developV3.checkout(); diff --git a/.prettierignore b/.prettierignore index d65bda2a4..b0a54c78d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,9 @@ **/*.json **/README.md +**/node_modules/ +**/bower_components/ +**/dist/ +**/public/ +**/*.min.js ./packages/core/scripts/api.handlebars ./packages/core/scripts/events.handlebars diff --git a/packages/core/package.json b/packages/core/package.json index 228261dd9..e554cd09b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -60,9 +60,7 @@ "scripts": { "docs": "node ./scripts/docs.js", "lint": "eslint src/**/*.js", - "precommit": "pretty-quick --staged", "pretest": "npm run lint", - "prettier": "prettier --config .prettierrc --write ./src/**/*.js", "release": "standard-version", "test": "tap test/*_tests.js --reporter spec --coverage" }, diff --git a/packages/core/test/files/annotations.js b/packages/core/test/files/annotations.js index f1077ed02..557b04676 100644 --- a/packages/core/test/files/annotations.js +++ b/packages/core/test/files/annotations.js @@ -1,14 +1,16 @@ var comments = { - "comments" : [ + comments: [ { - "el": "header[role=banner]", - "title" : "Masthead", - "comment": "The main header of the site doesn't take up too much screen real estate in order to keep the focus on the core content. It's using a linear CSS gradient instead of a background image to give greater design flexibility and reduce HTTP requests." + el: 'header[role=banner]', + title: 'Masthead', + comment: + "The main header of the site doesn't take up too much screen real estate in order to keep the focus on the core content. It's using a linear CSS gradient instead of a background image to give greater design flexibility and reduce HTTP requests.", }, { - "el": ".logo", - "title" : "Logo", - "comment": "The logo image is an SVG file, which ensures that the logo displays crisply even on high resolution displays. A PNG fallback is provided for browsers that don't support SVG images.
Further reading: Optimizing Web Experiences for High Resolution Screens
" - } - ] + el: '.logo', + title: 'Logo', + comment: + 'The logo image is an SVG file, which ensures that the logo displays crisply even on high resolution displays. A PNG fallback is provided for browsers that don\'t support SVG images.Further reading: Optimizing Web Experiences for High Resolution Screens
', + }, + ], }; diff --git a/packages/core/test/help_tests.js b/packages/core/test/help_tests.js index d62db006c..847c77a52 100644 --- a/packages/core/test/help_tests.js +++ b/packages/core/test/help_tests.js @@ -3,9 +3,7 @@ const tap = require('tap'); const help = require('../src/lib/help'); -tap.test('help - includes passed in version number', function( - test -) { +tap.test('help - includes passed in version number', function(test) { //arrange const version = '⚡'; diff --git a/packages/engine-handlebars/lib/engine_handlebars.js b/packages/engine-handlebars/lib/engine_handlebars.js index 1a5e5a7d3..dbeb88312 100644 --- a/packages/engine-handlebars/lib/engine_handlebars.js +++ b/packages/engine-handlebars/lib/engine_handlebars.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; /* * handlebars pattern engine for patternlab-node @@ -32,7 +32,10 @@ const findListItemsRE = /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|s const findAtPartialBlockRE = /{{#?>\s*@partial-block\s*}}/g; function escapeAtPartialBlock(partialString) { - var partial = partialString.replace(findAtPartialBlockRE, '{{> @partial-block }}'); + var partial = partialString.replace( + findAtPartialBlockRE, + '{{> @partial-block }}' + ); return partial; } @@ -51,14 +54,12 @@ var engine_handlebars = { Handlebars.registerPartial(partials); } - var compiled = Handlebars.compile( - escapeAtPartialBlock(pattern.template) - ); + var compiled = Handlebars.compile(escapeAtPartialBlock(pattern.template)); return Promise.resolve(compiled(data)); }, - registerPartial: function (pattern) { + registerPartial: function(pattern) { // register exact partial name Handlebars.registerPartial(pattern.patternPartial, pattern.template); @@ -70,7 +71,7 @@ var engine_handlebars = { var matches = pattern.template.match(findPartialsRE); return matches; }, - findPartialsWithStyleModifiers: function () { + findPartialsWithStyleModifiers: function() { // TODO: make the call to this from oPattern objects conditional on their // being implemented here. return []; @@ -78,47 +79,49 @@ var engine_handlebars = { // returns any patterns that match {{> value(foo:"bar") }} or {{> // value:mod(foo:"bar") }} within the pattern - findPartialsWithPatternParameters: function () { + findPartialsWithPatternParameters: function() { // TODO: make the call to this from oPattern objects conditional on their // being implemented here. return []; }, - findListItems: function (pattern) { + findListItems: function(pattern) { var matches = pattern.template.match(findListItemsRE); return matches; }, // given a pattern, and a partial string, tease out the "pattern key" and // return it. - findPartial: function (partialString) { + findPartial: function(partialString) { var partial = partialString.replace(findPartialsRE, '$1'); return partial; }, - spawnFile: function (config, fileName) { + 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 metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8'); + 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) { + * 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.hbs'); this.spawnFile(config, '_01-foot.hbs'); - } + }, }; module.exports = engine_handlebars; diff --git a/packages/engine-liquid/lib/engine_liquid.js b/packages/engine-liquid/lib/engine_liquid.js index 9c97e35b1..0f61aff59 100644 --- a/packages/engine-liquid/lib/engine_liquid.js +++ b/packages/engine-liquid/lib/engine_liquid.js @@ -7,22 +7,25 @@ * */ -"use strict"; +'use strict'; const fs = require('fs-extra'); const path = require('path'); const isDirectory = source => fs.lstatSync(source).isDirectory(); const getDirectories = source => - fs.readdirSync(source).map(name => path.join(source, name)).filter(isDirectory); + fs + .readdirSync(source) + .map(name => path.join(source, name)) + .filter(isDirectory); -const { lstatSync, readdirSync } = require('fs') -const { join } = require('path') +const { lstatSync, readdirSync } = require('fs'); +const { join } = require('path'); var utils = require('./util_liquid'); var Liquid = require('liquidjs'); let engine = Liquid({ - dynamicPartials: false + dynamicPartials: false, }); // This holds the config from from core. The core has to call @@ -48,11 +51,13 @@ module.exports = { // render it renderPattern: function renderPattern(pattern, data, partials) { - return engine.parseAndRender(pattern.template, data) - .then(function(html){ + return engine + .parseAndRender(pattern.template, data) + .then(function(html) { return html; - }).catch(function(ex){ - console.log(40, ex) + }) + .catch(function(ex) { + console.log(40, ex); }); }, @@ -67,7 +72,10 @@ module.exports = { var matches; if (typeof pattern === 'string') { matches = pattern.match(regex); - } else if (typeof pattern === 'object' && typeof pattern.template === 'string') { + } else if ( + typeof pattern === 'object' && + typeof pattern.template === 'string' + ) { matches = pattern.template.match(regex); } return matches; @@ -78,38 +86,51 @@ module.exports = { var matches = this.patternMatcher(pattern, this.findPartialsRE); return matches; }, - findPartialsWithStyleModifiers: function (pattern) { - var matches = this.patternMatcher(pattern, this.findPartialsWithStyleModifiersRE); + findPartialsWithStyleModifiers: function(pattern) { + var matches = this.patternMatcher( + pattern, + this.findPartialsWithStyleModifiersRE + ); return matches; }, // returns any patterns that match {{> value(foo:"bar") }} or {{> // value:mod(foo:"bar") }} within the pattern - findPartialsWithPatternParameters: function (pattern) { - var matches = this.patternMatcher(pattern, this.findPartialsWithPatternParametersRE); + findPartialsWithPatternParameters: function(pattern) { + var matches = this.patternMatcher( + pattern, + this.findPartialsWithPatternParametersRE + ); return matches; }, - findListItems: function (pattern) { + findListItems: function(pattern) { var matches = this.patternMatcher(pattern, this.findListItemsRE); return matches; }, // given a pattern, and a partial string, tease out the "pattern key" and // return it. - findPartial_new: function (partialString) { + findPartial_new: function(partialString) { var partial = partialString.replace(this.findPartialRE, '$1'); return partial; }, // GTP: the old implementation works better. We might not need // this.findPartialRE anymore if it works in all cases! - findPartial: function (partialString) { + findPartial: function(partialString) { //strip out the template cruft - var foundPatternPartial = partialString.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", ""); + var foundPatternPartial = partialString + .replace('{{> ', '') + .replace(' }}', '') + .replace('{{>', '') + .replace('}}', ''); // remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time if (foundPatternPartial.indexOf('(') > 0) { - foundPatternPartial = foundPatternPartial.substring(0, foundPatternPartial.indexOf('(')); + foundPatternPartial = foundPatternPartial.substring( + 0, + foundPatternPartial.indexOf('(') + ); } //remove any potential stylemodifiers. @@ -124,7 +145,7 @@ module.exports = { * * @param {object} config - the global config object from core */ - usePatternLabConfig: function (config) { + usePatternLabConfig: function(config) { patternLabConfig = config; let patternsPath = patternLabConfig.paths.source.patterns; @@ -138,34 +159,36 @@ module.exports = { engine = Liquid({ dynamicPartials: false, - root: allPaths + root: allPaths, }); }, - spawnFile: function (config, fileName) { + 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'); + 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) { + * 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.liquid'); this.spawnFile(config, '_01-foot.liquid'); - } + }, }; diff --git a/packages/engine-liquid/lib/util_liquid.js b/packages/engine-liquid/lib/util_liquid.js index 7508bc74a..3bc200d78 100644 --- a/packages/engine-liquid/lib/util_liquid.js +++ b/packages/engine-liquid/lib/util_liquid.js @@ -11,7 +11,9 @@ // the term "alphanumeric" includes underscores. // todo: document this exact regex long form. -var partialsRE = new RegExp(/{%\\include\\\s*?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(?:| )\(.*)?(?:\s*)?%}/g); +var partialsRE = new RegExp( + /{%\\include\\\s*?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(?:| )\(.*)?(?:\s*)?%}/g +); // look for an opening mustache include tag, followed by >=0 whitespaces var partialsWithStyleModifiersStr = '{{>\\s*'; @@ -34,7 +36,10 @@ partialsWithStyleModifiersStr += '(\\s*\\([^\\)]*\\))?'; // look for >=0 whitespaces, followed by closing mustache tag partialsWithStyleModifiersStr += '\\s*}}'; -var partialsWithStyleModifiersRE = new RegExp(partialsWithStyleModifiersStr, 'g'); +var partialsWithStyleModifiersRE = new RegExp( + partialsWithStyleModifiersStr, + 'g' +); // look for an opening mustache include tag, followed by >=0 whitespaces var partialsWithPatternParametersStr = '{{>\\s*'; @@ -55,7 +60,10 @@ partialsWithPatternParametersStr += '(\\s*\\([^\\)]*\\))'; // look for >=0 whitespaces, followed by closing mustache tag partialsWithPatternParametersStr += '\\s*}}'; -var partialsWithPatternParametersRE = new RegExp(partialsWithPatternParametersStr, 'g'); +var partialsWithPatternParametersRE = new RegExp( + partialsWithPatternParametersStr, + 'g' +); // look for an opening mustache loop tag, followed by >=0 whitespaces var listItemsStr = '{{#\\s*'; @@ -64,7 +72,8 @@ var listItemsStr = '{{#\\s*'; listItemsStr += '(list(I|i)tems\\.)'; // look for a number 1 - 20, spelled out -listItemsStr += '(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)'; +listItemsStr += + '(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)'; // look for >=0 whitespaces, followed by closing mustache tag listItemsStr += '\\s*}}'; @@ -95,7 +104,7 @@ var utilLiquid = { partialsWithStyleModifiersRE: partialsWithStyleModifiersRE, partialsWithPatternParametersRE: partialsWithPatternParametersRE, listItemsRE: listItemsRE, - partialKeyRE: partialKeyRE + partialKeyRE: partialKeyRE, }; module.exports = utilLiquid; diff --git a/packages/engine-nunjucks/lib/engine_nunjucks.js b/packages/engine-nunjucks/lib/engine_nunjucks.js index d5d0a93d7..5c149d3f9 100644 --- a/packages/engine-nunjucks/lib/engine_nunjucks.js +++ b/packages/engine-nunjucks/lib/engine_nunjucks.js @@ -18,7 +18,7 @@ * */ -"use strict"; +'use strict'; var fs = require('fs-extra'), path = require('path'), @@ -28,17 +28,18 @@ var fs = require('fs-extra'), env = nunjucks.configure(plConfig.paths.source.patterns), partialRegistry = []; - //////////////////////////// // LOAD ANY USER NUNJUCKS CONFIGURATIONS //////////////////////////// try { - var nunjucksConfig = require(path.join(plPath, 'patternlab-nunjucks-config.js')); + var nunjucksConfig = require(path.join( + plPath, + 'patternlab-nunjucks-config.js' + )); if (typeof nunjucksConfig == 'function') { nunjucksConfig(nunjucks, env); } -} catch (err) { } - +} catch (err) {} //////////////////////////// // HELPER FUNCTIONS @@ -46,12 +47,17 @@ try { // Might do some research on the solution. //////////////////////////// if (!String.prototype.replaceAll) { - String.prototype.replaceAll = function (str1, str2, ignore) { - return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, "\\$&"), (ignore ? "gi" : "g")), (typeof (str2) == "string") ? str2.replace(/\$/g, "$$$$") : str2); - } + String.prototype.replaceAll = function(str1, str2, ignore) { + return this.replace( + new RegExp( + str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, '\\$&'), + ignore ? 'gi' : 'g' + ), + typeof str2 == 'string' ? str2.replace(/\$/g, '$$$$') : str2 + ); + }; } - //////////////////////////// // NUNJUCKS ENGINE //////////////////////////// @@ -75,8 +81,7 @@ var engine_nunjucks = { pattern.extendedTemplate = this.replacePartials(pattern); var result = nunjucks.renderString(pattern.extendedTemplate, data); return Promise.resolve(result); - } - catch (err) { + } catch (err) { console.error('Failed to render pattern: ' + pattern.name); } }, @@ -88,69 +93,86 @@ var engine_nunjucks = { }, // given a pattern, and a partial string, tease out the "pattern key" and return it. - findPartial: function (partialString) { + findPartial: function(partialString) { try { var partial = partialString.match(this.findPartialKeyRE)[1]; partial = partial.replace(/["']/g, ''); return partial; - } - catch (err) { - console.error('Error occured when trying to find partial name in: ' + partialString); + } catch (err) { + console.error( + 'Error occured when trying to find partial name in: ' + partialString + ); } }, // keep track of partials and their paths so we can replace the name with the path - registerPartial: function (pattern) { + registerPartial: function(pattern) { // only register each partial once. Otherwise we'll eat up a ton of memory. if (partialRegistry.indexOf(pattern.patternPartial) === -1) { - partialRegistry[pattern.patternPartial] = pattern.relPath.replace(/\\/g, '/'); + partialRegistry[pattern.patternPartial] = pattern.relPath.replace( + /\\/g, + '/' + ); } }, - replacePartials: function (pattern) { + replacePartials: function(pattern) { try { var partials = this.findPartials(pattern); if (partials !== null) { - for (var i = 0; i < partials.length; i++) { // e.g. {% include "atoms-parent" %} + for (var i = 0; i < partials.length; i++) { + // e.g. {% include "atoms-parent" %} var partialName = this.findPartial(partials[i]); // e.g. atoms-parent var partialFullPath = partialRegistry[partialName]; // e.g. 00-atoms/01-parent.njk - var newPartial = partials[i].replaceAll(partialName, partialFullPath, true); // e.g. {% include "00-atoms/01-parent.njk" %} - pattern.extendedTemplate = pattern.extendedTemplate.replaceAll(partials[i], newPartial, true); + var newPartial = partials[i].replaceAll( + partialName, + partialFullPath, + true + ); // e.g. {% include "00-atoms/01-parent.njk" %} + pattern.extendedTemplate = pattern.extendedTemplate.replaceAll( + partials[i], + newPartial, + true + ); } } return pattern.extendedTemplate; - } - catch (err) { - console.error('Error occurred in replacing partial names with paths for patern: ' + pattern.name); + } catch (err) { + console.error( + 'Error occurred in replacing partial names with paths for patern: ' + + pattern.name + ); } }, // still requires the mustache syntax because of the way PL handles lists - findListItems: function (pattern) { + findListItems: function(pattern) { var matches = pattern.template.match(this.findListItemsRE); return matches; }, // handled by nunjucks. This is here to keep PL from erroring - findPartialsWithStyleModifiers: function () { + findPartialsWithStyleModifiers: function() { return null; }, // handled by nunjucks. This is here to keep PL from erroring - findPartialsWithPatternParameters: function () { + findPartialsWithPatternParameters: function() { return null; }, - spawnFile: function (config, fileName) { + 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'); + const metaFileContent = fs.readFileSync( + path.resolve(__dirname, '..', '_meta/', fileName), + 'utf8' + ); fs.outputFileSync(metaFilePath, metaFileContent); } }, @@ -162,10 +184,10 @@ var engine_nunjucks = { * @param {object} config - the global config object from core, since we won't * assume it's already present */ - spawnMeta: function (config) { + spawnMeta: function(config) { this.spawnFile(config, '_00-head.njk'); this.spawnFile(config, '_01-foot.njk'); - } + }, }; module.exports = engine_nunjucks; diff --git a/packages/engine-nunjucks/package.json b/packages/engine-nunjucks/package.json index 3c2ad19e4..34b03b63e 100644 --- a/packages/engine-nunjucks/package.json +++ b/packages/engine-nunjucks/package.json @@ -29,5 +29,8 @@ "scripts": { "test": "grunt travis --verbose" }, - "version": "0.1.3" + "version": "0.1.4-alpha.0", + "publishConfig": { + "access": "public" + } } diff --git a/packages/live-server/index.js b/packages/live-server/index.js index 7e80e3ff0..4da8f2db4 100644 --- a/packages/live-server/index.js +++ b/packages/live-server/index.js @@ -1,101 +1,120 @@ #!/usr/bin/env node var fs = require('fs'), - connect = require('connect'), - serveIndex = require('serve-index'), - logger = require('morgan'), - WebSocket = require('faye-websocket'), - path = require('path'), - url = require('url'), - http = require('http'), - send = require('send'), - open = require('opn'), - es = require("event-stream"), - os = require('os'), - chokidar = require('chokidar'); + connect = require('connect'), + serveIndex = require('serve-index'), + logger = require('morgan'), + WebSocket = require('faye-websocket'), + path = require('path'), + url = require('url'), + http = require('http'), + send = require('send'), + open = require('opn'), + es = require('event-stream'), + os = require('os'), + chokidar = require('chokidar'); require('colors'); -var INJECTED_CODE = fs.readFileSync(path.join(__dirname, "injected.html"), "utf8"); +var INJECTED_CODE = fs.readFileSync( + path.join(__dirname, 'injected.html'), + 'utf8' +); var LiveServer = { - server: null, - watcher: null, - logLevel: 2 + server: null, + watcher: null, + logLevel: 2, }; -function escape(html){ - return String(html) - .replace(/&(?!\w+;)/g, '&') - .replace(//g, '>') - .replace(/"/g, '"'); +function escape(html) { + return String(html) + .replace(/&(?!\w+;)/g, '&') + .replace(//g, '>') + .replace(/"/g, '"'); } // Based on connect.static(), but streamlined and with added code injecter function staticServer(root) { - var isFile = false; - try { // For supporting mounting files instead of just directories - isFile = fs.statSync(root).isFile(); - } catch (e) { - if (e.code !== "ENOENT") throw e; - } - return function(req, res, next) { - if (req.method !== "GET" && req.method !== "HEAD") return next(); - var reqpath = isFile ? "" : url.parse(req.url).pathname; - var hasNoOrigin = !req.headers.origin; - var injectCandidates = [ new RegExp("