UNPKG

vue3-structure-builder

Version:

`vue3-structure-builder` is a tool that helps developers quickly generate a modular and scalable file structure for Vue 3 projects. By defining a module structure in a `schema.js` file, this tool automatically generates directories, components, pages, sto

1 lines 10.8 kB
{"version":3,"file":"index.cjs","sources":["../../src/midelware/generateConfigs.js","../../src/index.js","../../src/midelware/checkModuleDir.js"],"sourcesContent":["import { createVueFile } from \"./check-type.js\";\nimport fs from \"fs\"\nimport Path from \"path\";\nexport const generateCongigs = (moduleList , is_i18n) => {\n const srcPath = Path.join(process.cwd(), 'src')\n const routeDirPath = Path.join(srcPath, 'router')\n if (fs.existsSync(routeDirPath)) {\n console.log(`mian Router directory is created`);\n } else {\n fs.mkdirSync(routeDirPath, { recursive: true });\n }\n const routerPath = Path.join(process.cwd(), 'src/router/index.ts');\n createVueFile(routerPath, \"router-config\", `name`, moduleList);\n const protectRouterPath = Path.join(process.cwd(), 'src/router/guards.ts');\n createVueFile(protectRouterPath, \"router-guards\", `name`, moduleList);\n if (is_i18n){\n console.log(\"process.cwd()>>>>>>>\" , process.cwd());\n const i18nDirPath = Path.join(srcPath, 'i18n');\n fs.mkdirSync(i18nDirPath, { recursive: true });\n const localsDirPath = Path.join(i18nDirPath, 'locales')\n fs.mkdirSync( localsDirPath, { recursive: true });\n const configFilePath = Path.join(i18nDirPath, 'index.ts');\n createVueFile(configFilePath, \"i18n_conf\", `index`);\n const enFilePath = Path.join(localsDirPath, 'en.ts')\n const arFilePath = Path.join(localsDirPath, 'ar.ts')\n createVueFile( enFilePath, \"i18n\", `en.ts`);\n createVueFile( arFilePath, \"i18n\", `ar.ts`);\n // process.chdir('../../')\n }\n}","import fs from 'fs';\nimport Path from 'path';\nimport { fileURLToPath } from 'url';\n// import schema from \"../../../moduels-schema/schema.js\"\nimport { createVueFile } from \"./midelware/check-type.js\"\nimport { generateCongigs } from './midelware/generateConfigs.js';\nimport { checkModulesDir } from './midelware/checkModuleDir.js';\n// import { integrateRoute } from './midelware/integrate-route.js';\n// \n// congigs\nconst args = process.argv.slice(2);\nlet path = args[0] && !args[0].includes('-i18n') ? args[0] : './src';\nlet i18n_config = args.includes('-i18n')\n//////////////////////////////////////\n/**\n * method create fils .\n * @param strList - array : structure list .\n * @param path - path will start from it to extract directorys and files for structure \n */\n let createdConfig = true;\n function createVueProject(strList, path) {\n // check modules dir is found, if not found will create dir for modules\n if (createdConfig) {\n checkModulesDir(path);\n generateCongigs(strList ,i18n_config );\n createdConfig = false\n }\n // create cofig (i18n , router & guards)\n /////////////////////////////////////////////\n // // : Move into the project directory\n // /////////////////////////////////////////\n process.chdir(`${path}/modules`);\n for (let i = 0; i < strList.length; i++) {\n fs.mkdirSync(`${strList[i].name}`); // Create a directory \n fs.mkdirSync(`${strList[i].name}/components`); // Create a components directory inside module\n fs.mkdirSync(`${strList[i].name}/pages`); // Create a pages directory inside module\n \n // get curent path\n const viewsDir = Path.join(process.cwd(), `${strList[i].name}`);\n // ///////////////////////\n // create component files\n //////////////////////////\n for (let j = 0; j < strList[i].components.length; j++) {\n const componentFilePath = Path.join(viewsDir, `components/${strList[i].components[j]}.vue`);\n createVueFile(componentFilePath, \"component\", strList[i].name);\n\n }\n // //////////////////\n // create page files\n //////////////////////\n if(strList[i]?.page?.length){\n console.log(strList[i]?.page?.length);\n for (let j = 0; j < strList[i]?.page.length; j++) {\n let componentFilePath = Path.join(viewsDir, `pages/${strList[i].page[j]}.vue`);\n createVueFile(componentFilePath, \"page\", strList[i].page[j] , strList[i]);\n }\n }\n // ///////////////////\n // check if has layout\n //////////////////////\n if (strList[i].layout) {\n fs.mkdirSync(`${strList[i].name}/layout`); // Create a layout directory\n const componentFilePath = Path.join(viewsDir, 'layout/index.vue');\n createVueFile(componentFilePath, \"layout\", strList[i].name);\n }\n // if(strList[i].layout || strList[i].children || strList[i].page ){\n const roterFilePath = Path.join(viewsDir, 'routes.tsx');\n createVueFile(roterFilePath, \"route\", `${strList[i].name}` , strList[i]);\n // }\n ///////////////////////////////////////////////////////////////////////////////\n // check if has store (pina) note: in future => user will chooise pinia or vuex\n ///////////////////////////////////////////////////////////////////////////////\n if (strList[i].store) {\n fs.mkdirSync(`${strList[i].name}/store`); // Create a store directory\n const componentFilePath = Path.join(viewsDir, 'store/index.ts');\n createVueFile(componentFilePath, \"store\", strList[i].name); // Create a store file\n }\n /////////////////////////\n // check if has children\n ////////////////////////\n if (strList[i].children) {\n fs.mkdirSync(`${strList[i].name}/modules`); // Create a module directory\n createVueProject(strList[i].children, `${strList[i].name}`);\n // setTimeout(() => {\n // console.log(\"viewsDir>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\" ,viewsDir);\n // integrateRoute(strList[i].name,`${viewsDir}`);\n // }, 1000);\n // integrateRoute(strList[i].name,viewsDir);\n process.chdir(\"../../\"); // back to parent path\n }\n }\n console.log('Project created successfully with the custom file structure!');\n // console.log(stucture);\n\n}\n// ------------------------------------\n// Dynamic import (optional schema.js)\n// ------------------------------------\n// let schema;\n\n// try {\n// schema = (await import(new URL(\"../../schema.js\", import.meta.url).href)).default;\n// createVueProject(schema, path);\n// } catch (err) {\n// console.warn(\"⚠️ schema.js not found. Please add the file manually in '../../schema.js'.\");\n// }\n// // start \n\n// if (fs.existsSync(schema)) {\n// createVueProject(schema, path);\n// } \n// const __filename = fileURLToPath(import.meta.url); // Get the current file path\n// const __dirname = Path.dirname(__filename); // Get the directory name\n\nlet schema;\n // const srcPath = Path.join(process.cwd(), initpath);\n // const modulesPath = Path.join(srcPath, 'modules')\nconst schemaPath = Path.join(process.cwd(), \"schema.js\");\n\nif (fs.existsSync(schemaPath)) {\n try {\n schema = (await import(schemaPath)).default;\n createVueProject(schema, path);\n } catch (err) {\n console.error(\"❌ Error importing schema.js:\", err);\n }\n} else {\n console.log(\"schemaPath => \", schemaPath);\n console.warn(\"⚠️ schema.js not found. Please add the file manually schema.js in root directory.\");\n}\n","import Path from \"path\";\nimport fs from \"fs\"\nexport const checkModulesDir = (initpath) => {\n const srcPath = Path.join(process.cwd(), initpath);\n const modulesPath = Path.join(srcPath, 'modules')\n if (!fs.existsSync(modulesPath)) {\n fs.mkdirSync(modulesPath, { recursive: true });\n } else {\n console.log(\"Main module dir directory already exists\");\n }\n}"],"names":["args","process","argv","slice","schema","path","includes","i18n_config","createdConfig","schemaPath","Path","join","cwd","fs","existsSync","import","default","createVueProject","strList","initpath","srcPath","modulesPath","console","log","mkdirSync","recursive","checkModulesDir","moduleList","is_i18n","routeDirPath","routerPath","createVueFile","protectRouterPath","i18nDirPath","localsDirPath","configFilePath","enFilePath","arFilePath","generateCongigs","chdir","i","length","name","viewsDir","j","components","componentFilePath","page","layout","roterFilePath","store","children","err","error","warn"],"mappings":"gGAGO,MCODA,EAAOC,QAAQC,KAAKC,MAAM,GAChC,IAuGIC,EAvGAC,EAAOL,EAAK,KAAOA,EAAK,GAAGM,SAAS,SAAYN,EAAK,GAAK,QAC1DO,EAAcP,EAAKM,SAAS,SAO3BE,GAAgB,EAkGrB,MAAMC,EAAaC,EAAKC,KAAKV,QAAQW,MAAO,aAE5C,GAAIC,EAAGC,WAAWL,GAChB,IACEL,SAAgBW,OAAON,IAAaO,QArGvC,SAASC,EAAiBC,EAASb,GAE9BG,ICpByB,CAACW,IAC5B,MAAMC,EAAUV,EAAKC,KAAKV,QAAQW,MAAOO,GACnCE,EAAcX,EAAKC,KAAKS,EAAS,WAClCP,EAAGC,WAAWO,GAGfC,QAAQC,IAAI,4CAFZV,EAAGW,UAAUH,EAAa,CAAEI,WAAW,GAG1C,EDcDC,CAAgBrB,GDpBW,EAACsB,EAAaC,KACzC,MAAMR,EAAUV,EAAKC,KAAKV,QAAQW,MAAO,OACnCiB,EAAenB,EAAKC,KAAKS,EAAS,UACpCP,EAAGC,WAAWe,GACdP,QAAQC,IAAI,oCAEZV,EAAGW,UAAUK,EAAc,CAAEJ,WAAW,IAE5C,MAAMK,EAAapB,EAAKC,KAAKV,QAAQW,MAAO,uBAC5CmB,EAAcD,EAAY,gBAAiB,OAAQH,GACnD,MAAMK,EAAoB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