import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import select from "@inquirer/select"; import { Command } from "commander"; import nodePlop, { type PlopGenerator } from "node-plop"; import { type Answers, type InitOptions, type LoaderOptions, type PluginOptions } from "./types.js"; import { logger, onFailureHandler, onSuccessHandler } from "./utils/logger.js"; const __dirname = dirname(fileURLToPath(import.meta.url)); const program = new Command(); const plop = await nodePlop(resolve(__dirname, "./plopfile.js")); const baseAnswers: Answers = { projectPath: process.cwd(), langType: "none", devServer: true, workboxWebpackPlugin: true, cssTool: "none", tsCompiler: "built-in", packageManager: "npm", }; const initValues: Record = { default: { ...baseAnswers, }, react: { ...baseAnswers, langType: "ES6", useReactState: true, }, vue: { ...baseAnswers, langType: "ES6", useVueStore: true, }, svelte: { ...baseAnswers, langType: "ES6", }, }; const initGenerators: Record = { default: plop.getGenerator("init-default"), react: plop.getGenerator("init-react"), vue: plop.getGenerator("init-vue"), svelte: plop.getGenerator("init-svelte"), }; const loaderGenerators: Record = { default: plop.getGenerator("loader-default"), }; const pluginGenerators: Record = { default: plop.getGenerator("plugin-default"), }; program .usage("[command] [options]") .helpOption("-h, --help", "Display help for command") .description("A CLI tool to generate a Webpack project"); program .command("init", { isDefault: true }) .aliases(["i", "n", "c", "create", "new"]) .description("Initialize a new Webpack project") .argument("[projectPath]", "Path to create the project") .option("-f, --force", "Skip the prompt and use the default values", false) .option("-t --template