@arc-js/initiator 0.0.6 → 0.0.8
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 +432 -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,433 @@ 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
|
+
let routePath = this.convertFilePathToRoutePath(filePath, moduleName);
|
|
194876
|
+
const componentName = this.extractComponentName(filePath, moduleName);
|
|
194877
|
+
const layoutComponent = this.findLayoutComponent(filePath, moduleName);
|
|
194878
|
+
const errorComponent = this.findErrorComponent(filePath, moduleName);
|
|
194879
|
+
const notFoundComponent = this.findNotFoundComponent(filePath, moduleName);
|
|
194880
|
+
const routeFile = {
|
|
194881
|
+
filePath,
|
|
194882
|
+
relativePath: path.relative(this.config.srcDir, filePath),
|
|
194883
|
+
routePath,
|
|
194884
|
+
componentName,
|
|
194885
|
+
layoutComponent,
|
|
194886
|
+
errorComponent,
|
|
194887
|
+
notFoundComponent,
|
|
194888
|
+
moduleName
|
|
194889
|
+
};
|
|
194890
|
+
this.routeFiles.push(routeFile);
|
|
194891
|
+
}
|
|
194892
|
+
catch (error) {
|
|
194893
|
+
console.error(`Error processing route file ${filePath}:`, error);
|
|
194894
|
+
}
|
|
194895
|
+
});
|
|
194896
|
+
}
|
|
194897
|
+
convertFilePathToRoutePath(filePath, moduleName) {
|
|
194898
|
+
let routePath = filePath;
|
|
194899
|
+
routePath = routePath.replace(this.config.srcDir, '');
|
|
194900
|
+
if (moduleName) {
|
|
194901
|
+
const modulePagesPrefix = `modules${path.sep}${moduleName}${path.sep}pages`;
|
|
194902
|
+
if (routePath.includes(modulePagesPrefix)) {
|
|
194903
|
+
routePath = routePath.substring(routePath.indexOf(modulePagesPrefix) + modulePagesPrefix.length);
|
|
194904
|
+
routePath = `/${moduleName}${routePath}`;
|
|
194905
|
+
}
|
|
194906
|
+
}
|
|
194907
|
+
else {
|
|
194908
|
+
const pagesPrefix = 'pages';
|
|
194909
|
+
if (routePath.includes(pagesPrefix)) {
|
|
194910
|
+
routePath = routePath.substring(routePath.indexOf(pagesPrefix) + pagesPrefix.length);
|
|
194911
|
+
}
|
|
194912
|
+
}
|
|
194913
|
+
routePath = routePath.replace(/\.(tsx|jsx)$/, '');
|
|
194914
|
+
routePath = routePath.replace(/\\/g, '/');
|
|
194915
|
+
if (routePath.endsWith('/index')) {
|
|
194916
|
+
routePath = routePath.replace(/\/index$/, '');
|
|
194917
|
+
}
|
|
194918
|
+
routePath = routePath.replace(/\[([^\]]+)\]/g, '{$1}');
|
|
194919
|
+
if (!routePath.startsWith('/')) {
|
|
194920
|
+
routePath = '/' + routePath;
|
|
194921
|
+
}
|
|
194922
|
+
if (routePath === '/' || routePath === '//') {
|
|
194923
|
+
return '/';
|
|
194924
|
+
}
|
|
194925
|
+
return routePath;
|
|
194926
|
+
}
|
|
194927
|
+
extractComponentName(filePath, moduleName) {
|
|
194928
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
194929
|
+
const dirName = path.dirname(filePath);
|
|
194930
|
+
const parentDirs = dirName.split(path.sep).filter(dir => dir && dir !== 'src' && dir !== 'modules' && dir !== 'pages' && dir !== moduleName);
|
|
194931
|
+
let componentName = moduleName ? this.toPascalCase(moduleName) : '';
|
|
194932
|
+
parentDirs.forEach(dir => {
|
|
194933
|
+
if (dir !== 'pages') {
|
|
194934
|
+
componentName += this.toPascalCase(dir);
|
|
194935
|
+
}
|
|
194936
|
+
});
|
|
194937
|
+
let cleanedFileName = fileName;
|
|
194938
|
+
if (fileName.startsWith('{') && fileName.endsWith('}')) {
|
|
194939
|
+
const paramName = fileName.substring(1, fileName.length - 1);
|
|
194940
|
+
cleanedFileName = `${this.toPascalCase(paramName)}Params`;
|
|
194941
|
+
}
|
|
194942
|
+
else {
|
|
194943
|
+
cleanedFileName = this.toPascalCase(fileName);
|
|
194944
|
+
}
|
|
194945
|
+
if (!cleanedFileName.endsWith('Page')) {
|
|
194946
|
+
cleanedFileName += 'Page';
|
|
194947
|
+
}
|
|
194948
|
+
return componentName + cleanedFileName;
|
|
194949
|
+
}
|
|
194950
|
+
toPascalCase(str) {
|
|
194951
|
+
return str
|
|
194952
|
+
.split(/[-_]/)
|
|
194953
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
194954
|
+
.join('');
|
|
194955
|
+
}
|
|
194956
|
+
findLayoutComponent(filePath, moduleName) {
|
|
194957
|
+
const dir = path.dirname(filePath);
|
|
194958
|
+
let currentDir = dir;
|
|
194959
|
+
while (currentDir !== this.config.srcDir && currentDir !== path.dirname(this.config.srcDir)) {
|
|
194960
|
+
const layoutPath = path.join(currentDir, `${this.config.layoutFileName}.tsx`);
|
|
194961
|
+
if (fs.existsSync(layoutPath)) {
|
|
194962
|
+
return this.generateComponentName(layoutPath, moduleName, 'Layout');
|
|
194963
|
+
}
|
|
194964
|
+
if (moduleName) {
|
|
194965
|
+
const modulePath = path.join(this.config.modulesDir, moduleName);
|
|
194966
|
+
if (currentDir === modulePath) {
|
|
194967
|
+
break;
|
|
194968
|
+
}
|
|
194969
|
+
}
|
|
194970
|
+
currentDir = path.dirname(currentDir);
|
|
194971
|
+
}
|
|
194972
|
+
const globalLayoutPath = path.join(this.config.pagesDir, `${this.config.layoutFileName}.tsx`);
|
|
194973
|
+
if (fs.existsSync(globalLayoutPath)) {
|
|
194974
|
+
return 'Layout';
|
|
194975
|
+
}
|
|
194976
|
+
return undefined;
|
|
194977
|
+
}
|
|
194978
|
+
findErrorComponent(filePath, moduleName) {
|
|
194979
|
+
const dir = path.dirname(filePath);
|
|
194980
|
+
let currentDir = dir;
|
|
194981
|
+
while (currentDir !== this.config.srcDir && currentDir !== path.dirname(this.config.srcDir)) {
|
|
194982
|
+
const errorPath = path.join(currentDir, `${this.config.errorFileName}.tsx`);
|
|
194983
|
+
if (fs.existsSync(errorPath)) {
|
|
194984
|
+
return this.generateComponentName(errorPath, moduleName, 'ErrorBoundary');
|
|
194985
|
+
}
|
|
194986
|
+
if (moduleName) {
|
|
194987
|
+
const modulePath = path.join(this.config.modulesDir, moduleName);
|
|
194988
|
+
if (currentDir === modulePath) {
|
|
194989
|
+
break;
|
|
194990
|
+
}
|
|
194991
|
+
}
|
|
194992
|
+
currentDir = path.dirname(currentDir);
|
|
194993
|
+
}
|
|
194994
|
+
const globalErrorPath = path.join(this.config.pagesDir, `${this.config.errorFileName}.tsx`);
|
|
194995
|
+
if (fs.existsSync(globalErrorPath)) {
|
|
194996
|
+
return 'ErrorBoundary';
|
|
194997
|
+
}
|
|
194998
|
+
return undefined;
|
|
194999
|
+
}
|
|
195000
|
+
findNotFoundComponent(filePath, moduleName) {
|
|
195001
|
+
if (!moduleName)
|
|
195002
|
+
return undefined;
|
|
195003
|
+
const modulePagesDir = path.join(this.config.modulesDir, moduleName, 'pages');
|
|
195004
|
+
const notFoundPath = path.join(modulePagesDir, `${this.config.notFoundFileName}.tsx`);
|
|
195005
|
+
if (fs.existsSync(notFoundPath)) {
|
|
195006
|
+
return this.generateComponentName(notFoundPath, moduleName, 'NotFound');
|
|
195007
|
+
}
|
|
195008
|
+
return undefined;
|
|
195009
|
+
}
|
|
195010
|
+
generateComponentName(filePath, moduleName, suffix) {
|
|
195011
|
+
if (!moduleName) {
|
|
195012
|
+
return suffix;
|
|
195013
|
+
}
|
|
195014
|
+
const relativePath = path.relative(path.join(this.config.modulesDir, moduleName, 'pages'), path.dirname(filePath));
|
|
195015
|
+
let componentName = this.toPascalCase(moduleName);
|
|
195016
|
+
if (relativePath && relativePath !== '.') {
|
|
195017
|
+
const dirNames = relativePath.split(path.sep).filter(dir => dir && dir !== '.');
|
|
195018
|
+
dirNames.forEach(dir => {
|
|
195019
|
+
componentName += this.toPascalCase(dir);
|
|
195020
|
+
});
|
|
195021
|
+
}
|
|
195022
|
+
return componentName + suffix;
|
|
195023
|
+
}
|
|
195024
|
+
generateAutoRoutesFile() {
|
|
195025
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195026
|
+
const outputDir = path.dirname(this.config.outputFile);
|
|
195027
|
+
if (!fs.existsSync(outputDir)) {
|
|
195028
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
195029
|
+
}
|
|
195030
|
+
const content = this.generateFileContent();
|
|
195031
|
+
fs.writeFileSync(this.config.outputFile, content, 'utf-8');
|
|
195032
|
+
});
|
|
195033
|
+
}
|
|
195034
|
+
getRelativeImportPath(targetPath) {
|
|
195035
|
+
const outputDir = path.dirname(this.config.outputFile);
|
|
195036
|
+
const relative = path.relative(outputDir, targetPath);
|
|
195037
|
+
let importPath = relative.replace(/\\/g, '/');
|
|
195038
|
+
if (!importPath.startsWith('.') && !importPath.startsWith('/')) {
|
|
195039
|
+
importPath = './' + importPath;
|
|
195040
|
+
}
|
|
195041
|
+
importPath = importPath.replace(/\.(tsx|jsx)$/, '');
|
|
195042
|
+
return importPath;
|
|
195043
|
+
}
|
|
195044
|
+
generateFileContent() {
|
|
195045
|
+
const components = new Set();
|
|
195046
|
+
const imports = [
|
|
195047
|
+
`import { lazy } from 'react';`,
|
|
195048
|
+
`import type { RouteObject } from 'react-router-dom';`,
|
|
195049
|
+
``
|
|
195050
|
+
];
|
|
195051
|
+
const globalLayoutPath = path.join(this.config.pagesDir, `${this.config.layoutFileName}.tsx`);
|
|
195052
|
+
const globalErrorPath = path.join(this.config.pagesDir, `${this.config.errorFileName}.tsx`);
|
|
195053
|
+
const global404Path = path.join(this.config.pagesDir, `${this.config.notFoundFileName}.tsx`);
|
|
195054
|
+
if (fs.existsSync(globalLayoutPath)) {
|
|
195055
|
+
const importPath = this.getRelativeImportPath(globalLayoutPath);
|
|
195056
|
+
imports.push(`const Layout = lazy(() => import('${importPath}'));`);
|
|
195057
|
+
components.add('Layout');
|
|
195058
|
+
}
|
|
195059
|
+
if (fs.existsSync(globalErrorPath)) {
|
|
195060
|
+
const importPath = this.getRelativeImportPath(globalErrorPath);
|
|
195061
|
+
imports.push(`const ErrorBoundary = lazy(() => import('${importPath}'));`);
|
|
195062
|
+
components.add('ErrorBoundary');
|
|
195063
|
+
}
|
|
195064
|
+
if (fs.existsSync(global404Path)) {
|
|
195065
|
+
const importPath = this.getRelativeImportPath(global404Path);
|
|
195066
|
+
imports.push(`const NotFound = lazy(() => import('${importPath}'));`);
|
|
195067
|
+
components.add('NotFound');
|
|
195068
|
+
}
|
|
195069
|
+
imports.push(``);
|
|
195070
|
+
const moduleComponents = new Map();
|
|
195071
|
+
this.routeFiles.forEach(route => {
|
|
195072
|
+
if (route.layoutComponent && !components.has(route.layoutComponent)) {
|
|
195073
|
+
components.add(route.layoutComponent);
|
|
195074
|
+
const layoutFile = this.findComponentFile(route.filePath, this.config.layoutFileName, route.moduleName);
|
|
195075
|
+
if (layoutFile) {
|
|
195076
|
+
const importPath = this.getRelativeImportPath(layoutFile);
|
|
195077
|
+
imports.push(`const ${route.layoutComponent} = lazy(() => import('${importPath}'));`);
|
|
195078
|
+
}
|
|
195079
|
+
}
|
|
195080
|
+
if (route.errorComponent && !components.has(route.errorComponent)) {
|
|
195081
|
+
components.add(route.errorComponent);
|
|
195082
|
+
const errorFile = this.findComponentFile(route.filePath, this.config.errorFileName, route.moduleName);
|
|
195083
|
+
if (errorFile) {
|
|
195084
|
+
const importPath = this.getRelativeImportPath(errorFile);
|
|
195085
|
+
imports.push(`const ${route.errorComponent} = lazy(() => import('${importPath}'));`);
|
|
195086
|
+
}
|
|
195087
|
+
}
|
|
195088
|
+
if (route.notFoundComponent && !components.has(route.notFoundComponent)) {
|
|
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}'));`);
|
|
195094
|
+
}
|
|
195095
|
+
}
|
|
195096
|
+
const importPath = this.getRelativeImportPath(route.filePath);
|
|
195097
|
+
imports.push(`const ${route.componentName} = lazy(() => import('${importPath}'));`);
|
|
195098
|
+
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
|
+
});
|
|
195106
|
+
imports.push(``);
|
|
195107
|
+
const routes = ['export const routes: RouteObject[] = ['];
|
|
195108
|
+
const sortedRoutes = this.routeFiles.sort((a, b) => {
|
|
195109
|
+
if (a.routePath === '/')
|
|
195110
|
+
return -1;
|
|
195111
|
+
if (b.routePath === '/')
|
|
195112
|
+
return 1;
|
|
195113
|
+
if (!a.moduleName && b.moduleName)
|
|
195114
|
+
return -1;
|
|
195115
|
+
if (a.moduleName && !b.moduleName)
|
|
195116
|
+
return 1;
|
|
195117
|
+
if (a.moduleName === b.moduleName) {
|
|
195118
|
+
return a.routePath.localeCompare(b.routePath);
|
|
195119
|
+
}
|
|
195120
|
+
return 0;
|
|
195121
|
+
});
|
|
195122
|
+
sortedRoutes.forEach((route, index) => {
|
|
195123
|
+
var _a;
|
|
195124
|
+
const routeLines = [' {'];
|
|
195125
|
+
routeLines.push(` path: '${route.routePath}',`);
|
|
195126
|
+
if (route.layoutComponent) {
|
|
195127
|
+
routeLines.push(` element: <${route.layoutComponent}><${route.componentName} /></${route.layoutComponent}>,`);
|
|
195128
|
+
}
|
|
195129
|
+
else {
|
|
195130
|
+
routeLines.push(` element: <${route.componentName} />,`);
|
|
195131
|
+
}
|
|
195132
|
+
if (route.errorComponent) {
|
|
195133
|
+
routeLines.push(` errorElement: <${route.errorComponent} />`);
|
|
195134
|
+
}
|
|
195135
|
+
if (routeLines[routeLines.length - 1].endsWith(',')) {
|
|
195136
|
+
routeLines[routeLines.length - 1] = routeLines[routeLines.length - 1].slice(0, -1);
|
|
195137
|
+
}
|
|
195138
|
+
routeLines.push(' }');
|
|
195139
|
+
if (index < sortedRoutes.length - 1) {
|
|
195140
|
+
routeLines[routeLines.length - 1] += ',';
|
|
195141
|
+
}
|
|
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
|
+
routes.push(routeLines.join('\n'));
|
|
195147
|
+
});
|
|
195148
|
+
const modulesWith404 = new Set();
|
|
195149
|
+
this.routeFiles.forEach(route => {
|
|
195150
|
+
if (route.notFoundComponent && route.moduleName && !modulesWith404.has(route.moduleName)) {
|
|
195151
|
+
modulesWith404.add(route.moduleName);
|
|
195152
|
+
routes.push(`,`);
|
|
195153
|
+
routes.push(` {`);
|
|
195154
|
+
routes.push(` path: '/${route.moduleName}/*',`);
|
|
195155
|
+
routes.push(` element: <${route.notFoundComponent} />`);
|
|
195156
|
+
routes.push(` }`);
|
|
195157
|
+
}
|
|
195158
|
+
});
|
|
195159
|
+
if (components.has('NotFound')) {
|
|
195160
|
+
if (routes[routes.length - 1].endsWith(',')) {
|
|
195161
|
+
routes[routes.length - 1] = routes[routes.length - 1].slice(0, -1);
|
|
195162
|
+
}
|
|
195163
|
+
routes.push(`,`);
|
|
195164
|
+
routes.push(` {`);
|
|
195165
|
+
routes.push(` path: '*',`);
|
|
195166
|
+
routes.push(` element: <NotFound />`);
|
|
195167
|
+
routes.push(` }`);
|
|
195168
|
+
}
|
|
195169
|
+
routes.push('];');
|
|
195170
|
+
routes.push('');
|
|
195171
|
+
routes.push('export default routes;');
|
|
195172
|
+
return [
|
|
195173
|
+
...imports,
|
|
195174
|
+
'',
|
|
195175
|
+
...routes
|
|
195176
|
+
].join('\n');
|
|
195177
|
+
}
|
|
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
|
+
}
|
|
195203
|
+
function RouteInitiator() {
|
|
195204
|
+
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$1) {
|
|
195205
|
+
const config = {};
|
|
195206
|
+
const generator = new RouteGenerator(config, dirname);
|
|
195207
|
+
try {
|
|
195208
|
+
yield generator.generate();
|
|
195209
|
+
console.log('🎉 Route generation completed successfully!');
|
|
195210
|
+
}
|
|
195211
|
+
catch (err) {
|
|
195212
|
+
console.error('❌ Failed to generate routes: ', err);
|
|
195213
|
+
}
|
|
195214
|
+
});
|
|
195215
|
+
}
|
|
195216
|
+
|
|
194794
195217
|
function index (dirname = __dirname) {
|
|
194795
195218
|
TranslationInitiator(dirname);
|
|
194796
195219
|
ConfigInitiator(dirname);
|
|
195220
|
+
RouteInitiator(dirname);
|
|
194797
195221
|
}
|
|
194798
195222
|
|
|
194799
195223
|
module.exports = index;
|
package/index.min.d.ts
CHANGED