Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show generator description from external plopfiles #402

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-feet-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"node-plop": patch
---

Show generator description from external plopfiles
6 changes: 5 additions & 1 deletion packages/node-plop/src/node-plop.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ async function nodePlop(plopfilePath = "", plopCfg = {}) {
genNameList,
includeCfg === true || include.generators,
setGenerator,
(proxyName) => ({ proxyName, proxy }),
(proxyName) => ({
proxyName,
proxy,
description: proxy.getGenerator(proxyName).description,
}),
);
loadAsset(
proxy.getPartialList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe("load-assets-from-plopfile", function () {
expect(plop.getPartialList().length).toBe(0);
});

test("plop.load should preserve descriptions of generators", async function () {
const plop = await nodePlop();
await plop.load(plopfilePath);

expect(plop.getGeneratorList()[1].description).toBe(plop.getGenerator("generator2").description);
expect(plop.getGeneratorList()[1].description).toBe("this is a skeleton plopfile");
});

test("plop.load should be able to include a subset of generators", async function () {
const plop = await nodePlop();
await plop.load(plopfilePath, {}, { generators: ["generator1"] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export default function (plop, config = {}) {
actions: [{ type: "add", path: "src/{{name}}.txt" }],
};
plop.setGenerator(`${cfg.prefix}generator1`, generatorObject);
plop.setGenerator(`${cfg.prefix}generator2`, generatorObject);
plop.setGenerator(`${cfg.prefix}generator2`, {
...generatorObject,
description: "this is a skeleton plopfile",
});
plop.setGenerator(`${cfg.prefix}generator3`, generatorObject);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default function (plop) {
plop.setGenerator("extra-generator1", {
description: "this is a skeleton plopfile",
prompts: [
{
type: "input",
name: "name",
message: "What is your name?",
validate: function (value) {
if (/.+/.test(value)) {
return true;
}
return "name is required";
},
},
],
});
}
5 changes: 4 additions & 1 deletion packages/plop/tests/examples/javascript/plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "path";
import fs from "fs";
import inquirerDirectory from "inquirer-directory";

export default function (plop) {
export default async function (plop) {
// starting prompt can be customized to display what you want
// plop.setWelcomeMessage('[CUSTOM]'.yellow + ' What can I do for you?');

Expand Down Expand Up @@ -36,6 +36,9 @@ export default function (plop) {
commentEnd: "",
});

// load generators from another plopfile in the project
await plop.load("./extra-generators.plopfile.js");

const delayLog = (msg) => (answers) =>
new Promise((resolve) => {
setTimeout(() => resolve(msg), 1000);
Expand Down
1 change: 1 addition & 0 deletions packages/plop/tests/input-processing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ test("Should handle generator prompt", async () => {
await userEvent.keyboard("[Enter]");

expect(await findByText("this is a test")).toBeInTheConsole();
expect(await findByText("this is a skeleton plopfile")).toBeInTheConsole();
});

test("Should bypass generator prompt", async () => {
Expand Down