pwa-create
Version:
A progressive web app stater template creator with various platform options
93 lines (92 loc) • 2.35 kB
JavaScript
// src/index.ts
import chalk from "chalk";
import prompts from "prompts";
import degit from "degit";
import { log } from "console";
import { execa } from "execa";
var questions = [
{
type: "text",
name: "projectName",
message: "What is your project/app name?",
initial: "my-app"
},
{
type: "select",
name: "framework",
message: "Choose a framework",
instructions: false,
onRender(kleur) {
this.message = kleur.red("Choose a framework");
},
choices: [
{ title: "Vanilla HTML", value: "vanilla-html" },
{ title: "React (Typescript)", value: "react-typescript" },
{ title: "React (Javascript)", value: "react-javascript" }
]
},
{
type: "confirm",
name: "installDependencies",
message: "Install project dependencies after initialize project?",
initial: true
},
{
type: (p) => p == true ? "select" : null,
name: "packageManager",
message: "Select a package manager",
choices: [
{
title: "npm",
value: "npm"
},
{
title: "pnpm",
value: "pnpm"
},
{
title: "yarn",
value: "yarn"
},
{
title: "bun",
value: "bun"
}
]
}
];
async function main() {
const response = await prompts(questions, {
onCancel(prompt) {
console.log(chalk.red(prompt.message));
console.log(chalk.red("\u274C pwa-create canceled \u{1F622}"));
}
});
const temp = `devusimple/pwa-create/templates/${response.framework}`;
const emitter = degit(temp, { force: true });
log(
chalk.green(`
\u{1F503} Scaffolding project into ./${response.projectName}...`)
);
await emitter.clone(response.projectName);
if (response.installDependencies) {
process.chdir(response.projectName);
log(chalk.cyan("\n\u{1F4E6} Installing dependencies...\n"));
await execa`${response.packageManager} install`;
log(chalk.green(`\u2705 Project "${response.projectName}" ready!`));
} else {
log(chalk.yellow("Done \u2705 now\n"));
log(
chalk.green(`
+---------------------------+
$ cd ${response.projectName}
$ ${response.packageManager} install
+---------------------------+
`)
);
}
}
main().catch((r) => {
console.error(r);
process.exit(1);
});