Skip to content

Commit

Permalink
Adds upgrade helper for 11ty/eleventy#3124
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 23, 2024
1 parent ffdade8 commit 519cac3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(require("./src/html-output-suffix.js"));
eleventyConfig.addPlugin(require("./src/alias-template-formats.js"));
eleventyConfig.addPlugin(require("./src/empty-formats.js"));
eleventyConfig.addPlugin(require("./src/plugin-land.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 @@ -30,6 +30,7 @@
"bugs": "https://github.com/11ty/eleventy-upgrade-help/issues",
"homepage": "https://www.11ty.dev/",
"dependencies": {
"fast-glob": "^3.3.2",
"kleur": "^4.1.5",
"minimist": "^1.2.8",
"semver": "^7.6.3"
Expand Down
3 changes: 3 additions & 0 deletions src/alias-template-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = function(eleventyConfig) {
console.log(chalk.green(`[${pkg.name}] PASSED`), `No aliases were added via \`eleventyConfig.addExtension()\`. If you had added an alias, it would need to be also added to your active template formats. Learn more about template formats: https://www.11ty.dev/docs/config/#template-formats or about this change: https://github.com/11ty/eleventy/issues/3302`);
} else {
for(let { key, extension, aliasKey } of eleventyConfig.extensionMap) {
if(!aliasKey) {
continue;
}
if(!templateFormatsActive.includes(extension)) {
console.log(chalk.red(`[${pkg.name}] ERROR`), `Aliases added via \`eleventyConfig.addExtension()\` must be added to your active template formats, via \`--formats=${extension}\` on the command line, the \`templateFormats: "${extension}"\` configuration object property, \`eleventyConfig.setTemplateFormats("${extension}")\`, or \`eleventyConfig.addTemplateFormats("${extension}")\` (additive). This *might* be what you want if you added a plugin but don’t want to currently process ${extension} files in Eleventy. Learn more about template formats: https://www.11ty.dev/docs/config/#template-formats or about this change: https://github.com/11ty/eleventy/issues/3302`);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/empty-formats.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const fs = require("node:fs");
const chalk = require("kleur");
const pkg = require("../package.json");

Expand All @@ -12,6 +11,6 @@ module.exports = function(eleventyConfig) {
if(argv.formats || argv.formats === undefined) {
console.log(chalk.green(`[${pkg.name}] PASSED`), `You aren’t using \`--formats=\` or \`--formats=''\` but if you were you should know that these are now empty template format sets. In previous versions, they were aliased to "*". Read more: https://github.com/11ty/eleventy/issues/3255`);
} else if(argv.formats === "" || argv.formats === null) {
console.log(chalk.red(`[${pkg.name}] ERROR`), `In Eleventy 3.0 \`--formats=""\` and \`formats=\` are empty template format sets. Previous versions aliased these to "*". Use \`--formats=*\` if you want that behavior in 3.0. Read more: https://github.com/11ty/eleventy/issues/3255`);
console.log(chalk.red(`[${pkg.name}] ERROR`), `In Eleventy 3.0 \`--formats=""\` and \`formats=\` are empty template format sets. Previous versions aliased these to "*". Use \`--formats=*\` if you want to keep using that behavior in 3.0. Read more: https://github.com/11ty/eleventy/issues/3255`);
}
};
27 changes: 27 additions & 0 deletions src/plugin-land.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const chalk = require("kleur");
const path = require("node:path");
const fastglob = require("fast-glob");
const pkg = require("../package.json");

module.exports = function(eleventyConfig) {
let installedPlugins = {};
for(let { key, extension, aliasKey } of eleventyConfig.extensionMap) {
installedPlugins[key] = true;
}

// template formats: * or explicit pug,ejs,haml,mustache,handlebars
// any of these files in your project

let allRemovedKeys = "pug,ejs,haml,mustache,handlebars".split(",");

for(let removedKey of allRemovedKeys) {
let foundFiles = fastglob.sync(`${eleventyConfig.directories.input}**/*.${removedKey}`);
if(foundFiles.length > 0) {
if( !installedPlugins[removedKey]) {
console.log(chalk.red(`[${pkg.name}] ERROR`), `Found ${foundFiles.length} ${removedKey} file${foundFiles.length !== 1 ? "s" : ""} in your project but the ${removedKey} plugin was moved from core to an officially supported plugin. You will need to add the plugin for ${removedKey}, available here: https://github.com/11ty/eleventy-plugin-template-languages and you can learn more about this here: https://github.com/11ty/eleventy/issues/3124`);
} else {
console.log(chalk.green(`[${pkg.name}] PASSED`), `You have installed the ${removedKey} plugin to handle the ${foundFiles.length} ${removedKey} file${foundFiles.length !== 1 ? "s" : ""} in your project. Learn more: https://github.com/11ty/eleventy/issues/3124`);
}
}
}
};

0 comments on commit 519cac3

Please sign in to comment.