diff --git a/build.js b/build.js index d5bd3cb654b00..bb7e6fa68937d 100755 --- a/build.js +++ b/build.js @@ -14,8 +14,6 @@ const path = require('path'); const Metalsmith = require('metalsmith'); const collections = require('metalsmith-collections'); const feed = require('metalsmith-feed'); -const discoverHelpers = require('metalsmith-discover-helpers'); -const discoverPartials = require('metalsmith-discover-partials'); const layouts = require('metalsmith-layouts'); const markdown = require('@metalsmith/markdown'); const permalinks = require('@metalsmith/permalinks'); @@ -29,6 +27,8 @@ const ncp = require('ncp'); const junk = require('junk'); const semver = require('semver'); const replace = require('metalsmith-one-replace'); +const glob = require('glob'); +const Handlebars = require('handlebars'); const githubLinks = require('./scripts/plugins/githubLinks'); const navigation = require('./scripts/plugins/navigation'); @@ -41,7 +41,7 @@ const latestVersion = require('./scripts/helpers/latestversion'); const DEFAULT_LANG = 'en'; // The history links of nodejs versions at doc/index.md -const nodejsVersionsContent = require('fs') +const nodejsVersionsContent = fs .readFileSync('./source/nodejsVersions.md') .toString(); @@ -190,18 +190,43 @@ function buildLocale(source, locale, opts) { // Finally, this compiles the rest of the layouts present in ./layouts. // They're language-agnostic, but have to be regenerated for every locale // anyways. - .use( - discoverPartials({ - directory: 'layouts/partials', - pattern: /\.hbs$/ - }) - ) - .use( - discoverHelpers({ - directory: 'scripts/helpers', - pattern: /\.js$/ - }) - ) + .use((files, metalsmith, done) => { + const fsPromises = require('fs/promises'); + glob( + `${metalsmith.path('layouts/partials')}/**/*.hbs`, + {}, + async (err, matches) => { + if (err) { + throw err; + } + await Promise.all( + matches.map(async (file) => { + const contents = await fsPromises.readFile(file, 'utf8'); + const id = path.basename(file, path.extname(file)); + return Handlebars.registerPartial(id, contents); + }) + ); + done(); + } + ); + }) + .use((files, metalsmith, done) => { + glob( + `${metalsmith.path('scripts/helpers')}/**/*.js`, + {}, + (err, matches) => { + if (err) { + throw err; + } + matches.forEach((file) => { + const fn = require(path.resolve(file)); + const id = path.basename(file, path.extname(file)); + return Handlebars.registerHelper(id, fn); + }); + done(); + } + ); + }) .use(layouts()) // Pipes the generated files into their respective subdirectory in the build // directory. diff --git a/package-lock.json b/package-lock.json index a91065ba99ab9..a8e882f9aadf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,8 +22,6 @@ "marked": "^4.0.14", "metalsmith": "^2.4.2", "metalsmith-collections": "^0.9.0", - "metalsmith-discover-helpers": "^0.1.1", - "metalsmith-discover-partials": "^0.1.2", "metalsmith-feed": "^1.0.0", "metalsmith-layouts": "^2.3.1", "metalsmith-one-replace": "^0.1.7", @@ -47,6 +45,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^6.0.0", + "glob": "^7.2.0", "lockfile-lint": "^4.7.4", "nock": "^13.2.4", "node-fetch": "^2.6.7", @@ -595,11 +594,6 @@ "node": ">=8" } }, - "node_modules/async": { - "version": "0.2.10", - "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", - "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=" - }, "node_modules/async-cache": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/async-cache/-/async-cache-1.1.0.tgz", @@ -960,14 +954,6 @@ "wrap-ansi": "^7.0.0" } }, - "node_modules/clone": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", - "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=", - "engines": { - "node": ">=0.8" - } - }, "node_modules/clone-regexp": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clone-regexp/-/clone-regexp-2.2.0.tgz", @@ -1239,14 +1225,6 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, - "node_modules/defaults": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", - "integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=", - "dependencies": { - "clone": "^1.0.2" - } - }, "node_modules/define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -2162,16 +2140,6 @@ "rimraf": "bin.js" } }, - "node_modules/fs-tools": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/fs-tools/-/fs-tools-0.5.0.tgz", - "integrity": "sha512-iJG+dKoTlWevEBvsZYkq7Fy1XJVYHMObel+MIKOf+3HbiENQG0JH5bgTlzJYsrdwZvft1vE/yl/P/T4wngAv8A==", - "deprecated": "Use shelljs, glob, mkdirp, rimraf, or other alternatives", - "dependencies": { - "async": "~ 0.2.9", - "lodash": "^4.17.10" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -3390,7 +3358,8 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "node_modules/lodash.clonedeepwith": { "version": "4.5.0", @@ -3855,32 +3824,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, - "node_modules/metalsmith-discover-helpers": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/metalsmith-discover-helpers/-/metalsmith-discover-helpers-0.1.1.tgz", - "integrity": "sha512-aM+O5osa5F+uM9iTenWzE8aaPhTkIH2ibmYRConud2YUjLO4IBt1MdryBNdDLAzn8nyQT/n/lVoqXTFsPGo6Sg==", - "dependencies": { - "defaults": "^1.0.3", - "fs-tools": "^0.5.0", - "handlebars": "*" - }, - "engines": { - "node": ">=0.12.0" - } - }, - "node_modules/metalsmith-discover-partials": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/metalsmith-discover-partials/-/metalsmith-discover-partials-0.1.2.tgz", - "integrity": "sha512-rjVOCSnoXJyEQand85o8l8Z9Yevbyis23q+gCA5Q6w5SG2L+H/jMQYGokpj3a5cOl0Fkl+MaXZSHJ9elpKYNFg==", - "dependencies": { - "defaults": "^1.0.3", - "fs-tools": "^0.5.0", - "handlebars": "*" - }, - "engines": { - "node": ">=0.12.0" - } - }, "node_modules/metalsmith-feed": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/metalsmith-feed/-/metalsmith-feed-1.0.0.tgz", @@ -8981,11 +8924,6 @@ "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true }, - "async": { - "version": "0.2.10", - "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", - "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=" - }, "async-cache": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/async-cache/-/async-cache-1.1.0.tgz", @@ -9211,11 +9149,6 @@ "wrap-ansi": "^7.0.0" } }, - "clone": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", - "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=" - }, "clone-regexp": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clone-regexp/-/clone-regexp-2.2.0.tgz", @@ -9429,14 +9362,6 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, - "defaults": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", - "integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=", - "requires": { - "clone": "^1.0.2" - } - }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -10137,15 +10062,6 @@ } } }, - "fs-tools": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/fs-tools/-/fs-tools-0.5.0.tgz", - "integrity": "sha512-iJG+dKoTlWevEBvsZYkq7Fy1XJVYHMObel+MIKOf+3HbiENQG0JH5bgTlzJYsrdwZvft1vE/yl/P/T4wngAv8A==", - "requires": { - "async": "~ 0.2.9", - "lodash": "^4.17.10" - } - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -11017,7 +10933,8 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "lodash.clonedeepwith": { "version": "4.5.0", @@ -11373,26 +11290,6 @@ } } }, - "metalsmith-discover-helpers": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/metalsmith-discover-helpers/-/metalsmith-discover-helpers-0.1.1.tgz", - "integrity": "sha512-aM+O5osa5F+uM9iTenWzE8aaPhTkIH2ibmYRConud2YUjLO4IBt1MdryBNdDLAzn8nyQT/n/lVoqXTFsPGo6Sg==", - "requires": { - "defaults": "^1.0.3", - "fs-tools": "^0.5.0", - "handlebars": "*" - } - }, - "metalsmith-discover-partials": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/metalsmith-discover-partials/-/metalsmith-discover-partials-0.1.2.tgz", - "integrity": "sha512-rjVOCSnoXJyEQand85o8l8Z9Yevbyis23q+gCA5Q6w5SG2L+H/jMQYGokpj3a5cOl0Fkl+MaXZSHJ9elpKYNFg==", - "requires": { - "defaults": "^1.0.3", - "fs-tools": "^0.5.0", - "handlebars": "*" - } - }, "metalsmith-feed": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/metalsmith-feed/-/metalsmith-feed-1.0.0.tgz", diff --git a/package.json b/package.json index f2e055835d7ad..2fcdfcb37e192 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,6 @@ "marked": "^4.0.14", "metalsmith": "^2.4.2", "metalsmith-collections": "^0.9.0", - "metalsmith-discover-helpers": "^0.1.1", - "metalsmith-discover-partials": "^0.1.2", "metalsmith-feed": "^1.0.0", "metalsmith-layouts": "^2.3.1", "metalsmith-one-replace": "^0.1.7", @@ -68,6 +66,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^6.0.0", + "glob": "^7.2.0", "lockfile-lint": "^4.7.4", "nock": "^13.2.4", "node-fetch": "^2.6.7",