@arc-js/initiator 0.0.82 → 0.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -194739,7 +194739,7 @@ class ConfigGenerator {
194739
194739
  const relative = path.relative(outputDir, targetPath);
194740
194740
  let importPath = relative.replace(/\\/g, '/');
194741
194741
  if (!importPath.startsWith('.') && !importPath.startsWith('/')) {
194742
- importPath = './' + importPath;
194742
+ importPath = '@/' + importPath;
194743
194743
  }
194744
194744
  return importPath;
194745
194745
  }
@@ -195182,7 +195182,7 @@ class RouteGenerator {
195182
195182
  lastModuleName = route.moduleName;
195183
195183
  }
195184
195184
  const routeLines = [' {'];
195185
- routeLines.push(` path: '${route.routePath}',`);
195185
+ routeLines.push(` path: '${route.routePath.replace(/\{([^}]+)\}/g, ':$1')}',`);
195186
195186
  let layoutComponent = route.layoutComponent;
195187
195187
  if (!layoutComponent && route.moduleName) {
195188
195188
  const moduleLayoutPath = path.join(this.config.modulesDir, route.moduleName, 'pages', `${this.config.layoutFileName}.tsx`);
@@ -195230,7 +195230,7 @@ class RouteGenerator {
195230
195230
  }
195231
195231
  routes.push(`,`);
195232
195232
  routes.push(` {`);
195233
- routes.push(` path: '/${moduleName}/*',`);
195233
+ routes.push(` path: '/${moduleName}/*',`.replace(/\{([^}]+)\}/g, ':$1'));
195234
195234
  routes.push(` element: <${componentName} />`);
195235
195235
  routes.push(` }`);
195236
195236
  }
@@ -195243,7 +195243,7 @@ class RouteGenerator {
195243
195243
  }
195244
195244
  routes.push(`,`);
195245
195245
  routes.push(` {`);
195246
- routes.push(` path: '*',`);
195246
+ routes.push(` path: '*',`.replace(/\{([^}]+)\}/g, ':$1'));
195247
195247
  routes.push(` element: <NotFound />`);
195248
195248
  routes.push(` }`);
195249
195249
  }
package/index.min.js CHANGED
@@ -376,7 +376,7 @@ ${e}
376
376
  }
377
377
  };
378
378
 
