From 13e0d3f27ec000e200d60a2053b5dbcb51dba33c Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Tue, 10 Aug 2021 18:31:38 -0400 Subject: [PATCH 1/6] use partials in validator Use the new partials param in templatedatavalidator instead of fs.existsSync. This is slightly more robust, for weird cases when somebody registers a card or universalsectiontemplate in an atypical folder. J=SLAP-1489 TEST=manual test that the validator will catch incorrect card and unviersalsectiontemplates --- hooks/templatedatavalidator.js | 47 ++-- static/package-lock.json | 396 ++++++++++++++++++++++++--------- static/package.json | 2 +- 3 files changed, 313 insertions(+), 132 deletions(-) diff --git a/hooks/templatedatavalidator.js b/hooks/templatedatavalidator.js index c77e24c9f..4b75f6c15 100644 --- a/hooks/templatedatavalidator.js +++ b/hooks/templatedatavalidator.js @@ -1,18 +1,21 @@ -var fs = require('fs'); -var path = require('path'); +const path = require('path'); const { parseJamboConfig } = require('../commands/helpers/utils/jamboconfigutils'); const { error } = require('../commands/helpers/utils/logger'); + /** * Validates page template's data configuration * * @param {Object} pageData data that gets passed into a page template + * @param {Object} partials + * mapping of partial name to partial. Handlebars + * converts partials from strings to Functions when they are used. * @returns {boolean} false if validator should throw an error */ -module.exports = function (pageData) { +module.exports = function (pageData, partials) { const jamboConfig = parseJamboConfig(); const validatorResults = [ isGlobalConfigValid(pageData.global_config), - isPageVerticalConfigValid(pageData, jamboConfig) + isPageVerticalConfigValid(pageData, jamboConfig, partials) ]; const isValid = validatorResults.every(result => result); return isValid; @@ -37,20 +40,21 @@ function isGlobalConfigValid(globalConfig) { * * @param {Object} pageData * @param {Object} jamboConfig + * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isPageVerticalConfigValid(pageData, jamboConfig) { +function isPageVerticalConfigValid(pageData, jamboConfig, partials) { const themeDirectory = path.join(jamboConfig.dirs.themes, jamboConfig.defaultTheme); return Object.keys(pageData.verticalsToConfig) .map(key => { if (key === 'Universal') { - return isAllVerticalConfigsValid(pageData.verticalConfigs, jamboConfig); + return isAllVerticalConfigsValid(pageData.verticalConfigs, jamboConfig, partials); } const universalSectionTemplate = pageData.verticalsToConfig[key].universalSectionTemplate; const cardType = pageData.verticalsToConfig[key].cardType; const validatorResults = [ - isUniversalSectionTemplateValid(key, themeDirectory, universalSectionTemplate), - isCardTypeValid(key, themeDirectory, cardType) + isUniversalSectionTemplateValid(key, themeDirectory, universalSectionTemplate, partials), + isCardTypeValid(key, themeDirectory, cardType, partials) ]; return validatorResults.every(result => result); }) @@ -63,15 +67,14 @@ function isPageVerticalConfigValid(pageData, jamboConfig) { * @param {string} verticalName * @param {string} themeDir * @param {string} template + * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isUniversalSectionTemplateValid(verticalName, themeDir, template) { - if (template) { +function isUniversalSectionTemplateValid(verticalName, themeDir, template, partials) { + if (template && !partials[`universalsectiontemplates/${template}`]) { const universalSectionPath = path.join(themeDir, 'universalsectiontemplates/', template + '.hbs'); - if (!fs.existsSync(universalSectionPath)) { - error(`Invalid universalSectionTemplate: can't find "${template}" at the expected path "${universalSectionPath}" for vertical "${verticalName}".`); - return false; - } + error(`Invalid universalSectionTemplate: can't find "${template}" at the expected path "${universalSectionPath}" for vertical "${verticalName}".`); + return false; } return true; } @@ -82,16 +85,15 @@ function isUniversalSectionTemplateValid(verticalName, themeDir, template) { * @param {string} verticalName * @param {string} themeDir * @param {string} cardType + * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isCardTypeValid(verticalName, themeDir, cardType) { - if (cardType) { +function isCardTypeValid(verticalName, themeDir, cardType, partials) { + if (cardType && !partials[`cards/${cardType}/component`]) { const cardTypePath = path.join(themeDir, 'cards/', cardType); const customCardTypePath = path.join('cards/', cardType); - if (!fs.existsSync(cardTypePath) && !fs.existsSync(customCardTypePath)) { - error(`Invalid cardType: can't find "${cardType}" at at the expected paths "${cardTypePath}" or "${customCardTypePath}" for vertical "${verticalName}".`); - return false; - } + error(`Invalid cardType: can't find "${cardType}" at at the expected paths "${cardTypePath}" or "${customCardTypePath}" for vertical "${verticalName}".`); + return false; } return true; } @@ -101,15 +103,16 @@ function isCardTypeValid(verticalName, themeDir, cardType) { * * @param {Object} verticalConfigs * @param {Object} jamboConfig + * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isAllVerticalConfigsValid(verticalConfigs, jamboConfig) { +function isAllVerticalConfigsValid(verticalConfigs, jamboConfig, partials) { if (!verticalConfigs) { return true; } return Object.keys(verticalConfigs) .map(key => { - return isPageVerticalConfigValid(verticalConfigs[key], jamboConfig); + return isPageVerticalConfigValid(verticalConfigs[key], jamboConfig, partials); }) .every(result => result); } \ No newline at end of file diff --git a/static/package-lock.json b/static/package-lock.json index 2a19b8493..2730bc273 100644 --- a/static/package-lock.json +++ b/static/package-lock.json @@ -1028,28 +1028,28 @@ "dev": true }, "@nodelib/fs.scandir": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz", - "integrity": "sha512-33g3pMJk3bg5nXbL/+CY6I2eJDzZAni49PfJnL5fghPTggPvBd/pFNSgJsdAgWptuFu7qq/ERvOYFlhvsLTCKA==", + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", "dev": true, "requires": { - "@nodelib/fs.stat": "2.0.4", + "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" } }, "@nodelib/fs.stat": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.4.tgz", - "integrity": "sha512-IYlHJA0clt2+Vg7bccq+TzRdJvv19c2INqBSsoOLp1je7xjtr7J26+WXR72MCdvU9q1qTzIWDfhMf+DRvQJK4Q==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", "dev": true }, "@nodelib/fs.walk": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.6.tgz", - "integrity": "sha512-8Broas6vTtW4GIXTAHDoE32hnN2M5ykgCpWGbuXHQ15vEMqr23pB76e/GZcYsZCHALv50ktd24qhEyKr6wBtow==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", "dev": true, "requires": { - "@nodelib/fs.scandir": "2.1.4", + "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" } }, @@ -1098,9 +1098,9 @@ "dev": true }, "@types/glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==", + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-w+LsMxKyYQm347Otw+IfBXOv9UWVjpHpCDdbBMt8Kz/xbvCYNjP+0qPh91Km3iKfSRLBB0P7fAMf0KHrPu+MyA==", "dev": true, "requires": { "@types/minimatch": "*", @@ -1120,9 +1120,9 @@ "dev": true }, "@types/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-1z8k4wzFnNjVK/tlxvrWuK5WMt6mydWWP7+zvH5eFep4oj+UkrfiJTRtjCeBXNpwaA/FYqqtb4/QS4ianFpIRA==", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", + "integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==", "dev": true }, "@types/node": { @@ -1520,6 +1520,48 @@ "picomatch": "^2.0.4" } }, + "aproba": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "dev": true + }, + "are-we-there-yet": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", + "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", + "dev": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1866,19 +1908,21 @@ "wrap-ansi": "^7.0.0" }, "dependencies": { - "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, - "strip-ansi": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", - "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "string-width": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", + "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", "dev": true, "requires": { - "ansi-regex": "^5.0.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" } } } @@ -1894,6 +1938,12 @@ "shallow-clone": "^3.0.0" } }, + "code-point-at": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", + "dev": true + }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -1979,6 +2029,12 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, + "console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", + "dev": true + }, "content-type": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", @@ -2321,6 +2377,12 @@ "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", "dev": true }, + "delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", + "dev": true + }, "detect-file": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/detect-file/-/detect-file-1.0.0.tgz", @@ -2430,9 +2492,9 @@ }, "dependencies": { "iconv-lite": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz", - "integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==", + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3.0.0" @@ -2739,17 +2801,16 @@ "dev": true }, "fast-glob": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.5.tgz", - "integrity": "sha512-2DtFcgT68wiTTiwZ2hNdJfcHNke9XOfnwmBRWXhmeKM8rF0TGwmC/Qto3S7RoZKp5cilZbxzO5iTNTQsJ+EeDg==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", + "integrity": "sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==", "dev": true, "requires": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.0", + "glob-parent": "^5.1.2", "merge2": "^1.3.0", - "micromatch": "^4.0.2", - "picomatch": "^2.2.1" + "micromatch": "^4.0.4" } }, "fast-json-stable-stringify": { @@ -2765,9 +2826,9 @@ "dev": true }, "fastq": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.11.0.tgz", - "integrity": "sha512-7Eczs8gIPDrVzT+EksYBcupqMyxSHXXrHOLRRxU2/DicV8789MRBRR8+Hc2uWzUupOs4YS4JzBmBxjjCVBxD/g==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.11.1.tgz", + "integrity": "sha512-HOnr8Mc60eNYl1gzwp6r5RoUyAn5/glBolUzP/Ez6IFVPMPirxn/9phgL6zhOtaTy7ISwPvQ+wT+hfcRZh/bzw==", "dev": true, "requires": { "reusify": "^1.0.4" @@ -2931,6 +2992,39 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "gauge": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", + "dev": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + } + } + }, "gaze": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/gaze/-/gaze-1.1.3.tgz", @@ -3012,15 +3106,15 @@ } }, "glob": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.0.6.tgz", - "integrity": "sha1-IRuvr0nlJbjNkyYNFKsTYVKz9Xo=", + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", + "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.2", + "minimatch": "^3.0.4", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } @@ -3071,9 +3165,9 @@ "dev": true }, "globby": { - "version": "11.0.3", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.3.tgz", - "integrity": "sha512-ffdmosjA807y7+lA1NM0jELARVmYul/715xiILEjo3hBLPTcirgQNnXECn5g3mtR8TOLCVbkfua1Hpen25/Xcg==", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.4.tgz", + "integrity": "sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==", "dev": true, "requires": { "array-union": "^2.1.0", @@ -3105,12 +3199,6 @@ "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", "dev": true }, - "path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true - }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -3437,6 +3525,12 @@ "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", "dev": true }, + "has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", + "dev": true + }, "he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", @@ -3546,9 +3640,9 @@ }, "dependencies": { "@babel/runtime": { - "version": "7.14.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.0.tgz", - "integrity": "sha512-JELkvo/DlpNdJ7dlyw/eY7E0suy5i5GQH+Vlxaq1nsNJ+H7f4Vtv3jMeCEgRhZZQFXTjldYfQgv2qmM6M1v5wA==", + "version": "7.15.3", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.15.3.tgz", + "integrity": "sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA==", "dev": true, "requires": { "regenerator-runtime": "^0.13.4" @@ -3580,9 +3674,9 @@ } }, "chalk": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", - "integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "dev": true, "requires": { "ansi-styles": "^4.1.0", @@ -3826,10 +3920,13 @@ "dev": true }, "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "dev": true, + "requires": { + "number-is-nan": "^1.0.0" + } }, "is-glob": { "version": "4.0.1", @@ -3907,6 +4004,12 @@ "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", "dev": true }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -3925,9 +4028,8 @@ "dev": true }, "jambo": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/jambo/-/jambo-1.11.0.tgz", - "integrity": "sha512-Rel9JJAj2jMMiiW+ghiw4BqrSZ5RC5WzuCinpktv4Jg/tZm7TAv3Qu7W4HKZLPSzEr/+3n4JeniamM2VcoTgiw==", + "version": "git+https://github.com/yext/jambo.git#2d76f4dfb0828656fdb757b3c934378e964927f8", + "from": "git+https://github.com/yext/jambo.git#develop", "dev": true, "requires": { "@babel/core": "^7.9.6", @@ -3943,18 +4045,30 @@ "i18next-conv": "^10.0.2", "lodash": "^4.17.15", "merge-options": "^2.0.0", + "npmlog": "^4.1.2", "prompts": "^2.3.1", - "simple-git": "^1.131.0", + "simple-git": "^2.40.0", "yargs": "^17.0.0" }, "dependencies": { + "debug": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", + "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, "simple-git": { - "version": "1.132.0", - "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-1.132.0.tgz", - "integrity": "sha512-xauHm1YqCTom1sC9eOjfq3/9RKiUA9iPnxBbrY2DdL8l4ADMu0jjM5l5lphQP5YWNqAL2aXC/OeuQ76vHtW5fg==", + "version": "2.42.0", + "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-2.42.0.tgz", + "integrity": "sha512-illpUX0bcrdB3AyvBGLz0ToRVP7lXNJOGVybGVuVk7PpivPNK5YKJx2aagKdKbveaMtt0DCLK4/jfjDb6b2M2g==", "dev": true, "requires": { - "debug": "^4.0.1" + "@kwsites/file-exists": "^1.1.1", + "@kwsites/promise-deferred": "^1.1.1", + "debug": "^4.3.1" } } } @@ -4598,6 +4712,18 @@ "path-key": "^1.0.0" } }, + "npmlog": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "dev": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, "nth-check": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.0.0.tgz", @@ -4607,6 +4733,12 @@ "boolbase": "^1.0.0" } }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "dev": true + }, "nwsapi": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.0.tgz", @@ -4833,6 +4965,12 @@ "integrity": "sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0=", "dev": true }, + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -5089,6 +5227,12 @@ "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==", "dev": true }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "dev": true + }, "prompts": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.1.tgz", @@ -5738,6 +5882,12 @@ "randombytes": "^2.1.0" } }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "dev": true + }, "shallow-clone": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", @@ -5880,29 +6030,29 @@ "dev": true }, "string-width": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", - "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.0" + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" }, "dependencies": { "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true }, "strip-ansi": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", - "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { - "ansi-regex": "^5.0.0" + "ansi-regex": "^2.0.0" } } } @@ -6265,9 +6415,9 @@ "dev": true }, "typescript": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz", - "integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", + "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", "dev": true }, "typical": { @@ -6277,9 +6427,9 @@ "dev": true }, "uglify-js": { - "version": "3.13.6", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.6.tgz", - "integrity": "sha512-rRprLwl8RVaS+Qvx3Wh5hPfPBn9++G6xkGlUupya0s5aDmNjI7z3lnRLB3u7sN4OmbB0pWgzhM9BEJyiWAwtAA==", + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.14.1.tgz", + "integrity": "sha512-JhS3hmcVaXlp/xSo3PKY5R0JqKs5M3IV+exdLHW99qKvKivPO4Z8qbej6mte17SOPqAOVMjt/XGgWacnFSzM3g==", "dev": true, "optional": true }, @@ -6759,6 +6909,15 @@ "isexe": "^2.0.0" } }, + "wide-align": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", + "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", + "dev": true, + "requires": { + "string-width": "^1.0.2 || 2" + } + }, "wildcard": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.0.tgz", @@ -6798,12 +6957,6 @@ "strip-ansi": "^6.0.0" }, "dependencies": { - "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", - "dev": true - }, "ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -6828,13 +6981,21 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "strip-ansi": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", - "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "string-width": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", + "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", "dev": true, "requires": { - "ansi-regex": "^5.0.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" } } } @@ -6903,15 +7064,21 @@ "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", "dev": true }, + "y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true + }, "yallist": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" }, "yargs": { - "version": "17.0.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.0.1.tgz", - "integrity": "sha512-xBBulfCc8Y6gLFcrPvtqKz9hz8SO0l1Ni8GgDekvBX2ro0HRQImDGnikfc33cgzcYUSncapnNcZDjVFIH3f6KQ==", + "version": "17.1.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.1.0.tgz", + "integrity": "sha512-SQr7qqmQ2sNijjJGHL4u7t8vyDZdZ3Ahkmo4sc1w5xI9TBX0QDdG/g4SFnxtWOsGLjwHQue57eFALfwFCnixgg==", "dev": true, "requires": { "cliui": "^7.0.2", @@ -6929,18 +7096,29 @@ "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", "dev": true }, - "y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true + }, + "string-width": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", + "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } } } }, "yargs-parser": { - "version": "20.2.7", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.7.tgz", - "integrity": "sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw==", + "version": "20.2.9", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", "dev": true }, "yocto-queue": { diff --git a/static/package.json b/static/package.json index b76c03c59..94a4bb861 100644 --- a/static/package.json +++ b/static/package.json @@ -30,7 +30,7 @@ "grunt-webpack": "^4.0.0", "html-loader": "^2.1.2", "html-webpack-plugin": "^5.3.1", - "jambo": "^1.11.0", + "jambo": "git+https://github.com/yext/jambo.git#develop", "jsdom": "^16.4.0", "mini-css-extract-plugin": "^1.6.0", "postcss": "^8.3.1", From 55c42b4e50ed1f658f088e73715249bed5b135e6 Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Thu, 12 Aug 2021 15:59:15 -0400 Subject: [PATCH 2/6] update desc --- hooks/templatedatavalidator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/templatedatavalidator.js b/hooks/templatedatavalidator.js index 4b75f6c15..45309ba2f 100644 --- a/hooks/templatedatavalidator.js +++ b/hooks/templatedatavalidator.js @@ -3,7 +3,7 @@ const { parseJamboConfig } = require('../commands/helpers/utils/jamboconfigutils const { error } = require('../commands/helpers/utils/logger'); /** - * Validates page template's data configuration + * Validates the template data and partials used during jambo build. * * @param {Object} pageData data that gets passed into a page template * @param {Object} partials From 13a15e8fa4666f3f0cc0b814b268dfb6abc6708c Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Thu, 12 Aug 2021 17:30:27 -0400 Subject: [PATCH 3/6] update error msg --- commands/helpers/utils/logger.js | 6 ++++- hooks/templatedataformatter.js | 1 + hooks/templatedatavalidator.js | 41 ++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/commands/helpers/utils/logger.js b/commands/helpers/utils/logger.js index 01e74bd6a..4e91927ac 100644 --- a/commands/helpers/utils/logger.js +++ b/commands/helpers/utils/logger.js @@ -4,7 +4,11 @@ log.heading = 'jambo'; log.headingStyle = { fg: 'magenta' }; // Don't display a log prefix. -const PREFIX = ''; +let PREFIX = ''; + +exports.setPrefix = function(prefix) { + PREFIX = prefix; +} /** * Sets the global logging level. diff --git a/hooks/templatedataformatter.js b/hooks/templatedataformatter.js index 3324b6a8a..5fa201138 100644 --- a/hooks/templatedataformatter.js +++ b/hooks/templatedataformatter.js @@ -24,6 +24,7 @@ module.exports = function (pageMetadata, siteLevelAttributes, pageNameToConfig) global_config: getLocalizedGlobalConfig(globalConfig, currentLocaleConfig, locale), params: currentLocaleConfig.params || {}, relativePath, + pageMetadata: { pageName }, env: { JAMBO_INJECTED_DATA: env.JAMBO_INJECTED_DATA } diff --git a/hooks/templatedatavalidator.js b/hooks/templatedatavalidator.js index 45309ba2f..04b53b1b7 100644 --- a/hooks/templatedatavalidator.js +++ b/hooks/templatedatavalidator.js @@ -1,6 +1,6 @@ const path = require('path'); const { parseJamboConfig } = require('../commands/helpers/utils/jamboconfigutils'); -const { error } = require('../commands/helpers/utils/logger'); +const { error, setPrefix } = require('../commands/helpers/utils/logger'); /** * Validates the template data and partials used during jambo build. @@ -12,6 +12,8 @@ const { error } = require('../commands/helpers/utils/logger'); * @returns {boolean} false if validator should throw an error */ module.exports = function (pageData, partials) { + const { pageName } = pageData.pageMetadata; + setPrefix(`${pageName}.json`); const jamboConfig = parseJamboConfig(); const validatorResults = [ isGlobalConfigValid(pageData.global_config), @@ -53,8 +55,8 @@ function isPageVerticalConfigValid(pageData, jamboConfig, partials) { const universalSectionTemplate = pageData.verticalsToConfig[key].universalSectionTemplate; const cardType = pageData.verticalsToConfig[key].cardType; const validatorResults = [ - isUniversalSectionTemplateValid(key, themeDirectory, universalSectionTemplate, partials), - isCardTypeValid(key, themeDirectory, cardType, partials) + isUniversalSectionTemplateValid(themeDirectory, universalSectionTemplate, partials), + isCardTypeValid(themeDirectory, cardType, partials) ]; return validatorResults.every(result => result); }) @@ -64,16 +66,16 @@ function isPageVerticalConfigValid(pageData, jamboConfig, partials) { /** * If universalsectiontemplate is defined, check whether the corresponding file exists in theme * - * @param {string} verticalName * @param {string} themeDir * @param {string} template * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isUniversalSectionTemplateValid(verticalName, themeDir, template, partials) { - if (template && !partials[`universalsectiontemplates/${template}`]) { +function isUniversalSectionTemplateValid(themeDir, template, partials) { + const partialName = `universalsectiontemplates/${template}`; + if (template && !partials[partialName]) { const universalSectionPath = path.join(themeDir, 'universalsectiontemplates/', template + '.hbs'); - error(`Invalid universalSectionTemplate: can't find "${template}" at the expected path "${universalSectionPath}" for vertical "${verticalName}".`); + logThatPartialDNE(partialName, [universalSectionPath]); return false; } return true; @@ -82,17 +84,17 @@ function isUniversalSectionTemplateValid(verticalName, themeDir, template, parti /** * If cardType is defined, check whether the corresponding file exists in theme or custom card folder * - * @param {string} verticalName * @param {string} themeDir * @param {string} cardType * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isCardTypeValid(verticalName, themeDir, cardType, partials) { - if (cardType && !partials[`cards/${cardType}/component`]) { - const cardTypePath = path.join(themeDir, 'cards/', cardType); - const customCardTypePath = path.join('cards/', cardType); - error(`Invalid cardType: can't find "${cardType}" at at the expected paths "${cardTypePath}" or "${customCardTypePath}" for vertical "${verticalName}".`); +function isCardTypeValid(themeDir, cardType, partials) { + const partial = `cards/${cardType}/component`; + if (cardType && !partials[partial]) { + const cardTypePath = path.join(themeDir, 'cards/', cardType, 'component.js'); + const customCardTypePath = path.join('cards/', cardType, 'component.js'); + logThatPartialDNE(partial, [cardTypePath, customCardTypePath]); return false; } return true; @@ -115,4 +117,17 @@ function isAllVerticalConfigsValid(verticalConfigs, jamboConfig, partials) { return isPageVerticalConfigValid(verticalConfigs[key], jamboConfig, partials); }) .every(result => result); +} + +function logThatPartialDNE(partialName, defaultLocations = []) { + let msg = `Cannot find partial ${partialName}.` + if (defaultLocations.length === 1) { + msg += `\nBy default this partial is located in ${defaultLocations[0]}`; + } else if (defaultLocations.length > 1) { + const lastLocation = defaultLocations[defaultLocations.length - 1]; + const commaSeparatedLocations = defaultLocations.slice(0, -1).join(', '); + const parsedLocations = `${commaSeparatedLocations}, or ${lastLocation}` + msg += `\nBy default this partial is located in ${parsedLocations}`; + } + error(msg); } \ No newline at end of file From 36e80724b5f10ed507a1bc4e89cb0e90363a3c8f Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Thu, 12 Aug 2021 17:32:06 -0400 Subject: [PATCH 4/6] add caveat to jsdoc --- commands/helpers/utils/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/helpers/utils/logger.js b/commands/helpers/utils/logger.js index 4e91927ac..bef29d955 100644 --- a/commands/helpers/utils/logger.js +++ b/commands/helpers/utils/logger.js @@ -3,7 +3,7 @@ const log = require('npmlog'); log.heading = 'jambo'; log.headingStyle = { fg: 'magenta' }; -// Don't display a log prefix. +// Don't display a log prefix by default. let PREFIX = ''; exports.setPrefix = function(prefix) { From f178a7a3d2c80b5b7aea1d49c8cf8073ce2419e5 Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Thu, 12 Aug 2021 17:38:00 -0400 Subject: [PATCH 5/6] remove oxford comma --- hooks/templatedatavalidator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/templatedatavalidator.js b/hooks/templatedatavalidator.js index 04b53b1b7..a110761c9 100644 --- a/hooks/templatedatavalidator.js +++ b/hooks/templatedatavalidator.js @@ -126,7 +126,7 @@ function logThatPartialDNE(partialName, defaultLocations = []) { } else if (defaultLocations.length > 1) { const lastLocation = defaultLocations[defaultLocations.length - 1]; const commaSeparatedLocations = defaultLocations.slice(0, -1).join(', '); - const parsedLocations = `${commaSeparatedLocations}, or ${lastLocation}` + const parsedLocations = `${commaSeparatedLocations} or ${lastLocation}` msg += `\nBy default this partial is located in ${parsedLocations}`; } error(msg); From 704f9a615ee5e11d8f1afb99ac5ac4f20aef8dce Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Thu, 12 Aug 2021 18:34:01 -0400 Subject: [PATCH 6/6] tweaks --- commands/helpers/utils/logger.js | 8 ++------ hooks/templatedataformatter.js | 1 - hooks/templatedatavalidator.js | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/commands/helpers/utils/logger.js b/commands/helpers/utils/logger.js index bef29d955..01e74bd6a 100644 --- a/commands/helpers/utils/logger.js +++ b/commands/helpers/utils/logger.js @@ -3,12 +3,8 @@ const log = require('npmlog'); log.heading = 'jambo'; log.headingStyle = { fg: 'magenta' }; -// Don't display a log prefix by default. -let PREFIX = ''; - -exports.setPrefix = function(prefix) { - PREFIX = prefix; -} +// Don't display a log prefix. +const PREFIX = ''; /** * Sets the global logging level. diff --git a/hooks/templatedataformatter.js b/hooks/templatedataformatter.js index 5fa201138..3324b6a8a 100644 --- a/hooks/templatedataformatter.js +++ b/hooks/templatedataformatter.js @@ -24,7 +24,6 @@ module.exports = function (pageMetadata, siteLevelAttributes, pageNameToConfig) global_config: getLocalizedGlobalConfig(globalConfig, currentLocaleConfig, locale), params: currentLocaleConfig.params || {}, relativePath, - pageMetadata: { pageName }, env: { JAMBO_INJECTED_DATA: env.JAMBO_INJECTED_DATA } diff --git a/hooks/templatedatavalidator.js b/hooks/templatedatavalidator.js index a110761c9..6f120ba08 100644 --- a/hooks/templatedatavalidator.js +++ b/hooks/templatedatavalidator.js @@ -1,6 +1,6 @@ const path = require('path'); const { parseJamboConfig } = require('../commands/helpers/utils/jamboconfigutils'); -const { error, setPrefix } = require('../commands/helpers/utils/logger'); +const { error } = require('../commands/helpers/utils/logger'); /** * Validates the template data and partials used during jambo build. @@ -12,8 +12,6 @@ const { error, setPrefix } = require('../commands/helpers/utils/logger'); * @returns {boolean} false if validator should throw an error */ module.exports = function (pageData, partials) { - const { pageName } = pageData.pageMetadata; - setPrefix(`${pageName}.json`); const jamboConfig = parseJamboConfig(); const validatorResults = [ isGlobalConfigValid(pageData.global_config), @@ -55,8 +53,8 @@ function isPageVerticalConfigValid(pageData, jamboConfig, partials) { const universalSectionTemplate = pageData.verticalsToConfig[key].universalSectionTemplate; const cardType = pageData.verticalsToConfig[key].cardType; const validatorResults = [ - isUniversalSectionTemplateValid(themeDirectory, universalSectionTemplate, partials), - isCardTypeValid(themeDirectory, cardType, partials) + isUniversalSectionTemplateValid(key, themeDirectory, universalSectionTemplate, partials), + isCardTypeValid(key, themeDirectory, cardType, partials) ]; return validatorResults.every(result => result); }) @@ -65,17 +63,18 @@ function isPageVerticalConfigValid(pageData, jamboConfig, partials) { /** * If universalsectiontemplate is defined, check whether the corresponding file exists in theme - * + * + * @param {string} verticalName * @param {string} themeDir * @param {string} template * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isUniversalSectionTemplateValid(themeDir, template, partials) { +function isUniversalSectionTemplateValid(verticalName, themeDir, template, partials) { const partialName = `universalsectiontemplates/${template}`; if (template && !partials[partialName]) { const universalSectionPath = path.join(themeDir, 'universalsectiontemplates/', template + '.hbs'); - logThatPartialDNE(partialName, [universalSectionPath]); + logThatPartialDNE(partialName, verticalName, [universalSectionPath]); return false; } return true; @@ -84,17 +83,18 @@ function isUniversalSectionTemplateValid(themeDir, template, partials) { /** * If cardType is defined, check whether the corresponding file exists in theme or custom card folder * + * @param {string} verticalName * @param {string} themeDir * @param {string} cardType * @param {Object} partials mapping of partial name to partial * @returns {boolean} */ -function isCardTypeValid(themeDir, cardType, partials) { +function isCardTypeValid(verticalName, themeDir, cardType, partials) { const partial = `cards/${cardType}/component`; if (cardType && !partials[partial]) { const cardTypePath = path.join(themeDir, 'cards/', cardType, 'component.js'); const customCardTypePath = path.join('cards/', cardType, 'component.js'); - logThatPartialDNE(partial, [cardTypePath, customCardTypePath]); + logThatPartialDNE(partial, verticalName, [cardTypePath, customCardTypePath]); return false; } return true; @@ -119,8 +119,8 @@ function isAllVerticalConfigsValid(verticalConfigs, jamboConfig, partials) { .every(result => result); } -function logThatPartialDNE(partialName, defaultLocations = []) { - let msg = `Cannot find partial ${partialName}.` +function logThatPartialDNE(partialName, verticalName, defaultLocations = []) { + let msg = `Cannot find partial \`${partialName}\` for vertical \`${verticalName}\`.` if (defaultLocations.length === 1) { msg += `\nBy default this partial is located in ${defaultLocations[0]}`; } else if (defaultLocations.length > 1) {