Skip to content

Commit

Permalink
Initial work to migrate to ESM node-plop
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Nov 24, 2021
1 parent ad7004f commit 91b854f
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 323 deletions.
551 changes: 249 additions & 302 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"interpret": "^2.2.0",
"liftoff": "^4.0.0",
"minimist": "^1.2.5",
"node-plop": "^0.26.3",
"node-plop": "^0.30.0-alpha.1",
"ora": "^6.0.1",
"v8flags": "^4.0.0"
},
Expand Down
20 changes: 14 additions & 6 deletions src/plop.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,27 @@ const progressSpinner = ora({
* One of the reasons we default generator arguments as anything past `--` is a few reasons:
* Primarily that there may be name-spacing issues when combining the arg order and named arg passing
*/
function run(env, _, passArgsBeforeDashes) {
async function run(env, _, passArgsBeforeDashes) {
const plopfilePath = env.configPath;

// handle basic argument flags like --help, --version, etc
handleArgFlags(env);

// use base path from argv or env if any is present, otherwise set it to the plopfile directory
const destBasePath = argv.dest || env.dest;
const plop = nodePlop(plopfilePath, {
destBasePath: destBasePath ? path.resolve(destBasePath) : undefined,
force: argv.force === true || argv.f === true || false,
});

let plop;
try {
plop = await nodePlop(plopfilePath, {
destBasePath: destBasePath ? path.resolve(destBasePath) : undefined,
force: argv.force === true || argv.f === true || false,
});
} catch (e) {
console.error(
chalk.red("[PLOP] ") + "Something went wrong with reading your plop file",
e
);
return;
}
const generators = plop.getGeneratorList();
const generatorNames = generators.map((v) => v.name);
const { generatorName, bypassArr, plopArgV } = getBypassAndGenerator(
Expand Down
6 changes: 5 additions & 1 deletion tests/examples/add-action/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"name": "plop-example-add-action"
"name": "plop-example-add-action",
"type": "module",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
4 changes: 2 additions & 2 deletions tests/examples/add-action/plopfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (plop) {
export default function (plop) {
plop.setGenerator("addAndNameFile", {
description: "Name that file",
prompts: [
Expand Down Expand Up @@ -34,4 +34,4 @@ module.exports = function (plop) {
},
],
});
};
}
6 changes: 5 additions & 1 deletion tests/examples/javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"name": "plop-example"
"name": "plop-example",
"type": "module",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
13 changes: 6 additions & 7 deletions tests/examples/javascript/plopfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
const path = require("path");

module.exports = function (plop) {
import path from "path";
import fs from "fs";
import inquirerDirectory from "inquirer-directory";
export default 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 @@ -99,7 +99,6 @@ module.exports = function (plop) {
process.chdir(plop.getPlopfilePath());

// custom function can be synchronous or async (by returning a promise)
var fs = require("fs");
var existsMsg = "psst {{name}}, change-me.txt already exists";
var copiedMsg = "hey {{name}}, I copied change-me.txt for you";
var changeFileName = "change-me.txt";
Expand Down Expand Up @@ -160,7 +159,7 @@ module.exports = function (plop) {
});

// adding a custom inquirer prompt type
plop.addPrompt("directory", require("inquirer-directory"));
plop.addPrompt("directory", inquirerDirectory);

plop.setGenerator("custom-prompt", {
description: "custom inquirer prompt example",
Expand Down Expand Up @@ -247,4 +246,4 @@ module.exports = function (plop) {
return actions;
},
});
};
}
6 changes: 5 additions & 1 deletion tests/examples/prompt-only/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"name": "plop-example-prompts-only"
"name": "plop-example-prompts-only",
"type": "module",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
4 changes: 2 additions & 2 deletions tests/examples/prompt-only/plopfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (plop) {
export default function (plop) {
plop.setGenerator("test", {
description: "this is a test",
prompts: [
Expand Down Expand Up @@ -27,4 +27,4 @@ module.exports = function (plop) {
},
],
});
};
}

0 comments on commit 91b854f

Please sign in to comment.