379
- export default translations;`}generateTypeDefinitions(){if(0===this.keys.length)return"string";let r={};return this.keys.forEach(e=>{var t=e.module||"core";r[t]||(r[t]=[]),r[t].push(e.key)}),Object.entries(r).map(([e,t])=>{t=t.filter((e,t,r)=>r.indexOf(e)===t).map(e=>`"${e}"`).join(" | ");return"core"===e?t:e+":"+t}).join(" | ")}}function TranslationInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$3){new TranslationGenerator({},e).generate().then(()=>{}).catch(e=>{})})}let __filename$2=url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("index.js",document.baseURI).href),__dirname$2=path.dirname(__filename$2);class ConfigGenerator{constructor(e={},t=__dirname$2){this.modules=new Set,this.config={srcDir:e.srcDir||pajoExports.Pajo.join(t,"src")||"",outputFile:e.outputFile||pajoExports.Pajo.join(t,"src\\auto-config.ts")||"",modulesDir:e.modulesDir||pajoExports.Pajo.join(t,"src\\modules")||"",rootConfigPath:e.rootConfigPath||pajoExports.Pajo.join(t,"src\\config.json")||"",projectRoot:e.projectRoot||t||""}}generate(){return __awaiter(this,void 0,void 0,function*(){yield this.discoverModules(),yield this.generateAutoConfigFile()})}discoverModules(){return __awaiter(this,void 0,void 0,function*(){try{var e;if(fs.existsSync(this.config.modulesDir))for(e of fs.readdirSync(this.config.modulesDir,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)){var t=path.join(this.config.modulesDir,e,"config.json");fs.existsSync(t)&&this.modules.add(e)}}catch(e){}})}generateAutoConfigFile(){return __awaiter(this,void 0,void 0,function*(){var e=path.dirname(this.config.outputFile),e=(fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),this.generateFileContent());fs.writeFileSync(this.config.outputFile,e,"utf-8")})}getRelativeImportPath(e){var t=path.dirname(this.config.outputFile);let r=path.relative(t,e).replace(/\\/g,"/");return r=r.startsWith(".")||r.startsWith("/")?r:"./"+r}generateFileContent(){let{rootConfigPath:e,modulesDir:r}=this.config;var t=Array.from(this.modules).sort(),n=fs.existsSync(e),i=n?this.getRelativeImportPath(e):null,n=n&&i?` 'app': (() => import('${i}').then(module => module.default || module))`:" 'app': (() => Promise.resolve({}))",i=t.map(e=>{var t=path.join(r,e,"config.json");return fs.existsSync(t)?` '${e}': (() => import('${this.getRelativeImportPath(t)}').then(module => module.default || module))`:` '${e}': (() => Promise.resolve({}))`}).join(",\n");return`export const configs = {
379
+ export default translations;`}generateTypeDefinitions(){if(0===this.keys.length)return"string";let r={};return this.keys.forEach(e=>{var t=e.module||"core";r[t]||(r[t]=[]),r[t].push(e.key)}),Object.entries(r).map(([e,t])=>{t=t.filter((e,t,r)=>r.indexOf(e)===t).map(e=>`"${e}"`).join(" | ");return"core"===e?t:e+":"+t}).join(" | ")}}function TranslationInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$3){new TranslationGenerator({},e).generate().then(()=>{}).catch(e=>{})})}let __filename$2=url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("index.js",document.baseURI).href),__dirname$2=path.dirname(__filename$2);class ConfigGenerator{constructor(e={},t=__dirname$2){this.modules=new Set,this.config={srcDir:e.srcDir||pajoExports.Pajo.join(t,"src")||"",outputFile:e.outputFile||pajoExports.Pajo.join(t,"src\\auto-config.ts")||"",modulesDir:e.modulesDir||pajoExports.Pajo.join(t,"src\\modules")||"",rootConfigPath:e.rootConfigPath||pajoExports.Pajo.join(t,"src\\config.json")||"",projectRoot:e.projectRoot||t||""}}generate(){return __awaiter(this,void 0,void 0,function*(){yield this.discoverModules(),yield this.generateAutoConfigFile()})}discoverModules(){return __awaiter(this,void 0,void 0,function*(){try{var e;if(fs.existsSync(this.config.modulesDir))for(e of fs.readdirSync(this.config.modulesDir,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)){var t=path.join(this.config.modulesDir,e,"config.json");fs.existsSync(t)&&this.modules.add(e)}}catch(e){}})}generateAutoConfigFile(){return __awaiter(this,void 0,void 0,function*(){var e=path.dirname(this.config.outputFile),e=(fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),this.generateFileContent());fs.writeFileSync(this.config.outputFile,e,"utf-8")})}getRelativeImportPath(e){var t=path.dirname(this.config.outputFile);let r=path.relative(t,e).replace(/\\/g,"/");return r=r.startsWith(".")||r.startsWith("/")?r:"@/"+r}generateFileContent(){let{rootConfigPath:e,modulesDir:r}=this.config;var t=Array.from(this.modules).sort(),n=fs.existsSync(e),i=n?this.getRelativeImportPath(e):null,n=n&&i?` 'app': (() => import('${i}').then(module => module.default || module))`:" 'app': (() => Promise.resolve({}))",i=t.map(e=>{var t=path.join(r,e,"config.json");return fs.existsSync(t)?` '${e}': (() => import('${this.getRelativeImportPath(t)}').then(module => module.default || module))`:` '${e}': (() => Promise.resolve({}))`}).join(",\n");return`export const configs = {
380
380
  'base': {
381
381
  ${n}
382
382
  },
@@ -385,5 +385,5 @@ ${0<i.length?i:" // No modules with config.json found"}
385
385
  }
386
386
  };
