diff --git a/.travis.yml b/.travis.yml index c185e08d3..844871fce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,15 @@ before_install: before_script: - npm install -g grunt-cli + - npm install patternengine-node-underscore + - npm install patternengine-node-handlebars + - npm install patternengine-node-twig branches: only: - master - dev + - issue/438-runAllTestsTravis notifications: webhooks: diff --git a/core/lib/object_factory.js b/core/lib/object_factory.js index e277c510d..71c07e4e6 100644 --- a/core/lib/object_factory.js +++ b/core/lib/object_factory.js @@ -6,7 +6,7 @@ var extend = require('util')._extend; // Pattern properties -var Pattern = function (relPath, data) { +var Pattern = function (relPath, data, patternlab) { // We expect relPath to be the path of the pattern template, relative to the // root of the pattern tree. Parse out the path parts and save the useful ones. var pathObj = path.parse(path.normalize(relPath)); @@ -29,10 +29,6 @@ var Pattern = function (relPath, data) { return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); }, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes - // calculated path from the root of the public directory to the generated html - // file for this pattern - this.patternLink = this.name + path.sep + this.name + '.html'; // '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html' - // the top-level pattern group this pattern belongs to. 'atoms' this.patternGroup = this.subdir.split(path.sep)[0].replace(/^\d*-/, ''); @@ -48,6 +44,10 @@ var Pattern = function (relPath, data) { // the joined pattern group and subgroup directory this.flatPatternPath = this.subdir.replace(/[\/\\]/g, '-'); // '00-atoms-00-global' + // calculated path from the root of the public directory to the generated + // (rendered!) html file for this pattern, to be shown in the iframe + this.patternLink = patternlab ? this.getPatternLink(patternlab, 'rendered') : null; + // The canonical "key" by which this pattern is known. This is the callable // name of the pattern. UPDATE: this.key is now known as this.patternPartial this.patternPartial = this.patternGroup + '-' + this.patternBaseName; @@ -84,6 +84,20 @@ Pattern.prototype = { } }, + // calculated path from the root of the public directory to the generated html + // file for this pattern. + // Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html' + getPatternLink: function (patternlab, suffixType) { + // if no suffixType is provided, we default to rendered + var suffixConfig = patternlab.config.outputFileSuffixes; + var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered; + + if (suffixType === 'rawTemplate') { + return this.name + path.sep + this.name + suffix + this.fileExtension; + } + return this.name + path.sep + this.name + suffix + '.html'; + }, + // the finders all delegate to the PatternEngine, which also encapsulates all // appropriate regexes findPartials: function () { @@ -111,16 +125,16 @@ Pattern.prototype = { // factory: creates an empty Pattern for miscellaneous internal use, such as // by list_item_hunter -Pattern.createEmpty = function (customProps) { - var pattern = new Pattern('', null); +Pattern.createEmpty = function (customProps, patternlab) { + var pattern = new Pattern('', null, patternlab); return extend(pattern, customProps); }; // factory: creates an Pattern object on-demand from a hash; the hash accepts // parameters that replace the positional parameters that the Pattern // constructor takes. -Pattern.create = function (relPath, data, customProps) { - var newPattern = new Pattern(relPath || '', data || null); +Pattern.create = function (relPath, data, customProps, patternlab) { + var newPattern = new Pattern(relPath || '', data || null, patternlab); return extend(newPattern, customProps); }; diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index 532d88f9d..1c305688d 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -94,7 +94,7 @@ var pattern_assembler = function () { function addPattern(pattern, patternlab) { //add the link to the global object - patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rendered + '.html'); + patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.patternLink; //only push to array if the array doesn't contain this pattern var isNew = true; @@ -213,7 +213,7 @@ var pattern_assembler = function () { if (proposedDirectoryStats.isDirectory()) { var subTypeMarkdownFileContents = fs.readFileSync(proposedDirectory + '.md', 'utf8'); var subTypeMarkdown = markdown_parser.parse(subTypeMarkdownFileContents); - var subTypePattern = new Pattern(relPath); + var subTypePattern = new Pattern(relPath, null, patternlab); subTypePattern.patternSectionSubtype = true; subTypePattern.patternLink = subTypePattern.name + '/index.html'; subTypePattern.patternDesc = subTypeMarkdown.markdown; @@ -244,7 +244,7 @@ var pattern_assembler = function () { if (!patternEngines.isPatternFile(filename, patternlab)) { return null; } //make a new Pattern Object - var currentPattern = new Pattern(relPath); + var currentPattern = new Pattern(relPath, null, patternlab); //if file is named in the syntax for variants if (patternEngines.isPseudoPatternJSON(filename)) { diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index ddc8aaa8b..b0c68175f 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -1,10 +1,10 @@ /* - * patternlab-node - v2.4.2 - 2016 + * patternlab-node - v2.4.3 - 2016 * * Brian Muenzenmeyer, Geoff Pursell, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -60,10 +60,10 @@ function processAllPatternsRecursive(pattern_assembler, patterns_dir, patternlab function checkConfiguration(patternlab) { //default the output suffixes if not present var outputFileSuffixes = { - rendered: '', + rendered: '.rendered', rawTemplate: '', markupOnly: '.markup-only' - } + }; if (!patternlab.config.outputFileSuffixes) { plutils.logOrange('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:'); @@ -355,13 +355,13 @@ var patternlab_engine = function (config) { //write the compiled template to the public patterns directory var patternPage = headHTML + pattern.patternPartialCode + footerHTML; - fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rendered + '.html'), patternPage); + fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered'), patternPage); //write the mustache file too - fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rawTemplate + pattern.fileExtension), pattern.template); + fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rawTemplate'), pattern.template); //write the encoded version too - fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.markupOnly + '.html'), pattern.patternPartialCode); + fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'markupOnly'), pattern.patternPartialCode); return true; }); diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index 104286366..a78240126 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -69,9 +69,9 @@ var ui_builder = function () { */ function writeFile(filePath, data, callback) { if (callback) { - fs.outputFile(filePath, data, callback); + fs.outputFileSync(filePath, data, callback); } else { - fs.outputFile(filePath, data); + fs.outputFileSync(filePath, data); } } @@ -82,7 +82,6 @@ var ui_builder = function () { * @returns boolean - whether or not the pattern is excluded */ function isPatternExcluded(pattern, patternlab) { - var styleGuideExcludes = patternlab.config.styleGuideExcludes; var isOmitted; // skip underscore-prefixed files @@ -103,16 +102,6 @@ var ui_builder = function () { return true; } - //this pattern is a member of any excluded pattern groups - isOmitted = styleGuideExcludes && styleGuideExcludes.length && _.some(styleGuideExcludes, function (exclude) { - return exclude === pattern.patternGroup; }); - if (isOmitted) { - if (patternlab.config.debug) { - console.log('Omitting ' + pattern.patternPartial + ' from styleguide patterns its patternGroup is specified in styleguideExcludes.'); - } - return true; - } - //this pattern is contained with a directory prefixed with an underscore (a handy way to hide whole directories from the nav isOmitted = pattern.relPath.charAt(0) === '_' || pattern.relPath.indexOf('/_') > -1; if (isOmitted) { @@ -154,7 +143,8 @@ var ui_builder = function () { engine: null, flatPatternPath: pattern.flatPatternPath, isDocPattern: true - } + }, + patternlab ); return docPattern; } @@ -463,6 +453,7 @@ var ui_builder = function () { var p; var typePatterns = []; + var styleGuideExcludes = patternlab.config.styleGuideExcludes; _.forOwn(patternTypeObj, function (patternSubtypes, patternSubtype) { @@ -492,7 +483,6 @@ var ui_builder = function () { return true; //stop yelling at us eslint we know we know }); - //do not create a viewall page for flat patterns if (!writeViewAllFile || !p) { return false; @@ -509,7 +499,19 @@ var ui_builder = function () { var viewAllHTML = buildViewAllHTML(patternlab, typePatterns, patternType); writeFile(paths.public.patterns + p.subdir + '/index.html', mainPageHeadHtml + viewAllHTML + footerHTML); - patterns = patterns.concat(typePatterns); + //determine if we should omit this patterntype completely from the viewall page + var omitPatternType = styleGuideExcludes && styleGuideExcludes.length + && _.some(styleGuideExcludes, function (exclude) { + return exclude === patternType; + }); + if (omitPatternType) { + if (patternlab.config.debug) { + console.log('Omitting ' + patternType + ' from building a viewall page because its patternGroup is specified in styleguideExcludes.'); + } + } else { + patterns = patterns.concat(typePatterns); + } + return true; //stop yelling at us eslint we know we know }); return patterns; diff --git a/package.json b/package.json index 68ae8715b..25442e032 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "patternlab-node", "description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).", - "version": "2.4.2", + "version": "2.4.3", "main": "./core/lib/patternlab.js", "dependencies": { "diveSync": "^0.3.0", diff --git a/patternlab-config.json b/patternlab-config.json index b3f2d975b..5292c76bd 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -54,5 +54,10 @@ }, "patternExportPatternPartials": [], "patternExportDirectory": "./pattern_exports/", - "cacheBust": true + "cacheBust": true, + "outputFileSuffixes": { + "rendered": ".rendered", + "rawTemplate": "", + "markupOnly": ".markup-only" + } } diff --git a/test/lineage_hunter_tests.js b/test/lineage_hunter_tests.js index 39a0bb1b2..aa77de5f1 100644 --- a/test/lineage_hunter_tests.js +++ b/test/lineage_hunter_tests.js @@ -30,15 +30,18 @@ function createBasePatternLabObject() { } }, outputFileSuffixes: { - rendered: '' - } + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + }, + patternStateCascade: ["inprogress", "inreview", "complete"] }; pl.data = {}; pl.data.link = {}; pl.config.debug = false; pl.patterns = []; pl.partials = {}; - pl.config.patternStateCascade = ["inprogress", "inreview", "complete"]; + return pl; } @@ -57,7 +60,7 @@ exports['lineage hunter '] = { var patternlab = { patterns: [ - { + Pattern.createEmpty({ "name": "00-atoms-03-images-00-logo", "subdir": "00-atoms\\03-images", "filename": "00-logo.mustache", @@ -75,8 +78,8 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] - }, - { + }), + Pattern.createEmpty({ "name": "01-molecules-05-navigation-00-primary-nav", "subdir": "01-molecules\\05-navigation", "filename": "00-primary-nav.mustache", @@ -94,8 +97,8 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] - }, - { + }), + Pattern.createEmpty({ "name": "01-molecules-04-forms-00-search", "subdir": "01-molecules\\04-forms", "filename": "00-search.mustache", @@ -113,11 +116,13 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] - } + }) ], config: { outputFileSuffixes: { - rendered: '' + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' } } }; @@ -150,7 +155,14 @@ exports['lineage hunter '] = { "template": "