UNPKG

lun-cli

Version:

generator react component using cli

69 lines (61 loc) 3.12 kB
'use strict'; const cac = require('cac'); const controller_lun_controller = require('./shared/lun-cli.59895f3a.cjs'); const node_module = require('node:module'); const fs = require('node:fs'); const config_constants = require('./shared/lun-cli.bf48af4c.cjs'); require('picocolors'); require('node:path'); var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); 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 = config_constants.extsConfigFile.map((ext) => { const configPath = controller_lun_controller.getRootPath(`lun.config.${ext}`); return fs__default.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$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href))); options = require$1(configPath); } resolve(options); } else resolve(config_constants.defaultConfig); }); }; const cli = cac.cac(""); const lun = new controller_lun_controller.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();