-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d152d6d
commit 656a74f
Showing
17 changed files
with
221 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,127 @@ | ||
"use strict"; | ||
|
||
const chalk = require("chalk"); | ||
const nodePlop = require("node-plop"); | ||
const fs = require("fs"); | ||
import chalk from "chalk"; | ||
import nodePlop from "node-plop"; | ||
import fs from "node:fs"; | ||
|
||
const defaultChoosingMessage = | ||
chalk.blue("[PLOP]") + " Please choose a generator."; | ||
|
||
module.exports = (function () { | ||
function getHelpMessage(generator) { | ||
const maxLen = Math.max( | ||
...generator.prompts.map((prompt) => prompt.name.length) | ||
); | ||
console.log( | ||
[ | ||
"", | ||
chalk.bold("Options:"), | ||
...generator.prompts.map( | ||
(prompt) => | ||
" --" + | ||
prompt.name + | ||
" ".repeat(maxLen - prompt.name.length + 2) + | ||
chalk.dim(prompt.help ? prompt.help : prompt.message) | ||
), | ||
].join("\n") | ||
); | ||
} | ||
|
||
function chooseOptionFromList(plopList, message) { | ||
const plop = nodePlop(); | ||
const generator = plop.setGenerator("choose", { | ||
prompts: [ | ||
{ | ||
type: "list", | ||
name: "generator", | ||
message: message || defaultChoosingMessage, | ||
choices: plopList.map(function (p) { | ||
return { | ||
name: | ||
p.name + | ||
chalk.gray(!!p.description ? " - " + p.description : ""), | ||
value: p.name, | ||
}; | ||
}), | ||
}, | ||
], | ||
}); | ||
return generator.runPrompts().then((results) => results.generator); | ||
} | ||
function getHelpMessage(generator) { | ||
const maxLen = Math.max( | ||
...generator.prompts.map((prompt) => prompt.name.length) | ||
); | ||
console.log( | ||
[ | ||
"", | ||
chalk.bold("Options:"), | ||
...generator.prompts.map( | ||
(prompt) => | ||
" --" + | ||
prompt.name + | ||
" ".repeat(maxLen - prompt.name.length + 2) + | ||
chalk.dim(prompt.help ? prompt.help : prompt.message) | ||
), | ||
].join("\n") | ||
); | ||
} | ||
|
||
function displayHelpScreen() { | ||
console.log( | ||
[ | ||
"", | ||
chalk.bold("Usage:"), | ||
" $ plop " + | ||
chalk.dim("Select from a list of available generators"), | ||
" $ plop <name> " + | ||
chalk.dim("Run a generator registered under that name"), | ||
" $ plop <name> [input] " + | ||
chalk.dim("Run the generator with input data to bypass prompts"), | ||
"", | ||
chalk.bold("Options:"), | ||
" -h, --help " + chalk.dim("Show this help display"), | ||
" -t, --show-type-names " + | ||
chalk.dim("Show type names instead of abbreviations"), | ||
" -i, --init " + chalk.dim("Generate a basic plopfile.js"), | ||
" -v, --version " + chalk.dim("Print current version"), | ||
" -f, --force " + chalk.dim("Run the generator forcefully"), | ||
"", | ||
chalk.dim(" ------------------------------------------------------"), | ||
chalk.dim(" ⚠ danger waits for those who venture below the line"), | ||
"", | ||
chalk.dim(" --plopfile Path to the plopfile"), | ||
chalk.dim( | ||
" --cwd Directory from which relative paths are calculated against while locating the plopfile" | ||
), | ||
chalk.dim( | ||
" --require String or array of modules to require before running plop" | ||
), | ||
chalk.dim( | ||
" --dest Output to this directory instead of the plopfile's parent directory" | ||
), | ||
"", | ||
chalk.bold("Examples:"), | ||
" $ " + chalk.blue("plop"), | ||
" $ " + chalk.blue("plop component"), | ||
" $ " + chalk.blue('plop component "name of component"'), | ||
"", | ||
].join("\n") | ||
); | ||
} | ||
function chooseOptionFromList(plopList, message) { | ||
const plop = nodePlop(); | ||
const generator = plop.setGenerator("choose", { | ||
prompts: [ | ||
{ | ||
type: "list", | ||
name: "generator", | ||
message: message || defaultChoosingMessage, | ||
choices: plopList.map(function (p) { | ||
return { | ||
name: | ||
p.name + chalk.gray(!!p.description ? " - " + p.description : ""), | ||
value: p.name, | ||
}; | ||
}), | ||
}, | ||
], | ||
}); | ||
return generator.runPrompts().then((results) => results.generator); | ||
} | ||
|
||
function createInitPlopfile(force = false) { | ||
var initString = | ||
"module.exports = function (plop) {\n\n" + | ||
"\tplop.setGenerator('basics', {\n" + | ||
"\t\tdescription: 'this is a skeleton plopfile',\n" + | ||
"\t\tprompts: [],\n" + | ||
"\t\tactions: []\n" + | ||
"\t});\n\n" + | ||
"};"; | ||
function displayHelpScreen() { | ||
console.log( | ||
[ | ||
"", | ||
chalk.bold("Usage:"), | ||
" $ plop " + | ||
chalk.dim("Select from a list of available generators"), | ||
" $ plop <name> " + | ||
chalk.dim("Run a generator registered under that name"), | ||
" $ plop <name> [input] " + | ||
chalk.dim("Run the generator with input data to bypass prompts"), | ||
"", | ||
chalk.bold("Options:"), | ||
" -h, --help " + chalk.dim("Show this help display"), | ||
" -t, --show-type-names " + | ||
chalk.dim("Show type names instead of abbreviations"), | ||
" -i, --init " + chalk.dim("Generate a basic plopfile.js"), | ||
" -v, --version " + chalk.dim("Print current version"), | ||
" -f, --force " + chalk.dim("Run the generator forcefully"), | ||
"", | ||
chalk.dim(" ------------------------------------------------------"), | ||
chalk.dim(" ⚠ danger waits for those who venture below the line"), | ||
"", | ||
chalk.dim(" --plopfile Path to the plopfile"), | ||
chalk.dim( | ||
" --cwd Directory from which relative paths are calculated against while locating the plopfile" | ||
), | ||
chalk.dim( | ||
" --require String or array of modules to require before running plop" | ||
), | ||
chalk.dim( | ||
" --dest Output to this directory instead of the plopfile's parent directory" | ||
), | ||
"", | ||
chalk.bold("Examples:"), | ||
" $ " + chalk.blue("plop"), | ||
" $ " + chalk.blue("plop component"), | ||
" $ " + chalk.blue('plop component "name of component"'), | ||
"", | ||
].join("\n") | ||
); | ||
} | ||
|
||
if (fs.existsSync(process.cwd() + "/plopfile.js") && force === false) { | ||
throw Error('"plopfile.js" already exists at this location.'); | ||
} | ||
function createInitPlopfile(force = false) { | ||
var initString = | ||
"module.exports = function (plop) {\n\n" + | ||
"\tplop.setGenerator('basics', {\n" + | ||
"\t\tdescription: 'this is a skeleton plopfile',\n" + | ||
"\t\tprompts: [],\n" + | ||
"\t\tactions: []\n" + | ||
"\t});\n\n" + | ||
"};"; | ||
|
||
fs.writeFileSync(process.cwd() + "/plopfile.js", initString); | ||
if (fs.existsSync(process.cwd() + "/plopfile.js") && force === false) { | ||
throw Error('"plopfile.js" already exists at this location.'); | ||
} | ||
|
||
const typeDisplay = { | ||
function: chalk.yellow("->"), | ||
add: chalk.green("++"), | ||
addMany: chalk.green("+!"), | ||
modify: `${chalk.green("+")}${chalk.red("-")}`, | ||
append: chalk.green("_+"), | ||
skip: chalk.green("--"), | ||
}; | ||
const typeMap = (name, noMap) => { | ||
const dimType = chalk.dim(name); | ||
return noMap ? dimType : typeDisplay[name] || dimType; | ||
}; | ||
fs.writeFileSync(process.cwd() + "/plopfile.js", initString); | ||
} | ||
|
||
const typeDisplay = { | ||
function: chalk.yellow("->"), | ||
add: chalk.green("++"), | ||
addMany: chalk.green("+!"), | ||
modify: `${chalk.green("+")}${chalk.red("-")}`, | ||
append: chalk.green("_+"), | ||
skip: chalk.green("--"), | ||
}; | ||
const typeMap = (name, noMap) => { | ||
const dimType = chalk.dim(name); | ||
return noMap ? dimType : typeDisplay[name] || dimType; | ||
}; | ||
|
||
return { | ||
chooseOptionFromList, | ||
displayHelpScreen, | ||
createInitPlopfile, | ||
typeMap, | ||
getHelpMessage, | ||
}; | ||
})(); | ||
export { | ||
chooseOptionFromList, | ||
displayHelpScreen, | ||
createInitPlopfile, | ||
typeMap, | ||
getHelpMessage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Liftoff = require("liftoff"); | ||
import * as Liftoff from "liftoff"; | ||
|
||
export { | ||
ActionConfig, | ||
|
Oops, something went wrong.