Skip to content

Commit

Permalink
Add helper plugin for 11ty/eleventy#3373
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 23, 2024
1 parent 3f31d81 commit 1081e07
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = function(eleventyConfig) {
console.log(chalk.blue(`[${pkg.name}] ---`));

// Full list of issues: https://github.com/11ty/eleventy/issues?q=milestone%3A%22Eleventy+3.0.0%22+is%3Aclosed+label%3Abreaking-change
eleventyConfig.addPlugin(require("./src/node-version"));
eleventyConfig.addPlugin(require("./src/node-version.js"));
eleventyConfig.addPlugin(require("./src/explicit-config-file.js"));

eleventyConfig.on("eleventy.after", () => {
console.log(chalk.blue(`[${pkg.name}] This plugin is intended for temporary use: once you’re satisfied please remove this plugin from your project!`));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"homepage": "https://www.11ty.dev/",
"dependencies": {
"kleur": "^4.1.5",
"minimist": "^1.2.8",
"semver": "^7.6.3"
},
"11ty": {
Expand Down
20 changes: 20 additions & 0 deletions src/explicit-config-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require("node:fs");
const chalk = require("kleur");
const pkg = require("../package.json");

const minimist = require("minimist");

const argv = minimist(process.argv.slice(2), {
string: ["config"]
});

module.exports = function(eleventyConfig) {
let type = chalk.blue("NOTICE");

if(argv.config && !fs.existsSync(argv.config)) {
// We’ll never get here because the configuration file has to work to run the upgrade plugin.
type = chalk.red("ERROR");
}

console.log(chalk.blue(`[${pkg.name}]`), type, `Eleventy will fail with an error when you point \`--config\` to a configuration file that does not exist. Previous versions ran as-is (without application configuration). Read more: https://github.com/11ty/eleventy/issues/3373`);
};

0 comments on commit 1081e07

Please sign in to comment.