387
387
 
388
- export default configs;`}}function ConfigInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$2){new ConfigGenerator({},e).generate().then(()=>{}).catch(e=>{})})}let __filename$1=url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("index.js",document.baseURI).href),__dirname$1=path.dirname(__filename$1);class RouteGenerator{constructor(e={},t=__dirname$1){this.routeFiles=[],this.modules=new Set,this.config={srcDir:e.srcDir||pajoExports.Pajo.join(t,"src")||"",modulesDir:e.modulesDir||pajoExports.Pajo.join(t,"src\\modules")||"",pagesDir:e.pagesDir||pajoExports.Pajo.join(t,"src\\pages")||"",outputFile:e.outputFile||pajoExports.Pajo.join(t,"src\\auto-routes.tsx")||"",layoutFileName:e.layoutFileName||"_layout",errorFileName:e.errorFileName||"_error",notFoundFileName:e.notFoundFileName||"_404"}}generate(){return __awaiter(this,void 0,void 0,function*(){yield this.findRouteFiles(),yield this.generateAutoRoutesFile()})}findRouteFiles(){return __awaiter(this,void 0,void 0,function*(){var e;if(this.routeFiles=[],yield this.scanDirectoryForRoutes(this.config.pagesDir),fs.existsSync(this.config.modulesDir))for(e of fs.readdirSync(this.config.modulesDir,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)){var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&(this.modules.add(e),yield this.scanDirectoryForRoutes(t,e))}})}scanDirectoryForRoutes(i,a){return __awaiter(this,void 0,void 0,function*(){try{var e;for(e of fs.readdirSync(i,{withFileTypes:!0})){var t,r,n=path.join(i,e.name);"node_modules"===e.name||"dist"===e.name||"build"===e.name||e.name.startsWith(".")||(e.isDirectory()?yield this.scanDirectoryForRoutes(n,a):e.isFile()&&(t=path.extname(e.name).toLowerCase(),[".tsx",".jsx"].includes(t))&&(r=path.basename(e.name,t))!==this.config.layoutFileName&&r!==this.config.errorFileName&&r!==this.config.notFoundFileName&&(yield this.processRouteFile(n,a)))}}catch(e){}})}processRouteFile(o,s){return __awaiter(this,void 0,void 0,function*(){try{var e=this.convertFilePathToRoutePath(o,s),t=this.extractComponentName(o,s),r=this.findLayoutComponent(o,s),n=this.findErrorComponent(o,s),i=this.findNotFoundComponent(o,s),a={filePath:o,relativePath:path.relative(this.config.srcDir,o),routePath:e,componentName:t,layoutComponent:r,errorComponent:n,notFoundComponent:i,moduleName:s};this.routeFiles.push(a)}catch(e){}})}convertFilePathToRoutePath(e,t){let r=e;return r=r.replace(this.config.srcDir,""),t?(e=`modules${path.sep}${t}${path.sep}pages`,r.includes(e)&&(r="/"+t+(r=r.substring(r.indexOf(e)+e.length)))):r.includes("pages")&&(r=r.substring(r.indexOf("pages")+"pages".length)),"/"===(r=(r=(r=(r=(r=r.replace(/\.(tsx|jsx)$/,"")).replace(/\\/g,"/")).endsWith("/index")?r.replace(/\/index$/,""):r).replace(/\[([^\]]+)\]/g,"{$1}")).startsWith("/")?r:"/"+r)||"//"===r?"/":r}extractComponentName(e,t){var r=path.basename(e,path.extname(e)),e=path.dirname(e).split(path.sep);let i=0;if(t){let n=path.sep+"modules"+path.sep+t+path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}else{let n=path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}i<0&&(i=0);e=e.slice(i);let n=t?this.toPascalCase(t):"",a=(e.forEach(e=>{e&&"pages"!==e&&(n+=this.toPascalCase(e))}),r);(a=r.startsWith("{")&&r.endsWith("}")?(t=r.substring(1,r.length-1),this.toPascalCase(t)+"Params"):this.toPascalCase(r)).endsWith("Page")||(a+="Page");return["Layout","ErrorBoundary","NotFound"].includes(a)&&(a+="Component"),n+a}toPascalCase(e){return e?e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(""):""}findLayoutComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.layoutFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"Layout");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx");if(fs.existsSync(e))return"Layout"}findErrorComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.errorFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"ErrorBoundary");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.errorFileName+".tsx");if(fs.existsSync(e))return"ErrorBoundary"}findNotFoundComponent(e,t){var r;if(t)return r=path.join(this.config.modulesDir,t,"pages"),r=path.join(r,this.config.notFoundFileName+".tsx"),fs.existsSync(r)?this.generateComponentName(r,t,"NotFound"):void 0}generateComponentName(e,t,r){if(!t)return r;var n=path.basename(e,path.extname(e)),e=path.dirname(e),i=path.join(this.config.modulesDir,t,"pages"),i=path.relative(i,e);let a=this.toPascalCase(t);return i&&"."!==i&&i.split(path.sep).filter(e=>e&&"."!==e).forEach(e=>{a+=this.toPascalCase(e)}),n!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName&&(a+=this.toPascalCase(n)),a+r}generateAutoRoutesFile(){return __awaiter(this,void 0,void 0,function*(){var e=path.dirname(this.config.outputFile),e=(fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),this.generateFileContent());fs.writeFileSync(this.config.outputFile,e,"utf-8")})}getRelativeImportPath(e){var t=path.dirname(this.config.outputFile);let r=path.relative(t,e).replace(/\\/g,"/");return r=(r=r.startsWith(".")||r.startsWith("/")?r:"./"+r).replace(/\.(tsx|jsx)$/,"")}generateFileContent(){let c=new Set,r=["import { lazy } from 'react';","import type { RouteObject } from 'react-router-dom';",""];var e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx"),t=path.join(this.config.pagesDir,this.config.errorFileName+".tsx"),n=path.join(this.config.pagesDir,this.config.notFoundFileName+".tsx");fs.existsSync(e)&&(e=this.getRelativeImportPath(e),r.push(`const Layout = lazy(() => import('${e}'));`),c.add("Layout")),fs.existsSync(t)&&(e=this.getRelativeImportPath(t),r.push(`const ErrorBoundary = lazy(() => import('${e}'));`),c.add("ErrorBoundary")),fs.existsSync(n)&&(t=this.getRelativeImportPath(n),r.push(`const NotFound = lazy(() => import('${t}'));`),c.add("NotFound")),r.push("");let l=new Map,i=(e,t=0,s)=>{if(fs.existsSync(e)){let o=e=>{try{var t;for(t of fs.readdirSync(e,{withFileTypes:!0})){var r,n,i,a=path.join(e,t.name);t.isDirectory()?o(a):t.isFile()&&(r=path.extname(t.name).toLowerCase(),![".tsx",".jsx"].includes(r)||(n=path.basename(t.name,r))!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName||(i=this.generateComponentName(a,s,n===this.config.layoutFileName?"Layout":n===this.config.errorFileName?"ErrorBoundary":"NotFound"),c.has(i))||(l.set(a,i),c.add(i)))}}catch(e){}};o(e)}},o=(i(this.config.pagesDir,!1),this.modules.forEach(e=>{var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&i(t,!0,e)}),l.forEach((e,t)=>{t=this.getRelativeImportPath(t);r.push(`const ${e} = lazy(() => import('${t}'));`)}),0<l.size&&r.push(""),this.routeFiles.forEach(e=>{var t=this.getRelativeImportPath(e.filePath);r.push(`const ${e.componentName} = lazy(() => import('${t}'));`),c.add(e.componentName)}),r.push(""),["export const routes: RouteObject[] = ["]),s=this.routeFiles.sort((e,t)=>"/"===e.routePath?-1:"/"===t.routePath?1:!e.moduleName&&t.moduleName?-1:e.moduleName&&!t.moduleName?1:e.moduleName===t.moduleName?e.routePath.localeCompare(t.routePath):0),_=void 0,a=(s.forEach((e,t)=>{e.moduleName!==_&&(void 0!==_&&o.push(""),e.moduleName&&o.push(` // ${e.moduleName} module routes`),_=e.moduleName);var r,n=[" {"];n.push(` path: '${e.routePath}',`);let i=e.layoutComponent,a=((i=!i&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.layoutFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"Layout"):i)?n.push(` element: <${i}><${e.componentName} /></${i}>,`):n.push(` element: <${e.componentName} />,`),e.errorComponent);(a=!a&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.errorFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"ErrorBoundary"):a)&&n.push(` errorElement: <${a} />`),n[n.length-1].endsWith(",")&&(n[n.length-1]=n[n.length-1].slice(0,-1)),n.push(" }"),t<s.length-1&&(n[n.length-1]+=","),o.push(n.join("\n"))}),new Set);return l.forEach((e,t)=>{var r;path.basename(t,path.extname(t))===this.config.notFoundFileName&&-1!==(r=(t=t.split(path.sep)).indexOf("modules"))&&r+1<t.length&&(t=t[r+1],a.has(t)||(a.add(t),o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(` path: '/${t}/*',`),o.push(` element: <${e} />`),o.push(" }")))}),c.has("NotFound")&&(o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(" path: '*',"),o.push(" element: <NotFound />"),o.push(" }")),o.push("];"),o.push(""),o.push("export default routes;"),[...r,"",...o].join("\n")}}function RouteInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$1){e=new RouteGenerator({},e);try{yield e.generate()}catch(e){}})}function index(e=__dirname){TranslationInitiator(e),ConfigInitiator(e),RouteInitiator(e)}module.exports=index;
388
+ export default configs;`}}function ConfigInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$2){new ConfigGenerator({},e).generate().then(()=>{}).catch(e=>{})})}let __filename$1=url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("index.js",document.baseURI).href),__dirname$1=path.dirname(__filename$1);class RouteGenerator{constructor(e={},t=__dirname$1){this.routeFiles=[],this.modules=new Set,this.config={srcDir:e.srcDir||pajoExports.Pajo.join(t,"src")||"",modulesDir:e.modulesDir||pajoExports.Pajo.join(t,"src\\modules")||"",pagesDir:e.pagesDir||pajoExports.Pajo.join(t,"src\\pages")||"",outputFile:e.outputFile||pajoExports.Pajo.join(t,"src\\auto-routes.tsx")||"",layoutFileName:e.layoutFileName||"_layout",errorFileName:e.errorFileName||"_error",notFoundFileName:e.notFoundFileName||"_404"}}generate(){return __awaiter(this,void 0,void 0,function*(){yield this.findRouteFiles(),yield this.generateAutoRoutesFile()})}findRouteFiles(){return __awaiter(this,void 0,void 0,function*(){var e;if(this.routeFiles=[],yield this.scanDirectoryForRoutes(this.config.pagesDir),fs.existsSync(this.config.modulesDir))for(e of fs.readdirSync(this.config.modulesDir,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)){var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&(this.modules.add(e),yield this.scanDirectoryForRoutes(t,e))}})}scanDirectoryForRoutes(i,a){return __awaiter(this,void 0,void 0,function*(){try{var e;for(e of fs.readdirSync(i,{withFileTypes:!0})){var t,r,n=path.join(i,e.name);"node_modules"===e.name||"dist"===e.name||"build"===e.name||e.name.startsWith(".")||(e.isDirectory()?yield this.scanDirectoryForRoutes(n,a):e.isFile()&&(t=path.extname(e.name).toLowerCase(),[".tsx",".jsx"].includes(t))&&(r=path.basename(e.name,t))!==this.config.layoutFileName&&r!==this.config.errorFileName&&r!==this.config.notFoundFileName&&(yield this.processRouteFile(n,a)))}}catch(e){}})}processRouteFile(o,s){return __awaiter(this,void 0,void 0,function*(){try{var e=this.convertFilePathToRoutePath(o,s),t=this.extractComponentName(o,s),r=this.findLayoutComponent(o,s),n=this.findErrorComponent(o,s),i=this.findNotFoundComponent(o,s),a={filePath:o,relativePath:path.relative(this.config.srcDir,o),routePath:e,componentName:t,layoutComponent:r,errorComponent:n,notFoundComponent:i,moduleName:s};this.routeFiles.push(a)}catch(e){}})}convertFilePathToRoutePath(e,t){let r=e;return r=r.replace(this.config.srcDir,""),t?(e=`modules${path.sep}${t}${path.sep}pages`,r.includes(e)&&(r="/"+t+(r=r.substring(r.indexOf(e)+e.length)))):r.includes("pages")&&(r=r.substring(r.indexOf("pages")+"pages".length)),"/"===(r=(r=(r=(r=(r=r.replace(/\.(tsx|jsx)$/,"")).replace(/\\/g,"/")).endsWith("/index")?r.replace(/\/index$/,""):r).replace(/\[([^\]]+)\]/g,"{$1}")).startsWith("/")?r:"/"+r)||"//"===r?"/":r}extractComponentName(e,t){var r=path.basename(e,path.extname(e)),e=path.dirname(e).split(path.sep);let i=0;if(t){let n=path.sep+"modules"+path.sep+t+path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}else{let n=path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}i<0&&(i=0);e=e.slice(i);let n=t?this.toPascalCase(t):"",a=(e.forEach(e=>{e&&"pages"!==e&&(n+=this.toPascalCase(e))}),r);(a=r.startsWith("{")&&r.endsWith("}")?(t=r.substring(1,r.length-1),this.toPascalCase(t)+"Params"):this.toPascalCase(r)).endsWith("Page")||(a+="Page");return["Layout","ErrorBoundary","NotFound"].includes(a)&&(a+="Component"),n+a}toPascalCase(e){return e?e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(""):""}findLayoutComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.layoutFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"Layout");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx");if(fs.existsSync(e))return"Layout"}findErrorComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.errorFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"ErrorBoundary");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.errorFileName+".tsx");if(fs.existsSync(e))return"ErrorBoundary"}findNotFoundComponent(e,t){var r;if(t)return r=path.join(this.config.modulesDir,t,"pages"),r=path.join(r,this.config.notFoundFileName+".tsx"),fs.existsSync(r)?this.generateComponentName(r,t,"NotFound"):void 0}generateComponentName(e,t,r){if(!t)return r;var n=path.basename(e,path.extname(e)),e=path.dirname(e),i=path.join(this.config.modulesDir,t,"pages"),i=path.relative(i,e);let a=this.toPascalCase(t);return i&&"."!==i&&i.split(path.sep).filter(e=>e&&"."!==e).forEach(e=>{a+=this.toPascalCase(e)}),n!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName&&(a+=this.toPascalCase(n)),a+r}generateAutoRoutesFile(){return __awaiter(this,void 0,void 0,function*(){var e=path.dirname(this.config.outputFile),e=(fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),this.generateFileContent());fs.writeFileSync(this.config.outputFile,e,"utf-8")})}getRelativeImportPath(e){var t=path.dirname(this.config.outputFile);let r=path.relative(t,e).replace(/\\/g,"/");return r=(r=r.startsWith(".")||r.startsWith("/")?r:"./"+r).replace(/\.(tsx|jsx)$/,"")}generateFileContent(){let c=new Set,r=["import { lazy } from 'react';","import type { RouteObject } from 'react-router-dom';",""];var e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx"),t=path.join(this.config.pagesDir,this.config.errorFileName+".tsx"),n=path.join(this.config.pagesDir,this.config.notFoundFileName+".tsx");fs.existsSync(e)&&(e=this.getRelativeImportPath(e),r.push(`const Layout = lazy(() => import('${e}'));`),c.add("Layout")),fs.existsSync(t)&&(e=this.getRelativeImportPath(t),r.push(`const ErrorBoundary = lazy(() => import('${e}'));`),c.add("ErrorBoundary")),fs.existsSync(n)&&(t=this.getRelativeImportPath(n),r.push(`const NotFound = lazy(() => import('${t}'));`),c.add("NotFound")),r.push("");let l=new Map,i=(e,t=0,s)=>{if(fs.existsSync(e)){let o=e=>{try{var t;for(t of fs.readdirSync(e,{withFileTypes:!0})){var r,n,i,a=path.join(e,t.name);t.isDirectory()?o(a):t.isFile()&&(r=path.extname(t.name).toLowerCase(),![".tsx",".jsx"].includes(r)||(n=path.basename(t.name,r))!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName||(i=this.generateComponentName(a,s,n===this.config.layoutFileName?"Layout":n===this.config.errorFileName?"ErrorBoundary":"NotFound"),c.has(i))||(l.set(a,i),c.add(i)))}}catch(e){}};o(e)}},o=(i(this.config.pagesDir,!1),this.modules.forEach(e=>{var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&i(t,!0,e)}),l.forEach((e,t)=>{t=this.getRelativeImportPath(t);r.push(`const ${e} = lazy(() => import('${t}'));`)}),0<l.size&&r.push(""),this.routeFiles.forEach(e=>{var t=this.getRelativeImportPath(e.filePath);r.push(`const ${e.componentName} = lazy(() => import('${t}'));`),c.add(e.componentName)}),r.push(""),["export const routes: RouteObject[] = ["]),s=this.routeFiles.sort((e,t)=>"/"===e.routePath?-1:"/"===t.routePath?1:!e.moduleName&&t.moduleName?-1:e.moduleName&&!t.moduleName?1:e.moduleName===t.moduleName?e.routePath.localeCompare(t.routePath):0),_=void 0,a=(s.forEach((e,t)=>{e.moduleName!==_&&(void 0!==_&&o.push(""),e.moduleName&&o.push(` // ${e.moduleName} module routes`),_=e.moduleName);var r,n=[" {"];n.push(` path: '${e.routePath.replace(/\{([^}]+)\}/g,":$1")}',`);let i=e.layoutComponent,a=((i=!i&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.layoutFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"Layout"):i)?n.push(` element: <${i}><${e.componentName} /></${i}>,`):n.push(` element: <${e.componentName} />,`),e.errorComponent);(a=!a&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.errorFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"ErrorBoundary"):a)&&n.push(` errorElement: <${a} />`),n[n.length-1].endsWith(",")&&(n[n.length-1]=n[n.length-1].slice(0,-1)),n.push(" }"),t<s.length-1&&(n[n.length-1]+=","),o.push(n.join("\n"))}),new Set);return l.forEach((e,t)=>{var r;path.basename(t,path.extname(t))===this.config.notFoundFileName&&-1!==(r=(t=t.split(path.sep)).indexOf("modules"))&&r+1<t.length&&(t=t[r+1],a.has(t)||(a.add(t),o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(` path: '/${t}/*',`.replace(/\{([^}]+)\}/g,":$1")),o.push(` element: <${e} />`),o.push(" }")))}),c.has("NotFound")&&(o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(" path: '*',".replace(/\{([^}]+)\}/g,":$1")),o.push(" element: <NotFound />"),o.push(" }")),o.push("];"),o.push(""),o.push("export default routes;"),[...r,"",...o].join("\n")}}function RouteInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$1){e=new RouteGenerator({},e);try{yield e.generate()}catch(e){}})}function index(e=__dirname){TranslationInitiator(e),ConfigInitiator(e),RouteInitiator(e)}module.exports=index;
389
389
  //# sourceMappingURL=index.min.js.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.82",
6
+ "version": "0.0.84",
7
7
  "description": "INITIATOR est un plugin d'initialisation intelligent pour les applications React avec TypeScript/Javascript. Il génère automatiquement les fichiers de configuration, de routage et d'internationalisation basés sur la structure de votre projet.",
8
8
  "main": "index.js",
9
9
  "keywords": [],