From 19b0cce707adc01680069cc21bc8138939ced8ab Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Fri, 27 Jan 2017 17:36:59 -0600 Subject: [PATCH 1/3] Add a configuration option to export all patterns. --- core/lib/pattern_exporter.js | 11 +++++++++++ patternlab-config.json | 1 + 2 files changed, 12 insertions(+) diff --git a/core/lib/pattern_exporter.js b/core/lib/pattern_exporter.js index 1b899a6a2..6cfb28a63 100644 --- a/core/lib/pattern_exporter.js +++ b/core/lib/pattern_exporter.js @@ -14,6 +14,17 @@ var pattern_exporter = function () { function exportPatterns(patternlab) { //read the config export options var exportPartials = patternlab.config.patternExportPatternPartials; + var exportAll = patternlab.config.patternExportAll; + + if (exportAll) { + for (var i = 0; i < patternlab.patterns.length; i++) { + if (!patternlab.patterns[i].patternPartial.startsWith('-')) { + fs.outputFileSync(patternlab.config.patternExportDirectory + patternlab.patterns[i].patternPartial + '.html', patternlab.patterns[i].patternPartialCode); + } + } + + return; + } //find the chosen patterns to export for (var i = 0; i < exportPartials.length; i++) { diff --git a/patternlab-config.json b/patternlab-config.json index 70ff944c7..ec6c82b39 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -52,6 +52,7 @@ "patternStateCascade": ["inprogress", "inreview", "complete"], "patternStates": { }, + "patternExportAll": false, "patternExportPatternPartials": [], "patternExportDirectory": "./pattern_exports/", "cacheBust": true, From 410032e42818ca3d44699c977b87a70ec62ac93e Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Fri, 27 Jan 2017 18:11:03 -0600 Subject: [PATCH 2/3] Make pattern export optionally preserve directory structure. Instead of prefixing patterns with "-", we prefix the directory path with "/". --- core/lib/pattern_exporter.js | 19 +++++++++++++++++-- patternlab-config.json | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/lib/pattern_exporter.js b/core/lib/pattern_exporter.js index 6cfb28a63..d89fa0cf2 100644 --- a/core/lib/pattern_exporter.js +++ b/core/lib/pattern_exporter.js @@ -1,6 +1,7 @@ "use strict"; var fs = require('fs-extra'); +var path = require('path'); var pattern_exporter = function () { @@ -19,7 +20,7 @@ var pattern_exporter = function () { if (exportAll) { for (var i = 0; i < patternlab.patterns.length; i++) { if (!patternlab.patterns[i].patternPartial.startsWith('-')) { - fs.outputFileSync(patternlab.config.patternExportDirectory + patternlab.patterns[i].patternPartial + '.html', patternlab.patterns[i].patternPartialCode); + exportSinglePattern(patternlab, patternlab.patterns[i]); } } @@ -31,12 +32,26 @@ var pattern_exporter = function () { for (var j = 0; j < patternlab.patterns.length; j++) { if (exportPartials[i] === patternlab.patterns[j].patternPartial) { //write matches to the desired location - fs.outputFileSync(patternlab.config.patternExportDirectory + patternlab.patterns[j].patternPartial + '.html', patternlab.patterns[j].patternPartialCode); + exportSinglePattern(patternlab, patternlab.patterns[j]); } } } } + function exportSinglePattern(patternlab, pattern) { + var preserveDirStructure = patternlab.config.patternExportPreserveDirectoryStructure; + var patternName = pattern.patternPartial; + var patternDir = patternlab.config.patternExportDirectory; + if (preserveDirStructure) { + // Extract the first part of the pattern partial as the directory in which + // it should go. + patternDir = path.join(patternDir, pattern.patternPartial.split('-')[0]); + patternName = pattern.patternPartial.split('-').slice(1).join('-'); + } + + fs.outputFileSync(path.join(patternDir, patternName) + '.html', pattern.patternPartialCode); + } + return { export_patterns: function (patternlab) { exportPatterns(patternlab); diff --git a/patternlab-config.json b/patternlab-config.json index ec6c82b39..127b370f0 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -53,6 +53,7 @@ "patternStates": { }, "patternExportAll": false, + "patternExportPreserveDirectoryStructure": false, "patternExportPatternPartials": [], "patternExportDirectory": "./pattern_exports/", "cacheBust": true, From 436dd99e50d808cd14691593b927209f1ecb663e Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Fri, 27 Jan 2017 18:26:37 -0600 Subject: [PATCH 3/3] Add ability to export raw patterns. Exporting "raw" patterns means that the export task is little more than a wrapper around a more condensed file naming method. Instead of outputting rendered HTML, the exporter outputs the raw patterns, augmented to remove any superfluous directory structure and prefixed ordering. --- core/lib/pattern_exporter.js | 9 ++++++++- patternlab-config.json | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/lib/pattern_exporter.js b/core/lib/pattern_exporter.js index d89fa0cf2..6333b7cf2 100644 --- a/core/lib/pattern_exporter.js +++ b/core/lib/pattern_exporter.js @@ -42,6 +42,8 @@ var pattern_exporter = function () { var preserveDirStructure = patternlab.config.patternExportPreserveDirectoryStructure; var patternName = pattern.patternPartial; var patternDir = patternlab.config.patternExportDirectory; + var patternCode = pattern.patternPartialCode; + var patternFileExtension = ".html"; if (preserveDirStructure) { // Extract the first part of the pattern partial as the directory in which // it should go. @@ -49,7 +51,12 @@ var pattern_exporter = function () { patternName = pattern.patternPartial.split('-').slice(1).join('-'); } - fs.outputFileSync(path.join(patternDir, patternName) + '.html', pattern.patternPartialCode); + if (patternlab.config.patternExportRaw) { + patternCode = pattern.extendedTemplate; + patternFileExtension = "." + JSON.parse(pattern.patternData).patternExtension; + } + + fs.outputFileSync(path.join(patternDir, patternName) + patternFileExtension, patternCode); } return { diff --git a/patternlab-config.json b/patternlab-config.json index 127b370f0..b410f98f3 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -54,6 +54,7 @@ }, "patternExportAll": false, "patternExportPreserveDirectoryStructure": false, + "patternExportRaw": false, "patternExportPatternPartials": [], "patternExportDirectory": "./pattern_exports/", "cacheBust": true,