UNPKG

@pluginarch/create-parch

Version:

this is way to create a ui project

163 lines (162 loc) 4.48 kB
// src/cli.ts var import_utils = require("@umijs/utils"); var import_path = require("path"); var import_package = require("../package.json"); var cwd = process.cwd(); var { isCancel, text, select, intro, outro } = import_utils.clackPrompts; var DEFAULT_DATA = { projName: "parch-proj-demo", author: "", version: import_package.version, appTemplate: "app" /* app */ }; var initScaffoldFlows = async function(opt) { var _a; let appTemplate = ((_a = opt.defaultData) == null ? void 0 : _a.appTemplate) || "app" /* app */; let [name] = opt.args._; let target = name ? (0, import_path.join)(cwd, name) : cwd; const useDefaultData = !!opt.args.default; const setAppName = async function() { name = await text({ message: "What's the proj folder name?", initialValue: name || "my-app", validate: (value) => { if (!value.length) { return "Please input project name"; } if (value != "." && import_utils.fsExtra.existsSync((0, import_path.join)(cwd, value))) { return `Folder ${value} already exists`; } } }); }; const selectAppTemplate = async function() { appTemplate = await select({ message: "Pick Parch App Template", options: [ { label: "UI Design App", value: "app" /* app */, hint: "for ui design app development" }, { label: "Parch Material", value: "material" /* material */, hint: "for material development" }, { label: "Parch Plugin", value: "plugin" /* plugin */, hint: "for plugin development" } ], initialValue: "app" /* app */ }); }; const createTemplateFiles = async () => { const questions = [ { name: "name", type: "text", message: `Input NPM package name (eg: example-proj)` }, { name: "description", type: "text", message: `Input project description` }, { name: "author", type: "text", message: `Input project author (Name <email@example.com>)` } ]; console.log(`aaa:target:${target}`, `path:${(0, import_path.join)(__dirname, "..", "templates", appTemplate)}`); const generator = new import_utils.BaseGenerator({ path: (0, import_path.join)(__dirname, "..", "templates", appTemplate), target, slient: true, data: useDefaultData ? opt.defaultData : { version: import_package.version }, questions }); await generator.run(); }; const createUIPojTemp = async function() { }; const createPluginTemp = async function() { appTemplate = await select({ message: "Pick Runtimetime Plugin Template", options: [ { label: "Runtime Plugin", value: "runtimePlugin" /* runtimePlugin */, hint: "for Runtime Plugin development" }, { label: "Compile Plugin", value: "compilePlugin" /* compilePlugin */, hint: "for Compile Plugin development" } ], initialValue: "runtimePlugin" /* runtimePlugin */ }); }; const createRuntimePluginTemp = async function() { }; const createCompilePluginTemp = async function() { }; const createMaterialTemp = async function() { }; const exitPrompt = () => { outro(import_utils.chalk.red("Exit create-umi")); process.exit(1); }; await setAppName(); if (isCancel(name)) { exitPrompt(); } target = (0, import_path.join)(cwd, name); await selectAppTemplate(); if (isCancel(appTemplate)) { exitPrompt(); } debugger; switch (appTemplate) { case "app": console.log("create UI Project Template"); break; case "plugin": console.log("create Plugin Template"); await createPluginTemp(); break; case "material": console.log("create Material Template"); await createMaterialTemp(); break; default: console.warn("unkonwn Proj Type"); break; } await createTemplateFiles(); }; var run = async function({ cwd: cwd2, args: args2, defaultData = DEFAULT_DATA }) { await initScaffoldFlows({ defaultData, args: args2, cwd: cwd2 }); }; var args = (0, import_utils.yParser)(process.argv.slice(2), { alias: { version: ["v"], help: ["h"] }, boolean: ["version"] }); run({ cwd: process.cwd(), args }); //# sourceMappingURL=cli.js.map