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

3 lines (2 loc) 2.33 kB
import e from"fs";import o from"path";import"url";import{c as n}from"../check-type-0a835837.js";const s=process.argv.slice(2);let c,r=s[0]&&!s[0].includes("-i18n")?s[0]:"./src",t=s.includes("-i18n"),i=!0;const a=o.join(process.cwd(),"schema.js");if(e.existsSync(a))try{c=(await import(a)).default,function s(c,r){i&&((n=>{const s=o.join(process.cwd(),n),c=o.join(s,"modules");e.existsSync(c)?console.log("Main module dir directory already exists"):e.mkdirSync(c,{recursive:!0})})(r),((s,c)=>{const r=o.join(process.cwd(),"src"),t=o.join(r,"router");e.existsSync(t)?console.log("mian Router directory is created"):e.mkdirSync(t,{recursive:!0});const i=o.join(process.cwd(),"src/router/index.ts");n(i,"router-config","name",s);const a=o.join(process.cwd(),"src/router/guards.ts");if(n(a,"router-guards","name",s),c){console.log("process.cwd()>>>>>>>",process.cwd());const s=o.join(r,"i18n");e.mkdirSync(s,{recursive:!0});const c=o.join(s,"locales");e.mkdirSync(c,{recursive:!0});const t=o.join(s,"index.ts");n(t,"i18n_conf","index");const i=o.join(c,"en.ts"),a=o.join(c,"ar.ts");n(i,"i18n","en.ts"),n(a,"i18n","ar.ts")}})(c,t),i=!1),process.chdir(`${r}/modules`);for(let r=0;r<c.length;r++){e.mkdirSync(`${c[r].name}`),e.mkdirSync(`${c[r].name}/components`),e.mkdirSync(`${c[r].name}/pages`);const t=o.join(process.cwd(),`${c[r].name}`);for(let e=0;e<c[r].components.length;e++){const s=o.join(t,`components/${c[r].components[e]}.vue`);n(s,"component",c[r].name)}if(c[r]?.page?.length){console.log(c[r]?.page?.length);for(let e=0;e<c[r]?.page.length;e++){let s=o.join(t,`pages/${c[r].page[e]}.vue`);n(s,"page",c[r].page[e],c[r])}}if(c[r].layout){e.mkdirSync(`${c[r].name}/layout`);const s=o.join(t,"layout/index.vue");n(s,"layout",c[r].name)}const i=o.join(t,"routes.tsx");if(n(i,"route",`${c[r].name}`,c[r]),c[r].store){e.mkdirSync(`${c[r].name}/store`);const s=o.join(t,"store/index.ts");n(s,"store",c[r].name)}c[r].children&&(e.mkdirSync(`${c[r].name}/modules`),s(c[r].children,`${c[r].name}`),process.chdir("../../"))}console.log("Project created successfully with the custom file structure!")}(c,r)}catch(e){console.error("❌ Error importing schema.js:",e)}else console.log("schemaPath => ",a),console.warn("⚠️ schema.js not found. Please add the file manually schema.js in root directory."); //# sourceMappingURL=index.js.map