UNPKG

lun-cli

Version:

generator react component using cli

71 lines (64 loc) 2.81 kB
import { cac } from 'cac'; import { g as getRootPath, L as Lun } from './shared/lun-cli.298a6694.mjs'; import { createRequire } from 'node:module'; import fs from 'node:fs'; import { e as extsConfigFile, d as defaultConfig } from './shared/lun-cli.0e98a1df.mjs'; import 'picocolors'; import 'node:path'; // -- Unbuild CommonJS Shims -- import __cjs_url__ from 'url'; import __cjs_path__ from 'path'; import __cjs_mod__ from 'module'; const __filename = __cjs_url__.fileURLToPath(import.meta.url); const __dirname = __cjs_path__.dirname(__filename); const require = __cjs_mod__.createRequire(import.meta.url); const version = "3.0.0"; const VERSION = version; const TEXT_TEMPLATE_FLAG_DESCRIPTION = "[react | react-ts] > Can generate component using react with javascript or typescript"; const getOptions = () => { return new Promise(async (resolve) => { const searchingFile = extsConfigFile.map((ext) => { const configPath = getRootPath(`lun.config.${ext}`); return fs.existsSync(configPath) ? configPath : false; }); if (searchingFile.some((cond) => typeof cond === "string")) { const configPath = searchingFile.find((cond) => typeof cond === "string"); let options; if (configPath.includes(".mjs")) { options = (await import(configPath)).default; } if (configPath.includes(".cjs")) { const require = createRequire(import.meta.url); options = require(configPath); } resolve(options); } else resolve(defaultConfig); }); }; const cli = cac(""); const lun = new Lun(); cli.command("generate-component [componentName]", "command for generate component").alias("gc").option("-t, --template <template>", TEXT_TEMPLATE_FLAG_DESCRIPTION).action(async (...options) => { const [componentName, args] = options; const { t: type } = args ?? {}; const optionsLunConfig = await getOptions(); lun.setOptions(optionsLunConfig); lun.createComponent({ componentName, type }); }); cli.command("generate-page [pageName]", "command for generate component type page").alias("gp").option("-t, --template <template>", TEXT_TEMPLATE_FLAG_DESCRIPTION).action(async (...options) => { const [pageName, args] = options; const { t: type } = args ?? {}; const optionsLunConfig = await getOptions(); lun.setOptions(optionsLunConfig); lun.createPage({ pageName, type }); }); cli.command("generate-context [contextName]", "command for generate context").alias("gctx").option("-t, --template <template>", TEXT_TEMPLATE_FLAG_DESCRIPTION).action(async (...options) => { const [contextName, args] = options; const { t: type } = args ?? {}; const optionsLunConfig = await getOptions(); lun.setOptions(optionsLunConfig); lun.createContext({ contextName, type }); }); cli.help(); cli.version(VERSION); cli.parse();