@arc-js/initiator 0.0.8 → 0.0.81
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 +141 -84
- package/index.min.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -194927,27 +194927,51 @@ class RouteGenerator {
|
|
|
194927
194927
|
extractComponentName(filePath, moduleName) {
|
|
194928
194928
|
const fileName = path.basename(filePath, path.extname(filePath));
|
|
194929
194929
|
const dirName = path.dirname(filePath);
|
|
194930
|
-
const
|
|
194930
|
+
const parts = dirName.split(path.sep);
|
|
194931
|
+
let startIndex = 0;
|
|
194932
|
+
if (moduleName) {
|
|
194933
|
+
const modulePagesPath = path.sep + 'modules' + path.sep + moduleName + path.sep + 'pages';
|
|
194934
|
+
startIndex = parts.findIndex((part, index, arr) => {
|
|
194935
|
+
const pathSoFar = arr.slice(0, index + 1).join(path.sep);
|
|
194936
|
+
return pathSoFar.endsWith(modulePagesPath);
|
|
194937
|
+
}) + 1;
|
|
194938
|
+
}
|
|
194939
|
+
else {
|
|
194940
|
+
const pagesPath = path.sep + 'pages';
|
|
194941
|
+
startIndex = parts.findIndex((part, index, arr) => {
|
|
194942
|
+
const pathSoFar = arr.slice(0, index + 1).join(path.sep);
|
|
194943
|
+
return pathSoFar.endsWith(pagesPath);
|
|
194944
|
+
}) + 1;
|
|
194945
|
+
}
|
|
194946
|
+
if (startIndex < 0)
|
|
194947
|
+
startIndex = 0;
|
|
194948
|
+
const relevantParts = parts.slice(startIndex);
|
|
194931
194949
|
let componentName = moduleName ? this.toPascalCase(moduleName) : '';
|
|
194932
|
-
|
|
194933
|
-
if (
|
|
194934
|
-
componentName += this.toPascalCase(
|
|
194950
|
+
relevantParts.forEach(part => {
|
|
194951
|
+
if (part && part !== 'pages') {
|
|
194952
|
+
componentName += this.toPascalCase(part);
|
|
194935
194953
|
}
|
|
194936
194954
|
});
|
|
194937
|
-
let
|
|
194955
|
+
let fileNamePart = fileName;
|
|
194938
194956
|
if (fileName.startsWith('{') && fileName.endsWith('}')) {
|
|
194939
194957
|
const paramName = fileName.substring(1, fileName.length - 1);
|
|
194940
|
-
|
|
194958
|
+
fileNamePart = this.toPascalCase(paramName) + 'Params';
|
|
194941
194959
|
}
|
|
194942
194960
|
else {
|
|
194943
|
-
|
|
194961
|
+
fileNamePart = this.toPascalCase(fileName);
|
|
194944
194962
|
}
|
|
194945
|
-
if (!
|
|
194946
|
-
|
|
194963
|
+
if (!fileNamePart.endsWith('Page')) {
|
|
194964
|
+
fileNamePart += 'Page';
|
|
194947
194965
|
}
|
|
194948
|
-
|
|
194966
|
+
const reservedNames = ['Layout', 'ErrorBoundary', 'NotFound'];
|
|
194967
|
+
if (reservedNames.includes(fileNamePart)) {
|
|
194968
|
+
fileNamePart += 'Component';
|
|
194969
|
+
}
|
|
194970
|
+
return componentName + fileNamePart;
|
|
194949
194971
|
}
|
|
194950
194972
|
toPascalCase(str) {
|
|
194973
|
+
if (!str)
|
|
194974
|
+
return '';
|
|
194951
194975
|
return str
|
|
194952
194976
|
.split(/[-_]/)
|
|
194953
194977
|
.map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
@@ -195011,14 +195035,22 @@ class RouteGenerator {
|
|
|
195011
195035
|
if (!moduleName) {
|
|
195012
195036
|
return suffix;
|
|
195013
195037
|
}
|
|
195014
|
-
const
|
|
195038
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
195039
|
+
const dirName = path.dirname(filePath);
|
|
195040
|
+
const modulePagesPath = path.join(this.config.modulesDir, moduleName, 'pages');
|
|
195041
|
+
const relativePath = path.relative(modulePagesPath, dirName);
|
|
195015
195042
|
let componentName = this.toPascalCase(moduleName);
|
|
195016
195043
|
if (relativePath && relativePath !== '.') {
|
|
195017
|
-
const
|
|
195018
|
-
|
|
195019
|
-
componentName += this.toPascalCase(
|
|
195044
|
+
const dirParts = relativePath.split(path.sep).filter(part => part && part !== '.');
|
|
195045
|
+
dirParts.forEach(part => {
|
|
195046
|
+
componentName += this.toPascalCase(part);
|
|
195020
195047
|
});
|
|
195021
195048
|
}
|
|
195049
|
+
if (fileName !== this.config.layoutFileName &&
|
|
195050
|
+
fileName !== this.config.errorFileName &&
|
|
195051
|
+
fileName !== this.config.notFoundFileName) {
|
|
195052
|
+
componentName += this.toPascalCase(fileName);
|
|
195053
|
+
}
|
|
195022
195054
|
return componentName + suffix;
|
|
195023
195055
|
}
|
|
195024
195056
|
generateAutoRoutesFile() {
|
|
@@ -195067,41 +195099,60 @@ class RouteGenerator {
|
|
|
195067
195099
|
components.add('NotFound');
|
|
195068
195100
|
}
|
|
195069
195101
|
imports.push(``);
|
|
195070
|
-
const
|
|
195071
|
-
|
|
195072
|
-
if (
|
|
195073
|
-
|
|
195074
|
-
|
|
195075
|
-
|
|
195076
|
-
const
|
|
195077
|
-
|
|
195078
|
-
|
|
195079
|
-
|
|
195080
|
-
|
|
195081
|
-
|
|
195082
|
-
|
|
195083
|
-
|
|
195084
|
-
|
|
195085
|
-
|
|
195102
|
+
const specialComponents = new Map();
|
|
195103
|
+
const findSpecialFiles = (baseDir, isModule = false, moduleName) => {
|
|
195104
|
+
if (!fs.existsSync(baseDir))
|
|
195105
|
+
return;
|
|
195106
|
+
const walkDir = (dir) => {
|
|
195107
|
+
try {
|
|
195108
|
+
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
195109
|
+
for (const item of items) {
|
|
195110
|
+
const fullPath = path.join(dir, item.name);
|
|
195111
|
+
if (item.isDirectory()) {
|
|
195112
|
+
walkDir(fullPath);
|
|
195113
|
+
}
|
|
195114
|
+
else if (item.isFile()) {
|
|
195115
|
+
const ext = path.extname(item.name).toLowerCase();
|
|
195116
|
+
if (['.tsx', '.jsx'].includes(ext)) {
|
|
195117
|
+
const fileName = path.basename(item.name, ext);
|
|
195118
|
+
if (fileName === this.config.layoutFileName ||
|
|
195119
|
+
fileName === this.config.errorFileName ||
|
|
195120
|
+
fileName === this.config.notFoundFileName) {
|
|
195121
|
+
const componentName = this.generateComponentName(fullPath, moduleName, fileName === this.config.layoutFileName ? 'Layout' :
|
|
195122
|
+
fileName === this.config.errorFileName ? 'ErrorBoundary' : 'NotFound');
|
|
195123
|
+
if (!components.has(componentName)) {
|
|
195124
|
+
specialComponents.set(fullPath, componentName);
|
|
195125
|
+
components.add(componentName);
|
|
195126
|
+
}
|
|
195127
|
+
}
|
|
195128
|
+
}
|
|
195129
|
+
}
|
|
195130
|
+
}
|
|
195086
195131
|
}
|
|
195087
|
-
|
|
195088
|
-
|
|
195089
|
-
components.add(route.notFoundComponent);
|
|
195090
|
-
const notFoundFile = this.findComponentFile(route.filePath, this.config.notFoundFileName, route.moduleName);
|
|
195091
|
-
if (notFoundFile) {
|
|
195092
|
-
const importPath = this.getRelativeImportPath(notFoundFile);
|
|
195093
|
-
imports.push(`const ${route.notFoundComponent} = lazy(() => import('${importPath}'));`);
|
|
195132
|
+
catch (error) {
|
|
195133
|
+
console.error(`Error walking directory ${dir}:`, error);
|
|
195094
195134
|
}
|
|
195135
|
+
};
|
|
195136
|
+
walkDir(baseDir);
|
|
195137
|
+
};
|
|
195138
|
+
findSpecialFiles(this.config.pagesDir, false);
|
|
195139
|
+
this.modules.forEach(moduleName => {
|
|
195140
|
+
const modulePagesDir = path.join(this.config.modulesDir, moduleName, 'pages');
|
|
195141
|
+
if (fs.existsSync(modulePagesDir)) {
|
|
195142
|
+
findSpecialFiles(modulePagesDir, true, moduleName);
|
|
195095
195143
|
}
|
|
195144
|
+
});
|
|
195145
|
+
specialComponents.forEach((componentName, filePath) => {
|
|
195146
|
+
const importPath = this.getRelativeImportPath(filePath);
|
|
195147
|
+
imports.push(`const ${componentName} = lazy(() => import('${importPath}'));`);
|
|
195148
|
+
});
|
|
195149
|
+
if (specialComponents.size > 0) {
|
|
195150
|
+
imports.push(``);
|
|
195151
|
+
}
|
|
195152
|
+
this.routeFiles.forEach(route => {
|
|
195096
195153
|
const importPath = this.getRelativeImportPath(route.filePath);
|
|
195097
195154
|
imports.push(`const ${route.componentName} = lazy(() => import('${importPath}'));`);
|
|
195098
195155
|
components.add(route.componentName);
|
|
195099
|
-
if (route.moduleName) {
|
|
195100
|
-
if (!moduleComponents.has(route.moduleName)) {
|
|
195101
|
-
moduleComponents.set(route.moduleName, new Set());
|
|
195102
|
-
}
|
|
195103
|
-
moduleComponents.get(route.moduleName).add(route.componentName);
|
|
195104
|
-
}
|
|
195105
195156
|
});
|
|
195106
195157
|
imports.push(``);
|
|
195107
195158
|
const routes = ['export const routes: RouteObject[] = ['];
|
|
@@ -195119,18 +195170,41 @@ class RouteGenerator {
|
|
|
195119
195170
|
}
|
|
195120
195171
|
return 0;
|
|
195121
195172
|
});
|
|
195173
|
+
let lastModuleName = undefined;
|
|
195122
195174
|
sortedRoutes.forEach((route, index) => {
|
|
195123
|
-
|
|
195175
|
+
if (route.moduleName !== lastModuleName) {
|
|
195176
|
+
if (lastModuleName !== undefined) {
|
|
195177
|
+
routes.push(``);
|
|
195178
|
+
}
|
|
195179
|
+
if (route.moduleName) {
|
|
195180
|
+
routes.push(` // ${route.moduleName} module routes`);
|
|
195181
|
+
}
|
|
195182
|
+
lastModuleName = route.moduleName;
|
|
195183
|
+
}
|
|
195124
195184
|
const routeLines = [' {'];
|
|
195125
195185
|
routeLines.push(` path: '${route.routePath}',`);
|
|
195126
|
-
|
|
195127
|
-
|
|
195186
|
+
let layoutComponent = route.layoutComponent;
|
|
195187
|
+
if (!layoutComponent && route.moduleName) {
|
|
195188
|
+
const moduleLayoutPath = path.join(this.config.modulesDir, route.moduleName, 'pages', `${this.config.layoutFileName}.tsx`);
|
|
195189
|
+
if (fs.existsSync(moduleLayoutPath)) {
|
|
195190
|
+
layoutComponent = this.generateComponentName(moduleLayoutPath, route.moduleName, 'Layout');
|
|
195191
|
+
}
|
|
195192
|
+
}
|
|
195193
|
+
if (layoutComponent) {
|
|
195194
|
+
routeLines.push(` element: <${layoutComponent}><${route.componentName} /></${layoutComponent}>,`);
|
|
195128
195195
|
}
|
|
195129
195196
|
else {
|
|
195130
195197
|
routeLines.push(` element: <${route.componentName} />,`);
|
|
195131
195198
|
}
|
|
195132
|
-
|
|
195133
|
-
|
|
195199
|
+
let errorComponent = route.errorComponent;
|
|
195200
|
+
if (!errorComponent && route.moduleName) {
|
|
195201
|
+
const moduleErrorPath = path.join(this.config.modulesDir, route.moduleName, 'pages', `${this.config.errorFileName}.tsx`);
|
|
195202
|
+
if (fs.existsSync(moduleErrorPath)) {
|
|
195203
|
+
errorComponent = this.generateComponentName(moduleErrorPath, route.moduleName, 'ErrorBoundary');
|
|
195204
|
+
}
|
|
195205
|
+
}
|
|
195206
|
+
if (errorComponent) {
|
|
195207
|
+
routeLines.push(` errorElement: <${errorComponent} />`);
|
|
195134
195208
|
}
|
|
195135
195209
|
if (routeLines[routeLines.length - 1].endsWith(',')) {
|
|
195136
195210
|
routeLines[routeLines.length - 1] = routeLines[routeLines.length - 1].slice(0, -1);
|
|
@@ -195139,21 +195213,28 @@ class RouteGenerator {
|
|
|
195139
195213
|
if (index < sortedRoutes.length - 1) {
|
|
195140
195214
|
routeLines[routeLines.length - 1] += ',';
|
|
195141
195215
|
}
|
|
195142
|
-
if (route.moduleName && (index === 0 ||
|
|
195143
|
-
((_a = sortedRoutes[index - 1]) === null || _a === void 0 ? void 0 : _a.moduleName) !== route.moduleName)) {
|
|
195144
|
-
routes.push(` // ${route.moduleName} module routes`);
|
|
195145
|
-
}
|
|
195146
195216
|
routes.push(routeLines.join('\n'));
|
|
195147
195217
|
});
|
|
195148
195218
|
const modulesWith404 = new Set();
|
|
195149
|
-
|
|
195150
|
-
|
|
195151
|
-
|
|
195152
|
-
|
|
195153
|
-
|
|
195154
|
-
|
|
195155
|
-
|
|
195156
|
-
|
|
195219
|
+
specialComponents.forEach((componentName, filePath) => {
|
|
195220
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
195221
|
+
if (fileName === this.config.notFoundFileName) {
|
|
195222
|
+
const pathParts = filePath.split(path.sep);
|
|
195223
|
+
const modulesIndex = pathParts.indexOf('modules');
|
|
195224
|
+
if (modulesIndex !== -1 && modulesIndex + 1 < pathParts.length) {
|
|
195225
|
+
const moduleName = pathParts[modulesIndex + 1];
|
|
195226
|
+
if (!modulesWith404.has(moduleName)) {
|
|
195227
|
+
modulesWith404.add(moduleName);
|
|
195228
|
+
if (routes[routes.length - 1].endsWith(',')) {
|
|
195229
|
+
routes[routes.length - 1] = routes[routes.length - 1].slice(0, -1);
|
|
195230
|
+
}
|
|
195231
|
+
routes.push(`,`);
|
|
195232
|
+
routes.push(` {`);
|
|
195233
|
+
routes.push(` path: '/${moduleName}/*',`);
|
|
195234
|
+
routes.push(` element: <${componentName} />`);
|
|
195235
|
+
routes.push(` }`);
|
|
195236
|
+
}
|
|
195237
|
+
}
|
|
195157
195238
|
}
|
|
195158
195239
|
});
|
|
195159
195240
|
if (components.has('NotFound')) {
|
|
@@ -195175,30 +195256,6 @@ class RouteGenerator {
|
|
|
195175
195256
|
...routes
|
|
195176
195257
|
].join('\n');
|
|
195177
195258
|
}
|
|
195178
|
-
findComponentFile(startPath, fileName, moduleName) {
|
|
195179
|
-
const dir = path.dirname(startPath);
|
|
195180
|
-
let currentDir = dir;
|
|
195181
|
-
while (currentDir !== this.config.srcDir && currentDir !== path.dirname(this.config.srcDir)) {
|
|
195182
|
-
const componentPath = path.join(currentDir, `${fileName}.tsx`);
|
|
195183
|
-
if (fs.existsSync(componentPath)) {
|
|
195184
|
-
return componentPath;
|
|
195185
|
-
}
|
|
195186
|
-
if (moduleName) {
|
|
195187
|
-
const modulePath = path.join(this.config.modulesDir, moduleName);
|
|
195188
|
-
if (currentDir === modulePath) {
|
|
195189
|
-
break;
|
|
195190
|
-
}
|
|
195191
|
-
}
|
|
195192
|
-
currentDir = path.dirname(currentDir);
|
|
195193
|
-
}
|
|
195194
|
-
if (!moduleName) {
|
|
195195
|
-
const globalPath = path.join(this.config.pagesDir, `${fileName}.tsx`);
|
|
195196
|
-
if (fs.existsSync(globalPath)) {
|
|
195197
|
-
return globalPath;
|
|
195198
|
-
}
|
|
195199
|
-
}
|
|
195200
|
-
return undefined;
|
|
195201
|
-
}
|
|
195202
195259
|
}
|
|
195203
195260
|
function RouteInitiator() {
|
|
195204
195261
|
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$1) {
|
package/index.min.js
CHANGED
|
@@ -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.ts")||"",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).
|
|
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.ts")||"",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;
|
|
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.
|
|
6
|
+
"version": "0.0.81",
|
|
7
7
|
"description": "INITIATOR est un système de gestion de configuration modulaire pour les applications React avec TypeScript/JavaScript. Il fournit une gestion centralisée des configurations, un chargement dynamique des modules, et une intégration transparente avec les variables d'environnement.",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"keywords": [],
|