From dd1d9abf1860e90a2bca18e3d0867e487830b117 Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Thu, 15 Dec 2016 20:30:37 -0500 Subject: [PATCH 1/9] add return doc to InsertNodes class --- src/web/huron.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/web/huron.js b/src/web/huron.js index 9db3b7b..c0bfc1d 100644 --- a/src/web/huron.js +++ b/src/web/huron.js @@ -45,6 +45,7 @@ class InsertNodes { * * @param {string} modifier - target modifier * @param {object} meta - module metadata + * @return {string} rendered - the modified HTML module */ static applyModifier(modifier, meta) { let rendered = false; @@ -68,6 +69,7 @@ class InsertNodes { * Get markup from any type of module (html, json or template) * * @param {string} content - String corresponding to markup + * @return {object} el.firstElementChild - HTML module */ static convertToElement(content) { const el = document.createElement('div'); @@ -84,6 +86,7 @@ class InsertNodes { * @param {array} filter.values - Values for property * @param {bool} filter.include - Whether the values should be included or excluded (true = include, false = exclude) * @param {object} moduleMeta - Filter for modules. Fields explained in the filterModules() function docs + * @return {bool} match - determine if modules need to be filtered */ static filterModules(filter, moduleMeta) { let match = true; @@ -113,6 +116,7 @@ class InsertNodes { * Generate a hash string from a module key * * @param {string} key - module key (require path) to convert into a hash + * @return {string} key - generated MD5 Hash */ static generateModuleHash(key) { return md5(key); @@ -123,6 +127,7 @@ class InsertNodes { * * @param {object} tag - tag to check * @param {object} meta - module metadata + * @return {bool} */ static isSectionHelper(tag, meta) { if ('prototype' === meta.type) { @@ -287,6 +292,7 @@ class InsertNodes { * return its associated module key * * @param {object} tag - tag to check + * @return {bool} associated module key */ getModuleKeyFromTag(tag) { const type = tag.dataset.huronType; @@ -309,6 +315,7 @@ class InsertNodes { * * @param {array} tags - array of DOM nodes * @param {bool} recurse - should we recurse this function with a new array + * @return {object} moduleList - Huron placeholder DOM node */ getModuleListFromTags(elements, recurse = true) { const moduleList = {}; @@ -676,7 +683,7 @@ class InsertNodes { * Verify specified element is using an acceptable huron type * * @param {string} type - type of partial (template, data, description, section or prototype ) - * @return {string} huron type or 'template' if invalid + * @return {string} type - huron type or 'template' if invalid */ validateType(type) { if ('data' === type) { From e1e54eb8568baa3267fe4ee62f8060ecdd1d23b8 Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 16 Dec 2016 11:00:03 -0500 Subject: [PATCH 2/9] update return doc cli/utils --- src/cli/utils.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cli/utils.js b/src/cli/utils.js index 59ce0cd..253121e 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -15,6 +15,7 @@ export const utils = { * * @function normalizeSectionData * @param {object} section - section data + * @return {object} section data */ normalizeSectionData(section) { const data = section.data || section; @@ -69,6 +70,7 @@ export const utils = { * @function getTemplateDataPair * @param {object} file - file object from path.parse() * @param {object} section - KSS section data + * @return {string} relative path to module JSON file */ getTemplateDataPair(file, section, store) { const huron = store.get('config'); @@ -105,6 +107,7 @@ export const utils = { * * @function normalizeHeader * @param {string} header - section header extracted from KSS documentation + * @return {string} modified header, lowercase and words separated by dash */ normalizeHeader(header) { return header @@ -118,6 +121,7 @@ export const utils = { * @function wrapMarkup * @param {string} content - html or template markup * @param {string} templateId - id of template (should be section reference) + * @return {string} modified HTML */ wrapMarkup(content, templateId) { return ` @@ -271,7 +275,7 @@ ${content} * @function writeSectionTemplate * @param {string} search - key on which to match section * @param {field} string - field in which to look to determine section - * @param {obj} sections - sections memory store + * @param {obj} store - sections memory store */ getSection(search, field, store) { const sectionValues = store @@ -297,6 +301,7 @@ ${content} * @param {string} search - key on which to match section * @param {field} string - field in which to look to determine section * @param {obj} sections - sections memory store + * @return {string} kssMatch - relative path to KSS directory */ matchKssDir(filepath, huron) { const kssSource = huron.get('kss'); From 49ef14c7529097b07fa3229a83d7b5101def51a2 Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 16 Dec 2016 11:38:28 -0500 Subject: [PATCH 3/9] update return doc cli/actions --- src/cli/actions.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cli/actions.js b/src/cli/actions.js index ed0f44a..76705a3 100644 --- a/src/cli/actions.js +++ b/src/cli/actions.js @@ -18,6 +18,7 @@ const chalk = require('chalk'); // Colorize terminal output * @param {object} data - object containing directory and file paths * @param {object} store - memory store * @param {object} huron - huron configuration options + * @return {object} newStore - map object of huron configurations */ export function initFiles(data, store, depth = 0) { const type = Object.prototype.toString.call(data); @@ -60,6 +61,7 @@ export function initFiles(data, store, depth = 0) { * * @param {string} filepath - path to updated file. usually passed in from Gaze * @param {object} store - memory store + * @return {object} store - map object of updated huron configurations */ export function updateFile(filepath, store) { const huron = store.get('config'); @@ -122,6 +124,7 @@ export function updateFile(filepath, store) { * * @param {string} filepath - path to updated file. usually passed in from Gaze * @param {object} store - memory store + * @return {object} newStore - map object of updated huron configurations */ export function deleteFile(filepath, store) { const huron = store.get('config'); From a17283b0f22797cc0bd78428b391930c0c54f3a8 Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 16 Dec 2016 12:25:22 -0500 Subject: [PATCH 4/9] update return doc cli/generate-config --- src/cli/generate-config.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cli/generate-config.js b/src/cli/generate-config.js index e7811ad..1c10d33 100644 --- a/src/cli/generate-config.js +++ b/src/cli/generate-config.js @@ -16,6 +16,7 @@ const cwd = process.cwd(); * * @function generateConfig * @param {object} config - local webpack config + * @return {object} newConfig - updated webpack configuration object */ export default function generateConfig(config) { let newConfig = config; @@ -57,6 +58,7 @@ export default function generateConfig(config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated webpack configuration object */ function configureEntries(huron, config) { const entry = config.entry[huron.entry]; @@ -86,6 +88,7 @@ function configureEntries(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated webpack configuration object */ function configurePlugins(huron, config) { const newConfig = config; @@ -107,6 +110,7 @@ function configurePlugins(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated webpack configuration object */ function configureLoaders(huron, config) { // Manage loaders @@ -138,6 +142,7 @@ function configureLoaders(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated webpack configuration object */ function configurePrototypes(huron, config) { const wrapperTemplate = fs.readFileSync( @@ -229,6 +234,7 @@ function configurePrototypes(huron, config) { * @param {array|string} assets - array of assets or single asset * @param {string} subdir - subdirectory in huron root from which to load additional asset * @param {object} huron - huron configuration object + * @return {array} assetResults - paths to js and css assets */ function moveAdditionalAssets(assets, subdir = '', huron) { const currentAssets = [].concat(assets); From af83cf87e71189d46cfda79ab14ccde20c6055d7 Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 16 Dec 2016 13:40:29 -0500 Subject: [PATCH 5/9] update return doc cli/handle-html --- src/cli/handle-html.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cli/handle-html.js b/src/cli/handle-html.js index 302be48..31bc98b 100644 --- a/src/cli/handle-html.js +++ b/src/cli/handle-html.js @@ -16,6 +16,7 @@ export const htmlHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} modified huron configuration */ updateTemplate(filepath, section, store) { const file = path.parse(filepath); @@ -57,6 +58,7 @@ export const htmlHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} modified huron configuration */ deleteTemplate(filepath, section, store) { const newSection = section; @@ -87,6 +89,7 @@ export const htmlHandler = { * @function updatePrototype * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store + * @return {object} modified huron configuration */ updatePrototype(filepath, store) { const file = path.parse(filepath); @@ -117,6 +120,7 @@ export const htmlHandler = { * @function deletePrototype * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store + * @return {object} modified huron configuration */ deletePrototype(filepath, store) { const file = path.parse(filepath); From 2b01590ac7089083c2adf1badf8a80ef456ce949 Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 16 Dec 2016 14:52:09 -0500 Subject: [PATCH 6/9] update return doc cli/handle-kss --- src/cli/handle-kss.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cli/handle-kss.js b/src/cli/handle-kss.js index 9e48ec9..868103b 100644 --- a/src/cli/handle-kss.js +++ b/src/cli/handle-kss.js @@ -19,6 +19,7 @@ export const kssHandler = { * @function updateKSS * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store + * @return {object} map object of updated huron configuration */ updateKSS(filepath, store) { const kssSource = fs.readFileSync(filepath, 'utf8'); @@ -79,6 +80,7 @@ export const kssHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - KSS section data * @param {object} store - memory store + * @return {object} map object of updated huron configuration */ deleteKSS(filepath, section, store) { const file = path.parse(filepath); @@ -94,6 +96,7 @@ export const kssHandler = { * @param {object} section - contains updated section data * @param {string} kssPath - path to KSS section * @param {object} store - memory store + * @return {object} map object of updated huron configuration */ updateSectionData(kssPath, section, oldSection, store) { const sectionFileInfo = path.parse(kssPath); @@ -303,6 +306,7 @@ export const kssHandler = { * @param {string} file - file object from path.parse() * @param {object} store - memory store * @param {bool} removed - has the file been removed or just the section information changed? + * @return {object} updated memory store with new descripton path info */ unsetSection(section, file, store, removed) { const sorted = store.getIn(['sections', 'sorted']); @@ -349,6 +353,7 @@ export const kssHandler = { * @function sortSection * @param {object} sorted - currently sorted sections * @param {string} reference - reference URI of section to sort + * @return {object} updated memory store with new descripton path info */ sortSection(sorted, reference, delimiter) { const parts = reference.split(delimiter); @@ -375,6 +380,7 @@ export const kssHandler = { * @function unsortSection * @param {object} sorted - currently sorted sections * @param {string} reference - reference URI of section to sort + * @return {object} updated memory store with new descripton path info */ unsortSection(sorted, reference, delimiter) { const parts = reference.split(delimiter); @@ -405,6 +411,7 @@ export const kssHandler = { * @param {object} oldSection - currently sorted sections * @param {object} newSection - reference URI of section to sort * @param {string} field - KSS field to check + * @return {bool} output a new module for the KSS field? */ fieldShouldOutput(oldSection, newSection, field) { return (oldSection && From ef85ee78bb89c19caf51b94f9a3d656e6cc76a3a Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 16 Dec 2016 15:43:04 -0500 Subject: [PATCH 7/9] update return doc cli/handle-templates --- src/cli/handle-templates.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cli/handle-templates.js b/src/cli/handle-templates.js index c016f09..683d324 100644 --- a/src/cli/handle-templates.js +++ b/src/cli/handle-templates.js @@ -15,6 +15,7 @@ export const templateHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} updated memory store */ updateTemplate(filepath, section, store) { const file = path.parse(filepath); @@ -72,6 +73,7 @@ export const templateHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} updated memory store */ deleteTemplate(filepath, section, store) { const file = path.parse(filepath); From febb12ca49421a4a2ac879cfe9a7c385e27d7e50 Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 23 Dec 2016 13:26:13 -0500 Subject: [PATCH 8/9] match return doc description when returning data store objects --- src/cli/actions.js | 6 +++--- src/cli/generate-config.js | 10 +++++----- src/cli/handle-html.js | 8 ++++---- src/cli/handle-kss.js | 18 +++++++++--------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/cli/actions.js b/src/cli/actions.js index 76705a3..3ef9984 100644 --- a/src/cli/actions.js +++ b/src/cli/actions.js @@ -18,7 +18,7 @@ const chalk = require('chalk'); // Colorize terminal output * @param {object} data - object containing directory and file paths * @param {object} store - memory store * @param {object} huron - huron configuration options - * @return {object} newStore - map object of huron configurations + * @return {object} newStore - map object of entire data store */ export function initFiles(data, store, depth = 0) { const type = Object.prototype.toString.call(data); @@ -61,7 +61,7 @@ export function initFiles(data, store, depth = 0) { * * @param {string} filepath - path to updated file. usually passed in from Gaze * @param {object} store - memory store - * @return {object} store - map object of updated huron configurations + * @return {object} store - map object of map object of entire data store */ export function updateFile(filepath, store) { const huron = store.get('config'); @@ -124,7 +124,7 @@ export function updateFile(filepath, store) { * * @param {string} filepath - path to updated file. usually passed in from Gaze * @param {object} store - memory store - * @return {object} newStore - map object of updated huron configurations + * @return {object} newStore - map object of map object of entire data store */ export function deleteFile(filepath, store) { const huron = store.get('config'); diff --git a/src/cli/generate-config.js b/src/cli/generate-config.js index 1c10d33..89a38d1 100644 --- a/src/cli/generate-config.js +++ b/src/cli/generate-config.js @@ -16,7 +16,7 @@ const cwd = process.cwd(); * * @function generateConfig * @param {object} config - local webpack config - * @return {object} newConfig - updated webpack configuration object + * @return {object} newConfig - updated data store */ export default function generateConfig(config) { let newConfig = config; @@ -58,7 +58,7 @@ export default function generateConfig(config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object - * @return {object} newConfig - updated webpack configuration object + * @return {object} newConfig - updated data store */ function configureEntries(huron, config) { const entry = config.entry[huron.entry]; @@ -88,7 +88,7 @@ function configureEntries(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object - * @return {object} newConfig - updated webpack configuration object + * @return {object} newConfig - updated data store */ function configurePlugins(huron, config) { const newConfig = config; @@ -110,7 +110,7 @@ function configurePlugins(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object - * @return {object} newConfig - updated webpack configuration object + * @return {object} newConfig - updated data store */ function configureLoaders(huron, config) { // Manage loaders @@ -142,7 +142,7 @@ function configureLoaders(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object - * @return {object} newConfig - updated webpack configuration object + * @return {object} newConfig - updated data store */ function configurePrototypes(huron, config) { const wrapperTemplate = fs.readFileSync( diff --git a/src/cli/handle-html.js b/src/cli/handle-html.js index 31bc98b..6eb45cc 100644 --- a/src/cli/handle-html.js +++ b/src/cli/handle-html.js @@ -16,7 +16,7 @@ export const htmlHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store - * @return {object} modified huron configuration + * @return {object} updated data store */ updateTemplate(filepath, section, store) { const file = path.parse(filepath); @@ -58,7 +58,7 @@ export const htmlHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store - * @return {object} modified huron configuration + * @return {object} updated data store */ deleteTemplate(filepath, section, store) { const newSection = section; @@ -89,7 +89,7 @@ export const htmlHandler = { * @function updatePrototype * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store - * @return {object} modified huron configuration + * @return {object} updated data store */ updatePrototype(filepath, store) { const file = path.parse(filepath); @@ -120,7 +120,7 @@ export const htmlHandler = { * @function deletePrototype * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store - * @return {object} modified huron configuration + * @return {object} updated data store */ deletePrototype(filepath, store) { const file = path.parse(filepath); diff --git a/src/cli/handle-kss.js b/src/cli/handle-kss.js index 868103b..754cc7f 100644 --- a/src/cli/handle-kss.js +++ b/src/cli/handle-kss.js @@ -19,7 +19,7 @@ export const kssHandler = { * @function updateKSS * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store - * @return {object} map object of updated huron configuration + * @return {object} updated data store */ updateKSS(filepath, store) { const kssSource = fs.readFileSync(filepath, 'utf8'); @@ -80,7 +80,7 @@ export const kssHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - KSS section data * @param {object} store - memory store - * @return {object} map object of updated huron configuration + * @return {object} updated data store */ deleteKSS(filepath, section, store) { const file = path.parse(filepath); @@ -96,7 +96,7 @@ export const kssHandler = { * @param {object} section - contains updated section data * @param {string} kssPath - path to KSS section * @param {object} store - memory store - * @return {object} map object of updated huron configuration + * @return {object} updated data store */ updateSectionData(kssPath, section, oldSection, store) { const sectionFileInfo = path.parse(kssPath); @@ -179,7 +179,7 @@ export const kssHandler = { * @function updateInlineTemplate * @param {string} oldSection - previous iteration of KSS data, if updated * @param {object} section - KSS section data - * @return {object} updated memory store with new template path info + * @return {object} updated data store with new template path info */ updateInlineTemplate(filepath, oldSection, section, store) { const newSection = section; @@ -216,7 +216,7 @@ export const kssHandler = { * @function updateDescription * @param {string} oldSection - previous iteration of KSS data, if updated * @param {object} section - KSS section data - * @return {object} updated memory store with new descripton path info + * @return {object} updated data store with new descripton path info */ updateDescription(filepath, oldSection, section, store) { const newSection = section; @@ -306,7 +306,7 @@ export const kssHandler = { * @param {string} file - file object from path.parse() * @param {object} store - memory store * @param {bool} removed - has the file been removed or just the section information changed? - * @return {object} updated memory store with new descripton path info + * @return {object} updated data store with new descripton path info */ unsetSection(section, file, store, removed) { const sorted = store.getIn(['sections', 'sorted']); @@ -353,7 +353,7 @@ export const kssHandler = { * @function sortSection * @param {object} sorted - currently sorted sections * @param {string} reference - reference URI of section to sort - * @return {object} updated memory store with new descripton path info + * @return {object} updated data store with new descripton path info */ sortSection(sorted, reference, delimiter) { const parts = reference.split(delimiter); @@ -380,7 +380,7 @@ export const kssHandler = { * @function unsortSection * @param {object} sorted - currently sorted sections * @param {string} reference - reference URI of section to sort - * @return {object} updated memory store with new descripton path info + * @return {object} updated data store with new descripton path info */ unsortSection(sorted, reference, delimiter) { const parts = reference.split(delimiter); @@ -411,7 +411,7 @@ export const kssHandler = { * @param {object} oldSection - currently sorted sections * @param {object} newSection - reference URI of section to sort * @param {string} field - KSS field to check - * @return {bool} output a new module for the KSS field? + * @return {bool} output a new module for the KSS field */ fieldShouldOutput(oldSection, newSection, field) { return (oldSection && From cd9f3116df864c7901ab9b28795ec835a345c27b Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Fri, 23 Dec 2016 13:28:04 -0500 Subject: [PATCH 9/9] run build --- dist/cli/actions.js | 3 +++ dist/cli/actions.js.map | 2 +- dist/cli/generate-config.js | 6 ++++++ dist/cli/generate-config.js.map | 2 +- dist/cli/handle-html.js | 4 ++++ dist/cli/handle-html.js.map | 2 +- dist/cli/handle-kss.js | 11 +++++++++-- dist/cli/handle-kss.js.map | 2 +- dist/cli/handle-templates.js | 2 ++ dist/cli/handle-templates.js.map | 2 +- dist/cli/utils.js | 7 ++++++- dist/cli/utils.js.map | 2 +- dist/web/huron.js | 9 ++++++++- dist/web/huron.js.map | 2 +- 14 files changed, 45 insertions(+), 11 deletions(-) diff --git a/dist/cli/actions.js b/dist/cli/actions.js index a85df59..7787f28 100644 --- a/dist/cli/actions.js +++ b/dist/cli/actions.js @@ -30,6 +30,7 @@ var chalk = require('chalk'); // Colorize terminal output * @param {object} data - object containing directory and file paths * @param {object} store - memory store * @param {object} huron - huron configuration options + * @return {object} newStore - map object of entire data store */ function initFiles(data, store) { var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; @@ -72,6 +73,7 @@ function initFiles(data, store) { * * @param {string} filepath - path to updated file. usually passed in from Gaze * @param {object} store - memory store + * @return {object} store - map object of map object of entire data store */ function updateFile(filepath, store) { var huron = store.get('config'); @@ -130,6 +132,7 @@ function updateFile(filepath, store) { * * @param {string} filepath - path to updated file. usually passed in from Gaze * @param {object} store - memory store + * @return {object} newStore - map object of map object of entire data store */ function deleteFile(filepath, store) { var huron = store.get('config'); diff --git a/dist/cli/actions.js.map b/dist/cli/actions.js.map index 3d8df5c..5a2d24e 100644 --- a/dist/cli/actions.js.map +++ b/dist/cli/actions.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/cli/actions.js"],"names":["initFiles","updateFile","deleteFile","path","require","chalk","data","store","depth","type","Object","prototype","toString","call","newStore","info","files","keys","reduce","prevStore","file","parse","ext","filepath","huron","get","field","section","indexOf","writeSectionTemplate","getSection","base","updateTemplate","dir","name","updatePrototype","console","log","red","extension","updateKSS","deleteTemplate","deletePrototype","deleteKSS","warn"],"mappings":";;;;;QAqBgBA,S,GAAAA,S;QA0CAC,U,GAAAA,U;QA8DAC,U,GAAAA,U;;AA1HhB;;AACA;;AACA;;AACA;;AAEA;AARA;;AAEA;AAOA,IA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,gBAAU,aAAMG,UAAN,CAAiBP,QAAjB,EAA2B,KAA3B,EAAkChB,KAAlC,CAAV;;AAEA,UAAIoB,OAAJ,EAAa;AACXb,mBAAW,sBAAW6B,SAAX,CAAqBpB,QAArB,EAA+BI,OAA/B,EAAwCpB,KAAxC,CAAX;AACD;AACD;;AAEF;AACE6B,cAAQQ,IAAR,EAAe;AACbvC,YAAMiC,GAAN,wBAA+BlB,KAAKc,IAApC,CADF;AAGA;AArCJ;;AAwCA,SAAOpB,QAAP;AACD","file":"actions.js","sourcesContent":["/** @module cli/actions */\n\n// Imports\nimport { htmlHandler } from './handle-html';\nimport { templateHandler } from './handle-templates';\nimport { kssHandler } from './handle-kss';\nimport { utils } from './utils';\n\n// Requires\nconst path = require('path');\nconst chalk = require('chalk'); // Colorize terminal output\n\n// EXPORTED FUNCTIONS\n\n/**\n * Recursively loop through initial watched files list from Gaze.\n *\n * @param {object} data - object containing directory and file paths\n * @param {object} store - memory store\n * @param {object} huron - huron configuration options\n */\nexport function initFiles(data, store, depth = 0) {\n const type = Object.prototype.toString.call(data);\n let newStore = store;\n let info;\n let files;\n\n switch (type) {\n case '[object Object]':\n files = Object.keys(data);\n newStore = files.reduce(\n (prevStore, file) => initFiles(data[file], prevStore, depth),\n newStore\n );\n break;\n\n case '[object Array]':\n newStore = data.reduce(\n (prevStore, file) => initFiles(file, prevStore, depth),\n newStore\n );\n break;\n\n case '[object String]':\n info = path.parse(data);\n if (info.ext) {\n newStore = updateFile(data, store);\n }\n break;\n\n default:\n break;\n }\n\n return newStore;\n}\n\n/**\n * Logic for updating and writing file information based on file type (extension)\n *\n * @param {string} filepath - path to updated file. usually passed in from Gaze\n * @param {object} store - memory store\n */\nexport function updateFile(filepath, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n let field;\n let section;\n\n if (- 1 !== filepath.indexOf(huron.get('sectionTemplate'))) {\n return utils.writeSectionTemplate(filepath, store);\n }\n\n switch (file.ext) {\n // Plain HTML template, external\n case '.html':\n section = utils.getSection(file.base, 'markup', store);\n\n if (section) {\n return htmlHandler.updateTemplate(filepath, section, store);\n } else if (\n - 1 !== file.dir.indexOf('prototypes') &&\n - 1 !== file.name.indexOf('prototype-')\n ) {\n return htmlHandler.updatePrototype(filepath, store);\n }\n\n console.log(chalk.red(`Failed to write file: ${file.name}`));\n break;\n\n // Handlebars template, external\n case huron.get('templates').extension:\n case '.json':\n field = ('.json' === file.ext) ? 'data' : 'markup';\n section = utils.getSection(file.base, field, store);\n\n if (section) {\n return templateHandler.updateTemplate(filepath, section, store);\n }\n\n console.log( // eslint-disable-line no-console\n chalk.red(`Could not find associated KSS section for ${filepath}`)\n );\n break;\n\n // KSS documentation (default extension is `.css`)\n // Will also output a template if markup is inline\n // Note: inline markup does _not_ support handlebars currently\n case huron.get('kssExtension'):\n return kssHandler.updateKSS(filepath, store);\n\n // This should never happen if Gaze is working properly\n default:\n return store;\n }\n\n return store;\n}\n\n/**\n * Logic for deleting file information and files based on file type (extension)\n *\n * @param {string} filepath - path to updated file. usually passed in from Gaze\n * @param {object} store - memory store\n */\nexport function deleteFile(filepath, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n let field = '';\n let section = null;\n let newStore = store;\n\n switch (file.ext) {\n // Plain HTML template, external\n case '.html':\n section = utils.getSection(file.base, 'markup', store);\n\n if (section) {\n newStore = htmlHandler.deleteTemplate(filepath, section, store);\n } else if (\n - 1 !== file.dir.indexOf('prototypes') &&\n - 1 !== file.name.indexOf('prototype-')\n ) {\n newStore = htmlHandler.deletePrototype(filepath, store);\n }\n break;\n\n case huron.get('templates').extension:\n case '.json':\n field = ('.json' === file.ext) ? 'data' : 'markup';\n section = utils.getSection(file.base, field, store);\n\n if (section) {\n newStore = templateHandler.deleteTemplate(filepath, section, store);\n }\n break;\n\n case huron.get('kssExtension'):\n section = utils.getSection(filepath, false, store);\n\n if (section) {\n newStore = kssHandler.deleteKSS(filepath, section, store);\n }\n break;\n\n default:\n console.warn( // eslint-disable-line no-console\n chalk.red(`Could not delete: ${file.name}`)\n );\n break;\n }\n\n return newStore;\n}\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/cli/actions.js"],"names":["initFiles","updateFile","deleteFile","path","require","chalk","data","store","depth","type","Object","prototype","toString","call","newStore","info","files","keys","reduce","prevStore","file","parse","ext","filepath","huron","get","field","section","indexOf","writeSectionTemplate","getSection","base","updateTemplate","dir","name","updatePrototype","console","log","red","extension","updateKSS","deleteTemplate","deletePrototype","deleteKSS","warn"],"mappings":";;;;;QAsBgBA,S,GAAAA,S;QA2CAC,U,GAAAA,U;QA+DAC,U,GAAAA,U;;AA7HhB;;AACA;;AACA;;AACA;;AAEA;AARA;;AAEA;AAOA,IAAMC,OAAOC,QAAQ,MAAR,CAAb;AACA,IAAMC,QAAQD,QAAQ,OAAR,CAAd,C,CAAgC;;AAEhC;;AAEA;;;;;;;;AAQO,SAASJ,SAAT,CAAmBM,IAAnB,EAAyBC,KAAzB,EAA2C;AAAA,MAAXC,KAAW,uEAAH,CAAG;;AAChD,MAAMC,OAAOC,OAAOC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BP,IAA/B,CAAb;AACA,MAAIQ,WAAWP,KAAf;AACA,MAAIQ,aAAJ;AACA,MAAIC,cAAJ;;AAEA,UAAQP,IAAR;AACE,SAAK,iBAAL;AACEO,cAAQN,OAAOO,IAAP,CAAYX,IAAZ,CAAR;AACAQ,iBAAWE,MAAME,MAAN,CACT,UAACC,SAAD,EAAYC,IAAZ;AAAA,eAAqBpB,UAAUM,KAAKc,IAAL,CAAV,EAAsBD,SAAtB,EAAiCX,KAAjC,CAArB;AAAA,OADS,EAETM,QAFS,CAAX;AAIA;;AAEF,SAAK,gBAAL;AACEA,iBAAWR,KAAKY,MAAL,CACT,UAACC,SAAD,EAAYC,IAAZ;AAAA,eAAqBpB,UAAUoB,IAAV,EAAgBD,SAAhB,EAA2BX,KAA3B,CAArB;AAAA,OADS,EAETM,QAFS,CAAX;AAIA;;AAEF,SAAK,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B,EAAsChB,KAAtC,CAAX;AACD;AACD;;AAEF,SAAKiB,MAAMC,GAAN,CAAU,WAAV,EAAuBc,SAA5B;AACA,SAAK,OAAL;AACEb,cAAS,YAAYN,KAAKE,GAAlB,GAAyB,MAAzB,GAAkC,QAA1C;AACAK,gBAAU,aAAMG,UAAN,CAAiBV,KAAKW,IAAtB,EAA4BL,KAA5B,EAAmCnB,KAAnC,CAAV;;AAEA,UAAIoB,OAAJ,EAAa;AACXb,mBAAW,iCAAgB2B,cAAhB,CAA+BlB,QAA/B,EAAyCI,OAAzC,EAAkDpB,KAAlD,CAAX;AACD;AACD;;AAEF,SAAKiB,MAAMC,GAAN,CAAU,cAAV,CAAL;AACEE,gBAAU,aAAMG,UAAN,CAAiBP,QAAjB,EAA2B,KAA3B,EAAkChB,KAAlC,CAAV;;AAEA,UAAIoB,OAAJ,EAAa;AACXb,mBAAW,sBAAW6B,SAAX,CAAqBpB,QAArB,EAA+BI,OAA/B,EAAwCpB,KAAxC,CAAX;AACD;AACD;;AAEF;AACE6B,cAAQQ,IAAR,EAAe;AACbvC,YAAMiC,GAAN,wBAA+BlB,KAAKc,IAApC,CADF;AAGA;AArCJ;;AAwCA,SAAOpB,QAAP;AACD","file":"actions.js","sourcesContent":["/** @module cli/actions */\n\n// Imports\nimport { htmlHandler } from './handle-html';\nimport { templateHandler } from './handle-templates';\nimport { kssHandler } from './handle-kss';\nimport { utils } from './utils';\n\n// Requires\nconst path = require('path');\nconst chalk = require('chalk'); // Colorize terminal output\n\n// EXPORTED FUNCTIONS\n\n/**\n * Recursively loop through initial watched files list from Gaze.\n *\n * @param {object} data - object containing directory and file paths\n * @param {object} store - memory store\n * @param {object} huron - huron configuration options\n * @return {object} newStore - map object of entire data store\n */\nexport function initFiles(data, store, depth = 0) {\n const type = Object.prototype.toString.call(data);\n let newStore = store;\n let info;\n let files;\n\n switch (type) {\n case '[object Object]':\n files = Object.keys(data);\n newStore = files.reduce(\n (prevStore, file) => initFiles(data[file], prevStore, depth),\n newStore\n );\n break;\n\n case '[object Array]':\n newStore = data.reduce(\n (prevStore, file) => initFiles(file, prevStore, depth),\n newStore\n );\n break;\n\n case '[object String]':\n info = path.parse(data);\n if (info.ext) {\n newStore = updateFile(data, store);\n }\n break;\n\n default:\n break;\n }\n\n return newStore;\n}\n\n/**\n * Logic for updating and writing file information based on file type (extension)\n *\n * @param {string} filepath - path to updated file. usually passed in from Gaze\n * @param {object} store - memory store\n * @return {object} store - map object of map object of entire data store\n */\nexport function updateFile(filepath, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n let field;\n let section;\n\n if (- 1 !== filepath.indexOf(huron.get('sectionTemplate'))) {\n return utils.writeSectionTemplate(filepath, store);\n }\n\n switch (file.ext) {\n // Plain HTML template, external\n case '.html':\n section = utils.getSection(file.base, 'markup', store);\n\n if (section) {\n return htmlHandler.updateTemplate(filepath, section, store);\n } else if (\n - 1 !== file.dir.indexOf('prototypes') &&\n - 1 !== file.name.indexOf('prototype-')\n ) {\n return htmlHandler.updatePrototype(filepath, store);\n }\n\n console.log(chalk.red(`Failed to write file: ${file.name}`));\n break;\n\n // Handlebars template, external\n case huron.get('templates').extension:\n case '.json':\n field = ('.json' === file.ext) ? 'data' : 'markup';\n section = utils.getSection(file.base, field, store);\n\n if (section) {\n return templateHandler.updateTemplate(filepath, section, store);\n }\n\n console.log( // eslint-disable-line no-console\n chalk.red(`Could not find associated KSS section for ${filepath}`)\n );\n break;\n\n // KSS documentation (default extension is `.css`)\n // Will also output a template if markup is inline\n // Note: inline markup does _not_ support handlebars currently\n case huron.get('kssExtension'):\n return kssHandler.updateKSS(filepath, store);\n\n // This should never happen if Gaze is working properly\n default:\n return store;\n }\n\n return store;\n}\n\n/**\n * Logic for deleting file information and files based on file type (extension)\n *\n * @param {string} filepath - path to updated file. usually passed in from Gaze\n * @param {object} store - memory store\n * @return {object} newStore - map object of map object of entire data store\n */\nexport function deleteFile(filepath, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n let field = '';\n let section = null;\n let newStore = store;\n\n switch (file.ext) {\n // Plain HTML template, external\n case '.html':\n section = utils.getSection(file.base, 'markup', store);\n\n if (section) {\n newStore = htmlHandler.deleteTemplate(filepath, section, store);\n } else if (\n - 1 !== file.dir.indexOf('prototypes') &&\n - 1 !== file.name.indexOf('prototype-')\n ) {\n newStore = htmlHandler.deletePrototype(filepath, store);\n }\n break;\n\n case huron.get('templates').extension:\n case '.json':\n field = ('.json' === file.ext) ? 'data' : 'markup';\n section = utils.getSection(file.base, field, store);\n\n if (section) {\n newStore = templateHandler.deleteTemplate(filepath, section, store);\n }\n break;\n\n case huron.get('kssExtension'):\n section = utils.getSection(filepath, false, store);\n\n if (section) {\n newStore = kssHandler.deleteKSS(filepath, section, store);\n }\n break;\n\n default:\n console.warn( // eslint-disable-line no-console\n chalk.red(`Could not delete: ${file.name}`)\n );\n break;\n }\n\n return newStore;\n}\n"]} \ No newline at end of file diff --git a/dist/cli/generate-config.js b/dist/cli/generate-config.js index 6ba4a8f..ac1079b 100644 --- a/dist/cli/generate-config.js +++ b/dist/cli/generate-config.js @@ -30,6 +30,7 @@ var cwd = process.cwd(); * * @function generateConfig * @param {object} config - local webpack config + * @return {object} newConfig - updated data store */ function generateConfig(config) { var newConfig = config; @@ -71,6 +72,7 @@ function generateConfig(config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated data store */ function configureEntries(huron, config) { var entry = config.entry[huron.entry]; @@ -92,6 +94,7 @@ function configureEntries(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated data store */ function configurePlugins(huron, config) { var newConfig = config; @@ -113,6 +116,7 @@ function configurePlugins(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated data store */ function configureLoaders(huron, config) { // Manage loaders @@ -140,6 +144,7 @@ function configureLoaders(huron, config) { * * @param {object} huron - huron configuration object * @param {object} config - webpack configuration object + * @return {object} newConfig - updated data store */ function configurePrototypes(huron, config) { var wrapperTemplate = fs.readFileSync(path.join(__dirname, '../../templates/prototype-template.ejs'), 'utf8'); @@ -216,6 +221,7 @@ function configurePrototypes(huron, config) { * @param {array|string} assets - array of assets or single asset * @param {string} subdir - subdirectory in huron root from which to load additional asset * @param {object} huron - huron configuration object + * @return {array} assetResults - paths to js and css assets */ function moveAdditionalAssets(assets) { var subdir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; diff --git a/dist/cli/generate-config.js.map b/dist/cli/generate-config.js.map index 49c7134..ea43c0f 100644 --- a/dist/cli/generate-config.js.map +++ b/dist/cli/generate-config.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/cli/generate-config.js"],"names":["generateConfig","defaultConfig","require","webpack","path","url","fs","HTMLWebpackPlugin","cwd","process","config","newConfig","huron","Object","assign","configureEntries","configurePlugins","configureLoaders","configurePrototypes","output","resolve","root","devServer","production","publicPath","port","entry","join","plugins","length","filter","plugin","constructor","name","push","HotModuleReplacementPlugin","templatesLoader","templates","loader","include","module","loaders","test","wrapperTemplate","readFileSync","__dirname","defaultHTMLPluginOptions","title","window","js","css","filename","template","inject","chunks","outputFileSync","prototypes","forEach","prototype","newPrototype","opts","hasOwnProperty","call","moveAdditionalAssets","concat","keys","assets","subdir","currentAssets","assetResults","asset","assetInfo","parse","assetURL","sourcePath","outputPath","base","loadPath","contents","isAbsolute","protocol","e","console","warn"],"mappings":";;;;;;;;kBAmBwBA,c;;AAjBxB;;;;;;oMAFA;;AAIA,IAAMC,gBAAgBC,QAAQ,6BAAR,CAAtB;AACA,IAAMC,UAAUD,QAAQ,SAAR,CAAhB;AACA,IAAME,OAAOF,QAAQ,MAAR,CAAb;AACA,IAAMG,MAAMH,QAAQ,KAAR,CAAZ;AACA,IAAMI,KAAKJ,QAAQ,UAAR,CAAX;AACA,IAAMK,oBAAoBL,QAAQ,qBAAR,CAA1B;;AAEA,IAAMM,MAAMC,QAAQD,GAAR,EAAZ;;AAEA;;;;;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G,MAA9B,EAA0D;AAAA,MAApBC,MAAoB,uEAAX,EAAW;AAAA,MAAPvD,KAAO;;AACxD,MAAMwD,gBAAgB,GAAGJ,MAAH,CAAUE,MAAV,CAAtB;AACA,MAAMG,eAAe,EAArB;;AAEAD,gBAAcX,OAAd,CAAsB,UAACa,KAAD,EAAW;AAC/B,QAAMC,YAAYnE,KAAKoE,KAAL,CAAWF,KAAX,CAAlB;AACA,QAAMG,WAAWpE,IAAImE,KAAJ,CAAUF,KAAV,CAAjB;AACA,QAAMI,aAAatE,KAAKuB,IAAL,CAAUnB,GAAV,EAAe8D,KAAf,CAAnB;AACA,QAAMK,aAAavE,KAAKgB,OAAL,CAAaZ,GAAb,EAAkBI,MAAMS,IAAxB,EAA8B8C,MAA9B,EAAsCI,UAAUK,IAAhD,CAAnB;AACA,QAAMC,WAAW,oBAAQtD,UAAR,GACfnB,KAAKuB,IAAL,CAAUwC,MAAV,EAAkBI,UAAUK,IAA5B,CADe,GAEfxE,KAAKuB,IAAL,CAAU,GAAV,EAAewC,MAAf,EAAuBI,UAAUK,IAAjC,CAFF,CAL+B,CAOW;AAC1C,QAAIE,WAAW,KAAf;;AAEA,QACE,CAAE1E,KAAK2E,UAAL,CAAgBT,KAAhB,CAAF,IACA,CAAEG,SAASO,QAFb,EAGE;AACA,UAAI;AACFF,mBAAWxE,GAAGsC,YAAH,CAAgB8B,UAAhB,CAAX;AACD,OAFD,CAEE,OAAOO,CAAP,EAAU;AACVC,gBAAQC,IAAR,qBAA+BT,UAA/B;AACD;;AAED,UAAII,QAAJ,EAAc;AACZxE,WAAGiD,cAAH,CAAkBoB,UAAlB,EAA8BG,QAA9B;AACAT,qBAAanC,IAAb,CAAkB2C,QAAlB;AACD;AACF,KAdD,MAcO;AACLR,mBAAanC,IAAb,CAAkBoC,KAAlB;AACD;AACF,GA3BD;;AA6BA,SAAOD,YAAP;AACD","file":"generate-config.js","sourcesContent":["/** @module cli/generate-config */\n\nimport program from './parse-args';\n\nconst defaultConfig = require('../../config/webpack.config');\nconst webpack = require('webpack');\nconst path = require('path');\nconst url = require('url');\nconst fs = require('fs-extra');\nconst HTMLWebpackPlugin = require('html-webpack-plugin');\n\nconst cwd = process.cwd();\n\n/**\n * Generate a mutant hybrid of the huron default webpack config and your local webpack config\n *\n * @function generateConfig\n * @param {object} config - local webpack config\n */\nexport default function generateConfig(config) {\n let newConfig = config;\n\n newConfig.huron = Object.assign({}, defaultConfig.huron, config.huron);\n const huron = newConfig.huron;\n\n // configure entries\n newConfig = configureEntries(huron, newConfig);\n\n // configure plugins\n newConfig = configurePlugins(huron, newConfig);\n\n // configure loaders\n newConfig = configureLoaders(huron, newConfig);\n\n // Add HTMLWebpackPlugin for each configured prototype\n newConfig = configurePrototypes(huron, newConfig);\n\n // Set ouput options\n newConfig.output = Object.assign({}, newConfig.output, defaultConfig.output);\n newConfig.output.path = path.resolve(cwd, huron.root);\n\n // Remove existing devServer settings\n delete newConfig.devServer;\n\n // Set publicPath\n if (! program.production) {\n newConfig.output.publicPath = `http://localhost:${huron.port}/${huron.root}`;\n } else {\n newConfig.output.publicPath = '';\n }\n\n return newConfig;\n}\n\n/**\n * Configure and manage webpack entry points\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n */\nfunction configureEntries(huron, config) {\n const entry = config.entry[huron.entry];\n const newConfig = config;\n\n newConfig.entry = {};\n\n if (! program.production) {\n newConfig.entry[huron.entry] = [\n `webpack-dev-server/client?http://localhost:${huron.port}`,\n 'webpack/hot/dev-server',\n path.join(cwd, huron.root, 'huron-assets/huron'),\n ...entry,\n ];\n } else {\n newConfig.entry[huron.entry] = [\n path.join(cwd, huron.root, 'huron-assets/huron'),\n ...entry,\n ];\n }\n\n return newConfig;\n}\n\n/**\n * Configure and manage webpack plugins\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n */\nfunction configurePlugins(huron, config) {\n const newConfig = config;\n\n if (! program.production) {\n if (newConfig.plugins && newConfig.plugins.length) {\n newConfig.plugins = newConfig.plugins.filter(\n (plugin) => 'HotModuleReplacementPlugin' !== plugin.constructor.name\n );\n }\n newConfig.plugins.push(new webpack.HotModuleReplacementPlugin());\n }\n\n return newConfig;\n}\n\n/**\n * Configure and manage webpack loaders\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n */\nfunction configureLoaders(huron, config) {\n // Manage loaders\n const templatesLoader = huron.templates.loader;\n const newConfig = config;\n\n templatesLoader.include = [path.join(cwd, huron.root)];\n newConfig.module = newConfig.module || {};\n newConfig.module.loaders = newConfig.module.loaders || [];\n newConfig.module.loaders.push(\n {\n test: /\\.html$/,\n loaders: ['html'],\n include: [path.join(cwd, huron.root)],\n },\n {\n test: /\\.json$/,\n loaders: ['json'],\n include: [path.join(cwd, huron.root)],\n },\n templatesLoader\n );\n\n return newConfig;\n}\n\n/**\n * Create an HTML webpack plugin for each configured prototype\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n */\nfunction configurePrototypes(huron, config) {\n const wrapperTemplate = fs.readFileSync(\n path.join(__dirname, '../../templates/prototype-template.ejs'),\n 'utf8'\n );\n const defaultHTMLPluginOptions = {\n title: '',\n window: huron.window,\n js: [],\n css: [],\n filename: 'index.html',\n template: path.join(huron.root, 'huron-assets/prototype-template.ejs'),\n inject: false,\n chunks: [huron.entry],\n };\n const newConfig = config;\n\n // Write prototype template file for HTML webpack plugin\n fs.outputFileSync(\n path.join(cwd, huron.root, 'huron-assets/prototype-template.ejs'),\n wrapperTemplate\n );\n\n huron.prototypes.forEach((prototype) => {\n const newPrototype = prototype;\n let opts = {};\n\n // Merge configured settings with default settings\n if ('string' === typeof prototype) {\n opts = Object.assign({}, defaultHTMLPluginOptions, {\n title: prototype,\n filename: `${prototype}.html`,\n });\n } else if (\n 'object' === typeof prototype &&\n {}.hasOwnProperty.call(prototype, 'title')\n ) {\n // Create filename based on configured title if not provided\n if (! prototype.filename) {\n newPrototype.filename = `${prototype.title}.html`;\n }\n\n // Move css assets for this prototype,\n // reset css option with new file paths\n if (prototype.css) {\n newPrototype.css = moveAdditionalAssets(prototype.css, 'css', huron);\n }\n\n // Move js assets for this prototype,\n // reset js option with new file paths\n if (prototype.js) {\n newPrototype.js = moveAdditionalAssets(prototype.js, 'js', huron);\n }\n\n opts = Object.assign({}, defaultHTMLPluginOptions, newPrototype);\n }\n\n // Move global css assets,\n // reset css option with new file paths\n if (huron.css.length) {\n opts.css = opts.css.concat(\n moveAdditionalAssets(huron.css, 'css', huron)\n );\n }\n\n // Move global js assets,\n // reset js option with new file paths\n if (huron.js.length) {\n opts.js = opts.js.concat(\n moveAdditionalAssets(huron.js, 'js', huron)\n );\n }\n\n // Push a new plugin for each configured prototype\n if (Object.keys(opts).length) {\n newConfig.plugins.push(\n new HTMLWebpackPlugin(opts)\n );\n }\n });\n\n return newConfig;\n}\n\n/**\n * Move relative (and local) js and css assets provided in huron options\n *\n * @param {array|string} assets - array of assets or single asset\n * @param {string} subdir - subdirectory in huron root from which to load additional asset\n * @param {object} huron - huron configuration object\n */\nfunction moveAdditionalAssets(assets, subdir = '', huron) {\n const currentAssets = [].concat(assets);\n const assetResults = [];\n\n currentAssets.forEach((asset) => {\n const assetInfo = path.parse(asset);\n const assetURL = url.parse(asset);\n const sourcePath = path.join(cwd, asset);\n const outputPath = path.resolve(cwd, huron.root, subdir, assetInfo.base);\n const loadPath = program.production ?\n path.join(subdir, assetInfo.base) :\n path.join('/', subdir, assetInfo.base); // Use absolute path in development\n let contents = false;\n\n if (\n ! path.isAbsolute(asset) &&\n ! assetURL.protocol\n ) {\n try {\n contents = fs.readFileSync(sourcePath);\n } catch (e) {\n console.warn(`could not read ${sourcePath}`);\n }\n\n if (contents) {\n fs.outputFileSync(outputPath, contents);\n assetResults.push(loadPath);\n }\n } else {\n assetResults.push(asset);\n }\n });\n\n return assetResults;\n}\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/cli/generate-config.js"],"names":["generateConfig","defaultConfig","require","webpack","path","url","fs","HTMLWebpackPlugin","cwd","process","config","newConfig","huron","Object","assign","configureEntries","configurePlugins","configureLoaders","configurePrototypes","output","resolve","root","devServer","production","publicPath","port","entry","join","plugins","length","filter","plugin","constructor","name","push","HotModuleReplacementPlugin","templatesLoader","templates","loader","include","module","loaders","test","wrapperTemplate","readFileSync","__dirname","defaultHTMLPluginOptions","title","window","js","css","filename","template","inject","chunks","outputFileSync","prototypes","forEach","prototype","newPrototype","opts","hasOwnProperty","call","moveAdditionalAssets","concat","keys","assets","subdir","currentAssets","assetResults","asset","assetInfo","parse","assetURL","sourcePath","outputPath","base","loadPath","contents","isAbsolute","protocol","e","console","warn"],"mappings":";;;;;;;;kBAoBwBA,c;;AAlBxB;;;;;;oMAFA;;AAIA,IAAMC,gBAAgBC,QAAQ,6BAAR,CAAtB;AACA,IAAMC,UAAUD,QAAQ,SAAR,CAAhB;AACA,IAAME,OAAOF,QAAQ,MAAR,CAAb;AACA,IAAMG,MAAMH,QAAQ,KAAR,CAAZ;AACA,IAAMI,KAAKJ,QAAQ,UAAR,CAAX;AACA,IAAMK,oBAAoBL,QAAQ,qBAAR,CAA1B;;AAEA,IAAMM,MAAMC,QAAQD,GAAR,EAAZ;;AAEA;;;;;;;AAOe,SAASR,cAAT,CAAwBU,MAAxB,EAAgC;AAC7C,MAAIC,YAAYD,MAAhB;;AAEAC,YAAUC,KAAV,GAAkBC,OAAOC,MAAP,CAAc,EAAd,EAAkBb,cAAcW,KAAhC,EAAuCF,OAAOE,KAA9C,CAAlB;AACA,MAAMA,QAAQD,UAAUC,KAAxB;;AAEA;AACAD,cAAYI,iBAAiBH,KAAjB,EAAwBD,SAAxB,CAAZ;;AAEA;AACAA,cAAYK,iBAAiBJ,KAAjB,EAAwBD,SAAxB,CAAZ;;AAEA;AACAA,cAAYM,iBAAiBL,KAAjB,EAAwBD,SAAxB,CAAZ;;AAEA;AACAA,cAAYO,oBAAoBN,KAApB,EAA2BD,SAA3B,CAAZ;;AAEA;AACAA,YAAUQ,MAAV,GAAmBN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AAUK,IAAhD,CAAnB;AACA,QAAMC,WAAW,oBAAQtD,UAAR,GACfnB,KAAKuB,IAAL,CAAUwC,MAAV,EAAkBI,UAAUK,IAA5B,CADe,GAEfxE,KAAKuB,IAAL,CAAU,GAAV,EAAewC,MAAf,EAAuBI,UAAUK,IAAjC,CAFF,CAL+B,CAOW;AAC1C,QAAIE,WAAW,KAAf;;AAEA,QACE,CAAE1E,KAAK2E,UAAL,CAAgBT,KAAhB,CAAF,IACA,CAAEG,SAASO,QAFb,EAGE;AACA,UAAI;AACFF,mBAAWxE,GAAGsC,YAAH,CAAgB8B,UAAhB,CAAX;AACD,OAFD,CAEE,OAAOO,CAAP,EAAU;AACVC,gBAAQC,IAAR,qBAA+BT,UAA/B;AACD;;AAED,UAAII,QAAJ,EAAc;AACZxE,WAAGiD,cAAH,CAAkBoB,UAAlB,EAA8BG,QAA9B;AACAT,qBAAanC,IAAb,CAAkB2C,QAAlB;AACD;AACF,KAdD,MAcO;AACLR,mBAAanC,IAAb,CAAkBoC,KAAlB;AACD;AACF,GA3BD;;AA6BA,SAAOD,YAAP;AACD","file":"generate-config.js","sourcesContent":["/** @module cli/generate-config */\n\nimport program from './parse-args';\n\nconst defaultConfig = require('../../config/webpack.config');\nconst webpack = require('webpack');\nconst path = require('path');\nconst url = require('url');\nconst fs = require('fs-extra');\nconst HTMLWebpackPlugin = require('html-webpack-plugin');\n\nconst cwd = process.cwd();\n\n/**\n * Generate a mutant hybrid of the huron default webpack config and your local webpack config\n *\n * @function generateConfig\n * @param {object} config - local webpack config\n * @return {object} newConfig - updated data store\n */\nexport default function generateConfig(config) {\n let newConfig = config;\n\n newConfig.huron = Object.assign({}, defaultConfig.huron, config.huron);\n const huron = newConfig.huron;\n\n // configure entries\n newConfig = configureEntries(huron, newConfig);\n\n // configure plugins\n newConfig = configurePlugins(huron, newConfig);\n\n // configure loaders\n newConfig = configureLoaders(huron, newConfig);\n\n // Add HTMLWebpackPlugin for each configured prototype\n newConfig = configurePrototypes(huron, newConfig);\n\n // Set ouput options\n newConfig.output = Object.assign({}, newConfig.output, defaultConfig.output);\n newConfig.output.path = path.resolve(cwd, huron.root);\n\n // Remove existing devServer settings\n delete newConfig.devServer;\n\n // Set publicPath\n if (! program.production) {\n newConfig.output.publicPath = `http://localhost:${huron.port}/${huron.root}`;\n } else {\n newConfig.output.publicPath = '';\n }\n\n return newConfig;\n}\n\n/**\n * Configure and manage webpack entry points\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n * @return {object} newConfig - updated data store\n */\nfunction configureEntries(huron, config) {\n const entry = config.entry[huron.entry];\n const newConfig = config;\n\n newConfig.entry = {};\n\n if (! program.production) {\n newConfig.entry[huron.entry] = [\n `webpack-dev-server/client?http://localhost:${huron.port}`,\n 'webpack/hot/dev-server',\n path.join(cwd, huron.root, 'huron-assets/huron'),\n ...entry,\n ];\n } else {\n newConfig.entry[huron.entry] = [\n path.join(cwd, huron.root, 'huron-assets/huron'),\n ...entry,\n ];\n }\n\n return newConfig;\n}\n\n/**\n * Configure and manage webpack plugins\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n * @return {object} newConfig - updated data store\n */\nfunction configurePlugins(huron, config) {\n const newConfig = config;\n\n if (! program.production) {\n if (newConfig.plugins && newConfig.plugins.length) {\n newConfig.plugins = newConfig.plugins.filter(\n (plugin) => 'HotModuleReplacementPlugin' !== plugin.constructor.name\n );\n }\n newConfig.plugins.push(new webpack.HotModuleReplacementPlugin());\n }\n\n return newConfig;\n}\n\n/**\n * Configure and manage webpack loaders\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n * @return {object} newConfig - updated data store\n */\nfunction configureLoaders(huron, config) {\n // Manage loaders\n const templatesLoader = huron.templates.loader;\n const newConfig = config;\n\n templatesLoader.include = [path.join(cwd, huron.root)];\n newConfig.module = newConfig.module || {};\n newConfig.module.loaders = newConfig.module.loaders || [];\n newConfig.module.loaders.push(\n {\n test: /\\.html$/,\n loaders: ['html'],\n include: [path.join(cwd, huron.root)],\n },\n {\n test: /\\.json$/,\n loaders: ['json'],\n include: [path.join(cwd, huron.root)],\n },\n templatesLoader\n );\n\n return newConfig;\n}\n\n/**\n * Create an HTML webpack plugin for each configured prototype\n *\n * @param {object} huron - huron configuration object\n * @param {object} config - webpack configuration object\n * @return {object} newConfig - updated data store\n */\nfunction configurePrototypes(huron, config) {\n const wrapperTemplate = fs.readFileSync(\n path.join(__dirname, '../../templates/prototype-template.ejs'),\n 'utf8'\n );\n const defaultHTMLPluginOptions = {\n title: '',\n window: huron.window,\n js: [],\n css: [],\n filename: 'index.html',\n template: path.join(huron.root, 'huron-assets/prototype-template.ejs'),\n inject: false,\n chunks: [huron.entry],\n };\n const newConfig = config;\n\n // Write prototype template file for HTML webpack plugin\n fs.outputFileSync(\n path.join(cwd, huron.root, 'huron-assets/prototype-template.ejs'),\n wrapperTemplate\n );\n\n huron.prototypes.forEach((prototype) => {\n const newPrototype = prototype;\n let opts = {};\n\n // Merge configured settings with default settings\n if ('string' === typeof prototype) {\n opts = Object.assign({}, defaultHTMLPluginOptions, {\n title: prototype,\n filename: `${prototype}.html`,\n });\n } else if (\n 'object' === typeof prototype &&\n {}.hasOwnProperty.call(prototype, 'title')\n ) {\n // Create filename based on configured title if not provided\n if (! prototype.filename) {\n newPrototype.filename = `${prototype.title}.html`;\n }\n\n // Move css assets for this prototype,\n // reset css option with new file paths\n if (prototype.css) {\n newPrototype.css = moveAdditionalAssets(prototype.css, 'css', huron);\n }\n\n // Move js assets for this prototype,\n // reset js option with new file paths\n if (prototype.js) {\n newPrototype.js = moveAdditionalAssets(prototype.js, 'js', huron);\n }\n\n opts = Object.assign({}, defaultHTMLPluginOptions, newPrototype);\n }\n\n // Move global css assets,\n // reset css option with new file paths\n if (huron.css.length) {\n opts.css = opts.css.concat(\n moveAdditionalAssets(huron.css, 'css', huron)\n );\n }\n\n // Move global js assets,\n // reset js option with new file paths\n if (huron.js.length) {\n opts.js = opts.js.concat(\n moveAdditionalAssets(huron.js, 'js', huron)\n );\n }\n\n // Push a new plugin for each configured prototype\n if (Object.keys(opts).length) {\n newConfig.plugins.push(\n new HTMLWebpackPlugin(opts)\n );\n }\n });\n\n return newConfig;\n}\n\n/**\n * Move relative (and local) js and css assets provided in huron options\n *\n * @param {array|string} assets - array of assets or single asset\n * @param {string} subdir - subdirectory in huron root from which to load additional asset\n * @param {object} huron - huron configuration object\n * @return {array} assetResults - paths to js and css assets\n */\nfunction moveAdditionalAssets(assets, subdir = '', huron) {\n const currentAssets = [].concat(assets);\n const assetResults = [];\n\n currentAssets.forEach((asset) => {\n const assetInfo = path.parse(asset);\n const assetURL = url.parse(asset);\n const sourcePath = path.join(cwd, asset);\n const outputPath = path.resolve(cwd, huron.root, subdir, assetInfo.base);\n const loadPath = program.production ?\n path.join(subdir, assetInfo.base) :\n path.join('/', subdir, assetInfo.base); // Use absolute path in development\n let contents = false;\n\n if (\n ! path.isAbsolute(asset) &&\n ! assetURL.protocol\n ) {\n try {\n contents = fs.readFileSync(sourcePath);\n } catch (e) {\n console.warn(`could not read ${sourcePath}`);\n }\n\n if (contents) {\n fs.outputFileSync(outputPath, contents);\n assetResults.push(loadPath);\n }\n } else {\n assetResults.push(asset);\n }\n });\n\n return assetResults;\n}\n"]} \ No newline at end of file diff --git a/dist/cli/handle-html.js b/dist/cli/handle-html.js index 9fa6741..4e29e53 100644 --- a/dist/cli/handle-html.js +++ b/dist/cli/handle-html.js @@ -22,6 +22,7 @@ var htmlHandler = exports.htmlHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} updated data store */ updateTemplate: function updateTemplate(filepath, section, store) { var file = path.parse(filepath); @@ -50,6 +51,7 @@ var htmlHandler = exports.htmlHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} updated data store */ deleteTemplate: function deleteTemplate(filepath, section, store) { var newSection = section; @@ -68,6 +70,7 @@ var htmlHandler = exports.htmlHandler = { * @function updatePrototype * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store + * @return {object} updated data store */ updatePrototype: function updatePrototype(filepath, store) { var file = path.parse(filepath); @@ -90,6 +93,7 @@ var htmlHandler = exports.htmlHandler = { * @function deletePrototype * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store + * @return {object} updated data store */ deletePrototype: function deletePrototype(filepath, store) { var file = path.parse(filepath); diff --git a/dist/cli/handle-html.js.map b/dist/cli/handle-html.js.map index 1178527..e38d8c3 100644 --- a/dist/cli/handle-html.js.map +++ b/dist/cli/handle-html.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/cli/handle-html.js"],"names":["path","require","fs","htmlHandler","updateTemplate","filepath","section","store","file","parse","content","readFileSync","newSection","templatePath","writeFile","referenceURI","templateContent","sectionPath","writeSectionData","setIn","kssPath","console","log","base","deleteTemplate","removeFile","updatePrototype","requirePath","name","deletePrototype"],"mappings":";;;;;;;AAEA;;AAEA,IAAMA,OAAOC,QAAQ,MAAR,CAAb,C,CAJA;;AAKA,IAAMC,KAAKD,QAAQ,UAAR,CAAX;;AAEA;AACO,IAAME,oCAAc;AAC3B;;AAEE;;;;;;;;AAQAC,gBAXyB,0BAWVC,QAXU,EAWAC,OAXA,EAWSC,KAXT,EAWgB;AACvC,QAAMC,OAAOR,KAAKS,KAAL,CAAWJ,QAAX,CAAb;AACA,QAAMK,UAAUR,GAAGS,YAAH,CAAgBN,QAAhB,EAA0B,MAA1B,CAAhB;AACA,QAAMO,aAAaN,OAAnB;;AAEA,QAAII,OAAJ,EAAa;AACXE,iBAAWC,YAAX,GAA0B,aAAMC,SAAN,CACxBR,QAAQS,YADgB,EAExB,UAFwB,EAGxBV,QAHwB,EAIxBK,OAJwB,EAKxBH,KALwB,CAA1B;AAOAK,iBAAWI,eAAX,GAA6BN,OAA7B;;AAEA;AACAE,iBAAWK,WAAX,GAAyB,aAAMC,gBAAN,CAAuBX,KA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AP;AACD,GAvGwB;;;AAyGzB;;;;;;;AAOAsB,iBAhHyB,2BAgHTxB,QAhHS,EAgHCE,KAhHD,EAgHQ;AAC/B,QAAMC,OAAOR,KAAKS,KAAL,CAAWJ,QAAX,CAAb;AACA,QAAMsB,cAAc,aAAMF,UAAN,CAClBjB,KAAKoB,IADa,EAElB,WAFkB,EAGlBvB,QAHkB,EAIlBE,KAJkB,CAApB;;AAOA,WAAOA,MAAMY,KAAN,CACH,CAAC,YAAD,EAAeX,KAAKoB,IAApB,CADG,EAEHD,WAFG,CAAP;AAID;AA7HwB,CAApB","file":"handle-html.js","sourcesContent":["/** @module cli/html-handler */\n\nimport { utils } from './utils';\n\nconst path = require('path');\nconst fs = require('fs-extra');\n\n/* eslint-disable */\nexport const htmlHandler = {\n/* eslint-enable */\n\n /**\n * Handle update of an HMTL template\n *\n * @function updateTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n */\n updateTemplate(filepath, section, store) {\n const file = path.parse(filepath);\n const content = fs.readFileSync(filepath, 'utf8');\n const newSection = section;\n\n if (content) {\n newSection.templatePath = utils.writeFile(\n section.referenceURI,\n 'template',\n filepath,\n content,\n store\n );\n newSection.templateContent = content;\n\n // Rewrite section data with template content\n newSection.sectionPath = utils.writeSectionData(store, newSection);\n\n return store\n .setIn(\n ['sections', 'sectionsByPath', section.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n }\n\n console.log(`File ${file.base} could not be read`);\n return store;\n },\n\n /**\n * Handle removal of an HMTL template\n *\n * @function deleteTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n */\n deleteTemplate(filepath, section, store) {\n const newSection = section;\n\n utils.removeFile(\n newSection.referenceURI,\n 'template',\n filepath,\n store\n );\n\n delete newSection.templatePath;\n\n return store\n .setIn(\n ['sections', 'sectionsByPath', section.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n },\n\n /**\n * Handle update for a prototype file\n *\n * @function updatePrototype\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} store - memory store\n */\n updatePrototype(filepath, store) {\n const file = path.parse(filepath);\n const content = fs.readFileSync(filepath, 'utf8');\n\n if (content) {\n const requirePath = utils.writeFile(\n file.name,\n 'prototype',\n filepath,\n content,\n store\n );\n\n return store.setIn(\n ['prototypes', file.name],\n requirePath\n );\n }\n\n console.log(`File ${file.base} could not be read`);\n return store;\n },\n\n /**\n * Handle removal of a prototype file\n *\n * @function deletePrototype\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} store - memory store\n */\n deletePrototype(filepath, store) {\n const file = path.parse(filepath);\n const requirePath = utils.removeFile(\n file.name,\n 'prototype',\n filepath,\n store\n );\n\n return store.setIn(\n ['prototypes', file.name],\n requirePath\n );\n },\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/cli/handle-html.js"],"names":["path","require","fs","htmlHandler","updateTemplate","filepath","section","store","file","parse","content","readFileSync","newSection","templatePath","writeFile","referenceURI","templateContent","sectionPath","writeSectionData","setIn","kssPath","console","log","base","deleteTemplate","removeFile","updatePrototype","requirePath","name","deletePrototype"],"mappings":";;;;;;;AAEA;;AAEA,IAAMA,OAAOC,QAAQ,MAAR,CAAb,C,CAJA;;AAKA,IAAMC,KAAKD,QAAQ,UAAR,CAAX;;AAEA;AACO,IAAME,oCAAc;AAC3B;;AAEE;;;;;;;;;AASAC,gBAZyB,0BAYVC,QAZU,EAYAC,OAZA,EAYSC,KAZT,EAYgB;AACvC,QAAMC,OAAOR,KAAKS,KAAL,CAAWJ,QAAX,CAAb;AACA,QAAMK,UAAUR,GAAGS,YAAH,CAAgBN,QAAhB,EAA0B,MAA1B,CAAhB;AACA,QAAMO,aAAaN,OAAnB;;AAEA,QAAII,OAAJ,EAAa;AACXE,iBAAWC,YAAX,GAA0B,aAAM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kB,EAIlBK,OAJkB,EAKlBH,KALkB,CAApB;;AAQA,aAAOA,MAAMY,KAAN,CACH,CAAC,YAAD,EAAeX,KAAKoB,IAApB,CADG,EAEHD,WAFG,CAAP;AAID;;AAEDN,YAAQC,GAAR,WAAoBd,KAAKe,IAAzB;AACA,WAAOhB,KAAP;AACD,GA1GwB;;;AA4GzB;;;;;;;;AAQAsB,iBApHyB,2BAoHTxB,QApHS,EAoHCE,KApHD,EAoHQ;AAC/B,QAAMC,OAAOR,KAAKS,KAAL,CAAWJ,QAAX,CAAb;AACA,QAAMsB,cAAc,aAAMF,UAAN,CAClBjB,KAAKoB,IADa,EAElB,WAFkB,EAGlBvB,QAHkB,EAIlBE,KAJkB,CAApB;;AAOA,WAAOA,MAAMY,KAAN,CACH,CAAC,YAAD,EAAeX,KAAKoB,IAApB,CADG,EAEHD,WAFG,CAAP;AAID;AAjIwB,CAApB","file":"handle-html.js","sourcesContent":["/** @module cli/html-handler */\n\nimport { utils } from './utils';\n\nconst path = require('path');\nconst fs = require('fs-extra');\n\n/* eslint-disable */\nexport const htmlHandler = {\n/* eslint-enable */\n\n /**\n * Handle update of an HMTL template\n *\n * @function updateTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n * @return {object} updated data store\n */\n updateTemplate(filepath, section, store) {\n const file = path.parse(filepath);\n const content = fs.readFileSync(filepath, 'utf8');\n const newSection = section;\n\n if (content) {\n newSection.templatePath = utils.writeFile(\n section.referenceURI,\n 'template',\n filepath,\n content,\n store\n );\n newSection.templateContent = content;\n\n // Rewrite section data with template content\n newSection.sectionPath = utils.writeSectionData(store, newSection);\n\n return store\n .setIn(\n ['sections', 'sectionsByPath', section.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n }\n\n console.log(`File ${file.base} could not be read`);\n return store;\n },\n\n /**\n * Handle removal of an HMTL template\n *\n * @function deleteTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n * @return {object} updated data store\n */\n deleteTemplate(filepath, section, store) {\n const newSection = section;\n\n utils.removeFile(\n newSection.referenceURI,\n 'template',\n filepath,\n store\n );\n\n delete newSection.templatePath;\n\n return store\n .setIn(\n ['sections', 'sectionsByPath', section.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n },\n\n /**\n * Handle update for a prototype file\n *\n * @function updatePrototype\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} store - memory store\n * @return {object} updated data store\n */\n updatePrototype(filepath, store) {\n const file = path.parse(filepath);\n const content = fs.readFileSync(filepath, 'utf8');\n\n if (content) {\n const requirePath = utils.writeFile(\n file.name,\n 'prototype',\n filepath,\n content,\n store\n );\n\n return store.setIn(\n ['prototypes', file.name],\n requirePath\n );\n }\n\n console.log(`File ${file.base} could not be read`);\n return store;\n },\n\n /**\n * Handle removal of a prototype file\n *\n * @function deletePrototype\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} store - memory store\n * @return {object} updated data store\n */\n deletePrototype(filepath, store) {\n const file = path.parse(filepath);\n const requirePath = utils.removeFile(\n file.name,\n 'prototype',\n filepath,\n store\n );\n\n return store.setIn(\n ['prototypes', file.name],\n requirePath\n );\n },\n};\n"]} \ No newline at end of file diff --git a/dist/cli/handle-kss.js b/dist/cli/handle-kss.js index 7a4e4af..0c4affd 100644 --- a/dist/cli/handle-kss.js +++ b/dist/cli/handle-kss.js @@ -27,6 +27,7 @@ var kssHandler = exports.kssHandler = { * @function updateKSS * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} store - memory store + * @return {object} updated data store */ updateKSS: function updateKSS(filepath, store) { var kssSource = fs.readFileSync(filepath, 'utf8'); @@ -74,6 +75,7 @@ var kssHandler = exports.kssHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - KSS section data * @param {object} store - memory store + * @return {object} updated data store */ deleteKSS: function deleteKSS(filepath, section, store) { var file = path.parse(filepath); @@ -90,6 +92,7 @@ var kssHandler = exports.kssHandler = { * @param {object} section - contains updated section data * @param {string} kssPath - path to KSS section * @param {object} store - memory store + * @return {object} updated data store */ updateSectionData: function updateSectionData(kssPath, section, oldSection, store) { var sectionFileInfo = path.parse(kssPath); @@ -130,7 +133,7 @@ var kssHandler = exports.kssHandler = { * @function updateInlineTemplate * @param {string} oldSection - previous iteration of KSS data, if updated * @param {object} section - KSS section data - * @return {object} updated memory store with new template path info + * @return {object} updated data store with new template path info */ updateInlineTemplate: function updateInlineTemplate(filepath, oldSection, section, store) { var newSection = section; @@ -154,7 +157,7 @@ var kssHandler = exports.kssHandler = { * @function updateDescription * @param {string} oldSection - previous iteration of KSS data, if updated * @param {object} section - KSS section data - * @return {object} updated memory store with new descripton path info + * @return {object} updated data store with new descripton path info */ updateDescription: function updateDescription(filepath, oldSection, section, store) { var newSection = section; @@ -216,6 +219,7 @@ var kssHandler = exports.kssHandler = { * @param {string} file - file object from path.parse() * @param {object} store - memory store * @param {bool} removed - has the file been removed or just the section information changed? + * @return {object} updated data store with new descripton path info */ unsetSection: function unsetSection(section, file, store, removed) { var sorted = store.getIn(['sections', 'sorted']); @@ -251,6 +255,7 @@ var kssHandler = exports.kssHandler = { * @function sortSection * @param {object} sorted - currently sorted sections * @param {string} reference - reference URI of section to sort + * @return {object} updated data store with new descripton path info */ sortSection: function sortSection(sorted, reference, delimiter) { var parts = reference.split(delimiter); @@ -276,6 +281,7 @@ var kssHandler = exports.kssHandler = { * @function unsortSection * @param {object} sorted - currently sorted sections * @param {string} reference - reference URI of section to sort + * @return {object} updated data store with new descripton path info */ unsortSection: function unsortSection(sorted, reference, delimiter) { var parts = reference.split(delimiter); @@ -305,6 +311,7 @@ var kssHandler = exports.kssHandler = { * @param {object} oldSection - currently sorted sections * @param {object} newSection - reference URI of section to sort * @param {string} field - KSS field to check + * @return {bool} output a new module for the KSS field */ fieldShouldOutput: function fieldShouldOutput(oldSection, newSection, field) { return oldSection && (oldSection[field] !== newSection[field] || oldSection.referenceURI !== newSection.referenceURI) || !oldSection; diff --git a/dist/cli/handle-kss.js.map b/dist/cli/handle-kss.js.map index 405d656..22d1966 100644 --- a/dist/cli/handle-kss.js.map +++ b/dist/cli/handle-kss.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/cli/handle-kss.js"],"names":["path","require","fs","parse","chalk","kssHandler","updateKSS","filepath","store","kssSource","readFileSync","huron","get","oldSection","getSection","file","newStore","styleguide","data","sections","length","section","normalizeSectionData","updateSectionData","referenceURI","unsetSection","console","log","green","magenta","deleteKSS","red","kssPath","sectionFileInfo","dataFilepath","join","dir","name","isInline","markup","match","newSort","sortSection","getIn","reference","newSection","Object","assign","updateInlineTemplate","removeFile","updateTemplateFields","updateDescription","sectionPath","writeSectionData","setIn","fieldShouldOutput","templatePath","writeFile","templateContent","descriptionPath","description","format","oldFilepath","forEach","field","deleteTemplate","updateTemplate","removed","sorted","unsortSection","deleteIn","delimiter","parts","split","newSorted","newParts","filter","part","idx","subsections","keys"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AAEA,IAAMA,OAAOC,QAAQ,MAAR,CAAb,C,CANA;;AAOA,IAAMC,KAAKD,QAAQ,UAAR,CAAX;AACA,IAAME,QAAQF,QAAQ,KAAR,EAAeE,KAA7B;AACA,IAAMC,QAAQH,QAAQ,OAAR,CAAd,C,CAAgC;;AAEhC;AACO,IAAMI,kCAAa;AAC1B;;AAEE;;;;;;;AAOAC,WAVwB,qBAUdC,QAVc,EAUJC,KAVI,EAUG;AACzB,QAAMC,YAAYP,GAAGQ,YAAH,CAAgBH,QAAhB,EAA0B,MAA1B,CAAlB;AACA,QAAMI,QAAQH,MAAMI,GAAN,CAAU,QAAV,CAAd;AACA,QAAMC,aAAa,aAAMC,UAAN,CAAiBP,QAAjB,EAA2B,KAA3B,EAAkCC,KAAlC,KAA4C,EAA/D;AACA,QAAMO,OAAOf,KAAKG,KA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AAb,CAAjB;AACAJ,kBAAUF,MAAM,CAAN,CAAV,IAAsBnE,WAAWgE,aAAX,CACpBK,UAAUF,MAAM,CAAN,CAAV,CADoB,EAEpBG,SAASxC,IAAT,CAAcoC,SAAd,CAFoB,EAGpBA,SAHoB,CAAtB;AAKD;AACF,KATD,MASO;AACL,aAAOG,UAAUF,MAAM,CAAN,CAAV,CAAP;AACD;;AAED,WAAOE,SAAP;AACD,GAjYuB;;;AAmYxB;;;;;;;;;AASAnB,mBA5YwB,6BA4YN1C,UA5YM,EA4YMgC,UA5YN,EA4YkBmB,KA5YlB,EA4YyB;AAC/C,WAAQnD,eACHA,WAAWmD,KAAX,MAAsBnB,WAAWmB,KAAX,CAAtB,IACDnD,WAAWW,YAAX,KAA4BqB,WAAWrB,YAFnC,CAAD,IAIL,CAAEX,UAJJ;AAKD;AAlZuB,CAAnB","file":"handle-kss.js","sourcesContent":["/** @module cli/kss-handler */\n\nimport { utils } from './utils';\nimport { templateHandler } from './handle-templates';\nimport { writeStore } from './require-templates';\n\nconst path = require('path');\nconst fs = require('fs-extra');\nconst parse = require('kss').parse;\nconst chalk = require('chalk'); // Colorize terminal output\n\n/* eslint-disable */\nexport const kssHandler = {\n/* eslint-enable */\n\n /**\n * Handle update of a KSS section\n *\n * @function updateKSS\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} store - memory store\n */\n updateKSS(filepath, store) {\n const kssSource = fs.readFileSync(filepath, 'utf8');\n const huron = store.get('config');\n const oldSection = utils.getSection(filepath, false, store) || {};\n const file = path.parse(filepath);\n let newStore = store;\n\n if (kssSource) {\n const styleguide = parse(kssSource, huron.get('kssOptions'));\n\n if (styleguide.data.sections.length) {\n const section = utils.normalizeSectionData(\n styleguide.data.sections[0]\n );\n\n // Update or add section data\n newStore = kssHandler.updateSectionData(\n filepath,\n section,\n oldSection,\n newStore\n );\n\n // Remove old section data if reference URI has changed\n if (oldSection &&\n oldSection.referenceURI &&\n oldSection.referenceURI !== section.referenceURI\n ) {\n newStore = this.unsetSection(oldSection, file, newStore, false);\n }\n\n writeStore(newStore);\n console.log(\n chalk.green(\n `KSS source in ${filepath} changed or added`\n )\n );\n return newStore;\n }\n\n console.log(chalk.magenta(`No KSS found in ${filepath}`));\n return newStore;\n }\n\n if (oldSection) {\n newStore = kssHandler.deleteKSS(filepath, oldSection, newStore);\n }\n\n console.log(chalk.red(`${filepath} not found or empty`)); // eslint-disable-line no-console\n return newStore;\n },\n\n /**\n * Handle removal of a KSS section\n *\n * @function deleteKSS\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - KSS section data\n * @param {object} store - memory store\n */\n deleteKSS(filepath, section, store) {\n const file = path.parse(filepath);\n\n // Remove section data from memory store\n return kssHandler.unsetSection(section, file, store, true);\n },\n\n /**\n * Update the sections store with new data for a specific section\n *\n * @function updateSectionData\n * @param {object} section - contains updated section data\n * @param {string} kssPath - path to KSS section\n * @param {object} store - memory store\n */\n updateSectionData(kssPath, section, oldSection, store) {\n const sectionFileInfo = path.parse(kssPath);\n const dataFilepath = path.join(\n sectionFileInfo.dir,\n `${sectionFileInfo.name}.json`\n );\n const isInline = null !== section.markup.match(/<\\/[^>]*>/);\n const newSort = kssHandler.sortSection(\n store.getIn(['sections', 'sorted']),\n section.reference,\n store.get('referenceDelimiter')\n );\n const newSection = Object.assign({}, oldSection, section);\n let newStore = store;\n\n // Required for reference from templates and data\n newSection.kssPath = kssPath;\n\n if (isInline) {\n // Set section value if inlineTempalte() returned a path\n newStore = kssHandler.updateInlineTemplate(\n kssPath,\n oldSection,\n newSection,\n newStore\n );\n } else {\n // Remove inline template, if it exists\n utils.removeFile(\n newSection.referenceURI,\n 'template',\n kssPath,\n store\n );\n // Update markup and data fields\n newStore = kssHandler.updateTemplateFields(\n sectionFileInfo,\n oldSection,\n newSection,\n newStore\n );\n }\n\n // Output section description\n newStore = kssHandler.updateDescription(\n kssPath,\n oldSection,\n newSection,\n newStore\n );\n\n // Output section data to a JSON file\n newSection.sectionPath = utils.writeSectionData(\n newStore,\n newSection,\n dataFilepath\n );\n\n // Update section sorting\n return newStore\n .setIn(\n ['sections', 'sorted'],\n newSort\n )\n .setIn(\n ['sections', 'sectionsByPath', kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n },\n\n /**\n * Handle detection and output of inline templates, which is markup written\n * in the KSS documentation itself as opposed to an external file\n *\n * @function updateInlineTemplate\n * @param {string} oldSection - previous iteration of KSS data, if updated\n * @param {object} section - KSS section data\n * @return {object} updated memory store with new template path info\n */\n updateInlineTemplate(filepath, oldSection, section, store) {\n const newSection = section;\n const newStore = store;\n\n // If we have inline markup\n if (this.fieldShouldOutput(oldSection, section, 'markup')) {\n newSection.templatePath = utils.writeFile(\n section.referenceURI,\n 'template',\n filepath,\n section.markup,\n store\n );\n newSection.templateContent = section.markup;\n\n return newStore\n .setIn(\n ['sections', 'sectionsByPath', filepath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n }\n\n return newStore;\n },\n\n /**\n * Handle output of section description\n *\n * @function updateDescription\n * @param {string} oldSection - previous iteration of KSS data, if updated\n * @param {object} section - KSS section data\n * @return {object} updated memory store with new descripton path info\n */\n updateDescription(filepath, oldSection, section, store) {\n const newSection = section;\n const newStore = store;\n\n // If we don't have previous KSS or the KSS has been updated\n if (this.fieldShouldOutput(oldSection, section, 'description')) {\n // Write new description\n newSection.descriptionPath = utils.writeFile(\n section.referenceURI,\n 'description',\n filepath,\n section.description,\n store\n );\n\n return newStore\n .setIn(\n ['sections', 'sectionsByPath', filepath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n }\n\n return newStore;\n },\n\n /**\n * Handle Data and Markup fields\n *\n * @function updateTemplateFields\n * @param {string} file - File data for KSS file from path.parse()\n * @param {object} oldSection - outdated KSS data\n * @param {object} section - KSS section data\n * @param {object} store - memory store\n * @return {object} KSS section data with updated asset paths\n */\n updateTemplateFields(file, oldSection, section, store) {\n const kssPath = path.format(file);\n const newSection = section;\n let filepath = '';\n let oldFilepath = '';\n let newStore = store;\n\n ['data', 'markup'].forEach((field) => {\n if (newSection[field]) {\n if (oldSection[field]) {\n oldFilepath = path.join(file.dir, oldSection[field]);\n newStore = templateHandler.deleteTemplate(\n oldFilepath,\n oldSection,\n newStore\n );\n }\n\n filepath = path.join(file.dir, newSection[field]);\n newStore = templateHandler.updateTemplate(\n filepath,\n newSection,\n newStore\n );\n } else {\n delete newSection[field];\n newStore = newStore\n .setIn(\n ['sections', 'sectionsByPath', kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', newSection.referenceURI],\n newSection\n );\n }\n });\n\n return newStore;\n },\n\n /**\n * Remove a section from the memory store\n *\n * @function unsetSection\n * @param {object} section - contains updated section data\n * @param {string} file - file object from path.parse()\n * @param {object} store - memory store\n * @param {bool} removed - has the file been removed or just the section information changed?\n */\n unsetSection(section, file, store, removed) {\n const sorted = store.getIn(['sections', 'sorted']);\n const kssPath = path.format(file);\n const dataFilepath = path.join(file.dir, `${file.name}.json`);\n const isInline = section.markup &&\n null !== section.markup.match(/<\\/[^>]*>/);\n const newSort = kssHandler.unsortSection(\n sorted,\n section.reference,\n store.get('referenceDelimiter')\n );\n let newStore = store;\n\n // Remove old section data\n utils.removeFile(\n section.referenceURI,\n 'section',\n dataFilepath,\n newStore\n );\n\n // Remove associated inline template\n if (isInline) {\n utils.removeFile(section.referenceURI, 'template', kssPath, newStore);\n }\n\n // Remove description template\n utils.removeFile(section.referenceURI, 'description', kssPath, newStore);\n\n // Remove data from sectionsByPath if file has been removed\n if (removed) {\n newStore = newStore.deleteIn(['sections', 'sectionsByPath', kssPath]);\n }\n\n return newStore\n .deleteIn(['sections', 'sectionsByURI', section.referenceURI])\n .setIn(['sections', 'sorted'], newSort);\n },\n\n /**\n * Sort sections and subsections\n *\n * @function sortSection\n * @param {object} sorted - currently sorted sections\n * @param {string} reference - reference URI of section to sort\n */\n sortSection(sorted, reference, delimiter) {\n const parts = reference.split(delimiter);\n const newSort = sorted[parts[0]] || {};\n const newSorted = sorted;\n\n if (1 < parts.length) {\n const newParts = parts.filter((part, idx) => 0 !== idx);\n newSorted[parts[0]] = kssHandler.sortSection(\n newSort,\n newParts.join(delimiter),\n delimiter\n );\n } else {\n newSorted[parts[0]] = newSort;\n }\n\n return newSorted;\n },\n\n /**\n * Remove a section from the sorted sections\n *\n * @function unsortSection\n * @param {object} sorted - currently sorted sections\n * @param {string} reference - reference URI of section to sort\n */\n unsortSection(sorted, reference, delimiter) {\n const parts = reference.split(delimiter);\n const subsections = Object.keys(sorted[parts[0]]);\n const newSorted = sorted;\n\n if (subsections.length) {\n if (1 < parts.length) {\n const newParts = parts.filter((part, idx) => 0 !== idx);\n newSorted[parts[0]] = kssHandler.unsortSection(\n newSorted[parts[0]],\n newParts.join(delimiter),\n delimiter\n );\n }\n } else {\n delete newSorted[parts[0]];\n }\n\n return newSorted;\n },\n\n /**\n * Compare a KSS field between old and new KSS data to see if we need to output\n * a new module for that field\n *\n * @function fieldShouldOutput\n * @param {object} oldSection - currently sorted sections\n * @param {object} newSection - reference URI of section to sort\n * @param {string} field - KSS field to check\n */\n fieldShouldOutput(oldSection, newSection, field) {\n return (oldSection &&\n (oldSection[field] !== newSection[field] ||\n oldSection.referenceURI !== newSection.referenceURI)\n ) ||\n ! oldSection;\n },\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/cli/handle-kss.js"],"names":["path","require","fs","parse","chalk","kssHandler","updateKSS","filepath","store","kssSource","readFileSync","huron","get","oldSection","getSection","file","newStore","styleguide","data","sections","length","section","normalizeSectionData","updateSectionData","referenceURI","unsetSection","console","log","green","magenta","deleteKSS","red","kssPath","sectionFileInfo","dataFilepath","join","dir","name","isInline","markup","match","newSort","sortSection","getIn","reference","newSection","Object","assign","updateInlineTemplate","removeFile","updateTemplateFields","updateDescription","sectionPath","writeSectionData","setIn","fieldShouldOutput","templatePath","writeFile","templateContent","descriptionPath","description","format","oldFilepath","forEach","field","deleteTemplate","updateTemplate","removed","sorted","unsortSection","deleteIn","delimiter","parts","split","newSorted","newParts","filter","part","idx","subsections","keys"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AAEA,IAAMA,OAAOC,QAAQ,MAAR,CAAb,C,CANA;;AAOA,IAAMC,KAAKD,QAAQ,UAAR,CAAX;AACA,IAAME,QAAQF,QAAQ,KAAR,EAAeE,KAA7B;AACA,IAAMC,QAAQH,QAAQ,OAAR,CAAd,C,CAAgC;;AAEhC;AACO,IAAMI,kCAAa;AAC1B;;AAEE;;;;;;;;AAQAC,WAXwB,qBAWdC,QAXc,EAWJC,KAXI,EAWG;AACzB,QAAMC,YAAYP,GAAGQ,YAAH,CAAgBH,QAAhB,EAA0B,MAA1B,CAAlB;AACA,QAAMI,QAAQH,MAAMI,GAAN,CAAU,QAAV,CAAd;AACA,QAAMC,aAAa,aAAMC,UAAN,CAAiBP,QAAjB,EAA2B,KAA3B,EAAkCC,KAAlC,KAA4C,EAA/D;AACA,QAAMO,OAAOf,KAAKG,KAAL,CAAWI,QAAX,CAAb;AACA,QAAIS,WAAWR,KAAf;;AAEA,QAAIC,SAAJ,EAAe;AACb,UAAMQ,aAAad,MAAMM,SAAN,EAAiBE,MAAMC,GAAN,CAAU,YAAV,CAAjB,CAAnB;;AAEA,UAAIK,WAAWC,IAAX,CAAgBC,QAAhB,CAAyBC,MAA7B,EAAqC;AACnC,YAAMC,UAAU,aAAMC,oBAAN,CACdL,WAAWC,IAAX,CAAgBC,QAAhB,CAAyB,CAAzB,CADc,CAAhB;;AAIA;AACAH,mBAAWX,WAAWkB,iBAAX,CACThB,QADS,EAETc,OAFS,EAGTR,UAHS,EAITG,QAJS,CAAX;;AAOA;AACA,YAAIH,cACFA,WAAWW,YADT,IAEFX,WAAWW,YAAX,KAA4BH,QAAQG,YAFtC,EAGE;AACAR,qBAAW,KAAKS,YAAL,CAAkBZ,UAAlB,EAA8BE,IAA9B,EAAoCC,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-kss.js","sourcesContent":["/** @module cli/kss-handler */\n\nimport { utils } from './utils';\nimport { templateHandler } from './handle-templates';\nimport { writeStore } from './require-templates';\n\nconst path = require('path');\nconst fs = require('fs-extra');\nconst parse = require('kss').parse;\nconst chalk = require('chalk'); // Colorize terminal output\n\n/* eslint-disable */\nexport const kssHandler = {\n/* eslint-enable */\n\n /**\n * Handle update of a KSS section\n *\n * @function updateKSS\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} store - memory store\n * @return {object} updated data store\n */\n updateKSS(filepath, store) {\n const kssSource = fs.readFileSync(filepath, 'utf8');\n const huron = store.get('config');\n const oldSection = utils.getSection(filepath, false, store) || {};\n const file = path.parse(filepath);\n let newStore = store;\n\n if (kssSource) {\n const styleguide = parse(kssSource, huron.get('kssOptions'));\n\n if (styleguide.data.sections.length) {\n const section = utils.normalizeSectionData(\n styleguide.data.sections[0]\n );\n\n // Update or add section data\n newStore = kssHandler.updateSectionData(\n filepath,\n section,\n oldSection,\n newStore\n );\n\n // Remove old section data if reference URI has changed\n if (oldSection &&\n oldSection.referenceURI &&\n oldSection.referenceURI !== section.referenceURI\n ) {\n newStore = this.unsetSection(oldSection, file, newStore, false);\n }\n\n writeStore(newStore);\n console.log(\n chalk.green(\n `KSS source in ${filepath} changed or added`\n )\n );\n return newStore;\n }\n\n console.log(chalk.magenta(`No KSS found in ${filepath}`));\n return newStore;\n }\n\n if (oldSection) {\n newStore = kssHandler.deleteKSS(filepath, oldSection, newStore);\n }\n\n console.log(chalk.red(`${filepath} not found or empty`)); // eslint-disable-line no-console\n return newStore;\n },\n\n /**\n * Handle removal of a KSS section\n *\n * @function deleteKSS\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - KSS section data\n * @param {object} store - memory store\n * @return {object} updated data store\n */\n deleteKSS(filepath, section, store) {\n const file = path.parse(filepath);\n\n // Remove section data from memory store\n return kssHandler.unsetSection(section, file, store, true);\n },\n\n /**\n * Update the sections store with new data for a specific section\n *\n * @function updateSectionData\n * @param {object} section - contains updated section data\n * @param {string} kssPath - path to KSS section\n * @param {object} store - memory store\n * @return {object} updated data store\n */\n updateSectionData(kssPath, section, oldSection, store) {\n const sectionFileInfo = path.parse(kssPath);\n const dataFilepath = path.join(\n sectionFileInfo.dir,\n `${sectionFileInfo.name}.json`\n );\n const isInline = null !== section.markup.match(/<\\/[^>]*>/);\n const newSort = kssHandler.sortSection(\n store.getIn(['sections', 'sorted']),\n section.reference,\n store.get('referenceDelimiter')\n );\n const newSection = Object.assign({}, oldSection, section);\n let newStore = store;\n\n // Required for reference from templates and data\n newSection.kssPath = kssPath;\n\n if (isInline) {\n // Set section value if inlineTempalte() returned a path\n newStore = kssHandler.updateInlineTemplate(\n kssPath,\n oldSection,\n newSection,\n newStore\n );\n } else {\n // Remove inline template, if it exists\n utils.removeFile(\n newSection.referenceURI,\n 'template',\n kssPath,\n store\n );\n // Update markup and data fields\n newStore = kssHandler.updateTemplateFields(\n sectionFileInfo,\n oldSection,\n newSection,\n newStore\n );\n }\n\n // Output section description\n newStore = kssHandler.updateDescription(\n kssPath,\n oldSection,\n newSection,\n newStore\n );\n\n // Output section data to a JSON file\n newSection.sectionPath = utils.writeSectionData(\n newStore,\n newSection,\n dataFilepath\n );\n\n // Update section sorting\n return newStore\n .setIn(\n ['sections', 'sorted'],\n newSort\n )\n .setIn(\n ['sections', 'sectionsByPath', kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n },\n\n /**\n * Handle detection and output of inline templates, which is markup written\n * in the KSS documentation itself as opposed to an external file\n *\n * @function updateInlineTemplate\n * @param {string} oldSection - previous iteration of KSS data, if updated\n * @param {object} section - KSS section data\n * @return {object} updated data store with new template path info\n */\n updateInlineTemplate(filepath, oldSection, section, store) {\n const newSection = section;\n const newStore = store;\n\n // If we have inline markup\n if (this.fieldShouldOutput(oldSection, section, 'markup')) {\n newSection.templatePath = utils.writeFile(\n section.referenceURI,\n 'template',\n filepath,\n section.markup,\n store\n );\n newSection.templateContent = section.markup;\n\n return newStore\n .setIn(\n ['sections', 'sectionsByPath', filepath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n }\n\n return newStore;\n },\n\n /**\n * Handle output of section description\n *\n * @function updateDescription\n * @param {string} oldSection - previous iteration of KSS data, if updated\n * @param {object} section - KSS section data\n * @return {object} updated data store with new descripton path info\n */\n updateDescription(filepath, oldSection, section, store) {\n const newSection = section;\n const newStore = store;\n\n // If we don't have previous KSS or the KSS has been updated\n if (this.fieldShouldOutput(oldSection, section, 'description')) {\n // Write new description\n newSection.descriptionPath = utils.writeFile(\n section.referenceURI,\n 'description',\n filepath,\n section.description,\n store\n );\n\n return newStore\n .setIn(\n ['sections', 'sectionsByPath', filepath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', section.referenceURI],\n newSection\n );\n }\n\n return newStore;\n },\n\n /**\n * Handle Data and Markup fields\n *\n * @function updateTemplateFields\n * @param {string} file - File data for KSS file from path.parse()\n * @param {object} oldSection - outdated KSS data\n * @param {object} section - KSS section data\n * @param {object} store - memory store\n * @return {object} KSS section data with updated asset paths\n */\n updateTemplateFields(file, oldSection, section, store) {\n const kssPath = path.format(file);\n const newSection = section;\n let filepath = '';\n let oldFilepath = '';\n let newStore = store;\n\n ['data', 'markup'].forEach((field) => {\n if (newSection[field]) {\n if (oldSection[field]) {\n oldFilepath = path.join(file.dir, oldSection[field]);\n newStore = templateHandler.deleteTemplate(\n oldFilepath,\n oldSection,\n newStore\n );\n }\n\n filepath = path.join(file.dir, newSection[field]);\n newStore = templateHandler.updateTemplate(\n filepath,\n newSection,\n newStore\n );\n } else {\n delete newSection[field];\n newStore = newStore\n .setIn(\n ['sections', 'sectionsByPath', kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', newSection.referenceURI],\n newSection\n );\n }\n });\n\n return newStore;\n },\n\n /**\n * Remove a section from the memory store\n *\n * @function unsetSection\n * @param {object} section - contains updated section data\n * @param {string} file - file object from path.parse()\n * @param {object} store - memory store\n * @param {bool} removed - has the file been removed or just the section information changed?\n * @return {object} updated data store with new descripton path info\n */\n unsetSection(section, file, store, removed) {\n const sorted = store.getIn(['sections', 'sorted']);\n const kssPath = path.format(file);\n const dataFilepath = path.join(file.dir, `${file.name}.json`);\n const isInline = section.markup &&\n null !== section.markup.match(/<\\/[^>]*>/);\n const newSort = kssHandler.unsortSection(\n sorted,\n section.reference,\n store.get('referenceDelimiter')\n );\n let newStore = store;\n\n // Remove old section data\n utils.removeFile(\n section.referenceURI,\n 'section',\n dataFilepath,\n newStore\n );\n\n // Remove associated inline template\n if (isInline) {\n utils.removeFile(section.referenceURI, 'template', kssPath, newStore);\n }\n\n // Remove description template\n utils.removeFile(section.referenceURI, 'description', kssPath, newStore);\n\n // Remove data from sectionsByPath if file has been removed\n if (removed) {\n newStore = newStore.deleteIn(['sections', 'sectionsByPath', kssPath]);\n }\n\n return newStore\n .deleteIn(['sections', 'sectionsByURI', section.referenceURI])\n .setIn(['sections', 'sorted'], newSort);\n },\n\n /**\n * Sort sections and subsections\n *\n * @function sortSection\n * @param {object} sorted - currently sorted sections\n * @param {string} reference - reference URI of section to sort\n * @return {object} updated data store with new descripton path info\n */\n sortSection(sorted, reference, delimiter) {\n const parts = reference.split(delimiter);\n const newSort = sorted[parts[0]] || {};\n const newSorted = sorted;\n\n if (1 < parts.length) {\n const newParts = parts.filter((part, idx) => 0 !== idx);\n newSorted[parts[0]] = kssHandler.sortSection(\n newSort,\n newParts.join(delimiter),\n delimiter\n );\n } else {\n newSorted[parts[0]] = newSort;\n }\n\n return newSorted;\n },\n\n /**\n * Remove a section from the sorted sections\n *\n * @function unsortSection\n * @param {object} sorted - currently sorted sections\n * @param {string} reference - reference URI of section to sort\n * @return {object} updated data store with new descripton path info\n */\n unsortSection(sorted, reference, delimiter) {\n const parts = reference.split(delimiter);\n const subsections = Object.keys(sorted[parts[0]]);\n const newSorted = sorted;\n\n if (subsections.length) {\n if (1 < parts.length) {\n const newParts = parts.filter((part, idx) => 0 !== idx);\n newSorted[parts[0]] = kssHandler.unsortSection(\n newSorted[parts[0]],\n newParts.join(delimiter),\n delimiter\n );\n }\n } else {\n delete newSorted[parts[0]];\n }\n\n return newSorted;\n },\n\n /**\n * Compare a KSS field between old and new KSS data to see if we need to output\n * a new module for that field\n *\n * @function fieldShouldOutput\n * @param {object} oldSection - currently sorted sections\n * @param {object} newSection - reference URI of section to sort\n * @param {string} field - KSS field to check\n * @return {bool} output a new module for the KSS field\n */\n fieldShouldOutput(oldSection, newSection, field) {\n return (oldSection &&\n (oldSection[field] !== newSection[field] ||\n oldSection.referenceURI !== newSection.referenceURI)\n ) ||\n ! oldSection;\n },\n};\n"]} \ No newline at end of file diff --git a/dist/cli/handle-templates.js b/dist/cli/handle-templates.js index 0e2d86b..bbe2cdc 100644 --- a/dist/cli/handle-templates.js +++ b/dist/cli/handle-templates.js @@ -22,6 +22,7 @@ var templateHandler = exports.templateHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} updated memory store */ updateTemplate: function updateTemplate(filepath, section, store) { var file = path.parse(filepath); @@ -62,6 +63,7 @@ var templateHandler = exports.templateHandler = { * @param {string} filepath - filepath of changed file (comes from gaze) * @param {object} section - contains KSS section data * @param {object} store - memory store + * @return {object} updated memory store */ deleteTemplate: function deleteTemplate(filepath, section, store) { var file = path.parse(filepath); diff --git a/dist/cli/handle-templates.js.map b/dist/cli/handle-templates.js.map index 9dfb0f7..de8b1d1 100644 --- a/dist/cli/handle-templates.js.map +++ b/dist/cli/handle-templates.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/cli/handle-templates.js"],"names":["path","require","fs","chalk","templateHandler","updateTemplate","filepath","section","store","file","parse","pairPath","getTemplateDataPair","type","ext","newSection","newStore","content","readFileSync","e","console","log","red","requirePath","writeFile","referenceURI","templateContent","sectionPath","writeSectionData","setIn","kssPath","deleteTemplate","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1C,CANG,EAOHf,UAPG,EASJc,KATI,CAUH,CAAC,UAAD,EAAa,eAAb,EAA8Bd,WAAWU,YAAzC,CAVG,EAWHV,UAXG,CAAP;AAaD;;AAED,WAAOC,QAAP;AACD,GAzD4B;;;AA2D7B;;;;;;;;AAQAe,gBAnE6B,0BAmEdzB,QAnEc,EAmEJC,OAnEI,EAmEKC,KAnEL,EAmEY;AACvC,QAAMC,OAAOT,KAAKU,KAAL,CAAWJ,QAAX,CAAb;AACA,QAAMO,OAAO,YAAYJ,KAAKK,GAAjB,GAAuB,MAAvB,GAAgC,UAA7C;AACA,QAAMC,aAAaR,OAAnB;AACA,QAAMS,WAAWR,KAAjB;;AAEA;AACA,QAAMe,cAAc,aAAMS,UAAN,CAClBjB,WAAWU,YADO,EAElBZ,IAFkB,EAGlBP,QAHkB,EAIlBU,QAJkB,CAApB;AAMA,WAAOD,WAAcF,IAAd,UAAP;;AAEA,WAAOG,SACJiB,QADI,CACK,CAAC,WAAD,EAAcV,WAAd,CADL,EAEJM,KAFI,CAGH,CAAC,UAAD,EAAa,gBAAb,EAA+Bd,WAAWe,OAA1C,CAHG,EAIHf,UAJG,EAMJc,KANI,CAOH,CAAC,UAAD,EAAa,eAAb,EAA8Bd,WAAWU,YAAzC,CAPG,EAQHV,UARG,CAAP;AAUD;AA5F4B,CAAxB","file":"handle-templates.js","sourcesContent":["/** @module cli/template-handler */\nimport { utils } from './utils';\n\nconst path = require('path');\nconst fs = require('fs-extra');\nconst chalk = require('chalk');\n\n/* eslint-disable */\nexport const templateHandler = {\n/* eslint-enable */\n /**\n * Handle update of a template or data (json) file\n *\n * @function updateTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n */\n updateTemplate(filepath, section, store) {\n const file = path.parse(filepath);\n const pairPath = utils.getTemplateDataPair(file, section, store);\n const type = '.json' === file.ext ? 'data' : 'template';\n const newSection = section;\n const newStore = store;\n let content = false;\n\n try {\n content = fs.readFileSync(filepath, 'utf8');\n } catch (e) {\n console.log(chalk.red(`${filepath} does not exist`));\n }\n\n if (content) {\n const requirePath = utils.writeFile(\n newSection.referenceURI,\n type,\n filepath,\n content,\n newStore\n );\n newSection[`${type}Path`] = requirePath;\n\n if ('template' === type) {\n newSection.templateContent = content;\n\n // Rewrite section data with template content\n newSection.sectionPath = utils.writeSectionData(newStore, newSection);\n }\n\n return newStore\n .setIn(\n ['templates', requirePath],\n pairPath\n )\n .setIn(\n ['sections', 'sectionsByPath', newSection.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', newSection.referenceURI],\n newSection\n );\n }\n\n return newStore;\n },\n\n /**\n * Handle removal of a template or data (json) file\n *\n * @function deleteTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n */\n deleteTemplate(filepath, section, store) {\n const file = path.parse(filepath);\n const type = '.json' === file.ext ? 'data' : 'template';\n const newSection = section;\n const newStore = store;\n\n // Remove partner\n const requirePath = utils.removeFile(\n newSection.referenceURI,\n type,\n filepath,\n newStore\n );\n delete newSection[`${type}Path`];\n\n return newStore\n .deleteIn(['templates', requirePath])\n .setIn(\n ['sections', 'sectionsByPath', newSection.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', newSection.referenceURI],\n newSection\n );\n },\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/cli/handle-templates.js"],"names":["path","require","fs","chalk","templateHandler","updateTemplate","filepath","section","store","file","parse","pairPath","getTemplateDataPair","type","ext","newSection","newStore","content","readFileSync","e","console","log","red","requirePath","writeFile","referenceURI","templateContent","sectionPath","writeSectionData","setIn","kssPath","deleteTemplate","removeFile","deleteIn"],"mappings":";;;;;;;AACA;;AAEA,IAAMA,OAAOC,QAAQ,MAAR,CAAb,C,CAHA;;AAIA,IAAMC,KAAKD,QAAQ,UAAR,CAAX;AACA,IAAME,QAAQF,QAAQ,OAAR,CAAd;;AAEA;AACO,IAA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gBArE6B,0BAqEdzB,QArEc,EAqEJC,OArEI,EAqEKC,KArEL,EAqEY;AACvC,QAAMC,OAAOT,KAAKU,KAAL,CAAWJ,QAAX,CAAb;AACA,QAAMO,OAAO,YAAYJ,KAAKK,GAAjB,GAAuB,MAAvB,GAAgC,UAA7C;AACA,QAAMC,aAAaR,OAAnB;AACA,QAAMS,WAAWR,KAAjB;;AAEA;AACA,QAAMe,cAAc,aAAMS,UAAN,CAClBjB,WAAWU,YADO,EAElBZ,IAFkB,EAGlBP,QAHkB,EAIlBU,QAJkB,CAApB;AAMA,WAAOD,WAAcF,IAAd,UAAP;;AAEA,WAAOG,SACJiB,QADI,CACK,CAAC,WAAD,EAAcV,WAAd,CADL,EAEJM,KAFI,CAGH,CAAC,UAAD,EAAa,gBAAb,EAA+Bd,WAAWe,OAA1C,CAHG,EAIHf,UAJG,EAMJc,KANI,CAOH,CAAC,UAAD,EAAa,eAAb,EAA8Bd,WAAWU,YAAzC,CAPG,EAQHV,UARG,CAAP;AAUD;AA9F4B,CAAxB","file":"handle-templates.js","sourcesContent":["/** @module cli/template-handler */\nimport { utils } from './utils';\n\nconst path = require('path');\nconst fs = require('fs-extra');\nconst chalk = require('chalk');\n\n/* eslint-disable */\nexport const templateHandler = {\n/* eslint-enable */\n /**\n * Handle update of a template or data (json) file\n *\n * @function updateTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n * @return {object} updated memory store\n */\n updateTemplate(filepath, section, store) {\n const file = path.parse(filepath);\n const pairPath = utils.getTemplateDataPair(file, section, store);\n const type = '.json' === file.ext ? 'data' : 'template';\n const newSection = section;\n const newStore = store;\n let content = false;\n\n try {\n content = fs.readFileSync(filepath, 'utf8');\n } catch (e) {\n console.log(chalk.red(`${filepath} does not exist`));\n }\n\n if (content) {\n const requirePath = utils.writeFile(\n newSection.referenceURI,\n type,\n filepath,\n content,\n newStore\n );\n newSection[`${type}Path`] = requirePath;\n\n if ('template' === type) {\n newSection.templateContent = content;\n\n // Rewrite section data with template content\n newSection.sectionPath = utils.writeSectionData(newStore, newSection);\n }\n\n return newStore\n .setIn(\n ['templates', requirePath],\n pairPath\n )\n .setIn(\n ['sections', 'sectionsByPath', newSection.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', newSection.referenceURI],\n newSection\n );\n }\n\n return newStore;\n },\n\n /**\n * Handle removal of a template or data (json) file\n *\n * @function deleteTemplate\n * @param {string} filepath - filepath of changed file (comes from gaze)\n * @param {object} section - contains KSS section data\n * @param {object} store - memory store\n * @return {object} updated memory store\n */\n deleteTemplate(filepath, section, store) {\n const file = path.parse(filepath);\n const type = '.json' === file.ext ? 'data' : 'template';\n const newSection = section;\n const newStore = store;\n\n // Remove partner\n const requirePath = utils.removeFile(\n newSection.referenceURI,\n type,\n filepath,\n newStore\n );\n delete newSection[`${type}Path`];\n\n return newStore\n .deleteIn(['templates', requirePath])\n .setIn(\n ['sections', 'sectionsByPath', newSection.kssPath],\n newSection\n )\n .setIn(\n ['sections', 'sectionsByURI', newSection.referenceURI],\n newSection\n );\n },\n};\n"]} \ No newline at end of file diff --git a/dist/cli/utils.js b/dist/cli/utils.js index d689091..bb5f09a 100644 --- a/dist/cli/utils.js +++ b/dist/cli/utils.js @@ -20,6 +20,7 @@ var utils = exports.utils = { * * @function normalizeSectionData * @param {object} section - section data + * @return {object} section data */ normalizeSectionData: function normalizeSectionData(section) { var data = section.data || section; @@ -68,6 +69,7 @@ var utils = exports.utils = { * @function getTemplateDataPair * @param {object} file - file object from path.parse() * @param {object} section - KSS section data + * @return {string} relative path to module JSON file */ getTemplateDataPair: function getTemplateDataPair(file, section, store) { var huron = store.get('config'); @@ -92,6 +94,7 @@ var utils = exports.utils = { * * @function normalizeHeader * @param {string} header - section header extracted from KSS documentation + * @return {string} modified header, lowercase and words separated by dash */ normalizeHeader: function normalizeHeader(header) { return header.toLowerCase().replace(/\s?\W\s?/g, '-'); @@ -104,6 +107,7 @@ var utils = exports.utils = { * @function wrapMarkup * @param {string} content - html or template markup * @param {string} templateId - id of template (should be section reference) + * @return {string} modified HTML */ wrapMarkup: function wrapMarkup(content, templateId) { return '\n\n\n'; @@ -238,7 +242,7 @@ var utils = exports.utils = { * @function writeSectionTemplate * @param {string} search - key on which to match section * @param {field} string - field in which to look to determine section - * @param {obj} sections - sections memory store + * @param {obj} store - sections memory store */ getSection: function getSection(search, field, store) { var sectionValues = store.getIn(['sections', 'sectionsByPath']).valueSeq(); @@ -263,6 +267,7 @@ var utils = exports.utils = { * @param {string} search - key on which to match section * @param {field} string - field in which to look to determine section * @param {obj} sections - sections memory store + * @return {string} kssMatch - relative path to KSS directory */ matchKssDir: function matchKssDir(filepath, huron) { var kssSource = huron.get('kss'); diff --git a/dist/cli/utils.js.map b/dist/cli/utils.js.map index 9f47eaa..7894aa1 100644 --- a/dist/cli/utils.js.map +++ b/dist/cli/utils.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/cli/utils.js"],"names":["cwd","process","path","require","fs","chalk","utils","normalizeSectionData","section","data","referenceURI","writeSectionData","store","sectionPath","outputPath","sectionFileInfo","hasOwnProperty","call","parse","kssPath","join","dir","name","writeFile","JSON","stringify","console","warn","red","getTemplateDataPair","file","huron","get","kssDir","matchKssDir","componentPath","relative","resolve","partnerType","ext","partnerExt","extension","pairPath","generateFilename","normalizeHeader","header","toLowerCase","replace","wrapMarkup","content","templateId","id","type","types","outputExt","indexOf","log","filepath","filename","outputRelative","newContent","outputFileSync","green","e","removeFile","removeSync","writeSectionTemplate","sectionTemplate","readFileSync","output","set","getSection","search","field","sectionValues","getIn","valueSeq","selectedSection","filter","value","kssSource","kssMatch","length","error"],"mappings":";;;;;AAAA;;AAEA,IAAMA,MAAMC,QAAQD,GAAR,EAAZ,C,CAA2B;AAC3B,IAAME,OAAOC,QAAQ,MAAR,CAAb;AACA,IAAMC,KAAKD,QAAQ,UAAR,CAAX;AACA,IAAME,QAAQF,QAAQ,OAAR,CAAd,C,CA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,eAAP;AACD,GAzRkB;;;AA2RnB;;;;;;;;AAQA3C,aAnSmB,uBAmSPuB,QAnSO,EAmSG1B,KAnSH,EAmSU;AAC3B,QAAMiD,YAAYjD,MAAMC,GAAN,CAAU,KAAV,CAAlB;AACA;AACA,QAAMiD,WAAWD,UAAUF,MAAV,CAAiB,UAACzD,GAAD;AAAA,aAAS,CAAC,CAAD,KAAOoC,SAASF,OAAT,CAAiBlC,GAAjB,CAAhB;AAAA,KAAjB,CAAjB;AACA;;AAEA,QAAI4D,SAASC,MAAb,EAAqB;AACnB,aAAOD,SAAS,CAAT,CAAP;AACD;;AAEDvD,YAAQyD,KAAR,CACE9E,MAAMuB,GAAN,eAAsB6B,QAAtB,qEADF;AAIA,WAAO,KAAP;AACD;AAlTkB,CAAd","file":"utils.js","sourcesContent":["/** @module cli/utilities */\n\nconst cwd = process.cwd(); // Current working directory\nconst path = require('path');\nconst fs = require('fs-extra');\nconst chalk = require('chalk'); // Colorize terminal output\n\n// Exports\n/* eslint-disable */\nexport const utils = {\n/* eslint-enable */\n\n /**\n * Ensure predictable data structure for KSS section data\n *\n * @function normalizeSectionData\n * @param {object} section - section data\n */\n normalizeSectionData(section) {\n const data = section.data || section;\n\n if (! data.referenceURI || '' === data.referenceURI) {\n data.referenceURI = section.referenceURI();\n }\n\n return data;\n },\n\n /**\n * Ensure predictable data structure for KSS section data\n *\n * @function writeSectionData\n * @param {object} store - data store\n * @param {object} section - section data\n * @param {string} sectionPath - output destination for section data file\n */\n writeSectionData(store, section, sectionPath = false) {\n let outputPath = sectionPath;\n let sectionFileInfo;\n\n if (! outputPath && {}.hasOwnProperty.call(section, 'kssPath')) {\n sectionFileInfo = path.parse(section.kssPath);\n outputPath = path.join(\n sectionFileInfo.dir,\n `${sectionFileInfo.name}.json`\n );\n }\n\n // Output section data\n if (outputPath) {\n return utils.writeFile(\n section.referenceURI,\n 'section',\n outputPath,\n JSON.stringify(section),\n store\n );\n }\n\n console.warn( // eslint-disable-line no-console\n chalk.red(`Failed to write section data for ${section.referenceURI}`)\n );\n return false;\n },\n\n /**\n * Find .json from a template file or vice versa\n *\n * @function getTemplateDataPair\n * @param {object} file - file object from path.parse()\n * @param {object} section - KSS section data\n */\n getTemplateDataPair(file, section, store) {\n const huron = store.get('config');\n const kssDir = utils.matchKssDir(file.dir, huron);\n\n if (kssDir) {\n const componentPath = path.relative(\n path.resolve(cwd, kssDir),\n file.dir\n );\n const partnerType = '.json' === file.ext ? 'template' : 'data';\n const partnerExt = '.json' === file.ext ?\n huron.get('templates').extension :\n '.json';\n\n const pairPath = path.join(\n componentPath,\n utils.generateFilename(\n section.referenceURI,\n partnerType,\n partnerExt,\n store\n )\n );\n\n return `./${pairPath}`;\n }\n\n return false;\n },\n\n /**\n * Normalize a section title for use as a filename\n *\n * @function normalizeHeader\n * @param {string} header - section header extracted from KSS documentation\n */\n normalizeHeader(header) {\n return header\n .toLowerCase()\n .replace(/\\s?\\W\\s?/g, '-');\n },\n\n /**\n * Wrap html in required template tags\n *\n * @function wrapMarkup\n * @param {string} content - html or template markup\n * @param {string} templateId - id of template (should be section reference)\n */\n wrapMarkup(content, templateId) {\n return `\n\n\\n`;\n },\n\n /**\n * Generate a filename based on referenceURI, type and file object\n *\n * @function generateFilename\n * @param {string} id - The name of the file (with extension).\n * @param {string} type - the type of file output\n * @param {object} ext - file extension\n * @param {store} store - data store\n * @return {string} Path to output file, relative to ouput dir (can be use in require statements)\n */\n generateFilename(id, type, ext, store) {\n // Type of file and its corresponding extension(s)\n const types = store.get('types');\n const outputExt = '.scss' !== ext ? ext : '.html';\n\n /* eslint-disable */\n if (-1 === types.indexOf(type)) {\n console.log(`Huron data ${type} does not exist`);\n return false;\n }\n /* eslint-enable */\n\n return `${id}-${type}${outputExt}`;\n },\n\n /**\n * Copy an HTML file into the huron output directory.\n *\n * @function writeFile\n * @param {string} id - The name of the file (with extension).\n * @param {string} content - The content of the file to write.\n * @param {string} type - the type of file output\n * @param {object} store - The data store\n * @return {string} Path to output file, relative to ouput dir (can be use in require statements)\n */\n writeFile(id, type, filepath, content, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n const filename = utils.generateFilename(id, type, file.ext, store);\n const kssDir = utils.matchKssDir(filepath, huron);\n\n if (kssDir) {\n const componentPath = path.relative(\n path.resolve(cwd, kssDir),\n file.dir\n );\n const outputRelative = path.join(\n huron.get('output'),\n componentPath,\n `${filename}`\n );\n const outputPath = path.resolve(cwd, huron.get('root'), outputRelative);\n let newContent = content;\n\n if ('data' !== type && 'section' !== type) {\n newContent = utils.wrapMarkup(content, id);\n }\n\n try {\n fs.outputFileSync(outputPath, newContent);\n console.log(chalk.green(`Writing ${outputRelative}`)); // eslint-disable-line no-console\n } catch (e) {\n console.log(chalk.red(`Failed to write ${outputRelative}`)); // eslint-disable-line no-console\n }\n\n return `./${outputRelative.replace(`${huron.get('output')}/`, '')}`;\n }\n\n return false;\n },\n\n /**\n * Delete a file in the huron output directory\n *\n * @function removeFile\n * @param {string} filename - The name of the file (with extension).\n * @param {object} store - The data store\n * @return {string} Path to output file, relative to ouput dir (can be use in require statements)\n */\n removeFile(id, type, filepath, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n const filename = utils.generateFilename(id, type, file.ext, store);\n const kssDir = utils.matchKssDir(filepath, huron);\n\n if (kssDir) {\n const componentPath = path.relative(\n path.resolve(cwd, kssDir),\n file.dir\n );\n const outputRelative = path.join(\n huron.get('output'),\n componentPath,\n `${filename}`\n );\n const outputPath = path.resolve(cwd, huron.get('root'), outputRelative);\n\n try {\n fs.removeSync(outputPath);\n console.log(chalk.green(`Removing ${outputRelative}`)); // eslint-disable-line no-console\n } catch (e) {\n console.log( // eslint-disable-line no-console\n chalk.red(`${outputRelative} does not exist or cannot be deleted`)\n );\n }\n\n return `./${outputRelative.replace(`${huron.get('output')}/`, '')}`;\n }\n\n return false;\n },\n\n /**\n * Write a template for sections\n *\n * @function writeSectionTemplate\n * @param {string} filepath - the original template file\n * @param {object} store - data store\n * @return {object} updated store\n */\n writeSectionTemplate(filepath, store) {\n const huron = store.get('config');\n const sectionTemplate = utils.wrapMarkup(fs.readFileSync(filepath, 'utf8'));\n const componentPath = './huron-sections/sections.hbs';\n const output = path.join(\n cwd,\n huron.get('root'),\n huron.get('output'),\n componentPath\n );\n\n // Move huron script and section template into huron root\n fs.outputFileSync(output, sectionTemplate);\n console.log(chalk.green(`writing section template to ${output}`)); // eslint-disable-line no-console\n\n return store.set('sectionTemplatePath', componentPath);\n },\n\n /**\n * Request for section data based on section reference\n *\n * @function writeSectionTemplate\n * @param {string} search - key on which to match section\n * @param {field} string - field in which to look to determine section\n * @param {obj} sections - sections memory store\n */\n getSection(search, field, store) {\n const sectionValues = store\n .getIn(['sections', 'sectionsByPath'])\n .valueSeq();\n let selectedSection = false;\n\n if (field) {\n selectedSection = sectionValues\n .filter((value) => value[field] === search)\n .get(0);\n } else {\n selectedSection = store.getIn(['sections', 'sectionsByPath', search]);\n }\n\n return selectedSection;\n },\n\n /**\n * Match which configured KSS directory the current file\n *\n * @function matchKssDir\n * @param {string} search - key on which to match section\n * @param {field} string - field in which to look to determine section\n * @param {obj} sections - sections memory store\n */\n matchKssDir(filepath, huron) {\n const kssSource = huron.get('kss');\n /* eslint-disable space-unary-ops */\n const kssMatch = kssSource.filter((dir) => -1 !== filepath.indexOf(dir));\n /* eslint-enable space-unary-ops */\n\n if (kssMatch.length) {\n return kssMatch[0];\n }\n\n console.error(\n chalk.red(`filepath ${filepath} does not exist in any\n of the configured KSS directories`)\n );\n return false;\n },\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/cli/utils.js"],"names":["cwd","process","path","require","fs","chalk","utils","normalizeSectionData","section","data","referenceURI","writeSectionData","store","sectionPath","outputPath","sectionFileInfo","hasOwnProperty","call","parse","kssPath","join","dir","name","writeFile","JSON","stringify","console","warn","red","getTemplateDataPair","file","huron","get","kssDir","matchKssDir","componentPath","relative","resolve","partnerType","ext","partnerExt","extension","pairPath","generateFilename","normalizeHeader","header","toLowerCase","replace","wrapMarkup","content","templateId","id","type","types","outputExt","indexOf","log","filepath","filename","outputRelative","newContent","outputFileSync","green","e","removeFile","removeSync","writeSectionTemplate","sectionTemplate","readFileSync","output","set","getSection","search","field","sectionValues","getIn","valueSeq","selectedSection","filter","value","kssSource","kssMatch","length","error"],"mappings":";;;;;AAAA;;AAEA,IAAMA,MAAMC,QAAQD,GAAR,EAAZ,C,CAA2B;AAC3B,IAAME,OAAOC,QAAQ,MAAR,CAAb;AACA,IAAMC,KAAKD,QAAQ,UAAR,CAAX;AACA,IAAME,QAAQF,QAAQ,OAAR,CAAd,C,CAAgC;;AAEhC;AACA;AACO,IAAMG,wBAAQ;AACrB;;AAEE;;;;;;;AAOAC,sBAVmB,gCAUEC,OAVF,EAUW;AAC5B,QAAMC,OAAOD,QAAQC,IAAR,IAAgBD,OAA7B;;AAEA,QAAI,CAAEC,KAAKC,YAAP,IAAuB,OAAOD,KAAKC,YAAvC,EAAqD;AACnDD,WAAKC,YAAL,GAAoBF,QAAQE,YAAR,EAApB;AACD;;AAED,WAAOD,IAAP;AACD,GAlBkB;;;AAoBnB;;;;;;;;AAQAE,kBA5BmB,4BA4BFC,KA5BE,EA4BKJ,OA5BL,EA4BmC;AAAA,QAArBK,WAAqB,uEAAP,KAAO;;AACpD,QAAIC,aAAaD,WAAjB;AACA,QAAIE,wBAAJ;;AAEA,QAAI,CAAED,UAAF,IAAgB,GAAGE,cAAH,CAAkBC,IAAlB,CAAuBT,OAAvB,EAAgC,SAAhC,CAApB,EAAgE;AAC9DO,wBAAkBb,KAAKgB,KAAL,CAAWV,QAAQW,OAAnB,CAAlB;AACAL,mBAAaZ,KAAKkB,IAAL,CACXL,gBAAgBM,GADL,EAERN,gBAAgBO,IAFR,WAAb;AAID;;AAED;AACA,QAAIR,UAAJ,EAAgB;AACd,aAAOR,MAAMiB,SAAN,CACLf,QAAQE,YADH,EAEL,SAFK,EAGLI,UAHK,EAILU,KAAKC,SAAL,CAAejB,OAAf,CAJK,E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B,CACb,CAAC,UAAD,EAAa,gBAAb,CADa,EAEnBC,QAFmB,EAAtB;AAGA,QAAIC,kBAAkB,KAAtB;;AAEA,QAAIJ,KAAJ,EAAW;AACTI,wBAAkBH,cACfI,MADe,CACR,UAACC,KAAD;AAAA,eAAWA,MAAMN,KAAN,MAAiBD,MAA5B;AAAA,OADQ,EAEfxC,GAFe,CAEX,CAFW,CAAlB;AAGD,KAJD,MAIO;AACL6C,wBAAkBjE,MAAM+D,KAAN,CAAY,CAAC,UAAD,EAAa,gBAAb,EAA+BH,MAA/B,CAAZ,CAAlB;AACD;;AAED,WAAOK,eAAP;AACD,GA7RkB;;;AA+RnB;;;;;;;;;AASA3C,aAxSmB,uBAwSPuB,QAxSO,EAwSG1B,KAxSH,EAwSU;AAC3B,QAAMiD,YAAYjD,MAAMC,GAAN,CAAU,KAAV,CAAlB;AACA;AACA,QAAMiD,WAAWD,UAAUF,MAAV,CAAiB,UAACzD,GAAD;AAAA,aAAS,CAAC,CAAD,KAAOoC,SAASF,OAAT,CAAiBlC,GAAjB,CAAhB;AAAA,KAAjB,CAAjB;AACA;;AAEA,QAAI4D,SAASC,MAAb,EAAqB;AACnB,aAAOD,SAAS,CAAT,CAAP;AACD;;AAEDvD,YAAQyD,KAAR,CACE9E,MAAMuB,GAAN,eAAsB6B,QAAtB,qEADF;AAIA,WAAO,KAAP;AACD;AAvTkB,CAAd","file":"utils.js","sourcesContent":["/** @module cli/utilities */\n\nconst cwd = process.cwd(); // Current working directory\nconst path = require('path');\nconst fs = require('fs-extra');\nconst chalk = require('chalk'); // Colorize terminal output\n\n// Exports\n/* eslint-disable */\nexport const utils = {\n/* eslint-enable */\n\n /**\n * Ensure predictable data structure for KSS section data\n *\n * @function normalizeSectionData\n * @param {object} section - section data\n * @return {object} section data\n */\n normalizeSectionData(section) {\n const data = section.data || section;\n\n if (! data.referenceURI || '' === data.referenceURI) {\n data.referenceURI = section.referenceURI();\n }\n\n return data;\n },\n\n /**\n * Ensure predictable data structure for KSS section data\n *\n * @function writeSectionData\n * @param {object} store - data store\n * @param {object} section - section data\n * @param {string} sectionPath - output destination for section data file\n */\n writeSectionData(store, section, sectionPath = false) {\n let outputPath = sectionPath;\n let sectionFileInfo;\n\n if (! outputPath && {}.hasOwnProperty.call(section, 'kssPath')) {\n sectionFileInfo = path.parse(section.kssPath);\n outputPath = path.join(\n sectionFileInfo.dir,\n `${sectionFileInfo.name}.json`\n );\n }\n\n // Output section data\n if (outputPath) {\n return utils.writeFile(\n section.referenceURI,\n 'section',\n outputPath,\n JSON.stringify(section),\n store\n );\n }\n\n console.warn( // eslint-disable-line no-console\n chalk.red(`Failed to write section data for ${section.referenceURI}`)\n );\n return false;\n },\n\n /**\n * Find .json from a template file or vice versa\n *\n * @function getTemplateDataPair\n * @param {object} file - file object from path.parse()\n * @param {object} section - KSS section data\n * @return {string} relative path to module JSON file\n */\n getTemplateDataPair(file, section, store) {\n const huron = store.get('config');\n const kssDir = utils.matchKssDir(file.dir, huron);\n\n if (kssDir) {\n const componentPath = path.relative(\n path.resolve(cwd, kssDir),\n file.dir\n );\n const partnerType = '.json' === file.ext ? 'template' : 'data';\n const partnerExt = '.json' === file.ext ?\n huron.get('templates').extension :\n '.json';\n\n const pairPath = path.join(\n componentPath,\n utils.generateFilename(\n section.referenceURI,\n partnerType,\n partnerExt,\n store\n )\n );\n\n return `./${pairPath}`;\n }\n\n return false;\n },\n\n /**\n * Normalize a section title for use as a filename\n *\n * @function normalizeHeader\n * @param {string} header - section header extracted from KSS documentation\n * @return {string} modified header, lowercase and words separated by dash\n */\n normalizeHeader(header) {\n return header\n .toLowerCase()\n .replace(/\\s?\\W\\s?/g, '-');\n },\n\n /**\n * Wrap html in required template tags\n *\n * @function wrapMarkup\n * @param {string} content - html or template markup\n * @param {string} templateId - id of template (should be section reference)\n * @return {string} modified HTML\n */\n wrapMarkup(content, templateId) {\n return `\n\n\\n`;\n },\n\n /**\n * Generate a filename based on referenceURI, type and file object\n *\n * @function generateFilename\n * @param {string} id - The name of the file (with extension).\n * @param {string} type - the type of file output\n * @param {object} ext - file extension\n * @param {store} store - data store\n * @return {string} Path to output file, relative to ouput dir (can be use in require statements)\n */\n generateFilename(id, type, ext, store) {\n // Type of file and its corresponding extension(s)\n const types = store.get('types');\n const outputExt = '.scss' !== ext ? ext : '.html';\n\n /* eslint-disable */\n if (-1 === types.indexOf(type)) {\n console.log(`Huron data ${type} does not exist`);\n return false;\n }\n /* eslint-enable */\n\n return `${id}-${type}${outputExt}`;\n },\n\n /**\n * Copy an HTML file into the huron output directory.\n *\n * @function writeFile\n * @param {string} id - The name of the file (with extension).\n * @param {string} content - The content of the file to write.\n * @param {string} type - the type of file output\n * @param {object} store - The data store\n * @return {string} Path to output file, relative to ouput dir (can be use in require statements)\n */\n writeFile(id, type, filepath, content, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n const filename = utils.generateFilename(id, type, file.ext, store);\n const kssDir = utils.matchKssDir(filepath, huron);\n\n if (kssDir) {\n const componentPath = path.relative(\n path.resolve(cwd, kssDir),\n file.dir\n );\n const outputRelative = path.join(\n huron.get('output'),\n componentPath,\n `${filename}`\n );\n const outputPath = path.resolve(cwd, huron.get('root'), outputRelative);\n let newContent = content;\n\n if ('data' !== type && 'section' !== type) {\n newContent = utils.wrapMarkup(content, id);\n }\n\n try {\n fs.outputFileSync(outputPath, newContent);\n console.log(chalk.green(`Writing ${outputRelative}`)); // eslint-disable-line no-console\n } catch (e) {\n console.log(chalk.red(`Failed to write ${outputRelative}`)); // eslint-disable-line no-console\n }\n\n return `./${outputRelative.replace(`${huron.get('output')}/`, '')}`;\n }\n\n return false;\n },\n\n /**\n * Delete a file in the huron output directory\n *\n * @function removeFile\n * @param {string} filename - The name of the file (with extension).\n * @param {object} store - The data store\n * @return {string} Path to output file, relative to ouput dir (can be use in require statements)\n */\n removeFile(id, type, filepath, store) {\n const huron = store.get('config');\n const file = path.parse(filepath);\n const filename = utils.generateFilename(id, type, file.ext, store);\n const kssDir = utils.matchKssDir(filepath, huron);\n\n if (kssDir) {\n const componentPath = path.relative(\n path.resolve(cwd, kssDir),\n file.dir\n );\n const outputRelative = path.join(\n huron.get('output'),\n componentPath,\n `${filename}`\n );\n const outputPath = path.resolve(cwd, huron.get('root'), outputRelative);\n\n try {\n fs.removeSync(outputPath);\n console.log(chalk.green(`Removing ${outputRelative}`)); // eslint-disable-line no-console\n } catch (e) {\n console.log( // eslint-disable-line no-console\n chalk.red(`${outputRelative} does not exist or cannot be deleted`)\n );\n }\n\n return `./${outputRelative.replace(`${huron.get('output')}/`, '')}`;\n }\n\n return false;\n },\n\n /**\n * Write a template for sections\n *\n * @function writeSectionTemplate\n * @param {string} filepath - the original template file\n * @param {object} store - data store\n * @return {object} updated store\n */\n writeSectionTemplate(filepath, store) {\n const huron = store.get('config');\n const sectionTemplate = utils.wrapMarkup(fs.readFileSync(filepath, 'utf8'));\n const componentPath = './huron-sections/sections.hbs';\n const output = path.join(\n cwd,\n huron.get('root'),\n huron.get('output'),\n componentPath\n );\n\n // Move huron script and section template into huron root\n fs.outputFileSync(output, sectionTemplate);\n console.log(chalk.green(`writing section template to ${output}`)); // eslint-disable-line no-console\n\n return store.set('sectionTemplatePath', componentPath);\n },\n\n /**\n * Request for section data based on section reference\n *\n * @function writeSectionTemplate\n * @param {string} search - key on which to match section\n * @param {field} string - field in which to look to determine section\n * @param {obj} store - sections memory store\n */\n getSection(search, field, store) {\n const sectionValues = store\n .getIn(['sections', 'sectionsByPath'])\n .valueSeq();\n let selectedSection = false;\n\n if (field) {\n selectedSection = sectionValues\n .filter((value) => value[field] === search)\n .get(0);\n } else {\n selectedSection = store.getIn(['sections', 'sectionsByPath', search]);\n }\n\n return selectedSection;\n },\n\n /**\n * Match which configured KSS directory the current file\n *\n * @function matchKssDir\n * @param {string} search - key on which to match section\n * @param {field} string - field in which to look to determine section\n * @param {obj} sections - sections memory store\n * @return {string} kssMatch - relative path to KSS directory\n */\n matchKssDir(filepath, huron) {\n const kssSource = huron.get('kss');\n /* eslint-disable space-unary-ops */\n const kssMatch = kssSource.filter((dir) => -1 !== filepath.indexOf(dir));\n /* eslint-enable space-unary-ops */\n\n if (kssMatch.length) {\n return kssMatch[0];\n }\n\n console.error(\n chalk.red(`filepath ${filepath} does not exist in any\n of the configured KSS directories`)\n );\n return false;\n },\n};\n"]} \ No newline at end of file diff --git a/dist/web/huron.js b/dist/web/huron.js index 12b568a..39ff72d 100644 --- a/dist/web/huron.js +++ b/dist/web/huron.js @@ -57,6 +57,7 @@ var InsertNodes = function () { * * @param {string} modifier - target modifier * @param {object} meta - module metadata + * @return {string} rendered - the modified HTML module */ @@ -225,6 +226,7 @@ var InsertNodes = function () { * return its associated module key * * @param {object} tag - tag to check + * @return {bool} associated module key */ }, { @@ -250,6 +252,7 @@ var InsertNodes = function () { * * @param {array} tags - array of DOM nodes * @param {bool} recurse - should we recurse this function with a new array + * @return {object} moduleList - Huron placeholder DOM node */ }, { @@ -616,7 +619,7 @@ var InsertNodes = function () { * Verify specified element is using an acceptable huron type * * @param {string} type - type of partial (template, data, description, section or prototype ) - * @return {string} huron type or 'template' if invalid + * @return {string} type - huron type or 'template' if invalid */ }, { @@ -683,6 +686,7 @@ var InsertNodes = function () { * Get markup from any type of module (html, json or template) * * @param {string} content - String corresponding to markup + * @return {object} el.firstElementChild - HTML module */ }, { @@ -702,6 +706,7 @@ var InsertNodes = function () { * @param {array} filter.values - Values for property * @param {bool} filter.include - Whether the values should be included or excluded (true = include, false = exclude) * @param {object} moduleMeta - Filter for modules. Fields explained in the filterModules() function docs + * @return {bool} match - determine if modules need to be filtered */ }, { @@ -726,6 +731,7 @@ var InsertNodes = function () { * Generate a hash string from a module key * * @param {string} key - module key (require path) to convert into a hash + * @return {string} key - generated MD5 Hash */ }, { @@ -739,6 +745,7 @@ var InsertNodes = function () { * * @param {object} tag - tag to check * @param {object} meta - module metadata + * @return {bool} */ }, { diff --git a/dist/web/huron.js.map b/dist/web/huron.js.map index 347622f..6daf9d8 100644 --- a/dist/web/huron.js.map +++ b/dist/web/huron.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/web/huron.js"],"names":["md5","require","module","hot","accept","InsertNodes","modules","store","_modules","_moduleIds","Object","keys","_config","_sections","_templates","_prototypes","_types","meta","cycleModules","cycleStyleguide","context","filter","moduleList","elementList","regenCache","document","querySelectorAll","getModuleListFromTags","forEach","key","replaceElements","loadModule","property","values","include","sectionsQuery","querySelector","menuQuery","innerHTML","outputSections","cycleSections","menuTrigger","createElement","classList","add","body","insertBefore","appendChild","childNodes","addEventListener","toggle","outputMenu","sections","sectionsByPath","templateTypes","type","id","indexOf","prototype","name","length","_sectionTemplatePath","testTypes","testSections","section","tempTypes","currentType","referenceURI","hashKey","renderData","getModuleRender","hash","generateModuleHash","assign","console","warn","tag","dataset","huronType","huronId","sectionsByURI","elements","recurse","newList","element","moduleKey","getModuleKeyFromTag","push","concat","render","data","cached","shouldLoad","moduleMeta","getMetaFromPath","filterModules","replaceTemplate","parent","el","sorted","templateId","newEl","hasSubmenu","menuTarget","nextMenu","title","header","sectionMenu","menuItem","link","tagName","cloneNode","placeholder","istopLevel","topLevelWrapper","topLevelSection","insertionEl","parentHash","selfHash","childrenHash","nextTag","previousSibling","removeOldTags","parentNode","removeChild","validateType","tags","replace","hasStyleguideHelpers","currentTag","modifiedPlaceholder","modifier","huronModifier","rendered","applyModifier","renderedTemplate","convertToElement","renderedContents","content","children","nodeType","isSectionHelper","style","display","includes","_store","config","templates","prototypes","types","sectionTemplatePath","firstElementChild","match","hasOwnProperty","call","value","Boolean","log","hasAttribute","insert"],"mappings":";;;;;;;;;;AAAA,IAAMA,MAAMC,QAAQ,QAAR,CAAZ;;AAEA;AACA;AACA,IAAIC,OAAOC,GAAX,EAAgB;AACdD,SAAOC,GAAP,CAAWC,MAAX;AACD;;AAED;;;;;;IAKMC,W;AAEJ,uBAAYC,OAAZ,EAAqBC,KAArB,EAA4B;AAAA;;AAC1B;AACA,SAAKC,QAAL,GAAgBF,OAAhB;AACA;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,O,EAAS;AAC/B,UAAMxC,KAAKzE,SAASiB,aAAT,CAAuB,KAAvB,CAAX;;AAEAwD,SAAG5D,SAAH,GAAeoG,OAAf;AACA,aAAOxC,GAAGqD,iBAAV;AACD;;AAED;;;;;;;;;;;;kCASqBlI,M,EAAQwE,U,EAAY;AACvC,UAAI2D,QAAQ,IAAZ;;AAEA;AACA,UACE,qBAAoBnI,MAApB,yCAAoBA,MAApB,MACA,GAAGoI,cAAH,CAAkBC,IAAlB,CAAuBrI,MAAvB,EAA+B,UAA/B,CADA,IAEA,GAAGoI,cAAH,CAAkBC,IAAlB,CAAuBrI,MAAvB,EAA+B,QAA/B,CAFA,IAGA,GAAGoI,cAAH,CAAkBC,IAAlB,CAAuBrI,MAAvB,EAA+B,SAA/B,CAJF,EAKE;AACAmI,gBAAQnI,OAAOY,MAAP,CAAcZ,MAAd,CACN,UAACsI,KAAD;AAAA,iBAAW9D,WAAWxE,OAAOW,QAAlB,MAAgC2H,KAA3C;AAAA,SADM,CAAR;AAGA,eAAOC,QAAQJ,MAAM5F,MAAd,MAA0BvC,OAAOa,OAAxC;AACD;;AAEDwC,cAAQmF,GAAR,uDACWxI,MADX;;AAKA,aAAOmI,KAAP;AACD;;AAED;;;;;;;;uCAK0B3H,G,EAAK;AAC7B,aAAO7B,IAAI6B,GAAJ,CAAP;AACD;;AAED;;;;;;;;;oCAMuB+C,G,EAAK3D,I,EAAM;AAChC,UAAI,gBAAgBA,KAAKsC,IAAzB,EAA+B;AAC7B,eAAOqB,IAAIkF,YAAJ,CAAiB,gBAAjB,KACLlF,IAAIkF,YAAJ,CAAiB,YAAjB,CADF;AAED;;AAED,aAAO,KAAP;AACD;;;;;AAokBH;;AAEA;AACA;AACA;AACA;;;AACA,IAAMC,SAAS,IAAI1J,WAAJ,CAAgBC,OAAhB,EAAyBC,KAAzB,CAAf;AACA","file":"huron.js","sourcesContent":["const md5 = require('js-md5');\n\n/* eslint-disable no-underscore-dangle */\n// Accept the huron.js module for Huron development\nif (module.hot) {\n module.hot.accept();\n}\n\n/** Class for inserting HTML snippets at particular insertion points.\n * Uses require() to grab html partials, then inserts that html\n * into an element with attribute [huron-id] corresponding to the reference URI of the target KSS section,\n * and [huron-type] corresponding with the required KSS field\n */\nclass InsertNodes {\n\n constructor(modules, store) {\n /** webpack module list in which keys are relative require paths and values are the module contents */\n this._modules = modules;\n /** array of module keys */\n this._moduleIds = Object.keys(modules);\n /** reference to the huron config */\n this._config = null;\n /** KSS sections organized in various formats including by reference URI, by module key, and modules sorted by parent/child */\n this._sections = null;\n /** Key/value pairs of partner data and template files */\n this._templates = null;\n /** array of prototypes */\n this._prototypes = null;\n /** array of valid huron placeholder types */\n this._types = null;\n\n /** Cache for module metadata */\n this.meta = {};\n\n /** Reference to entire memory store */\n this.store = store;\n\n // Inits\n this.cycleModules();\n this.cycleStyleguide();\n }\n\n /**\n * Apply a modifier to a render function\n *\n * @param {string} modifier - target modifier\n * @param {object} meta - module metadata\n */\n static applyModifier(modifier, meta) {\n let rendered = false;\n let data = meta.data;\n\n if (data) {\n // If we have a modifier, use it, otherwise use the entire data set\n if (modifier && meta.data[modifier]) {\n data = Object.assign({}, meta.data[modifier], { modifier });\n }\n\n rendered = meta.render(data);\n } else {\n rendered = meta.render();\n }\n\n return rendered;\n }\n\n /**\n * Get markup from any type of module (html, json or template)\n *\n * @param {string} content - String corresponding to markup\n */\n static convertToElement(content) {\n const el = document.createElement('div');\n\n el.innerHTML = content;\n return el.firstElementChild;\n }\n\n /**\n * Filter module object by module key or module type\n *\n * @param {object} filter - Filter for modules. Options:\n * @param {string} filter.property - Which property to filter ('key' or 'type')\n * @param {array} filter.values - Values for property\n * @param {bool} filter.include - Whether the values should be included or excluded (true = include, false = exclude)\n * @param {object} moduleMeta - Filter for modules. Fields explained in the filterModules() function docs\n */\n static filterModules(filter, moduleMeta) {\n let match = true;\n\n // Check if we should filter out any modules\n if (\n 'object' === typeof filter &&\n {}.hasOwnProperty.call(filter, 'property') &&\n {}.hasOwnProperty.call(filter, 'values') &&\n {}.hasOwnProperty.call(filter, 'include')\n ) {\n match = filter.values.filter(\n (value) => moduleMeta[filter.property] === value\n );\n return Boolean(match.length) === filter.include;\n }\n\n console.log(` // eslint-disable-line no-console\n filter ${filter} is not in a valid format.\n module filters must include 'property', 'values', and 'include' properties\n `);\n\n return match;\n }\n\n /**\n * Generate a hash string from a module key\n *\n * @param {string} key - module key (require path) to convert into a hash\n */\n static generateModuleHash(key) {\n return md5(key);\n }\n\n /**\n * Check if this tag is a styleguide helper\n *\n * @param {object} tag - tag to check\n * @param {object} meta - module metadata\n */\n static isSectionHelper(tag, meta) {\n if ('prototype' === meta.type) {\n return tag.hasAttribute('huron-sections') ||\n tag.hasAttribute('huron-menu');\n }\n\n return false;\n }\n\n /**\n * Replace all template markers with the actual template markup.\n *\n * @param {string} context - The hash context for the module\n * @param {object} filter - Filter for modules. Fields explained in the filterModules() function docs\n */\n cycleModules(context = false, filter = false) {\n let moduleList = {};\n let elementList = context;\n\n // We're replacing top-level elements\n if (! elementList) {\n this.regenCache();\n\n // Find all top-level huron placeholders\n elementList = document.querySelectorAll(\n '[data-huron-id][data-huron-type]'\n );\n }\n\n moduleList = this.getModuleListFromTags(elementList);\n\n // Loop through modules array\n Object.keys(moduleList).forEach((key) => {\n const module = this._modules[key];\n const replaceElements = moduleList[key];\n\n this.loadModule(key, module, replaceElements, true, filter);\n });\n }\n\n /**\n * Helper for reloading sections only\n */\n cycleSections() {\n this.cycleModules(false, {\n property: 'type',\n values: ['section'],\n include: true,\n });\n }\n\n /**\n * Reload styleguide sections and menu helpers\n */\n cycleStyleguide() {\n const sectionsQuery = document.querySelector('[huron-sections]');\n const menuQuery = document.querySelector('[huron-menu]');\n\n // Sections\n if (sectionsQuery) {\n sectionsQuery.innerHTML = '';\n this.outputSections(null, sectionsQuery);\n this.cycleSections();\n }\n\n // Menu\n if (menuQuery) {\n menuQuery.innerHTML = '';\n\n if (null === document.querySelector('.section-menu__expand')) {\n const menuTrigger = document.createElement('button');\n\n menuTrigger.classList.add('section-menu__expand');\n menuTrigger.innerHTML = 'Sections Menu';\n document.body.insertBefore(\n menuQuery.appendChild(menuTrigger),\n document.body.childNodes[0]\n );\n\n // Add menu trigger handler\n menuTrigger.addEventListener('click', () => {\n document.body.classList.toggle('section-menu-open');\n });\n }\n\n // Create menu\n this.outputMenu(null, menuQuery);\n }\n }\n\n /**\n * Get module metadata from a module require path\n *\n * @param {string} key - Module require path\n * @return {object} containing module id, module type, key and the module contents\n */\n getMetaFromPath(key, module) {\n const sections = this._sections.sectionsByPath;\n const templateTypes = this._types.filter((type) => 'prototype' !== type);\n let id = false;\n let type = false;\n\n /* eslint-disable space-unary-ops */\n if (-1 !== key.indexOf('./prototypes')) {\n /* eslint-enable space-unary-ops */\n const prototype = Object.keys(this._prototypes)\n .filter((name) => this._prototypes[name] === key);\n\n if (prototype.length) {\n id = prototype[0];\n type = 'prototype';\n }\n } else if (key === this._sectionTemplatePath) {\n id = 'sections-template';\n type = 'sections-template';\n } else {\n let testTypes = [];\n const testSections = Object.keys(sections).filter((section) => {\n const tempTypes = templateTypes.filter(\n (currentType) => sections[section][`${currentType}Path`] === key\n );\n\n if (tempTypes.length) {\n testTypes = tempTypes;\n return true;\n }\n\n return false;\n });\n\n if (\n testSections &&\n testSections.length &&\n testTypes &&\n testTypes.length\n ) {\n id = sections[testSections[0]].referenceURI;\n type = testTypes[0];\n }\n }\n\n if (id && type) {\n const hashKey = 'data' === type ? this._templates[key] : key;\n const renderData = this.getModuleRender(type, key, module);\n const hash = InsertNodes.generateModuleHash(hashKey);\n\n if (renderData) {\n return Object.assign({ id, type, key, hash, module }, renderData);\n }\n }\n\n console.warn( // eslint-disable-line no-console\n `Module '${key}' does not exist on the page\n or is no longer in use`\n );\n return false;\n }\n\n /**\n * Check if a tag is a huron placeholder and, if so,\n * return its associated module key\n *\n * @param {object} tag - tag to check\n */\n getModuleKeyFromTag(tag) {\n const type = tag.dataset.huronType;\n const id = tag.dataset.huronId;\n const section = this._sections.sectionsByURI[id];\n\n if (id && type) {\n if (section) {\n return section[`${type}Path`];\n } else if ('prototype' === type) {\n return this._prototypes[id];\n }\n }\n\n return false;\n }\n\n /**\n * Check if an array of elements contains a Huron placeholder\n *\n * @param {array} tags - array of DOM nodes\n * @param {bool} recurse - should we recurse this function with a new array\n */\n getModuleListFromTags(elements, recurse = true) {\n const moduleList = {};\n let newList = {};\n\n if (elements && elements.length) {\n elements.forEach((element) => {\n const moduleKey = this.getModuleKeyFromTag(element);\n\n if (moduleKey) {\n if (! moduleList[moduleKey]) {\n moduleList[moduleKey] = [];\n }\n moduleList[moduleKey].push(element);\n } else if (recurse) {\n newList = this.getModuleListFromTags(\n [...element.querySelectorAll('[data-huron-id][data-huron-type]')],\n false\n );\n\n Object.keys(newList).forEach((key) => {\n moduleList[key] = moduleList[key] ?\n moduleList[key].concat(newList[key]) :\n newList[key];\n });\n }\n });\n }\n\n return moduleList;\n }\n\n /**\n * Transform every module into a predictable object\n *\n * @param {object} type - Module metadata\n * @param {mixed} module - Module contents\n * @return {object} containing render function, render data and module id\n */\n getModuleRender(type, key, module) {\n let render = false;\n let data = false;\n\n if ('template' === type && 'function' === typeof module) {\n // It's a render function for a template\n render = module;\n data = this._modules[this._templates[key]];\n } else if (\n 'sections-template' === type &&\n 'function' === typeof module\n ) {\n // It's a kss section template\n render = module;\n } else if (\n 'section' === type &&\n 'object' === typeof module\n ) {\n // It's section data\n render = this._modules[this._sectionTemplatePath];\n data = module;\n } else if (\n ('template' === type || 'description' === type || 'prototype' === type) &&\n 'string' === typeof module\n ) {\n // it's straight HTML\n render = () => module;\n } else if ('data' === type && 'object' === typeof module) {\n // It's a data file (.json)\n render = this._modules[this._templates[key]];\n data = module;\n }\n\n // Only need render, as data will be left empty for static HTML\n if (render) {\n return { render, data };\n }\n\n return false;\n }\n\n /**\n * Replace all sections. For hot reloading use when the section template has changed.\n *\n * @param {object} replaceElements - The context (e.g. document) that you will query for the template ID to replace\n * @param {string} key - Module require path\n * @param {mixed} module - Module contents\n * @param {bool} cached - Whether or not to use cached values for module replacement\n * @param {object} filter - Filter for modules. Fields explained in the filterModules() function docs\n */\n loadModule(key, module, replaceElements, cached = false, filter = false) {\n let shouldLoad = true;\n let moduleMeta = false;\n\n // Check if we should load from internal module metadata cache\n if (cached) {\n moduleMeta = this.meta[key];\n } else {\n moduleMeta = this.meta[key] = this.getMetaFromPath(key, module);\n }\n\n if (moduleMeta) {\n if (filter) {\n shouldLoad = InsertNodes.filterModules(filter, moduleMeta);\n }\n\n if (shouldLoad) {\n this.replaceTemplate(moduleMeta, replaceElements);\n }\n }\n }\n\n /*\n * Helper function for inserting styleguide sections.\n *\n * Recurses over sorted styleguide sections and inserts a
    to be used as a menu for each section\n */\n outputMenu(parent, el, sections = this._sections.sorted) {\n let templateId = null;\n let newEl = el;\n\n Object.keys(sections).forEach((section) => {\n const hasSubmenu = Object.keys(sections[section]).length;\n let menuTarget;\n let nextMenu;\n\n if (parent) {\n templateId = `${parent}-${section}`;\n } else {\n templateId = section;\n }\n\n if (newEl) {\n const title = this._sections\n .sectionsByURI[templateId] ?\n this._sections\n .sectionsByURI[templateId]\n .header :\n templateId;\n const sectionMenu = document.createElement('ul');\n const menuItem = document.createElement('li');\n const link = `${title}`;\n\n sectionMenu.classList.add('section-menu');\n menuItem.classList.add('section-menu__item');\n menuItem.innerHTML = link;\n\n // Check if this is a UL and, if not, create one\n if ('UL' !== newEl.tagName) {\n menuTarget = sectionMenu.cloneNode();\n newEl.appendChild(menuTarget);\n newEl = menuTarget;\n }\n\n // Has subsections\n if (hasSubmenu) {\n nextMenu = sectionMenu.cloneNode();\n nextMenu.classList.add('section-menu--submenu');\n menuItem.classList.add('section-menu__item--has-submenu');\n menuItem.appendChild(nextMenu);\n }\n\n newEl.appendChild(menuItem);\n\n if (hasSubmenu) {\n this.outputMenu(\n templateId,\n nextMenu,\n sections[section]\n );\n }\n }\n });\n }\n\n /**\n * Helper function for inserting styleguide sections.\n *\n * Recurses over sorted styleguide sections and inserts a
    tag with [huron-id] equal to the section template name.\n */\n outputSections(parent, el, sections = this._sections.sorted) {\n let templateId = null;\n let placeholder = null;\n\n Object.keys(sections).forEach((section) => {\n let istopLevel = false;\n let topLevelWrapper = null;\n let topLevelSection = null;\n let insertionEl = el;\n\n // Generate section ID and check if it is top-level\n if (parent) {\n templateId = `${parent}-${section}`;\n } else {\n templateId = section;\n istopLevel = true;\n }\n\n if (el) {\n // Generate huron placeholder for this section\n placeholder = document.createElement('div');\n placeholder.dataset.huronId = templateId;\n placeholder.dataset.huronType = 'section';\n\n if (istopLevel) {\n // Generate wrapper to contain top-level section and all subsections underneath it\n topLevelWrapper = document.createElement('div');\n topLevelWrapper.classList.add('section--top-level__wrapper');\n\n // Generate wrapper for top-level section\n topLevelSection = document.createElement('div');\n topLevelSection.classList.add('section', 'section--top-level');\n\n // Append wrappers to huron-sections element\n topLevelSection.appendChild(placeholder);\n topLevelWrapper.appendChild(topLevelSection);\n el.appendChild(topLevelWrapper);\n insertionEl = topLevelWrapper;\n } else {\n // If this is not top-level, append placeholder\n el.appendChild(placeholder);\n }\n }\n\n // Recursively call this function to insert other sections\n if (Object.keys(sections[section]).length && placeholder) {\n this.outputSections(\n templateId,\n insertionEl,\n sections[section]\n );\n }\n });\n }\n\n /**\n * Regenerate module meta cache\n */\n regenCache() {\n Object.keys(this._modules).forEach((moduleKey) => {\n this.meta[moduleKey] = this.getMetaFromPath(\n moduleKey, this._modules[moduleKey]\n );\n });\n }\n\n /**\n * Recursively remove old tags\n *\n * @param {string} hash - hash of module for which we need to remove old tags\n * @param {object} tag - tag to start our search with\n * (usually the tag immediately preceding the current placeholder)\n */\n removeOldTags(hash, tag) {\n if (tag && tag.dataset) {\n if (\n tag.dataset.parentHash === hash &&\n tag.dataset.selfHash !== hash\n ) {\n // This is a child of the current module,\n // so remove it and its children (if applicable)\n const childrenHash = tag.dataset.selfHash;\n let nextTag = tag.previousSibling;\n\n if (childrenHash) {\n this.removeOldTags(childrenHash, nextTag);\n // Reset nextTag if we removed a child\n nextTag = tag.previousSibling;\n }\n\n tag.parentNode.removeChild(tag);\n this.removeOldTags(hash, nextTag);\n }\n }\n }\n\n /**\n * Replace a single template marker with template content.\n *\n * @param {object} replaceElements - Array of elements to check for Huron placeholders\n * @param {object} meta - Module metadata\n */\n replaceTemplate(meta, replaceElements) {\n const type = this.validateType(meta.type);\n const tags = [];\n let replace = replaceElements;\n let hasStyleguideHelpers = false;\n\n if (! replace) {\n replace = document.querySelectorAll(\n '[data-huron-id][data-huron-type]'\n );\n }\n\n if (type) {\n replace.forEach((tag) => {\n if (\n tag.dataset &&\n tag.dataset.huronId === meta.id &&\n tag.dataset.huronType === type\n ) {\n tags.push(tag);\n }\n });\n\n if (tags && tags.length && meta.render) {\n tags.forEach((currentTag) => {\n const modifiedPlaceholder = currentTag;\n const modifier = modifiedPlaceholder.dataset.huronModifier;\n const parent = modifiedPlaceholder.parentNode;\n const rendered = InsertNodes.applyModifier(modifier, meta);\n const renderedTemplate = InsertNodes.convertToElement(rendered)\n .querySelector('template');\n let renderedContents = null;\n\n // Remove existing module tags\n this.removeOldTags(meta.hash, modifiedPlaceholder.previousSibling);\n\n // Get the contents of the rendered template\n renderedContents = [\n ...renderedTemplate.content.children,\n ];\n\n // Insert each tag of the template contents before placeholder\n renderedContents.forEach((element) => {\n const newEl = element;\n\n if (1 === newEl.nodeType) {\n newEl.dataset.parentHash = meta.hash;\n hasStyleguideHelpers = ! hasStyleguideHelpers ?\n InsertNodes.isSectionHelper(newEl, meta) :\n hasStyleguideHelpers;\n\n parent.insertBefore(newEl, modifiedPlaceholder);\n }\n });\n\n // Add module hash to this placeholder\n modifiedPlaceholder.dataset.selfHash = meta.hash;\n\n // Hide the placeholder\n modifiedPlaceholder.style.display = 'none';\n\n // Recursively load modules, excluding the current one\n this.cycleModules(renderedContents, {\n property: 'key',\n values: [meta.key, this._sectionTemplatePath],\n include: false,\n });\n\n if (hasStyleguideHelpers) {\n this.cycleStyleguide();\n }\n });\n }\n } else {\n console.warn( // eslint-disable-line no-console\n `Could not render module\n section: ${meta.id}\n type: ${meta.type}`\n );\n }\n }\n\n /**\n * Verify specified element is using an acceptable huron type\n *\n * @param {string} type - type of partial (template, data, description, section or prototype )\n * @return {string} huron type or 'template' if invalid\n */\n validateType(type) {\n if ('data' === type) {\n return 'template';\n }\n\n if (! this._types.includes(type)) {\n return false;\n }\n\n return type;\n }\n\n /*\n * Set new modules object\n */\n set modules(modules) {\n this._modules = modules;\n this._moduleIds = Object.keys(modules);\n }\n\n /*\n * Set store\n */\n set store(store) {\n this._store = store;\n this._config = store.config;\n this._sections = store.sections;\n this._templates = store.templates;\n this._prototypes = store.prototypes;\n this._types = store.types;\n this._sectionTemplatePath = store.sectionTemplatePath;\n }\n}\n/* eslint-enable no-underscore-dangle */\n\n// Create a new instance of the InsertNodes class\n/*eslint-disable*/\n// Create object for modifiying the templates on the page and\n// initial first templates.\nconst insert = new InsertNodes(modules, store);\n/*eslint-enable*/\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/web/huron.js"],"names":["md5","require","module","hot","accept","InsertNodes","modules","store","_modules","_moduleIds","Object","keys","_config","_sections","_templates","_prototypes","_types","meta","cycleModules","cycleStyleguide","context","filter","moduleList","elementList","regenCache","document","querySelectorAll","getModuleListFromTags","forEach","key","replaceElements","loadModule","property","values","include","sectionsQuery","querySelector","menuQuery","innerHTML","outputSections","cycleSections","menuTrigger","createElement","classList","add","body","insertBefore","appendChild","childNodes","addEventListener","toggle","outputMenu","sections","sectionsByPath","templateTypes","type","id","indexOf","prototype","name","length","_sectionTemplatePath","testTypes","testSections","section","tempTypes","currentType","referenceURI","hashKey","renderData","getModuleRender","hash","generateModuleHash","assign","console","warn","tag","dataset","huronType","huronId","sectionsByURI","elements","recurse","newList","element","moduleKey","getModuleKeyFromTag","push","concat","render","data","cached","shouldLoad","moduleMeta","getMetaFromPath","filterModules","replaceTemplate","parent","el","sorted","templateId","newEl","hasSubmenu","menuTarget","nextMenu","title","header","sectionMenu","menuItem","link","tagName","cloneNode","placeholder","istopLevel","topLevelWrapper","topLevelSection","insertionEl","parentHash","selfHash","childrenHash","nextTag","previousSibling","removeOldTags","parentNode","removeChild","validateType","tags","replace","hasStyleguideHelpers","currentTag","modifiedPlaceholder","modifier","huronModifier","rendered","applyModifier","renderedTemplate","convertToElement","renderedContents","content","children","nodeType","isSectionHelper","style","display","includes","_store","config","templates","prototypes","types","sectionTemplatePath","firstElementChild","match","hasOwnProperty","call","value","Boolean","log","hasAttribute","insert"],"mappings":";;;;;;;;;;AAAA,IAAMA,MAAMC,QAAQ,QAAR,CAAZ;;AAEA;AACA;AACA,IAAIC,OAAOC,GAAX,EAAgB;AACdD,SAAOC,GAAP,CAAWC,MAAX;AACD;;AAED;;;;;;IAKMC,W;AAEJ,uBAAYC,OAAZ,EAAqBC,KAArB,EAA4B;AAAA;;AAC1B;AACA,SAAKC,QAAL,GAAgBF,OAAhB;AACA;AACA,SAAKG,UAAL,GAAkBC,OAAOC,IAAP,CAAYL,OAAZ,CAAlB;AACA;AACA,SAAKM,OAAL,GAAe,IAAf;AACA;AACA,SAAKC,SAAL,GAAiB,IAAjB;AACA;AACA,SAAKC,UAAL,GAAkB,IAAlB;AACA;AACA,SAAKC,WAAL,GAAmB,IAAnB;AACA;AACA,SAAKC,MAAL,GAAc,IAAd;;AAEA;AACA,SAAKC,IAAL,GAAY,EAAZ;;AAEA;AACA,SAAKV,KAAL,GAAaA,KAAb;;AAEA;AACA,SAAKW,YAAL;AACA,SAAKC,eAAL;AACD;;AAED;;;;;;;;;;;;;AAkGA;;;;;;mCAM8C;AAAA;;AAAA,UAAjCC,OAAiC,uEAAvB,KAAuB;AAAA,UAAhBC,MAAgB,uEAAP,KAAO;;AAC5C,UAAIC,aAAa,EAAjB;AACA,UAAIC,cAAcH,OAAlB;;AAEA;AACA,UAAI,CAAEG,WAAN,EAAmB;AACjB,aAAKC,UAAL;;AAEA;AACAD,sBAAcE,SAASC,gBAAT,CACZ,k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QAAQJ,MAAM5F,MAAd,MAA0BvC,OAAOa,OAAxC;AACD;;AAEDwC,cAAQmF,GAAR,uDACWxI,MADX;;AAKA,aAAOmI,KAAP;AACD;;AAED;;;;;;;;;uCAM0B3H,G,EAAK;AAC7B,aAAO7B,IAAI6B,GAAJ,CAAP;AACD;;AAED;;;;;;;;;;oCAOuB+C,G,EAAK3D,I,EAAM;AAChC,UAAI,gBAAgBA,KAAKsC,IAAzB,EAA+B;AAC7B,eAAOqB,IAAIkF,YAAJ,CAAiB,gBAAjB,KACLlF,IAAIkF,YAAJ,CAAiB,YAAjB,CADF;AAED;;AAED,aAAO,KAAP;AACD;;;;;AAskBH;;AAEA;AACA;AACA;AACA;;;AACA,IAAMC,SAAS,IAAI1J,WAAJ,CAAgBC,OAAhB,EAAyBC,KAAzB,CAAf;AACA","file":"huron.js","sourcesContent":["const md5 = require('js-md5');\n\n/* eslint-disable no-underscore-dangle */\n// Accept the huron.js module for Huron development\nif (module.hot) {\n module.hot.accept();\n}\n\n/** Class for inserting HTML snippets at particular insertion points.\n * Uses require() to grab html partials, then inserts that html\n * into an element with attribute [huron-id] corresponding to the reference URI of the target KSS section,\n * and [huron-type] corresponding with the required KSS field\n */\nclass InsertNodes {\n\n constructor(modules, store) {\n /** webpack module list in which keys are relative require paths and values are the module contents */\n this._modules = modules;\n /** array of module keys */\n this._moduleIds = Object.keys(modules);\n /** reference to the huron config */\n this._config = null;\n /** KSS sections organized in various formats including by reference URI, by module key, and modules sorted by parent/child */\n this._sections = null;\n /** Key/value pairs of partner data and template files */\n this._templates = null;\n /** array of prototypes */\n this._prototypes = null;\n /** array of valid huron placeholder types */\n this._types = null;\n\n /** Cache for module metadata */\n this.meta = {};\n\n /** Reference to entire memory store */\n this.store = store;\n\n // Inits\n this.cycleModules();\n this.cycleStyleguide();\n }\n\n /**\n * Apply a modifier to a render function\n *\n * @param {string} modifier - target modifier\n * @param {object} meta - module metadata\n * @return {string} rendered - the modified HTML module\n */\n static applyModifier(modifier, meta) {\n let rendered = false;\n let data = meta.data;\n\n if (data) {\n // If we have a modifier, use it, otherwise use the entire data set\n if (modifier && meta.data[modifier]) {\n data = Object.assign({}, meta.data[modifier], { modifier });\n }\n\n rendered = meta.render(data);\n } else {\n rendered = meta.render();\n }\n\n return rendered;\n }\n\n /**\n * Get markup from any type of module (html, json or template)\n *\n * @param {string} content - String corresponding to markup\n * @return {object} el.firstElementChild - HTML module\n */\n static convertToElement(content) {\n const el = document.createElement('div');\n\n el.innerHTML = content;\n return el.firstElementChild;\n }\n\n /**\n * Filter module object by module key or module type\n *\n * @param {object} filter - Filter for modules. Options:\n * @param {string} filter.property - Which property to filter ('key' or 'type')\n * @param {array} filter.values - Values for property\n * @param {bool} filter.include - Whether the values should be included or excluded (true = include, false = exclude)\n * @param {object} moduleMeta - Filter for modules. Fields explained in the filterModules() function docs\n * @return {bool} match - determine if modules need to be filtered\n */\n static filterModules(filter, moduleMeta) {\n let match = true;\n\n // Check if we should filter out any modules\n if (\n 'object' === typeof filter &&\n {}.hasOwnProperty.call(filter, 'property') &&\n {}.hasOwnProperty.call(filter, 'values') &&\n {}.hasOwnProperty.call(filter, 'include')\n ) {\n match = filter.values.filter(\n (value) => moduleMeta[filter.property] === value\n );\n return Boolean(match.length) === filter.include;\n }\n\n console.log(` // eslint-disable-line no-console\n filter ${filter} is not in a valid format.\n module filters must include 'property', 'values', and 'include' properties\n `);\n\n return match;\n }\n\n /**\n * Generate a hash string from a module key\n *\n * @param {string} key - module key (require path) to convert into a hash\n * @return {string} key - generated MD5 Hash\n */\n static generateModuleHash(key) {\n return md5(key);\n }\n\n /**\n * Check if this tag is a styleguide helper\n *\n * @param {object} tag - tag to check\n * @param {object} meta - module metadata\n * @return {bool}\n */\n static isSectionHelper(tag, meta) {\n if ('prototype' === meta.type) {\n return tag.hasAttribute('huron-sections') ||\n tag.hasAttribute('huron-menu');\n }\n\n return false;\n }\n\n /**\n * Replace all template markers with the actual template markup.\n *\n * @param {string} context - The hash context for the module\n * @param {object} filter - Filter for modules. Fields explained in the filterModules() function docs\n */\n cycleModules(context = false, filter = false) {\n let moduleList = {};\n let elementList = context;\n\n // We're replacing top-level elements\n if (! elementList) {\n this.regenCache();\n\n // Find all top-level huron placeholders\n elementList = document.querySelectorAll(\n '[data-huron-id][data-huron-type]'\n );\n }\n\n moduleList = this.getModuleListFromTags(elementList);\n\n // Loop through modules array\n Object.keys(moduleList).forEach((key) => {\n const module = this._modules[key];\n const replaceElements = moduleList[key];\n\n this.loadModule(key, module, replaceElements, true, filter);\n });\n }\n\n /**\n * Helper for reloading sections only\n */\n cycleSections() {\n this.cycleModules(false, {\n property: 'type',\n values: ['section'],\n include: true,\n });\n }\n\n /**\n * Reload styleguide sections and menu helpers\n */\n cycleStyleguide() {\n const sectionsQuery = document.querySelector('[huron-sections]');\n const menuQuery = document.querySelector('[huron-menu]');\n\n // Sections\n if (sectionsQuery) {\n sectionsQuery.innerHTML = '';\n this.outputSections(null, sectionsQuery);\n this.cycleSections();\n }\n\n // Menu\n if (menuQuery) {\n menuQuery.innerHTML = '';\n\n if (null === document.querySelector('.section-menu__expand')) {\n const menuTrigger = document.createElement('button');\n\n menuTrigger.classList.add('section-menu__expand');\n menuTrigger.innerHTML = 'Sections Menu';\n document.body.insertBefore(\n menuQuery.appendChild(menuTrigger),\n document.body.childNodes[0]\n );\n\n // Add menu trigger handler\n menuTrigger.addEventListener('click', () => {\n document.body.classList.toggle('section-menu-open');\n });\n }\n\n // Create menu\n this.outputMenu(null, menuQuery);\n }\n }\n\n /**\n * Get module metadata from a module require path\n *\n * @param {string} key - Module require path\n * @return {object} containing module id, module type, key and the module contents\n */\n getMetaFromPath(key, module) {\n const sections = this._sections.sectionsByPath;\n const templateTypes = this._types.filter((type) => 'prototype' !== type);\n let id = false;\n let type = false;\n\n /* eslint-disable space-unary-ops */\n if (-1 !== key.indexOf('./prototypes')) {\n /* eslint-enable space-unary-ops */\n const prototype = Object.keys(this._prototypes)\n .filter((name) => this._prototypes[name] === key);\n\n if (prototype.length) {\n id = prototype[0];\n type = 'prototype';\n }\n } else if (key === this._sectionTemplatePath) {\n id = 'sections-template';\n type = 'sections-template';\n } else {\n let testTypes = [];\n const testSections = Object.keys(sections).filter((section) => {\n const tempTypes = templateTypes.filter(\n (currentType) => sections[section][`${currentType}Path`] === key\n );\n\n if (tempTypes.length) {\n testTypes = tempTypes;\n return true;\n }\n\n return false;\n });\n\n if (\n testSections &&\n testSections.length &&\n testTypes &&\n testTypes.length\n ) {\n id = sections[testSections[0]].referenceURI;\n type = testTypes[0];\n }\n }\n\n if (id && type) {\n const hashKey = 'data' === type ? this._templates[key] : key;\n const renderData = this.getModuleRender(type, key, module);\n const hash = InsertNodes.generateModuleHash(hashKey);\n\n if (renderData) {\n return Object.assign({ id, type, key, hash, module }, renderData);\n }\n }\n\n console.warn( // eslint-disable-line no-console\n `Module '${key}' does not exist on the page\n or is no longer in use`\n );\n return false;\n }\n\n /**\n * Check if a tag is a huron placeholder and, if so,\n * return its associated module key\n *\n * @param {object} tag - tag to check\n * @return {bool} associated module key\n */\n getModuleKeyFromTag(tag) {\n const type = tag.dataset.huronType;\n const id = tag.dataset.huronId;\n const section = this._sections.sectionsByURI[id];\n\n if (id && type) {\n if (section) {\n return section[`${type}Path`];\n } else if ('prototype' === type) {\n return this._prototypes[id];\n }\n }\n\n return false;\n }\n\n /**\n * Check if an array of elements contains a Huron placeholder\n *\n * @param {array} tags - array of DOM nodes\n * @param {bool} recurse - should we recurse this function with a new array\n * @return {object} moduleList - Huron placeholder DOM node\n */\n getModuleListFromTags(elements, recurse = true) {\n const moduleList = {};\n let newList = {};\n\n if (elements && elements.length) {\n elements.forEach((element) => {\n const moduleKey = this.getModuleKeyFromTag(element);\n\n if (moduleKey) {\n if (! moduleList[moduleKey]) {\n moduleList[moduleKey] = [];\n }\n moduleList[moduleKey].push(element);\n } else if (recurse) {\n newList = this.getModuleListFromTags(\n [...element.querySelectorAll('[data-huron-id][data-huron-type]')],\n false\n );\n\n Object.keys(newList).forEach((key) => {\n moduleList[key] = moduleList[key] ?\n moduleList[key].concat(newList[key]) :\n newList[key];\n });\n }\n });\n }\n\n return moduleList;\n }\n\n /**\n * Transform every module into a predictable object\n *\n * @param {object} type - Module metadata\n * @param {mixed} module - Module contents\n * @return {object} containing render function, render data and module id\n */\n getModuleRender(type, key, module) {\n let render = false;\n let data = false;\n\n if ('template' === type && 'function' === typeof module) {\n // It's a render function for a template\n render = module;\n data = this._modules[this._templates[key]];\n } else if (\n 'sections-template' === type &&\n 'function' === typeof module\n ) {\n // It's a kss section template\n render = module;\n } else if (\n 'section' === type &&\n 'object' === typeof module\n ) {\n // It's section data\n render = this._modules[this._sectionTemplatePath];\n data = module;\n } else if (\n ('template' === type || 'description' === type || 'prototype' === type) &&\n 'string' === typeof module\n ) {\n // it's straight HTML\n render = () => module;\n } else if ('data' === type && 'object' === typeof module) {\n // It's a data file (.json)\n render = this._modules[this._templates[key]];\n data = module;\n }\n\n // Only need render, as data will be left empty for static HTML\n if (render) {\n return { render, data };\n }\n\n return false;\n }\n\n /**\n * Replace all sections. For hot reloading use when the section template has changed.\n *\n * @param {object} replaceElements - The context (e.g. document) that you will query for the template ID to replace\n * @param {string} key - Module require path\n * @param {mixed} module - Module contents\n * @param {bool} cached - Whether or not to use cached values for module replacement\n * @param {object} filter - Filter for modules. Fields explained in the filterModules() function docs\n */\n loadModule(key, module, replaceElements, cached = false, filter = false) {\n let shouldLoad = true;\n let moduleMeta = false;\n\n // Check if we should load from internal module metadata cache\n if (cached) {\n moduleMeta = this.meta[key];\n } else {\n moduleMeta = this.meta[key] = this.getMetaFromPath(key, module);\n }\n\n if (moduleMeta) {\n if (filter) {\n shouldLoad = InsertNodes.filterModules(filter, moduleMeta);\n }\n\n if (shouldLoad) {\n this.replaceTemplate(moduleMeta, replaceElements);\n }\n }\n }\n\n /*\n * Helper function for inserting styleguide sections.\n *\n * Recurses over sorted styleguide sections and inserts a
      to be used as a menu for each section\n */\n outputMenu(parent, el, sections = this._sections.sorted) {\n let templateId = null;\n let newEl = el;\n\n Object.keys(sections).forEach((section) => {\n const hasSubmenu = Object.keys(sections[section]).length;\n let menuTarget;\n let nextMenu;\n\n if (parent) {\n templateId = `${parent}-${section}`;\n } else {\n templateId = section;\n }\n\n if (newEl) {\n const title = this._sections\n .sectionsByURI[templateId] ?\n this._sections\n .sectionsByURI[templateId]\n .header :\n templateId;\n const sectionMenu = document.createElement('ul');\n const menuItem = document.createElement('li');\n const link = `${title}`;\n\n sectionMenu.classList.add('section-menu');\n menuItem.classList.add('section-menu__item');\n menuItem.innerHTML = link;\n\n // Check if this is a UL and, if not, create one\n if ('UL' !== newEl.tagName) {\n menuTarget = sectionMenu.cloneNode();\n newEl.appendChild(menuTarget);\n newEl = menuTarget;\n }\n\n // Has subsections\n if (hasSubmenu) {\n nextMenu = sectionMenu.cloneNode();\n nextMenu.classList.add('section-menu--submenu');\n menuItem.classList.add('section-menu__item--has-submenu');\n menuItem.appendChild(nextMenu);\n }\n\n newEl.appendChild(menuItem);\n\n if (hasSubmenu) {\n this.outputMenu(\n templateId,\n nextMenu,\n sections[section]\n );\n }\n }\n });\n }\n\n /**\n * Helper function for inserting styleguide sections.\n *\n * Recurses over sorted styleguide sections and inserts a
      tag with [huron-id] equal to the section template name.\n */\n outputSections(parent, el, sections = this._sections.sorted) {\n let templateId = null;\n let placeholder = null;\n\n Object.keys(sections).forEach((section) => {\n let istopLevel = false;\n let topLevelWrapper = null;\n let topLevelSection = null;\n let insertionEl = el;\n\n // Generate section ID and check if it is top-level\n if (parent) {\n templateId = `${parent}-${section}`;\n } else {\n templateId = section;\n istopLevel = true;\n }\n\n if (el) {\n // Generate huron placeholder for this section\n placeholder = document.createElement('div');\n placeholder.dataset.huronId = templateId;\n placeholder.dataset.huronType = 'section';\n\n if (istopLevel) {\n // Generate wrapper to contain top-level section and all subsections underneath it\n topLevelWrapper = document.createElement('div');\n topLevelWrapper.classList.add('section--top-level__wrapper');\n\n // Generate wrapper for top-level section\n topLevelSection = document.createElement('div');\n topLevelSection.classList.add('section', 'section--top-level');\n\n // Append wrappers to huron-sections element\n topLevelSection.appendChild(placeholder);\n topLevelWrapper.appendChild(topLevelSection);\n el.appendChild(topLevelWrapper);\n insertionEl = topLevelWrapper;\n } else {\n // If this is not top-level, append placeholder\n el.appendChild(placeholder);\n }\n }\n\n // Recursively call this function to insert other sections\n if (Object.keys(sections[section]).length && placeholder) {\n this.outputSections(\n templateId,\n insertionEl,\n sections[section]\n );\n }\n });\n }\n\n /**\n * Regenerate module meta cache\n */\n regenCache() {\n Object.keys(this._modules).forEach((moduleKey) => {\n this.meta[moduleKey] = this.getMetaFromPath(\n moduleKey, this._modules[moduleKey]\n );\n });\n }\n\n /**\n * Recursively remove old tags\n *\n * @param {string} hash - hash of module for which we need to remove old tags\n * @param {object} tag - tag to start our search with\n * (usually the tag immediately preceding the current placeholder)\n */\n removeOldTags(hash, tag) {\n if (tag && tag.dataset) {\n if (\n tag.dataset.parentHash === hash &&\n tag.dataset.selfHash !== hash\n ) {\n // This is a child of the current module,\n // so remove it and its children (if applicable)\n const childrenHash = tag.dataset.selfHash;\n let nextTag = tag.previousSibling;\n\n if (childrenHash) {\n this.removeOldTags(childrenHash, nextTag);\n // Reset nextTag if we removed a child\n nextTag = tag.previousSibling;\n }\n\n tag.parentNode.removeChild(tag);\n this.removeOldTags(hash, nextTag);\n }\n }\n }\n\n /**\n * Replace a single template marker with template content.\n *\n * @param {object} replaceElements - Array of elements to check for Huron placeholders\n * @param {object} meta - Module metadata\n */\n replaceTemplate(meta, replaceElements) {\n const type = this.validateType(meta.type);\n const tags = [];\n let replace = replaceElements;\n let hasStyleguideHelpers = false;\n\n if (! replace) {\n replace = document.querySelectorAll(\n '[data-huron-id][data-huron-type]'\n );\n }\n\n if (type) {\n replace.forEach((tag) => {\n if (\n tag.dataset &&\n tag.dataset.huronId === meta.id &&\n tag.dataset.huronType === type\n ) {\n tags.push(tag);\n }\n });\n\n if (tags && tags.length && meta.render) {\n tags.forEach((currentTag) => {\n const modifiedPlaceholder = currentTag;\n const modifier = modifiedPlaceholder.dataset.huronModifier;\n const parent = modifiedPlaceholder.parentNode;\n const rendered = InsertNodes.applyModifier(modifier, meta);\n const renderedTemplate = InsertNodes.convertToElement(rendered)\n .querySelector('template');\n let renderedContents = null;\n\n // Remove existing module tags\n this.removeOldTags(meta.hash, modifiedPlaceholder.previousSibling);\n\n // Get the contents of the rendered template\n renderedContents = [\n ...renderedTemplate.content.children,\n ];\n\n // Insert each tag of the template contents before placeholder\n renderedContents.forEach((element) => {\n const newEl = element;\n\n if (1 === newEl.nodeType) {\n newEl.dataset.parentHash = meta.hash;\n hasStyleguideHelpers = ! hasStyleguideHelpers ?\n InsertNodes.isSectionHelper(newEl, meta) :\n hasStyleguideHelpers;\n\n parent.insertBefore(newEl, modifiedPlaceholder);\n }\n });\n\n // Add module hash to this placeholder\n modifiedPlaceholder.dataset.selfHash = meta.hash;\n\n // Hide the placeholder\n modifiedPlaceholder.style.display = 'none';\n\n // Recursively load modules, excluding the current one\n this.cycleModules(renderedContents, {\n property: 'key',\n values: [meta.key, this._sectionTemplatePath],\n include: false,\n });\n\n if (hasStyleguideHelpers) {\n this.cycleStyleguide();\n }\n });\n }\n } else {\n console.warn( // eslint-disable-line no-console\n `Could not render module\n section: ${meta.id}\n type: ${meta.type}`\n );\n }\n }\n\n /**\n * Verify specified element is using an acceptable huron type\n *\n * @param {string} type - type of partial (template, data, description, section or prototype )\n * @return {string} type - huron type or 'template' if invalid\n */\n validateType(type) {\n if ('data' === type) {\n return 'template';\n }\n\n if (! this._types.includes(type)) {\n return false;\n }\n\n return type;\n }\n\n /*\n * Set new modules object\n */\n set modules(modules) {\n this._modules = modules;\n this._moduleIds = Object.keys(modules);\n }\n\n /*\n * Set store\n */\n set store(store) {\n this._store = store;\n this._config = store.config;\n this._sections = store.sections;\n this._templates = store.templates;\n this._prototypes = store.prototypes;\n this._types = store.types;\n this._sectionTemplatePath = store.sectionTemplatePath;\n }\n}\n/* eslint-enable no-underscore-dangle */\n\n// Create a new instance of the InsertNodes class\n/*eslint-disable*/\n// Create object for modifiying the templates on the page and\n// initial first templates.\nconst insert = new InsertNodes(modules, store);\n/*eslint-enable*/\n"]} \ No newline at end of file