@arc-js/initiator 0.0.6 → 0.0.7
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.d.ts +1 -1
- package/index.js +396 -8
- package/index.min.d.ts +1 -1
- package/index.min.js +22 -22
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -194418,10 +194418,10 @@ function requirePajo () {
|
|
|
194418
194418
|
|
|
194419
194419
|
var pajoExports = requirePajo();
|
|
194420
194420
|
|
|
194421
|
-
const __filename$
|
|
194422
|
-
const __dirname$
|
|
194421
|
+
const __filename$3 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
|
|
194422
|
+
const __dirname$3 = path.dirname(__filename$3);
|
|
194423
194423
|
class TranslationGenerator {
|
|
194424
|
-
constructor(config = {}, dirname = __dirname$
|
|
194424
|
+
constructor(config = {}, dirname = __dirname$3) {
|
|
194425
194425
|
this.keys = [];
|
|
194426
194426
|
this.modules = new Set();
|
|
194427
194427
|
this.importedModules = new Set();
|
|
@@ -194667,7 +194667,7 @@ export default translations;`;
|
|
|
194667
194667
|
}
|
|
194668
194668
|
}
|
|
194669
194669
|
function TranslationInitiator() {
|
|
194670
|
-
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$
|
|
194670
|
+
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$3) {
|
|
194671
194671
|
const config = {};
|
|
194672
194672
|
const generator = new TranslationGenerator(config, dirname);
|
|
194673
194673
|
generator.generate().then(() => {
|
|
@@ -194678,10 +194678,10 @@ function TranslationInitiator() {
|
|
|
194678
194678
|
});
|
|
194679
194679
|
}
|
|
194680
194680
|
|
|
194681
|
-
const __filename$
|
|
194682
|
-
const __dirname$
|
|
194681
|
+
const __filename$2 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
|
|
194682
|
+
const __dirname$2 = path.dirname(__filename$2);
|
|
194683
194683
|
class ConfigGenerator {
|
|
194684
|
-
constructor(config = {}, dirname = __dirname$
|
|
194684
|
+
constructor(config = {}, dirname = __dirname$2) {
|
|
194685
194685
|
this.modules = new Set();
|
|
194686
194686
|
this.config = {
|
|
194687
194687
|
srcDir: config.srcDir || pajoExports.Pajo.join(dirname, 'src') || '',
|
|
@@ -194780,7 +194780,7 @@ export default configs;`;
|
|
|
194780
194780
|
}
|
|
194781
194781
|
}
|
|
194782
194782
|
function ConfigInitiator() {
|
|
194783
|
-
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$
|
|
194783
|
+
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$2) {
|
|
194784
194784
|
const config = {};
|
|
194785
194785
|
const generator = new ConfigGenerator(config, dirname);
|
|
194786
194786
|
generator.generate().then(() => {
|
|
@@ -194791,9 +194791,397 @@ function ConfigInitiator() {
|
|
|
194791
194791
|
});
|
|
194792
194792
|
}
|
|
194793
194793
|
|
|
194794
|
+
const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
|
|
194795
|
+
const __dirname$1 = path.dirname(__filename$1);
|
|
194796
|
+
class RouteGenerator {
|
|
194797
|
+
constructor(config = {}, dirname = __dirname$1) {
|
|
194798
|
+
this.routeFiles = [];
|
|
194799
|
+
this.modules = new Set();
|
|
194800
|
+
this.config = {
|
|
194801
|
+
srcDir: config.srcDir || pajoExports.Pajo.join(dirname, 'src') || '',
|
|
194802
|
+
modulesDir: config.modulesDir || pajoExports.Pajo.join(dirname, 'src\\modules') || '',
|
|
194803
|
+
pagesDir: config.pagesDir || pajoExports.Pajo.join(dirname, 'src\\pages') || '',
|
|
194804
|
+
outputFile: config.outputFile || pajoExports.Pajo.join(dirname, 'src\\auto-routes.ts') || '',
|
|
194805
|
+
layoutFileName: config.layoutFileName || '_layout',
|
|
194806
|
+
errorFileName: config.errorFileName || '_error',
|
|
194807
|
+
notFoundFileName: config.notFoundFileName || '_404'
|
|
194808
|
+
};
|
|
194809
|
+
console.log(`--> RouteGenerator config:: `, this.config);
|
|
194810
|
+
}
|
|
194811
|
+
generate() {
|
|
194812
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194813
|
+
console.log('🔍 Scanning for route files...');
|
|
194814
|
+
yield this.findRouteFiles();
|
|
194815
|
+
yield this.generateAutoRoutesFile();
|
|
194816
|
+
console.log(`✅ Generated ${this.config.outputFile} with ${this.routeFiles.length} routes`);
|
|
194817
|
+
console.log(`📦 Found modules with routes: ${Array.from(this.modules).join(', ')}`);
|
|
194818
|
+
});
|
|
194819
|
+
}
|
|
194820
|
+
findRouteFiles() {
|
|
194821
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194822
|
+
this.routeFiles = [];
|
|
194823
|
+
yield this.scanDirectoryForRoutes(this.config.pagesDir);
|
|
194824
|
+
if (fs.existsSync(this.config.modulesDir)) {
|
|
194825
|
+
const moduleDirs = fs.readdirSync(this.config.modulesDir, { withFileTypes: true })
|
|
194826
|
+
.filter(dirent => dirent.isDirectory())
|
|
194827
|
+
.map(dirent => dirent.name);
|
|
194828
|
+
for (const moduleName of moduleDirs) {
|
|
194829
|
+
const modulePagesDir = path.join(this.config.modulesDir, moduleName, 'pages');
|
|
194830
|
+
if (fs.existsSync(modulePagesDir)) {
|
|
194831
|
+
this.modules.add(moduleName);
|
|
194832
|
+
yield this.scanDirectoryForRoutes(modulePagesDir, moduleName);
|
|
194833
|
+
}
|
|
194834
|
+
}
|
|
194835
|
+
}
|
|
194836
|
+
});
|
|
194837
|
+
}
|
|
194838
|
+
scanDirectoryForRoutes(dir, moduleName) {
|
|
194839
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194840
|
+
try {
|
|
194841
|
+
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
194842
|
+
for (const item of items) {
|
|
194843
|
+
const fullPath = path.join(dir, item.name);
|
|
194844
|
+
if (item.name === 'node_modules' ||
|
|
194845
|
+
item.name === 'dist' ||
|
|
194846
|
+
item.name === 'build' ||
|
|
194847
|
+
item.name.startsWith('.')) {
|
|
194848
|
+
continue;
|
|
194849
|
+
}
|
|
194850
|
+
if (item.isDirectory()) {
|
|
194851
|
+
yield this.scanDirectoryForRoutes(fullPath, moduleName);
|
|
194852
|
+
}
|
|
194853
|
+
else if (item.isFile()) {
|
|
194854
|
+
const ext = path.extname(item.name).toLowerCase();
|
|
194855
|
+
if (['.tsx', '.jsx'].includes(ext)) {
|
|
194856
|
+
const fileName = path.basename(item.name, ext);
|
|
194857
|
+
if (fileName === this.config.layoutFileName ||
|
|
194858
|
+
fileName === this.config.errorFileName ||
|
|
194859
|
+
fileName === this.config.notFoundFileName) {
|
|
194860
|
+
continue;
|
|
194861
|
+
}
|
|
194862
|
+
yield this.processRouteFile(fullPath, moduleName);
|
|
194863
|
+
}
|
|
194864
|
+
}
|
|
194865
|
+
}
|
|
194866
|
+
}
|
|
194867
|
+
catch (error) {
|
|
194868
|
+
console.error(`Error scanning directory ${dir}:`, error);
|
|
194869
|
+
}
|
|
194870
|
+
});
|
|
194871
|
+
}
|
|
194872
|
+
processRouteFile(filePath, moduleName) {
|
|
194873
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194874
|
+
try {
|
|
194875
|
+
const relativePath = path.relative(this.config.srcDir, filePath);
|
|
194876
|
+
let routePath = this.convertFilePathToRoutePath(filePath, moduleName);
|
|
194877
|
+
const componentName = this.extractComponentName(filePath);
|
|
194878
|
+
const hasLayout = this.checkForLayoutFile(filePath, moduleName);
|
|
194879
|
+
const hasError = this.checkForErrorFile(filePath, moduleName);
|
|
194880
|
+
const routeFile = {
|
|
194881
|
+
filePath,
|
|
194882
|
+
relativePath,
|
|
194883
|
+
routePath,
|
|
194884
|
+
componentName,
|
|
194885
|
+
hasLayout,
|
|
194886
|
+
hasError,
|
|
194887
|
+
moduleName
|
|
194888
|
+
};
|
|
194889
|
+
this.routeFiles.push(routeFile);
|
|
194890
|
+
}
|
|
194891
|
+
catch (error) {
|
|
194892
|
+
console.error(`Error processing route file ${filePath}:`, error);
|
|
194893
|
+
}
|
|
194894
|
+
});
|
|
194895
|
+
}
|
|
194896
|
+
convertFilePathToRoutePath(filePath, moduleName) {
|
|
194897
|
+
let routePath = filePath;
|
|
194898
|
+
routePath = routePath.replace(this.config.srcDir, '');
|
|
194899
|
+
if (moduleName) {
|
|
194900
|
+
routePath = routePath.replace(new RegExp(`modules\\\\${moduleName}\\\\pages`), '');
|
|
194901
|
+
routePath = routePath.replace(new RegExp(`modules/${moduleName}/pages`), '');
|
|
194902
|
+
}
|
|
194903
|
+
else {
|
|
194904
|
+
routePath = routePath.replace(/pages[\\/]/, '');
|
|
194905
|
+
}
|
|
194906
|
+
routePath = routePath.replace(/\.(tsx|jsx)$/, '');
|
|
194907
|
+
routePath = routePath.replace(/\\/g, '/');
|
|
194908
|
+
if (routePath.endsWith('/index')) {
|
|
194909
|
+
routePath = routePath.replace(/\/index$/, '');
|
|
194910
|
+
}
|
|
194911
|
+
routePath = routePath.replace(/\[([^\]]+)\]/g, ':$1');
|
|
194912
|
+
if (!routePath.startsWith('/')) {
|
|
194913
|
+
routePath = '/' + routePath;
|
|
194914
|
+
}
|
|
194915
|
+
if (routePath === '/') {
|
|
194916
|
+
return '/';
|
|
194917
|
+
}
|
|
194918
|
+
return routePath;
|
|
194919
|
+
}
|
|
194920
|
+
extractComponentName(filePath) {
|
|
194921
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
194922
|
+
const pascalName = fileName
|
|
194923
|
+
.split(/[-_]/)
|
|
194924
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
194925
|
+
.join('');
|
|
194926
|
+
const reservedNames = ['Layout', 'Error', 'NotFound', 'ErrorBoundary'];
|
|
194927
|
+
const finalName = reservedNames.includes(pascalName) ? `${pascalName}Page` : pascalName;
|
|
194928
|
+
return `${finalName}Page`;
|
|
194929
|
+
}
|
|
194930
|
+
checkForLayoutFile(filePath, moduleName) {
|
|
194931
|
+
const dir = path.dirname(filePath);
|
|
194932
|
+
const layoutPath = path.join(dir, `${this.config.layoutFileName}.tsx`);
|
|
194933
|
+
if (fs.existsSync(layoutPath)) {
|
|
194934
|
+
return true;
|
|
194935
|
+
}
|
|
194936
|
+
let currentDir = dir;
|
|
194937
|
+
while (currentDir !== this.config.srcDir && currentDir !== path.dirname(this.config.srcDir)) {
|
|
194938
|
+
const parentLayoutPath = path.join(currentDir, `${this.config.layoutFileName}.tsx`);
|
|
194939
|
+
if (fs.existsSync(parentLayoutPath)) {
|
|
194940
|
+
return true;
|
|
194941
|
+
}
|
|
194942
|
+
if (moduleName) {
|
|
194943
|
+
const moduleLayoutPath = path.join(this.config.modulesDir, moduleName, 'pages', `${this.config.layoutFileName}.tsx`);
|
|
194944
|
+
if (fs.existsSync(moduleLayoutPath)) {
|
|
194945
|
+
return true;
|
|
194946
|
+
}
|
|
194947
|
+
}
|
|
194948
|
+
currentDir = path.dirname(currentDir);
|
|
194949
|
+
}
|
|
194950
|
+
const globalLayoutPath = path.join(this.config.pagesDir, `${this.config.layoutFileName}.tsx`);
|
|
194951
|
+
return fs.existsSync(globalLayoutPath);
|
|
194952
|
+
}
|
|
194953
|
+
checkForErrorFile(filePath, moduleName) {
|
|
194954
|
+
const dir = path.dirname(filePath);
|
|
194955
|
+
const errorPath = path.join(dir, `${this.config.errorFileName}.tsx`);
|
|
194956
|
+
if (fs.existsSync(errorPath)) {
|
|
194957
|
+
return true;
|
|
194958
|
+
}
|
|
194959
|
+
let currentDir = dir;
|
|
194960
|
+
while (currentDir !== this.config.srcDir && currentDir !== path.dirname(this.config.srcDir)) {
|
|
194961
|
+
const parentErrorPath = path.join(currentDir, `${this.config.errorFileName}.tsx`);
|
|
194962
|
+
if (fs.existsSync(parentErrorPath)) {
|
|
194963
|
+
return true;
|
|
194964
|
+
}
|
|
194965
|
+
if (moduleName) {
|
|
194966
|
+
const moduleErrorPath = path.join(this.config.modulesDir, moduleName, 'pages', `${this.config.errorFileName}.tsx`);
|
|
194967
|
+
if (fs.existsSync(moduleErrorPath)) {
|
|
194968
|
+
return true;
|
|
194969
|
+
}
|
|
194970
|
+
}
|
|
194971
|
+
currentDir = path.dirname(currentDir);
|
|
194972
|
+
}
|
|
194973
|
+
const globalErrorPath = path.join(this.config.pagesDir, `${this.config.errorFileName}.tsx`);
|
|
194974
|
+
return fs.existsSync(globalErrorPath);
|
|
194975
|
+
}
|
|
194976
|
+
generateAutoRoutesFile() {
|
|
194977
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194978
|
+
const outputDir = path.dirname(this.config.outputFile);
|
|
194979
|
+
if (!fs.existsSync(outputDir)) {
|
|
194980
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
194981
|
+
}
|
|
194982
|
+
const content = this.generateFileContent();
|
|
194983
|
+
fs.writeFileSync(this.config.outputFile, content, 'utf-8');
|
|
194984
|
+
});
|
|
194985
|
+
}
|
|
194986
|
+
getRelativeImportPath(targetPath) {
|
|
194987
|
+
const outputDir = path.dirname(this.config.outputFile);
|
|
194988
|
+
const relative = path.relative(outputDir, targetPath);
|
|
194989
|
+
let importPath = relative.replace(/\\/g, '/');
|
|
194990
|
+
if (!importPath.startsWith('.') && !importPath.startsWith('/')) {
|
|
194991
|
+
importPath = './' + importPath;
|
|
194992
|
+
}
|
|
194993
|
+
importPath = importPath.replace(/\.(tsx|jsx)$/, '');
|
|
194994
|
+
return importPath;
|
|
194995
|
+
}
|
|
194996
|
+
escapeTemplateString(str) {
|
|
194997
|
+
return str
|
|
194998
|
+
.replace(/\\/g, '\\\\')
|
|
194999
|
+
.replace(/`/g, '\\`')
|
|
195000
|
+
.replace(/\${/g, '\\${');
|
|
195001
|
+
}
|
|
195002
|
+
generateFileContent() {
|
|
195003
|
+
const moduleRoutes = {};
|
|
195004
|
+
const globalRoutes = [];
|
|
195005
|
+
this.routeFiles.forEach(route => {
|
|
195006
|
+
if (route.moduleName) {
|
|
195007
|
+
if (!moduleRoutes[route.moduleName]) {
|
|
195008
|
+
moduleRoutes[route.moduleName] = [];
|
|
195009
|
+
}
|
|
195010
|
+
moduleRoutes[route.moduleName].push(route);
|
|
195011
|
+
}
|
|
195012
|
+
else {
|
|
195013
|
+
globalRoutes.push(route);
|
|
195014
|
+
}
|
|
195015
|
+
});
|
|
195016
|
+
const globalLayoutPath = path.join(this.config.pagesDir, `${this.config.layoutFileName}.tsx`);
|
|
195017
|
+
const globalErrorPath = path.join(this.config.pagesDir, `${this.config.errorFileName}.tsx`);
|
|
195018
|
+
const global404Path = path.join(this.config.pagesDir, `${this.config.notFoundFileName}.tsx`);
|
|
195019
|
+
const hasGlobalLayout = fs.existsSync(globalLayoutPath);
|
|
195020
|
+
const hasGlobalError = fs.existsSync(globalErrorPath);
|
|
195021
|
+
const hasGlobal404 = fs.existsSync(global404Path);
|
|
195022
|
+
const imports = [
|
|
195023
|
+
`import { lazy } from 'react';`,
|
|
195024
|
+
`import type { RouteObject } from 'react-router-dom';`,
|
|
195025
|
+
``
|
|
195026
|
+
];
|
|
195027
|
+
if (hasGlobalLayout) {
|
|
195028
|
+
const importPath = this.getRelativeImportPath(globalLayoutPath);
|
|
195029
|
+
imports.push(`const Layout = lazy(() => import('${this.escapeTemplateString(importPath)}'));`);
|
|
195030
|
+
}
|
|
195031
|
+
else {
|
|
195032
|
+
imports.push(`// No global layout found`);
|
|
195033
|
+
}
|
|
195034
|
+
if (hasGlobalError) {
|
|
195035
|
+
const importPath = this.getRelativeImportPath(globalErrorPath);
|
|
195036
|
+
imports.push(`const ErrorBoundary = lazy(() => import('${this.escapeTemplateString(importPath)}'));`);
|
|
195037
|
+
}
|
|
195038
|
+
else {
|
|
195039
|
+
imports.push(`// No global error boundary found`);
|
|
195040
|
+
}
|
|
195041
|
+
if (hasGlobal404) {
|
|
195042
|
+
const importPath = this.getRelativeImportPath(global404Path);
|
|
195043
|
+
imports.push(`const NotFound = lazy(() => import('${this.escapeTemplateString(importPath)}'));`);
|
|
195044
|
+
}
|
|
195045
|
+
else {
|
|
195046
|
+
imports.push(`// No 404 page found`);
|
|
195047
|
+
}
|
|
195048
|
+
imports.push(``);
|
|
195049
|
+
Object.keys(moduleRoutes).forEach(moduleName => {
|
|
195050
|
+
const moduleLayoutPath = path.join(this.config.modulesDir, moduleName, 'pages', `${this.config.layoutFileName}.tsx`);
|
|
195051
|
+
const moduleErrorPath = path.join(this.config.modulesDir, moduleName, 'pages', `${this.config.errorFileName}.tsx`);
|
|
195052
|
+
const hasModuleLayout = fs.existsSync(moduleLayoutPath);
|
|
195053
|
+
const hasModuleError = fs.existsSync(moduleErrorPath);
|
|
195054
|
+
if (hasModuleLayout) {
|
|
195055
|
+
const importPath = this.getRelativeImportPath(moduleLayoutPath);
|
|
195056
|
+
imports.push(`const ${moduleName}Layout = lazy(() => import('${this.escapeTemplateString(importPath)}'));`);
|
|
195057
|
+
}
|
|
195058
|
+
else {
|
|
195059
|
+
imports.push(`// No layout found for ${moduleName} module`);
|
|
195060
|
+
}
|
|
195061
|
+
if (hasModuleError) {
|
|
195062
|
+
const importPath = this.getRelativeImportPath(moduleErrorPath);
|
|
195063
|
+
imports.push(`const ${moduleName}ErrorBoundary = lazy(() => import('${this.escapeTemplateString(importPath)}'));`);
|
|
195064
|
+
}
|
|
195065
|
+
else {
|
|
195066
|
+
imports.push(`// No error boundary found for ${moduleName} module`);
|
|
195067
|
+
}
|
|
195068
|
+
imports.push(``);
|
|
195069
|
+
});
|
|
195070
|
+
if (globalRoutes.length > 0) {
|
|
195071
|
+
imports.push(`// Global routes imports`);
|
|
195072
|
+
globalRoutes.forEach(route => {
|
|
195073
|
+
const importPath = this.getRelativeImportPath(route.filePath);
|
|
195074
|
+
imports.push(`const ${route.componentName} = lazy(() => import('${this.escapeTemplateString(importPath)}'));`);
|
|
195075
|
+
});
|
|
195076
|
+
imports.push(``);
|
|
195077
|
+
}
|
|
195078
|
+
Object.entries(moduleRoutes).forEach(([moduleName, routes]) => {
|
|
195079
|
+
if (routes.length > 0) {
|
|
195080
|
+
imports.push(`// ${moduleName} module imports`);
|
|
195081
|
+
routes.forEach(route => {
|
|
195082
|
+
const importPath = this.getRelativeImportPath(route.filePath);
|
|
195083
|
+
imports.push(`const ${route.componentName} = lazy(() => import('${this.escapeTemplateString(importPath)}'));`);
|
|
195084
|
+
});
|
|
195085
|
+
imports.push(``);
|
|
195086
|
+
}
|
|
195087
|
+
});
|
|
195088
|
+
const routes = ['export const routes: RouteObject[] = ['];
|
|
195089
|
+
if (globalRoutes.length > 0) {
|
|
195090
|
+
globalRoutes.forEach((route, index) => {
|
|
195091
|
+
const routeObj = [' {'];
|
|
195092
|
+
routeObj.push(` path: '${route.routePath.replace(/'/g, "\\'")}',`);
|
|
195093
|
+
if (route.hasLayout && hasGlobalLayout) {
|
|
195094
|
+
routeObj.push(` element: <Layout><${route.componentName} /></Layout>,`);
|
|
195095
|
+
}
|
|
195096
|
+
else {
|
|
195097
|
+
routeObj.push(` element: <${route.componentName} />,`);
|
|
195098
|
+
}
|
|
195099
|
+
if (route.hasError && hasGlobalError) {
|
|
195100
|
+
routeObj.push(` errorElement: <ErrorBoundary />`);
|
|
195101
|
+
}
|
|
195102
|
+
const lastLine = routeObj[routeObj.length - 1];
|
|
195103
|
+
if (!lastLine.endsWith(',')) {
|
|
195104
|
+
routeObj[routeObj.length - 1] = lastLine + ',';
|
|
195105
|
+
}
|
|
195106
|
+
routeObj.push(' }');
|
|
195107
|
+
if (index < globalRoutes.length - 1 || Object.keys(moduleRoutes).length > 0) {
|
|
195108
|
+
routeObj[routeObj.length - 1] += ',';
|
|
195109
|
+
}
|
|
195110
|
+
routes.push(routeObj.join('\n'));
|
|
195111
|
+
});
|
|
195112
|
+
}
|
|
195113
|
+
Object.entries(moduleRoutes).forEach(([moduleName, moduleRoutesList], moduleIndex) => {
|
|
195114
|
+
if (moduleRoutesList.length > 0) {
|
|
195115
|
+
if (globalRoutes.length > 0 || moduleIndex > 0) {
|
|
195116
|
+
routes.push('');
|
|
195117
|
+
}
|
|
195118
|
+
routes.push(` // ${moduleName} module routes`);
|
|
195119
|
+
moduleRoutesList.forEach((route, routeIndex) => {
|
|
195120
|
+
const routeObj = [' {'];
|
|
195121
|
+
routeObj.push(` path: '${route.routePath.replace(/'/g, "\\'")}',`);
|
|
195122
|
+
const hasModuleLayout = fs.existsSync(path.join(this.config.modulesDir, moduleName, 'pages', `${this.config.layoutFileName}.tsx`));
|
|
195123
|
+
const hasModuleError = fs.existsSync(path.join(this.config.modulesDir, moduleName, 'pages', `${this.config.errorFileName}.tsx`));
|
|
195124
|
+
if (route.hasLayout && hasModuleLayout) {
|
|
195125
|
+
routeObj.push(` element: <${moduleName}Layout><${route.componentName} /></${moduleName}Layout>,`);
|
|
195126
|
+
}
|
|
195127
|
+
else {
|
|
195128
|
+
routeObj.push(` element: <${route.componentName} />,`);
|
|
195129
|
+
}
|
|
195130
|
+
if (route.hasError && hasModuleError) {
|
|
195131
|
+
routeObj.push(` errorElement: <${moduleName}ErrorBoundary />`);
|
|
195132
|
+
}
|
|
195133
|
+
const lastLine = routeObj[routeObj.length - 1];
|
|
195134
|
+
if (!lastLine.endsWith(',')) {
|
|
195135
|
+
routeObj[routeObj.length - 1] = lastLine + ',';
|
|
195136
|
+
}
|
|
195137
|
+
routeObj.push(' }');
|
|
195138
|
+
const isLastModule = moduleIndex === Object.keys(moduleRoutes).length - 1;
|
|
195139
|
+
const isLastRoute = routeIndex === moduleRoutesList.length - 1;
|
|
195140
|
+
if (!(isLastModule && isLastRoute && !hasGlobal404)) {
|
|
195141
|
+
routeObj[routeObj.length - 1] += ',';
|
|
195142
|
+
}
|
|
195143
|
+
routes.push(routeObj.join('\n'));
|
|
195144
|
+
});
|
|
195145
|
+
}
|
|
195146
|
+
});
|
|
195147
|
+
if (hasGlobal404) {
|
|
195148
|
+
if (globalRoutes.length > 0 || Object.keys(moduleRoutes).length > 0) {
|
|
195149
|
+
routes.push('');
|
|
195150
|
+
}
|
|
195151
|
+
routes.push(' // 404 page');
|
|
195152
|
+
routes.push(' {');
|
|
195153
|
+
routes.push(` path: '*',`);
|
|
195154
|
+
routes.push(` element: <NotFound />`);
|
|
195155
|
+
routes.push(' }');
|
|
195156
|
+
}
|
|
195157
|
+
routes.push('];');
|
|
195158
|
+
routes.push('');
|
|
195159
|
+
routes.push('export default routes;');
|
|
195160
|
+
return [
|
|
195161
|
+
...imports,
|
|
195162
|
+
'',
|
|
195163
|
+
...routes
|
|
195164
|
+
].join('\n');
|
|
195165
|
+
}
|
|
195166
|
+
}
|
|
195167
|
+
function RouteInitiator() {
|
|
195168
|
+
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$1) {
|
|
195169
|
+
const config = {};
|
|
195170
|
+
const generator = new RouteGenerator(config, dirname);
|
|
195171
|
+
try {
|
|
195172
|
+
yield generator.generate();
|
|
195173
|
+
console.log('🎉 Route generation completed successfully!');
|
|
195174
|
+
}
|
|
195175
|
+
catch (err) {
|
|
195176
|
+
console.error('❌ Failed to generate routes: ', err);
|
|
195177
|
+
}
|
|
195178
|
+
});
|
|
195179
|
+
}
|
|
195180
|
+
|
|
194794
195181
|
function index (dirname = __dirname) {
|
|
194795
195182
|
TranslationInitiator(dirname);
|
|
194796
195183
|
ConfigInitiator(dirname);
|
|
195184
|
+
RouteInitiator(dirname);
|
|
194797
195185
|
}
|
|
194798
195186
|
|
|
194799
195187
|
module.exports = index;
|
package/index.min.d.ts
CHANGED