ryuu.cli
Version:
Ryuu's Timesaver CLI
58 lines (51 loc) • 1.67 kB
JavaScript
const prompts = require("prompts");
const { red } = require("kolorist");
const { resolve, join } = require("path");
const { readdir, copyFile, mkdir } = require("fs").promises;
const FRAMEWORKS = [
{
value: 0,
name: "Next.js + Windi CSS",
},
{
value: 1,
name: "Next.js + Windi CSS + Nest.js",
},
];
const copyDirectory = async (src, dest) => {
const [entries] = await Promise.all([readdir(src, { withFileTypes: true }), mkdir(dest, { recursive: true })]);
await Promise.all(
entries.map((entry) => {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
return entry.isDirectory() ? copyDirectory(srcPath, destPath) : copyFile(srcPath, destPath);
})
);
};
async function init() {
console.log(red("\nThis will write to the current Directory."));
var result = await prompts([
{
type: "select",
name: "framework",
message: "Select a template",
initial: 0,
choices: FRAMEWORKS.map((framework) => {
return {
title: framework.name,
value: framework.value,
};
}),
},
]);
switch (result.framework) {
case 0:
await copyDirectory(resolve(`${__dirname}\\templates`, "nw"), ".");
break;
case 1:
await copyDirectory(resolve(`${__dirname}\\templates`, "nwn"), ".");
break;
}
}
init().catch((e) => console.error(e));