imagination-gen
Version:
<img src="https://salvage.is-inside.me/SWZL7qgA.png" alt="Imagination-Gen" width="250" /><br>
58 lines (57 loc) • 1.85 kB
JavaScript
const FSE = require("fs-extra");
const PROMPTS = require("prompts");
const { fstat } = require("fs");
const { join } = require('path');
(async () => {
const PROMPT = await PROMPTS([
{
name: "PROJECT",
message: "Please specify the project type.",
type: "autocompleteMultiselect",
choices: FSE.readdirSync(join(__dirname, "templates")),
validate: (v) => (v == "" ? "Can't be blank" : true),
},
{
name: "NAME",
message: "Please specify the name of the project.",
type: "text",
validate: (v) => (v == "" ? "Can't be blank" : true),
},
]);
FSE.copySync(
// `./templates/${FSE.readdirSync(join(__dirname,'templates'))[PROMPT.PROJECT]}`,
// "./" + PROMPT.NAME,
join(__dirname, `templates`, FSE.readdirSync(join(__dirname, `templates`)[PROMPT.PROJECT])),
join(process.cwd(), PROMPT.NAME),
{
filter: function (src, dest) {
if (src.includes("node_modules")) return false;
else return true;
},
}
);
console.log("Writing to package.json...");
FSE.readdirSync(join(process.cwd(), PROMPT.NAME)).map((FILE) => {
if (FSE.lstatSync(join(process.cwd(), PROMPT.NAME, FILE)).isDirectory());
else {
FSE.writeFileSync(
join(process.cwd(), PROMPT.NAME, FILE),
FSE.readFileSync(join(process.cwd(), PROMPT.NAME, FILE))
.toString()
.replace(/{proj_name}/gi, PROMPT.NAME)
);
}
});
console.log("Installing modules...");
require("child_process").execSync(`cd ${PROMPT.NAME} && npm i`);
console.log(
`We did it! You just created your very own ${
FSE.readdirSync(join(__dirname, "templates"))[PROMPT.PROJECT]
}!`
);
console.log(
"We recommend you cd into your directory first: cd " + PROMPT.NAME
);
console.log("Happy hacking!");
})();