@arc-js/core 0.0.57 → 0.0.59
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/README.md +371 -409
- package/config.d.ts +1 -5
- package/config.js +1 -6
- package/config.min.js +1 -1
- package/{rooting.hooks.jsx → hooks.jsx} +3 -6
- package/{rooting.hooks.tsx → hooks.tsx} +4 -5
- package/package.json +2 -6
- package/utils.d.ts +1 -2
- package/utils.js +1 -6
- package/utils.min.js +1 -1
- package/auto-rooting.jsx +0 -25
- package/auto-rooting.tsx +0 -52
- package/minimal-config.d.ts +0 -33
- package/minimal-config.js +0 -93
- package/minimal-config.min.js +0 -2
- package/routes-utils.d.ts +0 -17
- package/routes-utils.js +0 -243
- package/routes-utils.min.js +0 -2
- package/types.d.ts +0 -31
- package/types.js +0 -1
- package/types.min.js +0 -2
- package/vite.config.ts +0 -14
package/config.d.ts
CHANGED
package/config.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
const NODEENV = 'development';
|
|
3
2
|
const langs = ['en', 'fr'];
|
|
4
3
|
const langCodes = {
|
|
5
4
|
'fr': 'fr_FR',
|
|
6
5
|
'en': 'en_US',
|
|
7
6
|
};
|
|
8
|
-
const PATH_CONFIG = {
|
|
9
|
-
SRC_DIR: '/src',
|
|
10
|
-
};
|
|
11
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
|
|
12
7
|
|
|
13
|
-
export { NODEENV,
|
|
8
|
+
export { NODEENV, langCodes, langs };
|
package/config.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
let NODEENV="development",langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"};export{NODEENV,langCodes,langs};
|
|
2
2
|
//# sourceMappingURL=config.min.js.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { useEffect } from 'react';
|
|
2
3
|
import { useLocation, useNavigate, useParams, generatePath, createSearchParams, matchPath } from 'react-router-dom';
|
|
3
4
|
import { getLang } from './utils';
|
|
4
|
-
import { qust } from '@arc-js/qust'
|
|
5
|
-
import React from "react"
|
|
6
|
-
|
|
5
|
+
import { qust } from '@arc-js/qust'
|
|
7
6
|
|
|
8
7
|
function getParams() {
|
|
9
8
|
const queryString = window.location.search;
|
|
@@ -33,9 +32,7 @@ export function nativeResolveRoute(config, incorrectUrl = "") {
|
|
|
33
32
|
}
|
|
34
33
|
return res;
|
|
35
34
|
} catch (error) {
|
|
36
|
-
|
|
37
|
-
console.log(error);
|
|
38
|
-
}
|
|
35
|
+
console.error(error);
|
|
39
36
|
return incorrectUrl;
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useLocation, useNavigate, useParams, generatePath, createSearchParams,
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
import { useLocation, useNavigate, useParams, generatePath, createSearchParams, matchPath } from 'react-router-dom';
|
|
3
|
+
import type { NavigateFunction, Params } from 'react-router';
|
|
3
4
|
import { getLang } from './utils';
|
|
4
5
|
import { qust, Qust } from '@arc-js/qust';
|
|
5
6
|
|
|
@@ -98,9 +99,7 @@ export function nativeResolveRoute(config: ConfigResolveRoute, incorrectUrl: str
|
|
|
98
99
|
|
|
99
100
|
return res;
|
|
100
101
|
} catch (error) {
|
|
101
|
-
|
|
102
|
-
console.log(error);
|
|
103
|
-
}
|
|
102
|
+
console.error(error);
|
|
104
103
|
|
|
105
104
|
return incorrectUrl;
|
|
106
105
|
}
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.0.
|
|
7
|
-
"description": "CORE est un
|
|
6
|
+
"version": "0.0.59",
|
|
7
|
+
"description": "CORE est un ensemble de hooks et utilitaires de routage avancés pour les applications React avec TypeScript/JavaScript. Il fournit des fonctionnalités de navigation avancées, une gestion automatique des langues et des utilitaires pour simplifier le développement d'applications React Router.",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"keywords": [],
|
|
10
10
|
"author": "INICODE <contact.inicode@gmail.com>",
|
|
@@ -14,15 +14,11 @@
|
|
|
14
14
|
"login": "npm login"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@vitejs/plugin-react": "^4.3.4",
|
|
18
|
-
"vite": "^6.4.1"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
19
|
"react-router-dom": "^7.11.0",
|
|
22
20
|
"react": "^19.2.3",
|
|
23
21
|
"react-dom": "^19.2.3",
|
|
24
|
-
"vite-plugin-html": "^3.2.2",
|
|
25
|
-
"vite-tsconfig-paths": "^5.1.4",
|
|
26
22
|
"@arc-js/qust": "^0.0.3"
|
|
27
23
|
}
|
|
28
24
|
}
|
package/utils.d.ts
CHANGED
package/utils.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
const langs = ['en', 'fr'];
|
|
3
2
|
const langCodes = {
|
|
4
3
|
'fr': 'fr_FR',
|
|
5
4
|
'en': 'en_US',
|
|
6
5
|
};
|
|
7
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
|
|
8
6
|
|
|
9
7
|
function getLang(lang) {
|
|
10
8
|
let result = lang;
|
|
@@ -14,8 +12,5 @@ function getLang(lang) {
|
|
|
14
12
|
function getLangCode(lang) {
|
|
15
13
|
return langCodes[getLang(lang)];
|
|
16
14
|
}
|
|
17
|
-
function getSrcPath() {
|
|
18
|
-
return SRC_DIR;
|
|
19
|
-
}
|
|
20
15
|
|
|
21
|
-
export { getLang, getLangCode
|
|
16
|
+
export { getLang, getLangCode };
|
package/utils.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
let langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"};function getLang(n){return langs.includes(n)?n:"fr"}function getLangCode(n){return langCodes[getLang(n)]}export{getLang,getLangCode};
|
|
2
2
|
//# sourceMappingURL=utils.min.js.map
|
package/auto-rooting.jsx
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as autoRoutes from './routes-utils';
|
|
2
|
-
import { useRootingActions } from './rooting.hooks';
|
|
3
|
-
import React from "react";
|
|
4
|
-
|
|
5
|
-
export default () => {
|
|
6
|
-
let routes = autoRoutes.routes.map(route => ({
|
|
7
|
-
path: route.path,
|
|
8
|
-
element: route.layout ? React.createElement(route.layout, null, React.createElement(route.component, null)) : React.createElement(route.component, null),
|
|
9
|
-
...(!!route.error ? {
|
|
10
|
-
errorElement: React.createElement(route.error, null)
|
|
11
|
-
} : {})
|
|
12
|
-
}));
|
|
13
|
-
let homeRoute = undefined;
|
|
14
|
-
let notFoundRoute = undefined;
|
|
15
|
-
homeRoute = routes.find(a => a.path === '/');
|
|
16
|
-
notFoundRoute = routes.find(a => a.path === '*');
|
|
17
|
-
routes = [...(!!homeRoute ? [homeRoute] : []), ...routes.filter(route => !(!!route.path && ['/', '*'].includes(route.path))), ...(!!notFoundRoute ? [notFoundRoute] : [])].filter(route => !!route.path && route.path.indexOf('/_404') === -1 && route.path.indexOf('/_layout') === -1);
|
|
18
|
-
if (process.env?.NODE_ENV === 'development') {
|
|
19
|
-
console.log(`[router -> routes.tsx] notFoundRoute:: `, notFoundRoute);
|
|
20
|
-
console.log(`[router -> routes.tsx] autoRoutes:: `, autoRoutes);
|
|
21
|
-
console.log(`[router -> routes.tsx] routes:: `, routes);
|
|
22
|
-
}
|
|
23
|
-
return routes;
|
|
24
|
-
};
|
|
25
|
-
export { useRootingActions };
|
package/auto-rooting.tsx
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Navigate, RouteObject } from "react-router-dom";
|
|
2
|
-
import { lazy } from 'react';
|
|
3
|
-
import * as autoRoutes from './routes-utils';
|
|
4
|
-
import { useRootingActions } from './rooting.hooks';
|
|
5
|
-
import { RouteDefinition } from './types';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export default () => {
|
|
10
|
-
let routes: RouteObject[] = autoRoutes.routes.map((route) => ({
|
|
11
|
-
path: route.path,
|
|
12
|
-
element: route.layout ? (
|
|
13
|
-
<route.layout>
|
|
14
|
-
<route.component />
|
|
15
|
-
</route.layout>
|
|
16
|
-
) : (
|
|
17
|
-
<route.component />
|
|
18
|
-
),
|
|
19
|
-
...(!!route.error ? {
|
|
20
|
-
errorElement: <route.error />,
|
|
21
|
-
} : {}),
|
|
22
|
-
}));
|
|
23
|
-
let homeRoute: RouteObject | undefined = undefined;
|
|
24
|
-
let notFoundRoute: RouteObject | undefined = undefined;
|
|
25
|
-
homeRoute = routes.find((a) => a.path === '/');
|
|
26
|
-
notFoundRoute = routes.find((a) => a.path === '*');
|
|
27
|
-
routes = [
|
|
28
|
-
...(!!homeRoute ? [homeRoute] : []),
|
|
29
|
-
...routes.filter((route) => !(
|
|
30
|
-
!!route.path &&
|
|
31
|
-
['/', '*'].includes(route.path)
|
|
32
|
-
)),
|
|
33
|
-
...(!!notFoundRoute ? [notFoundRoute] : []),
|
|
34
|
-
].filter((route) => (
|
|
35
|
-
!!route.path && (
|
|
36
|
-
route.path.indexOf('/_404') === -1 &&
|
|
37
|
-
route.path.indexOf('/_layout') === -1
|
|
38
|
-
)
|
|
39
|
-
));
|
|
40
|
-
|
|
41
|
-
if(process.env?.NODE_ENV === 'development') {
|
|
42
|
-
console.log(`[router -> routes.tsx] notFoundRoute:: `, notFoundRoute);
|
|
43
|
-
console.log(`[router -> routes.tsx] autoRoutes:: `, autoRoutes);
|
|
44
|
-
console.log(`[router -> routes.tsx] routes:: `, routes);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return routes;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export {
|
|
51
|
-
useRootingActions,
|
|
52
|
-
};
|
package/minimal-config.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
interface RouteDefinition {
|
|
4
|
-
truePath: string;
|
|
5
|
-
pathParent?: string;
|
|
6
|
-
path: string;
|
|
7
|
-
component: React.ComponentType<any>;
|
|
8
|
-
layout?: React.ComponentType<{
|
|
9
|
-
children: ReactNode;
|
|
10
|
-
}>;
|
|
11
|
-
error?: React.ComponentType<{}>;
|
|
12
|
-
}
|
|
13
|
-
interface ConfigDefinition {
|
|
14
|
-
parentTruePath: string;
|
|
15
|
-
truePath: string;
|
|
16
|
-
path: string;
|
|
17
|
-
name: string | undefined;
|
|
18
|
-
config: ConfigDatasDefinition;
|
|
19
|
-
}
|
|
20
|
-
interface ConfigDatasDefinition {
|
|
21
|
-
path: string;
|
|
22
|
-
name: string | undefined;
|
|
23
|
-
author: string | undefined;
|
|
24
|
-
isEnabled: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare const configModules: Record<string, () => Promise<any>>;
|
|
28
|
-
declare function cleanPathConfig(filePath: string): string;
|
|
29
|
-
declare function filePathToConfigPath(filePath: string, isParent?: boolean): string;
|
|
30
|
-
declare function getAllConfig(): Promise<ConfigDefinition[]>;
|
|
31
|
-
declare function findConfigModuleRoute(route: RouteDefinition, configDatas: ConfigDefinition[]): ConfigDatasDefinition | undefined;
|
|
32
|
-
|
|
33
|
-
export { cleanPathConfig, configModules, filePathToConfigPath, findConfigModuleRoute, getAllConfig };
|
package/minimal-config.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
16
|
-
var e = new Error(message);
|
|
17
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
var _a;
|
|
21
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
|
|
22
|
-
|
|
23
|
-
const configModules = import.meta.glob([
|
|
24
|
-
'@/config.json',
|
|
25
|
-
'@/modules/**/config.json'
|
|
26
|
-
]);
|
|
27
|
-
function cleanPathConfig(filePath) {
|
|
28
|
-
const srcPath = SRC_DIR;
|
|
29
|
-
return filePath
|
|
30
|
-
.replace(new RegExp(`^${srcPath}`), '')
|
|
31
|
-
.replace(new RegExp(`^${srcPath}/modules`), '')
|
|
32
|
-
.replace(/^\/modules\//, '')
|
|
33
|
-
.replace(/config\.json$/, '');
|
|
34
|
-
}
|
|
35
|
-
function filePathToConfigPath(filePath, isParent = false) {
|
|
36
|
-
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
37
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
38
|
-
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
39
|
-
subPath.length > 0)).join('/');
|
|
40
|
-
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
41
|
-
}
|
|
42
|
-
function getAllConfig() {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
45
|
-
const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
|
|
46
|
-
const configPath = filePathToConfigPath(filePath);
|
|
47
|
-
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
48
|
-
nameConfig = (typeof nameConfig === 'string' &&
|
|
49
|
-
nameConfig.length > 0) ? nameConfig : undefined;
|
|
50
|
-
let config = (yield module()).default;
|
|
51
|
-
config = (typeof config === 'object' &&
|
|
52
|
-
!Array.isArray(config) &&
|
|
53
|
-
Object.keys(config).length > 0) ? {
|
|
54
|
-
path: ((typeof (config === null || config === void 0 ? void 0 : config.path) === 'string' &&
|
|
55
|
-
(config === null || config === void 0 ? void 0 : config.path.length) > 0) ? config === null || config === void 0 ? void 0 : config.path : configPath),
|
|
56
|
-
name: ((typeof (config === null || config === void 0 ? void 0 : config.name) === 'string' &&
|
|
57
|
-
(config === null || config === void 0 ? void 0 : config.name.length) > 0) ? config === null || config === void 0 ? void 0 : config.name : nameConfig),
|
|
58
|
-
description: ((typeof (config === null || config === void 0 ? void 0 : config.description) === 'string' &&
|
|
59
|
-
(config === null || config === void 0 ? void 0 : config.description.length) > 0) ? config === null || config === void 0 ? void 0 : config.description : undefined),
|
|
60
|
-
author: ((typeof (config === null || config === void 0 ? void 0 : config.author) === 'string' &&
|
|
61
|
-
(config === null || config === void 0 ? void 0 : config.author.length) > 0) ? config === null || config === void 0 ? void 0 : config.author : undefined),
|
|
62
|
-
isEnabled: ((typeof (config === null || config === void 0 ? void 0 : config.isEnabled) === 'boolean') ? config === null || config === void 0 ? void 0 : config.isEnabled : true),
|
|
63
|
-
} : {
|
|
64
|
-
path: configPath,
|
|
65
|
-
name: nameConfig,
|
|
66
|
-
author: undefined,
|
|
67
|
-
isEnabled: true,
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
parentTruePath,
|
|
71
|
-
truePath: filePath,
|
|
72
|
-
path: configPath,
|
|
73
|
-
name: nameConfig,
|
|
74
|
-
description: undefined,
|
|
75
|
-
config,
|
|
76
|
-
};
|
|
77
|
-
})));
|
|
78
|
-
return configs;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function findConfigModuleRoute(route, configDatas) {
|
|
82
|
-
var _a;
|
|
83
|
-
const res = (_a = configDatas.sort((a, b) => {
|
|
84
|
-
if (a.truePath.split('/').length > b.truePath.split('/').length)
|
|
85
|
-
return -1;
|
|
86
|
-
if (a.truePath.split('/').length < b.truePath.split('/').length)
|
|
87
|
-
return 1;
|
|
88
|
-
return 0;
|
|
89
|
-
}).find((config) => (route.truePath.indexOf(config.parentTruePath) === 0))) === null || _a === void 0 ? void 0 : _a.config;
|
|
90
|
-
return res;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { cleanPathConfig, configModules, filePathToConfigPath, findConfigModuleRoute, getAllConfig };
|
package/minimal-config.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function __awaiter(n,a,r,u){return new(r=r||Promise)(function(e,t){function o(n){try{l(u.next(n))}catch(n){t(n)}}function i(n){try{l(u.throw(n))}catch(n){t(n)}}function l(n){var t;n.done?e(n.value):((t=n.value)instanceof r?t:new r(function(n){n(t)})).then(o,i)}l((u=u.apply(n,a||[])).next())})}var _a;let SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.VITE_APP_SRC_DIR)||"/src",configModules=import.meta.glob(["@/config.json","@/modules/**/config.json"]);function cleanPathConfig(n){var t=SRC_DIR;return n.replace(new RegExp("^"+t),"").replace(new RegExp(`^${t}/modules`),"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(n,t=!1){let e=(t="boolean"==typeof t&&t)?n.replace(/config\.json$/,""):cleanPathConfig(n);return(e=e.split("/").filter(n=>"string"==typeof n&&0<n.length).join("/")).startsWith("/")?e:("/"+e).split("//").join("/")}function getAllConfig(){return __awaiter(this,void 0,void 0,function*(){return yield Promise.all(Object.entries(configModules).map(n=>__awaiter(this,[n],void 0,function*([n,t]){var e=filePathToConfigPath(n,!0).split("/").join("/"),o=filePathToConfigPath(n),i="string"==typeof(i=o.split("/").filter((n,t,e)=>0<t).join("/"))&&0<i.length?i:void 0,t=(yield t()).default;return{parentTruePath:e,truePath:n,path:o,name:i,description:void 0,config:"object"==typeof t&&!Array.isArray(t)&&0<Object.keys(t).length?{path:"string"==typeof(null==t?void 0:t.path)&&0<(null==t?void 0:t.path.length)?null==t?void 0:t.path:o,name:"string"==typeof(null==t?void 0:t.name)&&0<(null==t?void 0:t.name.length)?null==t?void 0:t.name:i,description:!("string"==typeof(null==t?void 0:t.description)&&0<(null==t?void 0:t.description.length))||null==t?void 0:t.description,author:!("string"==typeof(null==t?void 0:t.author)&&0<(null==t?void 0:t.author.length))||null==t?void 0:t.author,isEnabled:"boolean"!=typeof(null==t?void 0:t.isEnabled)||(null==t?void 0:t.isEnabled)}:{path:o,name:i,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(t,n){return null==(n=n.sort((n,t)=>n.truePath.split("/").length>t.truePath.split("/").length?-1:n.truePath.split("/").length<t.truePath.split("/").length?1:0).find(n=>0===t.truePath.indexOf(n.parentTruePath)))?void 0:n.config}export{cleanPathConfig,configModules,filePathToConfigPath,findConfigModuleRoute,getAllConfig};
|
|
2
|
-
//# sourceMappingURL=minimal-config.min.js.map
|
package/routes-utils.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
interface RouteDefinition {
|
|
4
|
-
truePath: string;
|
|
5
|
-
pathParent?: string;
|
|
6
|
-
path: string;
|
|
7
|
-
component: React.ComponentType<any>;
|
|
8
|
-
layout?: React.ComponentType<{
|
|
9
|
-
children: ReactNode;
|
|
10
|
-
}>;
|
|
11
|
-
error?: React.ComponentType<{}>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare function getRoutes(): Promise<RouteDefinition[]>;
|
|
15
|
-
declare const routes: RouteDefinition[];
|
|
16
|
-
|
|
17
|
-
export { getRoutes, routes };
|
package/routes-utils.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
16
|
-
var e = new Error(message);
|
|
17
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
var _a;
|
|
21
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
|
|
22
|
-
|
|
23
|
-
const configModules = import.meta.glob([
|
|
24
|
-
'@/config.json',
|
|
25
|
-
'@/modules/**/config.json'
|
|
26
|
-
]);
|
|
27
|
-
function cleanPathConfig(filePath) {
|
|
28
|
-
const srcPath = SRC_DIR;
|
|
29
|
-
return filePath
|
|
30
|
-
.replace(new RegExp(`^${srcPath}`), '')
|
|
31
|
-
.replace(new RegExp(`^${srcPath}/modules`), '')
|
|
32
|
-
.replace(/^\/modules\//, '')
|
|
33
|
-
.replace(/config\.json$/, '');
|
|
34
|
-
}
|
|
35
|
-
function filePathToConfigPath(filePath, isParent = false) {
|
|
36
|
-
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
37
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
38
|
-
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
39
|
-
subPath.length > 0)).join('/');
|
|
40
|
-
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
41
|
-
}
|
|
42
|
-
function getAllConfig() {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
45
|
-
const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
|
|
46
|
-
const configPath = filePathToConfigPath(filePath);
|
|
47
|
-
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
48
|
-
nameConfig = (typeof nameConfig === 'string' &&
|
|
49
|
-
nameConfig.length > 0) ? nameConfig : undefined;
|
|
50
|
-
let config = (yield module()).default;
|
|
51
|
-
config = (typeof config === 'object' &&
|
|
52
|
-
!Array.isArray(config) &&
|
|
53
|
-
Object.keys(config).length > 0) ? {
|
|
54
|
-
path: ((typeof (config === null || config === void 0 ? void 0 : config.path) === 'string' &&
|
|
55
|
-
(config === null || config === void 0 ? void 0 : config.path.length) > 0) ? config === null || config === void 0 ? void 0 : config.path : configPath),
|
|
56
|
-
name: ((typeof (config === null || config === void 0 ? void 0 : config.name) === 'string' &&
|
|
57
|
-
(config === null || config === void 0 ? void 0 : config.name.length) > 0) ? config === null || config === void 0 ? void 0 : config.name : nameConfig),
|
|
58
|
-
description: ((typeof (config === null || config === void 0 ? void 0 : config.description) === 'string' &&
|
|
59
|
-
(config === null || config === void 0 ? void 0 : config.description.length) > 0) ? config === null || config === void 0 ? void 0 : config.description : undefined),
|
|
60
|
-
author: ((typeof (config === null || config === void 0 ? void 0 : config.author) === 'string' &&
|
|
61
|
-
(config === null || config === void 0 ? void 0 : config.author.length) > 0) ? config === null || config === void 0 ? void 0 : config.author : undefined),
|
|
62
|
-
isEnabled: ((typeof (config === null || config === void 0 ? void 0 : config.isEnabled) === 'boolean') ? config === null || config === void 0 ? void 0 : config.isEnabled : true),
|
|
63
|
-
} : {
|
|
64
|
-
path: configPath,
|
|
65
|
-
name: nameConfig,
|
|
66
|
-
author: undefined,
|
|
67
|
-
isEnabled: true,
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
parentTruePath,
|
|
71
|
-
truePath: filePath,
|
|
72
|
-
path: configPath,
|
|
73
|
-
name: nameConfig,
|
|
74
|
-
description: undefined,
|
|
75
|
-
config,
|
|
76
|
-
};
|
|
77
|
-
})));
|
|
78
|
-
return configs;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function findConfigModuleRoute(route, configDatas) {
|
|
82
|
-
var _a;
|
|
83
|
-
const res = (_a = configDatas.sort((a, b) => {
|
|
84
|
-
if (a.truePath.split('/').length > b.truePath.split('/').length)
|
|
85
|
-
return -1;
|
|
86
|
-
if (a.truePath.split('/').length < b.truePath.split('/').length)
|
|
87
|
-
return 1;
|
|
88
|
-
return 0;
|
|
89
|
-
}).find((config) => (route.truePath.indexOf(config.parentTruePath) === 0))) === null || _a === void 0 ? void 0 : _a.config;
|
|
90
|
-
return res;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const errorPageName = '_error';
|
|
94
|
-
const defaultErrorPath = `${SRC_DIR}/pages/_error`;
|
|
95
|
-
const notFoundPageName = '_404';
|
|
96
|
-
const notFoundPagePath = '*';
|
|
97
|
-
const defaultLayoutPath = `${SRC_DIR}/pages/_layout`;
|
|
98
|
-
const layoutName = '_layout';
|
|
99
|
-
const indexPageName = 'index';
|
|
100
|
-
const indexPageRule = /\/index$/;
|
|
101
|
-
const indexPagePath = '/';
|
|
102
|
-
const pageModules = import.meta.glob([
|
|
103
|
-
'@/pages/**/*.tsx',
|
|
104
|
-
'@/modules/**/pages/**/*.tsx'
|
|
105
|
-
]);
|
|
106
|
-
function cleanPathPage(filePath) {
|
|
107
|
-
const srcPath = SRC_DIR;
|
|
108
|
-
return filePath
|
|
109
|
-
.replace(new RegExp(`^${srcPath}/pages`), '')
|
|
110
|
-
.replace(new RegExp(`^${srcPath}/modules`), '')
|
|
111
|
-
.replace(/\/pages\//, '/')
|
|
112
|
-
.replace(/\.tsx$/, '')
|
|
113
|
-
.replace(/\{([^\]]+)\}/g, ':$1');
|
|
114
|
-
}
|
|
115
|
-
function filePathToRoutePath(filePath) {
|
|
116
|
-
let routePath = cleanPathPage(filePath);
|
|
117
|
-
if (routePath.endsWith(`/${indexPageName}`)) {
|
|
118
|
-
routePath = routePath.replace(indexPageRule, '') || indexPagePath;
|
|
119
|
-
}
|
|
120
|
-
else if (routePath === `${indexPageName}`) {
|
|
121
|
-
routePath = indexPagePath;
|
|
122
|
-
}
|
|
123
|
-
else if (routePath === notFoundPageName) {
|
|
124
|
-
routePath = notFoundPagePath;
|
|
125
|
-
return routePath;
|
|
126
|
-
}
|
|
127
|
-
return routePath.startsWith(indexPagePath) ? routePath : `/${routePath}`;
|
|
128
|
-
}
|
|
129
|
-
function findLayoutForPage(filePath) {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
const layoutPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${layoutName}.tsx`);
|
|
133
|
-
const layoutModules = import.meta.glob('@/modules/**/_layout.tsx', { eager: true });
|
|
134
|
-
const defaultLayoutModules = import.meta.glob('@/pages/_layout.tsx', { eager: true });
|
|
135
|
-
return ((_a = layoutModules[layoutPath]) === null || _a === void 0 ? void 0 : _a.default) || ((_b = defaultLayoutModules[`${defaultLayoutPath}.tsx`]) === null || _b === void 0 ? void 0 : _b.default);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
function findErrorForPage(filePath) {
|
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
var _a, _b, _c;
|
|
141
|
-
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
142
|
-
const errorModules = import.meta.glob('@/modules/**/_error.tsx', { eager: true });
|
|
143
|
-
const defaultErrorModules = import.meta.glob('@/pages/_error.tsx', { eager: true });
|
|
144
|
-
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'debug') {
|
|
145
|
-
console.log(`[@arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
|
|
146
|
-
filePath,
|
|
147
|
-
errorPath,
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
return ((_b = errorModules[errorPath]) === null || _b === void 0 ? void 0 : _b.default) || ((_c = defaultErrorModules[`${defaultErrorPath}.tsx`]) === null || _c === void 0 ? void 0 : _c.default);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
function findErrorForPageLink(filePath) {
|
|
154
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
156
|
-
return cleanPathPage(errorPath).split(SRC_DIR).join('');
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function nearestRoute(targetRoute, routes) {
|
|
160
|
-
const possibleLayouts = routes.map((route) => (Object.assign(Object.assign({}, route), { path: (route.path || '').split('/').filter((partRoute, indexPartRoute, arrayPartRoute) => ((arrayPartRoute.length >= 2 &&
|
|
161
|
-
typeof (arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2]) === 'string' &&
|
|
162
|
-
(arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2].length) <= 0 &&
|
|
163
|
-
indexPartRoute < (arrayPartRoute.length - 2)) ||
|
|
164
|
-
(!(arrayPartRoute.length >= 2 &&
|
|
165
|
-
typeof (arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2]) === 'string' &&
|
|
166
|
-
(arrayPartRoute === null || arrayPartRoute === void 0 ? void 0 : arrayPartRoute[arrayPartRoute.length - 2].length) <= 0) &&
|
|
167
|
-
indexPartRoute < (arrayPartRoute.length - 1)))).join('/') }))).filter((route) => targetRoute.path.indexOf(route.path) === 0).sort((a, b) => {
|
|
168
|
-
if (a.path.indexOf(targetRoute.path) > b.path.indexOf(targetRoute.path))
|
|
169
|
-
return -1;
|
|
170
|
-
if (a.path.indexOf(targetRoute.path) < b.path.indexOf(targetRoute.path))
|
|
171
|
-
return 1;
|
|
172
|
-
if (a.path.split('/').length > b.path.split('/').length)
|
|
173
|
-
return -1;
|
|
174
|
-
if (a.path.split('/').length < b.path.split('/').length)
|
|
175
|
-
return 1;
|
|
176
|
-
return 0;
|
|
177
|
-
});
|
|
178
|
-
return possibleLayouts === null || possibleLayouts === void 0 ? void 0 : possibleLayouts[0];
|
|
179
|
-
}
|
|
180
|
-
function getRoutes() {
|
|
181
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
var _a, _b, _c;
|
|
183
|
-
const configs = yield getAllConfig();
|
|
184
|
-
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
|
|
185
|
-
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
|
|
186
|
-
}
|
|
187
|
-
let routes = yield Promise.all(Object.entries(pageModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
188
|
-
let layout = (!([
|
|
189
|
-
notFoundPageName
|
|
190
|
-
].map((path) => (cleanPathPage(path))).includes(cleanPathPage(filePath)))) ? yield findLayoutForPage(filePath) : undefined;
|
|
191
|
-
let erroPage = yield findErrorForPage(filePath);
|
|
192
|
-
yield findErrorForPageLink(filePath);
|
|
193
|
-
const routePath = filePathToRoutePath(filePath);
|
|
194
|
-
const component = (yield module()).default;
|
|
195
|
-
const routePathParent = routePath.split('/').filter((val, index, arr) => (typeof val === 'string' &&
|
|
196
|
-
val.length > 0 &&
|
|
197
|
-
index < (arr.length - 1))).join('/');
|
|
198
|
-
return {
|
|
199
|
-
truePath: filePath,
|
|
200
|
-
path: routePath,
|
|
201
|
-
component,
|
|
202
|
-
layout,
|
|
203
|
-
error: erroPage,
|
|
204
|
-
pathParent: routePathParent,
|
|
205
|
-
};
|
|
206
|
-
})));
|
|
207
|
-
const notFoundRoutes = routes.filter((route) => (!!route.truePath &&
|
|
208
|
-
route.truePath.split('/').filter((partRoute) => partRoute.indexOf('_404.tsx') !== -1).length > 0)).map((route) => (Object.assign(Object.assign({}, route), { path: route.path.split('/').map((partRoute) => partRoute.split('_404').join(notFoundPagePath)).join('/') })));
|
|
209
|
-
routes = [
|
|
210
|
-
...routes.filter((route) => !(!!route.truePath &&
|
|
211
|
-
route.truePath.split('/').filter((partRoute) => partRoute.indexOf('_404.tsx') !== -1).length > 0)),
|
|
212
|
-
...notFoundRoutes,
|
|
213
|
-
];
|
|
214
|
-
const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
|
|
215
|
-
const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
|
|
216
|
-
if (((_b = process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') {
|
|
217
|
-
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | notFoundRoutes:: `, notFoundRoutes);
|
|
218
|
-
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | routes:: `, routes);
|
|
219
|
-
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | layoutRoutes:: `, layoutRoutes);
|
|
220
|
-
}
|
|
221
|
-
routes = routes.map((route) => {
|
|
222
|
-
var _a, _b;
|
|
223
|
-
return (Object.assign(Object.assign({}, route), { layout: ((_a = nearestRoute(route, layoutRoutes)) === null || _a === void 0 ? void 0 : _a.component) || route.layout, error: ((_b = nearestRoute(route, errorRoutes)) === null || _b === void 0 ? void 0 : _b.component) || route.error }));
|
|
224
|
-
});
|
|
225
|
-
const routesF = routes.map((route, indexRoute) => {
|
|
226
|
-
const routeConfig = findConfigModuleRoute(route, configs);
|
|
227
|
-
if (typeof (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) === 'string' &&
|
|
228
|
-
(routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path.length) > 0 &&
|
|
229
|
-
(routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) != '/') {
|
|
230
|
-
route.path = route.path.split('/').filter((subPath, indexSubPath, path) => (indexSubPath > 1)).join('/');
|
|
231
|
-
route.path = `${routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path}/${route.path}`.split('//').join('/');
|
|
232
|
-
}
|
|
233
|
-
return route;
|
|
234
|
-
});
|
|
235
|
-
if (((_c = process.env) === null || _c === void 0 ? void 0 : _c.NODE_ENV) === 'development') {
|
|
236
|
-
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
|
|
237
|
-
}
|
|
238
|
-
return routesF;
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
const routes = await getRoutes();
|
|
242
|
-
|
|
243
|
-
export { getRoutes, routes };
|
package/routes-utils.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function __awaiter(e,l,r,u){return new(r=r||Promise)(function(n,t){function a(e){try{o(u.next(e))}catch(e){t(e)}}function i(e){try{o(u.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(a,i)}o((u=u.apply(e,l||[])).next())})}var _a;let SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.VITE_APP_SRC_DIR)||"/src",configModules=import.meta.glob(["@/config.json","@/modules/**/config.json"]);function cleanPathConfig(e){var t=SRC_DIR;return e.replace(new RegExp("^"+t),"").replace(new RegExp(`^${t}/modules`),"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(e,t=!1){let n=(t="boolean"==typeof t&&t)?e.replace(/config\.json$/,""):cleanPathConfig(e);return(n=n.split("/").filter(e=>"string"==typeof e&&0<e.length).join("/")).startsWith("/")?n:("/"+n).split("//").join("/")}function getAllConfig(){return __awaiter(this,void 0,void 0,function*(){return yield Promise.all(Object.entries(configModules).map(e=>__awaiter(this,[e],void 0,function*([e,t]){var n=filePathToConfigPath(e,!0).split("/").join("/"),a=filePathToConfigPath(e),i="string"==typeof(i=a.split("/").filter((e,t,n)=>0<t).join("/"))&&0<i.length?i:void 0,t=(yield t()).default;return{parentTruePath:n,truePath:e,path:a,name:i,description:void 0,config:"object"==typeof t&&!Array.isArray(t)&&0<Object.keys(t).length?{path:"string"==typeof(null==t?void 0:t.path)&&0<(null==t?void 0:t.path.length)?null==t?void 0:t.path:a,name:"string"==typeof(null==t?void 0:t.name)&&0<(null==t?void 0:t.name.length)?null==t?void 0:t.name:i,description:!("string"==typeof(null==t?void 0:t.description)&&0<(null==t?void 0:t.description.length))||null==t?void 0:t.description,author:!("string"==typeof(null==t?void 0:t.author)&&0<(null==t?void 0:t.author.length))||null==t?void 0:t.author,isEnabled:"boolean"!=typeof(null==t?void 0:t.isEnabled)||(null==t?void 0:t.isEnabled)}:{path:a,name:i,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(t,e){return null==(e=e.sort((e,t)=>e.truePath.split("/").length>t.truePath.split("/").length?-1:e.truePath.split("/").length<t.truePath.split("/").length?1:0).find(e=>0===t.truePath.indexOf(e.parentTruePath)))?void 0:e.config}let errorPageName="_error",defaultErrorPath=SRC_DIR+"/pages/_error",notFoundPageName="_404",notFoundPagePath="*",defaultLayoutPath=SRC_DIR+"/pages/_layout",layoutName="_layout",indexPageName="index",indexPageRule=/\/index$/,indexPagePath="/",pageModules=import.meta.glob(["@/pages/**/*.tsx","@/modules/**/pages/**/*.tsx"]);function cleanPathPage(e){var t=SRC_DIR;return e.replace(new RegExp(`^${t}/pages`),"").replace(new RegExp(`^${t}/modules`),"").replace(/\/pages\//,"/").replace(/\.tsx$/,"").replace(/\{([^\]]+)\}/g,":$1")}function filePathToRoutePath(e){let t=cleanPathPage(e);if(t.endsWith("/"+indexPageName))t=t.replace(indexPageRule,"")||indexPagePath;else if(t===""+indexPageName)t=indexPagePath;else if(t===notFoundPageName)return t=notFoundPagePath;return t.startsWith(indexPagePath)?t:"/"+t}function findLayoutForPage(a){return __awaiter(this,void 0,void 0,function*(){var e=a.replace(/\/pages\/.*\.tsx$/,`/pages/${layoutName}.tsx`),t=import.meta.glob("@/modules/**/_layout.tsx",{eager:!0}),n=import.meta.glob("@/pages/_layout.tsx",{eager:!0});return(null==(t=t[e])?void 0:t.default)||(null==(e=n[defaultLayoutPath+".tsx"])?void 0:e.default)})}function findErrorForPage(i){return __awaiter(this,void 0,void 0,function*(){var e,t=i.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`),n=import.meta.glob("@/modules/**/_error.tsx",{eager:!0}),a=import.meta.glob("@/pages/_error.tsx",{eager:!0});return null!=(e=process.env)&&e.NODE_ENV,(null==(e=n[t])?void 0:e.default)||(null==(n=a[defaultErrorPath+".tsx"])?void 0:n.default)})}function findErrorForPageLink(e){return __awaiter(this,void 0,void 0,function*(){return cleanPathPage(e.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`)).split(SRC_DIR).join("")})}function nearestRoute(n,e){e=e.map(e=>Object.assign(Object.assign({},e),{path:(e.path||"").split("/").filter((e,t,n)=>2<=n.length&&"string"==typeof(null==n?void 0:n[n.length-2])&&(null==n?void 0:n[n.length-2].length)<=0&&t<n.length-2||!(2<=n.length&&"string"==typeof(null==n?void 0:n[n.length-2])&&(null==n?void 0:n[n.length-2].length)<=0)&&t<n.length-1).join("/")})).filter(e=>0===n.path.indexOf(e.path)).sort((e,t)=>e.path.indexOf(n.path)>t.path.indexOf(n.path)?-1:e.path.indexOf(n.path)<t.path.indexOf(n.path)?1:e.path.split("/").length>t.path.split("/").length?-1:e.path.split("/").length<t.path.split("/").length?1:0);return null==e?void 0:e[0]}function getRoutes(){return __awaiter(this,void 0,void 0,function*(){let e,t,n,a=yield getAllConfig(),i=(null==(e=process.env)||e.NODE_ENV,yield Promise.all(Object.entries(pageModules).map(e=>__awaiter(this,[e],void 0,function*([e,t]){var n=[notFoundPageName].map(e=>cleanPathPage(e)).includes(cleanPathPage(e))?void 0:yield findLayoutForPage(e),a=yield findErrorForPage(e),i=(yield findErrorForPageLink(e),filePathToRoutePath(e)),t=(yield t()).default,o=i.split("/").filter((e,t,n)=>"string"==typeof e&&0<e.length&&t<n.length-1).join("/");return{truePath:e,path:i,component:t,layout:n,error:a,pathParent:o}}))));var o=i.filter(e=>!!e.truePath&&0<e.truePath.split("/").filter(e=>-1!==e.indexOf("_404.tsx")).length).map(e=>Object.assign(Object.assign({},e),{path:e.path.split("/").map(e=>e.split("_404").join(notFoundPagePath)).join("/")}));let l=(i=[...i.filter(e=>!(e.truePath&&0<e.truePath.split("/").filter(e=>-1!==e.indexOf("_404.tsx")).length)),...o]).filter(e=>!!e.path&&-1!==e.path.indexOf("/_layout")),r=i.filter(e=>!!e.path&&-1!==e.path.indexOf("/_error"));null!=(t=process.env)&&t.NODE_ENV;o=(i=i.map(e=>{var t;return Object.assign(Object.assign({},e),{layout:(null==(t=nearestRoute(e,l))?void 0:t.component)||e.layout,error:(null==(t=nearestRoute(e,r))?void 0:t.component)||e.error})})).map((e,t)=>{var n=findConfigModuleRoute(e,a);return"string"==typeof(null==n?void 0:n.path)&&0<(null==n?void 0:n.path.length)&&"/"!=(null==n?void 0:n.path)&&(e.path=e.path.split("/").filter((e,t,n)=>1<t).join("/"),e.path=(`${null==n?void 0:n.path}/`+e.path).split("//").join("/")),e});return null!=(n=process.env)&&n.NODE_ENV,o})}let routes=await getRoutes();export{getRoutes,routes};
|
|
2
|
-
//# sourceMappingURL=routes-utils.min.js.map
|