@arc-js/core 0.0.20 → 0.0.40
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 +1 -3
- package/auto-rooting.jsx +2 -6
- package/auto-rooting.tsx +1 -4
- package/minimal-config.js +4 -4
- package/minimal-config.min.js +1 -1
- package/package.json +2 -2
- package/rooting.hooks.jsx +2 -86
- package/rooting.hooks.tsx +19 -73
- package/routes-utils.js +21 -21
- package/routes-utils.min.js +1 -1
package/README.md
CHANGED
package/auto-rooting.jsx
CHANGED
|
@@ -2,16 +2,12 @@ import * as autoRoutes from './routes-utils';
|
|
|
2
2
|
import { useRootingActions } from './rooting.hooks';
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Permet d'initialiser toutes les routes de l'application
|
|
7
|
-
* @returns RouteObject[]
|
|
8
|
-
*/
|
|
9
5
|
export default () => {
|
|
10
6
|
let routes = autoRoutes.routes.map(route => ({
|
|
11
7
|
path: route.path,
|
|
12
|
-
element: route.layout ?
|
|
8
|
+
element: route.layout ? React.createElement(route.layout, null, React.createElement(route.component, null)) : React.createElement(route.component, null),
|
|
13
9
|
...(!!route.error ? {
|
|
14
|
-
errorElement:
|
|
10
|
+
errorElement: React.createElement(route.error, null)
|
|
15
11
|
} : {})
|
|
16
12
|
}));
|
|
17
13
|
let homeRoute = undefined;
|
package/auto-rooting.tsx
CHANGED
|
@@ -5,10 +5,7 @@ import { useRootingActions } from './rooting.hooks';
|
|
|
5
5
|
import { RouteDefinition } from './types';
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
* Permet d'initialiser toutes les routes de l'application
|
|
10
|
-
* @returns RouteObject[]
|
|
11
|
-
*/
|
|
8
|
+
|
|
12
9
|
export default () => {
|
|
13
10
|
let routes: RouteObject[] = autoRoutes.routes.map((route) => ({
|
|
14
11
|
path: route.path,
|
package/minimal-config.js
CHANGED
|
@@ -18,13 +18,13 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const configModules = import.meta.glob([
|
|
21
|
-
'
|
|
22
|
-
'
|
|
21
|
+
'./config.json',
|
|
22
|
+
'./modules/**/config.json'
|
|
23
23
|
]);
|
|
24
24
|
function cleanPathConfig(filePath) {
|
|
25
25
|
return filePath
|
|
26
|
-
.replace(
|
|
27
|
-
.replace(
|
|
26
|
+
.replace(/^\./, '')
|
|
27
|
+
.replace(/^\.\/modules\//, '')
|
|
28
28
|
.replace(/^\/modules\//, '')
|
|
29
29
|
.replace(/config\.json$/, '');
|
|
30
30
|
}
|
package/minimal-config.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function __awaiter(t,a,r,u){return new(r=r||Promise)(function(e,n){function i(t){try{l(u.next(t))}catch(t){n(t)}}function o(t){try{l(u.throw(t))}catch(t){n(t)}}function l(t){var n;t.done?e(t.value):((n=t.value)instanceof r?n:new r(function(t){t(n)})).then(i,o)}l((u=u.apply(t,a||[])).next())})}let configModules=import.meta.glob(["
|
|
1
|
+
function __awaiter(t,a,r,u){return new(r=r||Promise)(function(e,n){function i(t){try{l(u.next(t))}catch(t){n(t)}}function o(t){try{l(u.throw(t))}catch(t){n(t)}}function l(t){var n;t.done?e(t.value):((n=t.value)instanceof r?n:new r(function(t){t(n)})).then(i,o)}l((u=u.apply(t,a||[])).next())})}let configModules=import.meta.glob(["./config.json","./modules/**/config.json"]);function cleanPathConfig(t){return t.replace(/^\./,"").replace(/^\.\/modules\//,"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(t,n=!1){let e=(n="boolean"==typeof n&&n)?t.replace(/config\.json$/,""):cleanPathConfig(t);return(e=e.split("/").filter(t=>"string"==typeof t&&0<t.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(t=>__awaiter(this,[t],void 0,function*([t,n]){var e=filePathToConfigPath(t,!0).split("/").join("/"),i=filePathToConfigPath(t),o="string"==typeof(o=i.split("/").filter((t,n,e)=>0<n).join("/"))&&0<o.length?o:void 0,n=(yield n()).default;return{parentTruePath:e,truePath:t,path:i,name:o,description:void 0,config:"object"==typeof n&&!Array.isArray(n)&&0<Object.keys(n).length?{path:"string"==typeof(null==n?void 0:n.path)&&0<(null==n?void 0:n.path.length)?null==n?void 0:n.path:i,name:"string"==typeof(null==n?void 0:n.name)&&0<(null==n?void 0:n.name.length)?null==n?void 0:n.name:o,description:!("string"==typeof(null==n?void 0:n.description)&&0<(null==n?void 0:n.description.length))||null==n?void 0:n.description,author:!("string"==typeof(null==n?void 0:n.author)&&0<(null==n?void 0:n.author.length))||null==n?void 0:n.author,isEnabled:"boolean"!=typeof(null==n?void 0:n.isEnabled)||(null==n?void 0:n.isEnabled)}:{path:i,name:o,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(n,t){return null==(t=t.sort((t,n)=>t.truePath.split("/").length>n.truePath.split("/").length?-1:t.truePath.split("/").length<n.truePath.split("/").length?1:0).find(t=>0===n.truePath.indexOf(t.parentTruePath)))?void 0:t.config}export{cleanPathConfig,configModules,filePathToConfigPath,findConfigModuleRoute,getAllConfig};
|
|
2
2
|
//# sourceMappingURL=minimal-config.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.40",
|
|
7
7
|
"description": "CORE est un module de routage intelligent et auto-configuré pour les applications React avec TypeScript/Javascript. Il fournit un système de routage basé sur la structure de fichiers, des hooks de navigation avancés et une configuration minimale pour les applications modulaires.",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"keywords": [],
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
"react-router-dom": "^7.11.0",
|
|
21
21
|
"react": "^19.2.3",
|
|
22
22
|
"react-dom": "^19.2.3",
|
|
23
|
-
"@arc-js/qust": "^0.0.
|
|
23
|
+
"@arc-js/qust": "^0.0.3"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/rooting.hooks.jsx
CHANGED
|
@@ -2,49 +2,15 @@ import { useEffect } from 'react';
|
|
|
2
2
|
import { useLocation, useNavigate, useParams, generatePath, createSearchParams, matchPath } from 'react-router-dom';
|
|
3
3
|
import { getLang } from './utils';
|
|
4
4
|
import { qust } from '@arc-js/qust';
|
|
5
|
-
import React from "react"
|
|
5
|
+
import React from "react"
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Interface du paramètre de configuration de la fonction "goAndReloadRoute" .
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Cette fonction permet de recuperer tous les parameters de l'url
|
|
16
|
-
*/
|
|
17
8
|
function getParams() {
|
|
18
9
|
const queryString = window.location.search;
|
|
19
10
|
const urlParams = new URLSearchParams(queryString);
|
|
20
11
|
return urlParams;
|
|
21
12
|
}
|
|
22
|
-
;
|
|
23
|
-
/**
|
|
24
|
-
* Interface du paramètre de configuration de la fonction "goAndReloadRoute" .
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
;
|
|
28
|
-
/**
|
|
29
|
-
* Interface du paramètre de configuration de la fonction "resolveRoute" .
|
|
30
|
-
*/
|
|
31
13
|
|
|
32
|
-
;
|
|
33
|
-
/**
|
|
34
|
-
* Interface du paramètre de configuration de la fonction "goToRoute" .
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
;
|
|
38
|
-
/**
|
|
39
|
-
* Interface de retour du hooks "useRootingActions".
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Cette fonction permet de recuperer une route en fonction de son path, ses paramètres et ses query parameters.
|
|
44
|
-
* @param config - la donnée de la route à ressortir
|
|
45
|
-
* @param incorrectUrl - la route qui sera prise en compte si le path n'existe pas
|
|
46
|
-
* @returns string
|
|
47
|
-
*/
|
|
48
14
|
export function nativeResolveRoute(config, incorrectUrl = "") {
|
|
49
15
|
try {
|
|
50
16
|
const params = typeof config?.params === 'object' && Array.isArray(config?.params) === false ? config?.params : {};
|
|
@@ -73,45 +39,15 @@ export function nativeResolveRoute(config, incorrectUrl = "") {
|
|
|
73
39
|
return incorrectUrl;
|
|
74
40
|
}
|
|
75
41
|
}
|
|
76
|
-
;
|
|
77
42
|
|
|
78
|
-
/**
|
|
79
|
-
* Ce hooks contient toutes les actions necessaires pour le routing.
|
|
80
|
-
* - recuperer les paramètres de la route
|
|
81
|
-
* - Recuperer les query parameters de la route
|
|
82
|
-
* - naviguer au travers des routes
|
|
83
|
-
* - recuperer une route en fonction de son path, ses paramètres et ses query parameters
|
|
84
|
-
* - naviguer vers une route en fonction de son path, ses paramètres et ses query parameters
|
|
85
|
-
* - naviguer vers une route en fonction de son path, ses paramètres et ses query parameters en rafraîchissant le navigateur
|
|
86
|
-
* - recuperer l'url de la route courante
|
|
87
|
-
* - recuperer la chaîne de caractères contenant les query parameters
|
|
88
|
-
* @type {() => RootingActionReturns}
|
|
89
|
-
* @returns {RootingActionReturns} Resultat du hooks.
|
|
90
|
-
*/
|
|
91
43
|
export const useRootingActions = () => {
|
|
92
44
|
const location = useLocation();
|
|
93
45
|
const pathname = location.pathname;
|
|
94
|
-
/**
|
|
95
|
-
* L'ensemble des parametres de la route
|
|
96
|
-
* @type {Readonly<Params<string>>}
|
|
97
|
-
*/
|
|
98
46
|
const params = useParams();
|
|
99
|
-
/**
|
|
100
|
-
* L'url de la route courante
|
|
101
|
-
* @type {string}
|
|
102
|
-
*/
|
|
103
47
|
const pathName = useLocation().pathname;
|
|
104
|
-
/**
|
|
105
|
-
* La chaîne de caractères contenant les query parameters
|
|
106
|
-
* @type {string}
|
|
107
|
-
*/
|
|
108
48
|
const urlSearch = useLocation().search;
|
|
109
49
|
const paramsData = new URLSearchParams(useLocation().search);
|
|
110
50
|
|
|
111
|
-
/**
|
|
112
|
-
* L'ensemble des query parameters de la route
|
|
113
|
-
* @type {any}
|
|
114
|
-
*/
|
|
115
51
|
let queries = {};
|
|
116
52
|
for (const key of paramsData.keys()) {
|
|
117
53
|
const valueParamsData = paramsData.getAll(key).length === 1 ? paramsData.getAll(key)[0] : paramsData.getAll(key);
|
|
@@ -122,21 +58,10 @@ export const useRootingActions = () => {
|
|
|
122
58
|
}
|
|
123
59
|
const navigate = useNavigate();
|
|
124
60
|
|
|
125
|
-
/**
|
|
126
|
-
* Cette fonction permet de recuperer une route en fonction de son path, ses paramètres et ses query parameters.
|
|
127
|
-
* @param {ConfigResolveRoute} config - Paramètre de configuration ou de paramètrage.
|
|
128
|
-
* @type {(config: ConfigResolveRoute) => string}
|
|
129
|
-
* @returns {string} Resultat de la fonction.
|
|
130
|
-
*/
|
|
131
61
|
const resolveRoute = config => {
|
|
132
62
|
const incorrectUrl = pathName;
|
|
133
63
|
return nativeResolveRoute(config, incorrectUrl);
|
|
134
64
|
};
|
|
135
|
-
/**
|
|
136
|
-
* Cette fonction permet de naviguer vers une route en fonction de son path, ses paramètres et ses query parameters.
|
|
137
|
-
* @param {ConfigGoToRoute} config - Paramètre de configuration ou de paramètrage.
|
|
138
|
-
* @type {(config: ConfigGoToRoute) => void}
|
|
139
|
-
*/
|
|
140
65
|
const goToRoute = (config, loaderHandler = () => {}) => {
|
|
141
66
|
loaderHandler = !!loaderHandler ? loaderHandler : () => {};
|
|
142
67
|
if (!config?.queries) {
|
|
@@ -169,11 +94,6 @@ export const useRootingActions = () => {
|
|
|
169
94
|
});
|
|
170
95
|
}
|
|
171
96
|
};
|
|
172
|
-
/**
|
|
173
|
-
* Cette fonction permet de naviguer vers une route en fonction de son path, ses paramètres et ses query parameters en rafraîchissant le navigateur.
|
|
174
|
-
* @param {ConfigGoAndReloadRoute} config - Paramètre de configuration ou de paramètrage.
|
|
175
|
-
* @type {(config: ConfigGoAndReloadRoute) => void}
|
|
176
|
-
*/
|
|
177
97
|
const goAndReloadRoute = (config, loaderHandler = () => {}) => {
|
|
178
98
|
loaderHandler = !!loaderHandler ? loaderHandler : () => {};
|
|
179
99
|
if (!config?.queries) {
|
|
@@ -188,11 +108,7 @@ export const useRootingActions = () => {
|
|
|
188
108
|
lang
|
|
189
109
|
};
|
|
190
110
|
config.queries = Object.fromEntries(Object.entries(config.queries || {}).filter(([key, value]) => value !== undefined && value !== null));
|
|
191
|
-
config.params = Object.fromEntries(Object.entries(config.params || {}).filter(([key, value]) => value !== undefined && value !== null))
|
|
192
|
-
// goToRoute({
|
|
193
|
-
// ...config,
|
|
194
|
-
// refreshPage: false,
|
|
195
|
-
// })
|
|
111
|
+
config.params = Object.fromEntries(Object.entries(config.params || {}).filter(([key, value]) => value !== undefined && value !== null))
|
|
196
112
|
const url = resolveRoute(config);
|
|
197
113
|
window.location = url;
|
|
198
114
|
if (typeof !!config?.enableLoader === 'undefined' && typeof !!config?.enableLoader === 'boolean' && !!config?.enableLoader) {
|
package/rooting.hooks.tsx
CHANGED
|
@@ -4,9 +4,7 @@ import { getLang } from './utils';
|
|
|
4
4
|
import { qust, Qust } from '@arc-js/qust';
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* Interface du paramètre de configuration de la fonction "goAndReloadRoute" .
|
|
9
|
-
*/
|
|
7
|
+
|
|
10
8
|
export interface ConfigGoToSpecificUrl {
|
|
11
9
|
path?: string;
|
|
12
10
|
queries?: any;
|
|
@@ -15,34 +13,26 @@ export interface ConfigGoToSpecificUrl {
|
|
|
15
13
|
enableLoader?: boolean;
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
* Cette fonction permet de recuperer tous les parameters de l'url
|
|
20
|
-
*/
|
|
16
|
+
|
|
21
17
|
function getParams() {
|
|
22
18
|
const queryString = window.location.search;
|
|
23
19
|
const urlParams = new URLSearchParams(queryString);
|
|
24
20
|
return urlParams;
|
|
25
21
|
};
|
|
26
|
-
|
|
27
|
-
* Interface du paramètre de configuration de la fonction "goAndReloadRoute" .
|
|
28
|
-
*/
|
|
22
|
+
|
|
29
23
|
export interface ConfigGoAndReloadRoute {
|
|
30
24
|
path?: string;
|
|
31
25
|
params?: any;
|
|
32
26
|
queries?: any;
|
|
33
27
|
enableLoader?: boolean;
|
|
34
28
|
};
|
|
35
|
-
|
|
36
|
-
* Interface du paramètre de configuration de la fonction "resolveRoute" .
|
|
37
|
-
*/
|
|
29
|
+
|
|
38
30
|
export interface ConfigResolveRoute {
|
|
39
31
|
path?: string;
|
|
40
32
|
params?: any;
|
|
41
33
|
queries?: any;
|
|
42
34
|
};
|
|
43
|
-
|
|
44
|
-
* Interface du paramètre de configuration de la fonction "goToRoute" .
|
|
45
|
-
*/
|
|
35
|
+
|
|
46
36
|
export interface ConfigGoToRoute {
|
|
47
37
|
path?: string;
|
|
48
38
|
params?: any;
|
|
@@ -51,9 +41,7 @@ export interface ConfigGoToRoute {
|
|
|
51
41
|
replace?: boolean;
|
|
52
42
|
enableLoader?: boolean;
|
|
53
43
|
};
|
|
54
|
-
|
|
55
|
-
* Interface de retour du hooks "useRootingActions".
|
|
56
|
-
*/
|
|
44
|
+
|
|
57
45
|
export interface RootingActionReturns {
|
|
58
46
|
params: Readonly<Params<string>>;
|
|
59
47
|
queries: any;
|
|
@@ -76,12 +64,7 @@ export interface RootingActionReturns {
|
|
|
76
64
|
}
|
|
77
65
|
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
* Cette fonction permet de recuperer une route en fonction de son path, ses paramètres et ses query parameters.
|
|
81
|
-
* @param config - la donnée de la route à ressortir
|
|
82
|
-
* @param incorrectUrl - la route qui sera prise en compte si le path n'existe pas
|
|
83
|
-
* @returns string
|
|
84
|
-
*/
|
|
67
|
+
|
|
85
68
|
export function nativeResolveRoute(config: ConfigResolveRoute, incorrectUrl: string = "") {
|
|
86
69
|
try {
|
|
87
70
|
const params = (
|
|
@@ -123,43 +106,19 @@ export function nativeResolveRoute(config: ConfigResolveRoute, incorrectUrl: str
|
|
|
123
106
|
}
|
|
124
107
|
};
|
|
125
108
|
|
|
126
|
-
|
|
127
|
-
* Ce hooks contient toutes les actions necessaires pour le routing.
|
|
128
|
-
* - recuperer les paramètres de la route
|
|
129
|
-
* - Recuperer les query parameters de la route
|
|
130
|
-
* - naviguer au travers des routes
|
|
131
|
-
* - recuperer une route en fonction de son path, ses paramètres et ses query parameters
|
|
132
|
-
* - naviguer vers une route en fonction de son path, ses paramètres et ses query parameters
|
|
133
|
-
* - naviguer vers une route en fonction de son path, ses paramètres et ses query parameters en rafraîchissant le navigateur
|
|
134
|
-
* - recuperer l'url de la route courante
|
|
135
|
-
* - recuperer la chaîne de caractères contenant les query parameters
|
|
136
|
-
* @type {() => RootingActionReturns}
|
|
137
|
-
* @returns {RootingActionReturns} Resultat du hooks.
|
|
138
|
-
*/
|
|
109
|
+
|
|
139
110
|
export const useRootingActions = () => {
|
|
140
111
|
const location = useLocation();
|
|
141
112
|
const pathname = location.pathname;
|
|
142
|
-
|
|
143
|
-
* L'ensemble des parametres de la route
|
|
144
|
-
* @type {Readonly<Params<string>>}
|
|
145
|
-
*/
|
|
113
|
+
|
|
146
114
|
const params = useParams();
|
|
147
|
-
|
|
148
|
-
* L'url de la route courante
|
|
149
|
-
* @type {string}
|
|
150
|
-
*/
|
|
115
|
+
|
|
151
116
|
const pathName = useLocation().pathname;
|
|
152
|
-
|
|
153
|
-
* La chaîne de caractères contenant les query parameters
|
|
154
|
-
* @type {string}
|
|
155
|
-
*/
|
|
117
|
+
|
|
156
118
|
const urlSearch = useLocation().search;
|
|
157
119
|
const paramsData = new URLSearchParams(useLocation().search);
|
|
158
120
|
|
|
159
|
-
|
|
160
|
-
* L'ensemble des query parameters de la route
|
|
161
|
-
* @type {any}
|
|
162
|
-
*/
|
|
121
|
+
|
|
163
122
|
let queries: any = {};
|
|
164
123
|
for (const key of paramsData.keys()) {
|
|
165
124
|
const valueParamsData: any = (
|
|
@@ -172,21 +131,12 @@ export const useRootingActions = () => {
|
|
|
172
131
|
}
|
|
173
132
|
const navigate = useNavigate();
|
|
174
133
|
|
|
175
|
-
|
|
176
|
-
* Cette fonction permet de recuperer une route en fonction de son path, ses paramètres et ses query parameters.
|
|
177
|
-
* @param {ConfigResolveRoute} config - Paramètre de configuration ou de paramètrage.
|
|
178
|
-
* @type {(config: ConfigResolveRoute) => string}
|
|
179
|
-
* @returns {string} Resultat de la fonction.
|
|
180
|
-
*/
|
|
134
|
+
|
|
181
135
|
const resolveRoute = (config: ConfigResolveRoute) => {
|
|
182
136
|
const incorrectUrl = pathName;
|
|
183
137
|
return nativeResolveRoute(config, incorrectUrl);
|
|
184
138
|
};
|
|
185
|
-
|
|
186
|
-
* Cette fonction permet de naviguer vers une route en fonction de son path, ses paramètres et ses query parameters.
|
|
187
|
-
* @param {ConfigGoToRoute} config - Paramètre de configuration ou de paramètrage.
|
|
188
|
-
* @type {(config: ConfigGoToRoute) => void}
|
|
189
|
-
*/
|
|
139
|
+
|
|
190
140
|
const goToRoute = (
|
|
191
141
|
config: ConfigGoToRoute,
|
|
192
142
|
loaderHandler = () => {},
|
|
@@ -239,11 +189,7 @@ export const useRootingActions = () => {
|
|
|
239
189
|
);
|
|
240
190
|
}
|
|
241
191
|
};
|
|
242
|
-
|
|
243
|
-
* Cette fonction permet de naviguer vers une route en fonction de son path, ses paramètres et ses query parameters en rafraîchissant le navigateur.
|
|
244
|
-
* @param {ConfigGoAndReloadRoute} config - Paramètre de configuration ou de paramètrage.
|
|
245
|
-
* @type {(config: ConfigGoAndReloadRoute) => void}
|
|
246
|
-
*/
|
|
192
|
+
|
|
247
193
|
const goAndReloadRoute = (
|
|
248
194
|
config: ConfigGoAndReloadRoute,
|
|
249
195
|
loaderHandler = () => {},
|
|
@@ -266,10 +212,10 @@ export const useRootingActions = () => {
|
|
|
266
212
|
config.params = Object.fromEntries(
|
|
267
213
|
Object.entries(config.params || {}).filter(([key, value]) => value !== undefined && value !== null)
|
|
268
214
|
);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
273
219
|
const url = resolveRoute(config);
|
|
274
220
|
|
|
275
221
|
window.location = url as string & Location;
|
package/routes-utils.js
CHANGED
|
@@ -18,13 +18,13 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const configModules = import.meta.glob([
|
|
21
|
-
'
|
|
22
|
-
'
|
|
21
|
+
'./config.json',
|
|
22
|
+
'./modules/**/config.json'
|
|
23
23
|
]);
|
|
24
24
|
function cleanPathConfig(filePath) {
|
|
25
25
|
return filePath
|
|
26
|
-
.replace(
|
|
27
|
-
.replace(
|
|
26
|
+
.replace(/^\./, '')
|
|
27
|
+
.replace(/^\.\/modules\//, '')
|
|
28
28
|
.replace(/^\/modules\//, '')
|
|
29
29
|
.replace(/config\.json$/, '');
|
|
30
30
|
}
|
|
@@ -87,22 +87,22 @@ function findConfigModuleRoute(route, configDatas) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
const errorPageName = '_error';
|
|
90
|
-
const defaultErrorPath = '
|
|
90
|
+
const defaultErrorPath = './pages/_error';
|
|
91
91
|
const notFoundPageName = '_404';
|
|
92
92
|
const notFoundPagePath = '*';
|
|
93
|
-
const defaultLayoutPath = '
|
|
93
|
+
const defaultLayoutPath = './pages/_layout';
|
|
94
94
|
const layoutName = '_layout';
|
|
95
95
|
const indexPageName = 'index';
|
|
96
96
|
const indexPageRule = /\/index$/;
|
|
97
97
|
const indexPagePath = '/';
|
|
98
98
|
const pageModules = import.meta.glob([
|
|
99
|
-
'
|
|
100
|
-
'
|
|
99
|
+
'./pages/**/*.tsx',
|
|
100
|
+
'./modules/**/pages/**/*.tsx'
|
|
101
101
|
]);
|
|
102
102
|
function cleanPathPage(filePath) {
|
|
103
103
|
return filePath
|
|
104
|
-
.replace(
|
|
105
|
-
.replace(
|
|
104
|
+
.replace(/^\.\/pages\//, '')
|
|
105
|
+
.replace(/^\.\/modules\//, '')
|
|
106
106
|
.replace(/\/pages\//, '/')
|
|
107
107
|
.replace(/\.tsx$/, '')
|
|
108
108
|
.replace(/\{([^\]]+)\}/g, ':$1');
|
|
@@ -125,8 +125,8 @@ function findLayoutForPage(filePath) {
|
|
|
125
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
126
|
var _a, _b;
|
|
127
127
|
const layoutPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${layoutName}.tsx`);
|
|
128
|
-
const layoutModules = import.meta.glob('
|
|
129
|
-
const defaultLayoutModules = import.meta.glob('
|
|
128
|
+
const layoutModules = import.meta.glob('./modules/**/_layout.tsx', { eager: true });
|
|
129
|
+
const defaultLayoutModules = import.meta.glob('./pages/_layout.tsx', { eager: true });
|
|
130
130
|
return ((_a = layoutModules[layoutPath]) === null || _a === void 0 ? void 0 : _a.default) || ((_b = defaultLayoutModules[`${defaultLayoutPath}.tsx`]) === null || _b === void 0 ? void 0 : _b.default);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
@@ -134,10 +134,10 @@ function findErrorForPage(filePath) {
|
|
|
134
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
135
|
var _a, _b, _c;
|
|
136
136
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
137
|
-
const errorModules = import.meta.glob("
|
|
138
|
-
const defaultErrorModules = import.meta.glob("
|
|
137
|
+
const errorModules = import.meta.glob("./modules/**/_error.tsx", { eager: true });
|
|
138
|
+
const defaultErrorModules = import.meta.glob("./pages/_error.tsx", { eager: true });
|
|
139
139
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'debug') {
|
|
140
|
-
console.log(`[
|
|
140
|
+
console.log(`[@arc-js -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
|
|
141
141
|
filePath,
|
|
142
142
|
errorPath,
|
|
143
143
|
}));
|
|
@@ -148,7 +148,7 @@ function findErrorForPage(filePath) {
|
|
|
148
148
|
function findErrorForPageLink(filePath) {
|
|
149
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
150
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
151
|
-
return cleanPathPage(errorPath).split('
|
|
151
|
+
return cleanPathPage(errorPath).split('./').join('');
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
function nearestRoute(targetRoute, routes) {
|
|
@@ -177,7 +177,7 @@ function getRoutes() {
|
|
|
177
177
|
var _a, _b, _c;
|
|
178
178
|
const configs = yield getAllConfig();
|
|
179
179
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
|
|
180
|
-
console.log(`[
|
|
180
|
+
console.log(`[@arc-js -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
|
|
181
181
|
}
|
|
182
182
|
let routes = yield Promise.all(Object.entries(pageModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
183
183
|
let layout = (!([
|
|
@@ -209,9 +209,9 @@ function getRoutes() {
|
|
|
209
209
|
const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
|
|
210
210
|
const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
|
|
211
211
|
if (((_b = process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') {
|
|
212
|
-
console.log(`[
|
|
213
|
-
console.log(`[
|
|
214
|
-
console.log(`[
|
|
212
|
+
console.log(`[@arc-js -> core -> rooter -> routes-utils] getRoutes | notFoundRoutes:: `, notFoundRoutes);
|
|
213
|
+
console.log(`[@arc-js -> core -> rooter -> routes-utils] getRoutes | routes:: `, routes);
|
|
214
|
+
console.log(`[@arc-js -> core -> rooter -> routes-utils] getRoutes | layoutRoutes:: `, layoutRoutes);
|
|
215
215
|
}
|
|
216
216
|
routes = routes.map((route) => {
|
|
217
217
|
var _a, _b;
|
|
@@ -228,7 +228,7 @@ function getRoutes() {
|
|
|
228
228
|
return route;
|
|
229
229
|
});
|
|
230
230
|
if (((_c = process.env) === null || _c === void 0 ? void 0 : _c.NODE_ENV) === 'development') {
|
|
231
|
-
console.log(`[
|
|
231
|
+
console.log(`[@arc-js -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
|
|
232
232
|
}
|
|
233
233
|
return routesF;
|
|
234
234
|
});
|
package/routes-utils.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function __awaiter(t,l,r,u){return new(r=r||Promise)(function(n,e){function a(t){try{o(u.next(t))}catch(t){e(t)}}function i(t){try{o(u.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?n(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(a,i)}o((u=u.apply(t,l||[])).next())})}let configModules=import.meta.glob(["
|
|
1
|
+
function __awaiter(t,l,r,u){return new(r=r||Promise)(function(n,e){function a(t){try{o(u.next(t))}catch(t){e(t)}}function i(t){try{o(u.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?n(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(a,i)}o((u=u.apply(t,l||[])).next())})}let configModules=import.meta.glob(["./config.json","./modules/**/config.json"]);function cleanPathConfig(t){return t.replace(/^\./,"").replace(/^\.\/modules\//,"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(t,e=!1){let n=(e="boolean"==typeof e&&e)?t.replace(/config\.json$/,""):cleanPathConfig(t);return(n=n.split("/").filter(t=>"string"==typeof t&&0<t.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(t=>__awaiter(this,[t],void 0,function*([t,e]){var n=filePathToConfigPath(t,!0).split("/").join("/"),a=filePathToConfigPath(t),i="string"==typeof(i=a.split("/").filter((t,e,n)=>0<e).join("/"))&&0<i.length?i:void 0,e=(yield e()).default;return{parentTruePath:n,truePath:t,path:a,name:i,description:void 0,config:"object"==typeof e&&!Array.isArray(e)&&0<Object.keys(e).length?{path:"string"==typeof(null==e?void 0:e.path)&&0<(null==e?void 0:e.path.length)?null==e?void 0:e.path:a,name:"string"==typeof(null==e?void 0:e.name)&&0<(null==e?void 0:e.name.length)?null==e?void 0:e.name:i,description:!("string"==typeof(null==e?void 0:e.description)&&0<(null==e?void 0:e.description.length))||null==e?void 0:e.description,author:!("string"==typeof(null==e?void 0:e.author)&&0<(null==e?void 0:e.author.length))||null==e?void 0:e.author,isEnabled:"boolean"!=typeof(null==e?void 0:e.isEnabled)||(null==e?void 0:e.isEnabled)}:{path:a,name:i,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(e,t){return null==(t=t.sort((t,e)=>t.truePath.split("/").length>e.truePath.split("/").length?-1:t.truePath.split("/").length<e.truePath.split("/").length?1:0).find(t=>0===e.truePath.indexOf(t.parentTruePath)))?void 0:t.config}let errorPageName="_error",defaultErrorPath="./pages/_error",notFoundPageName="_404",notFoundPagePath="*",defaultLayoutPath="./pages/_layout",layoutName="_layout",indexPageName="index",indexPageRule=/\/index$/,indexPagePath="/",pageModules=import.meta.glob(["./pages/**/*.tsx","./modules/**/pages/**/*.tsx"]);function cleanPathPage(t){return t.replace(/^\.\/pages\//,"").replace(/^\.\/modules\//,"").replace(/\/pages\//,"/").replace(/\.tsx$/,"").replace(/\{([^\]]+)\}/g,":$1")}function filePathToRoutePath(t){let e=cleanPathPage(t);if(e.endsWith("/"+indexPageName))e=e.replace(indexPageRule,"")||indexPagePath;else if(e===""+indexPageName)e=indexPagePath;else if(e===notFoundPageName)return e=notFoundPagePath;return e.startsWith(indexPagePath)?e:"/"+e}function findLayoutForPage(a){return __awaiter(this,void 0,void 0,function*(){var t=a.replace(/\/pages\/.*\.tsx$/,`/pages/${layoutName}.tsx`),e=import.meta.glob("./modules/**/_layout.tsx",{eager:!0}),n=import.meta.glob("./pages/_layout.tsx",{eager:!0});return(null==(e=e[t])?void 0:e.default)||(null==(t=n[defaultLayoutPath+".tsx"])?void 0:t.default)})}function findErrorForPage(i){return __awaiter(this,void 0,void 0,function*(){var t,e=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!=(t=process.env)&&t.NODE_ENV,(null==(t=n[e])?void 0:t.default)||(null==(n=a[defaultErrorPath+".tsx"])?void 0:n.default)})}function findErrorForPageLink(t){return __awaiter(this,void 0,void 0,function*(){return cleanPathPage(t.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`)).split("./").join("")})}function nearestRoute(n,t){t=t.map(t=>Object.assign(Object.assign({},t),{path:(t.path||"").split("/").filter((t,e,n)=>2<=n.length&&"string"==typeof(null==n?void 0:n[n.length-2])&&(null==n?void 0:n[n.length-2].length)<=0&&e<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)&&e<n.length-1).join("/")})).filter(t=>0===n.path.indexOf(t.path)).sort((t,e)=>t.path.indexOf(n.path)>e.path.indexOf(n.path)?-1:t.path.indexOf(n.path)<e.path.indexOf(n.path)?1:t.path.split("/").length>e.path.split("/").length?-1:t.path.split("/").length<e.path.split("/").length?1:0);return null==t?void 0:t[0]}function getRoutes(){return __awaiter(this,void 0,void 0,function*(){let t,e,n,a=yield getAllConfig(),i=(null==(t=process.env)||t.NODE_ENV,yield Promise.all(Object.entries(pageModules).map(t=>__awaiter(this,[t],void 0,function*([t,e]){var n=[notFoundPageName].map(t=>cleanPathPage(t)).includes(cleanPathPage(t))?void 0:yield findLayoutForPage(t),a=yield findErrorForPage(t),i=(yield findErrorForPageLink(t),filePathToRoutePath(t)),e=(yield e()).default,o=i.split("/").filter((t,e,n)=>"string"==typeof t&&0<t.length&&e<n.length-1).join("/");return{truePath:t,path:i,component:e,layout:n,error:a,pathParent:o}}))));var o=i.filter(t=>!!t.truePath&&0<t.truePath.split("/").filter(t=>-1!==t.indexOf("_404.tsx")).length).map(t=>Object.assign(Object.assign({},t),{path:t.path.split("/").map(t=>t.split("_404").join(notFoundPagePath)).join("/")}));let l=(i=[...i.filter(t=>!(t.truePath&&0<t.truePath.split("/").filter(t=>-1!==t.indexOf("_404.tsx")).length)),...o]).filter(t=>!!t.path&&-1!==t.path.indexOf("/_layout")),r=i.filter(t=>!!t.path&&-1!==t.path.indexOf("/_error"));null!=(e=process.env)&&e.NODE_ENV;o=(i=i.map(t=>{var e;return Object.assign(Object.assign({},t),{layout:(null==(e=nearestRoute(t,l))?void 0:e.component)||t.layout,error:(null==(e=nearestRoute(t,r))?void 0:e.component)||t.error})})).map((t,e)=>{var n=findConfigModuleRoute(t,a);return"string"==typeof(null==n?void 0:n.path)&&0<(null==n?void 0:n.path.length)&&"/"!=(null==n?void 0:n.path)&&(t.path=t.path.split("/").filter((t,e,n)=>1<e).join("/"),t.path=(`${null==n?void 0:n.path}/`+t.path).split("//").join("/")),t});return null!=(n=process.env)&&n.NODE_ENV,o})}let routes=await getRoutes();export{getRoutes,routes};
|
|
2
2
|
//# sourceMappingURL=routes-utils.min.js.map
|