@arc-js/core 0.0.52 → 0.0.54
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/auto-rooting.jsx +3 -6
- package/auto-rooting.tsx +3 -7
- package/config.js +1 -1
- package/config.min.js +1 -1
- package/minimal-config.d.ts +5 -6
- package/minimal-config.js +14 -26
- package/minimal-config.min.js +1 -1
- package/package.json +1 -1
- package/rooting.hooks.jsx +1 -1
- package/rooting.hooks.tsx +1 -1
- package/routes-utils.d.ts +3 -2
- package/routes-utils.js +52 -71
- package/routes-utils.min.js +1 -1
- package/utils.js +1 -1
- package/utils.min.js +1 -1
package/auto-rooting.jsx
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import * as autoRoutes from './routes-utils';
|
|
1
2
|
import { useRootingActions } from './rooting.hooks';
|
|
2
|
-
import { getSrcPath } from "./utils";
|
|
3
|
-
import { getRoutes } from "./routes-utils";
|
|
4
3
|
import React from "react";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const autoRoutes = await getRoutes(srcPath);
|
|
9
|
-
let routes = autoRoutes.map(route => ({
|
|
5
|
+
export default () => {
|
|
6
|
+
let routes = autoRoutes.routes.map(route => ({
|
|
10
7
|
path: route.path,
|
|
11
8
|
element: route.layout ? React.createElement(route.layout, null, React.createElement(route.component, null)) : React.createElement(route.component, null),
|
|
12
9
|
...(!!route.error ? {
|
package/auto-rooting.tsx
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { Navigate, RouteObject } from "react-router-dom";
|
|
2
2
|
import { lazy } from 'react';
|
|
3
|
+
import * as autoRoutes from './routes-utils';
|
|
3
4
|
import { useRootingActions } from './rooting.hooks';
|
|
4
5
|
import { RouteDefinition } from './types';
|
|
5
|
-
import { getSrcPath } from "./utils";
|
|
6
|
-
import { getRoutes } from "./routes-utils";
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
export default
|
|
11
|
-
|
|
12
|
-
) => {
|
|
13
|
-
const autoRoutes: RouteDefinition[] = await getRoutes(srcPath);
|
|
14
|
-
let routes: RouteObject[] = autoRoutes.map((route) => ({
|
|
9
|
+
export default () => {
|
|
10
|
+
let routes: RouteObject[] = autoRoutes.routes.map((route) => ({
|
|
15
11
|
path: route.path,
|
|
16
12
|
element: route.layout ? (
|
|
17
13
|
<route.layout>
|
package/config.js
CHANGED
|
@@ -8,6 +8,6 @@ const langCodes = {
|
|
|
8
8
|
const PATH_CONFIG = {
|
|
9
9
|
SRC_DIR: '/src',
|
|
10
10
|
};
|
|
11
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.
|
|
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
12
|
|
|
13
13
|
export { NODEENV, PATH_CONFIG, SRC_DIR, langCodes, langs };
|
package/config.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _a;let NODEENV="development",langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"},PATH_CONFIG={SRC_DIR:"/src"},SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.
|
|
1
|
+
var _a;let NODEENV="development",langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"},PATH_CONFIG={SRC_DIR:"/src"},SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.VITE_APP_SRC_DIR)||"/src";export{NODEENV,PATH_CONFIG,SRC_DIR,langCodes,langs};
|
|
2
2
|
//# sourceMappingURL=config.min.js.map
|
package/minimal-config.d.ts
CHANGED
|
@@ -24,11 +24,10 @@ interface ConfigDatasDefinition {
|
|
|
24
24
|
isEnabled: boolean;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
declare
|
|
28
|
-
declare function
|
|
29
|
-
declare function
|
|
30
|
-
declare function
|
|
31
|
-
declare function getAllConfig(srcPath?: string): Promise<ConfigDefinition[]>;
|
|
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[]>;
|
|
32
31
|
declare function findConfigModuleRoute(route: RouteDefinition, configDatas: ConfigDefinition[]): ConfigDatasDefinition | undefined;
|
|
33
32
|
|
|
34
|
-
export { cleanPathConfig, filePathToConfigPath, findConfigModuleRoute, getAllConfig
|
|
33
|
+
export { cleanPathConfig, configModules, filePathToConfigPath, findConfigModuleRoute, getAllConfig };
|
package/minimal-config.js
CHANGED
|
@@ -18,44 +18,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
var _a;
|
|
21
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _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
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
function getConfigModules(srcPath = getSrcPath()) {
|
|
31
|
-
const allPatterns = [
|
|
32
|
-
`${srcPath}/config.json`,
|
|
33
|
-
`${srcPath}/modules/**/config.json`
|
|
34
|
-
];
|
|
35
|
-
return import.meta.glob(allPatterns);
|
|
36
|
-
}
|
|
37
|
-
function cleanPathConfig(filePath, srcPath = getSrcPath()) {
|
|
23
|
+
const configModules = import.meta.glob([
|
|
24
|
+
'@/config.json',
|
|
25
|
+
'@/modules/**/config.json'
|
|
26
|
+
]);
|
|
27
|
+
function cleanPathConfig(filePath) {
|
|
28
|
+
const srcPath = SRC_DIR;
|
|
38
29
|
return filePath
|
|
39
30
|
.replace(new RegExp(`^${srcPath}`), '')
|
|
40
|
-
.replace(new RegExp(`^${srcPath}/modules
|
|
31
|
+
.replace(new RegExp(`^${srcPath}/modules`), '')
|
|
41
32
|
.replace(/^\/modules\//, '')
|
|
42
33
|
.replace(/config\.json$/, '');
|
|
43
34
|
}
|
|
44
|
-
function filePathToConfigPath(filePath, isParent = false
|
|
35
|
+
function filePathToConfigPath(filePath, isParent = false) {
|
|
45
36
|
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
46
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath
|
|
47
|
-
configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
|
|
37
|
+
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
48
38
|
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
49
39
|
subPath.length > 0)).join('/');
|
|
50
40
|
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
51
41
|
}
|
|
52
42
|
function getAllConfig() {
|
|
53
|
-
return __awaiter(this,
|
|
54
|
-
const configModules = getConfigModules(srcPath);
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
44
|
let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
56
|
-
const parentTruePath = filePathToConfigPath(filePath, true
|
|
57
|
-
const configPath = filePathToConfigPath(filePath
|
|
58
|
-
filePath.replace(new RegExp(`^${srcPath}`), '');
|
|
45
|
+
const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
|
|
46
|
+
const configPath = filePathToConfigPath(filePath);
|
|
59
47
|
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
60
48
|
nameConfig = (typeof nameConfig === 'string' &&
|
|
61
49
|
nameConfig.length > 0) ? nameConfig : undefined;
|
|
@@ -102,4 +90,4 @@ function findConfigModuleRoute(route, configDatas) {
|
|
|
102
90
|
return res;
|
|
103
91
|
}
|
|
104
92
|
|
|
105
|
-
export { cleanPathConfig, filePathToConfigPath, findConfigModuleRoute, getAllConfig
|
|
93
|
+
export { cleanPathConfig, configModules, filePathToConfigPath, findConfigModuleRoute, getAllConfig };
|
package/minimal-config.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function __awaiter(
|
|
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
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.54",
|
|
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": [],
|
package/rooting.hooks.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useLocation, useNavigate, useParams, generatePath, createSearchParams, matchPath } from 'react-router-dom';
|
|
3
3
|
import { getLang } from './utils';
|
|
4
|
-
import { qust } from '
|
|
4
|
+
import { qust } from '@arc-js/qust';
|
|
5
5
|
import React from "react"
|
|
6
6
|
|
|
7
7
|
|
package/rooting.hooks.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useContext, useEffect } from 'react';
|
|
2
2
|
import { useLocation, useNavigate, useParams, generatePath, createSearchParams, NavigateFunction, Params, matchPath } from 'react-router-dom';
|
|
3
3
|
import { getLang } from './utils';
|
|
4
|
-
import { qust, Qust } from '
|
|
4
|
+
import { qust, Qust } from '@arc-js/qust';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
package/routes-utils.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface RouteDefinition {
|
|
|
11
11
|
error?: React.ComponentType<{}>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
declare function getRoutes(
|
|
14
|
+
declare function getRoutes(): Promise<RouteDefinition[]>;
|
|
15
|
+
declare const routes: RouteDefinition[];
|
|
15
16
|
|
|
16
|
-
export { getRoutes };
|
|
17
|
+
export { getRoutes, routes };
|
package/routes-utils.js
CHANGED
|
@@ -18,41 +18,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
var _a;
|
|
21
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _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
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
`${srcPath}/config.json`,
|
|
30
|
-
`${srcPath}/modules/**/config.json`
|
|
31
|
-
];
|
|
32
|
-
return import.meta.glob(allPatterns);
|
|
33
|
-
}
|
|
34
|
-
function cleanPathConfig(filePath, srcPath = getSrcPath()) {
|
|
23
|
+
const configModules = import.meta.glob([
|
|
24
|
+
'@/config.json',
|
|
25
|
+
'@/modules/**/config.json'
|
|
26
|
+
]);
|
|
27
|
+
function cleanPathConfig(filePath) {
|
|
28
|
+
const srcPath = SRC_DIR;
|
|
35
29
|
return filePath
|
|
36
30
|
.replace(new RegExp(`^${srcPath}`), '')
|
|
37
|
-
.replace(new RegExp(`^${srcPath}/modules
|
|
31
|
+
.replace(new RegExp(`^${srcPath}/modules`), '')
|
|
38
32
|
.replace(/^\/modules\//, '')
|
|
39
33
|
.replace(/config\.json$/, '');
|
|
40
34
|
}
|
|
41
|
-
function filePathToConfigPath(filePath, isParent = false
|
|
35
|
+
function filePathToConfigPath(filePath, isParent = false) {
|
|
42
36
|
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
43
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath
|
|
44
|
-
configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
|
|
37
|
+
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
45
38
|
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
46
39
|
subPath.length > 0)).join('/');
|
|
47
40
|
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
48
41
|
}
|
|
49
42
|
function getAllConfig() {
|
|
50
|
-
return __awaiter(this,
|
|
51
|
-
const configModules = getConfigModules(srcPath);
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
44
|
let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
53
|
-
const parentTruePath = filePathToConfigPath(filePath, true
|
|
54
|
-
const configPath = filePathToConfigPath(filePath
|
|
55
|
-
filePath.replace(new RegExp(`^${srcPath}`), '');
|
|
45
|
+
const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
|
|
46
|
+
const configPath = filePathToConfigPath(filePath);
|
|
56
47
|
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
57
48
|
nameConfig = (typeof nameConfig === 'string' &&
|
|
58
49
|
nameConfig.length > 0) ? nameConfig : undefined;
|
|
@@ -99,36 +90,30 @@ function findConfigModuleRoute(route, configDatas) {
|
|
|
99
90
|
return res;
|
|
100
91
|
}
|
|
101
92
|
|
|
102
|
-
function getDefaultErrorPath(srcPath = getSrcPath()) {
|
|
103
|
-
return `${srcPath}/pages/_error`;
|
|
104
|
-
}
|
|
105
|
-
function getDefaultLayoutPath(srcPath = getSrcPath()) {
|
|
106
|
-
return `${srcPath}/pages/_layout`;
|
|
107
|
-
}
|
|
108
93
|
const errorPageName = '_error';
|
|
94
|
+
const defaultErrorPath = `${SRC_DIR}/pages/_error`;
|
|
109
95
|
const notFoundPageName = '_404';
|
|
110
96
|
const notFoundPagePath = '*';
|
|
97
|
+
const defaultLayoutPath = `${SRC_DIR}/pages/_layout`;
|
|
111
98
|
const layoutName = '_layout';
|
|
112
99
|
const indexPageName = 'index';
|
|
113
100
|
const indexPageRule = /\/index$/;
|
|
114
101
|
const indexPagePath = '/';
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
function cleanPathPage(filePath, srcPath = getSrcPath()) {
|
|
102
|
+
const pageModules = import.meta.glob([
|
|
103
|
+
'@/pages/**/*.tsx',
|
|
104
|
+
'@/modules/**/pages/**/*.tsx'
|
|
105
|
+
]);
|
|
106
|
+
function cleanPathPage(filePath) {
|
|
107
|
+
const srcPath = SRC_DIR;
|
|
123
108
|
return filePath
|
|
124
|
-
.replace(new RegExp(`^${srcPath}/pages
|
|
125
|
-
.replace(new RegExp(`^${srcPath}/
|
|
109
|
+
.replace(new RegExp(`^${srcPath}/pages`), '')
|
|
110
|
+
.replace(new RegExp(`^${srcPath}/pages`), '')
|
|
126
111
|
.replace(/\/pages\//, '/')
|
|
127
112
|
.replace(/\.tsx$/, '')
|
|
128
113
|
.replace(/\{([^\]]+)\}/g, ':$1');
|
|
129
114
|
}
|
|
130
|
-
function filePathToRoutePath(filePath
|
|
131
|
-
let routePath = cleanPathPage(filePath
|
|
115
|
+
function filePathToRoutePath(filePath) {
|
|
116
|
+
let routePath = cleanPathPage(filePath);
|
|
132
117
|
if (routePath.endsWith(`/${indexPageName}`)) {
|
|
133
118
|
routePath = routePath.replace(indexPageRule, '') || indexPagePath;
|
|
134
119
|
}
|
|
@@ -141,38 +126,34 @@ function filePathToRoutePath(filePath, srcPath = getSrcPath()) {
|
|
|
141
126
|
}
|
|
142
127
|
return routePath.startsWith(indexPagePath) ? routePath : `/${routePath}`;
|
|
143
128
|
}
|
|
144
|
-
function findLayoutForPage(
|
|
145
|
-
return __awaiter(this,
|
|
129
|
+
function findLayoutForPage(filePath) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
131
|
var _a, _b;
|
|
147
|
-
const defaultLayoutPath = getDefaultLayoutPath(srcPath);
|
|
148
132
|
const layoutPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${layoutName}.tsx`);
|
|
149
|
-
const layoutModules = import.meta.glob(
|
|
150
|
-
const defaultLayoutModules = import.meta.glob(
|
|
151
|
-
return ((_a = layoutModules[layoutPath]) === null || _a === void 0 ? void 0 : _a.default) ||
|
|
152
|
-
((_b = defaultLayoutModules[`${defaultLayoutPath}.tsx`]) === null || _b === void 0 ? void 0 : _b.default);
|
|
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);
|
|
153
136
|
});
|
|
154
137
|
}
|
|
155
|
-
function findErrorForPage(
|
|
156
|
-
return __awaiter(this,
|
|
138
|
+
function findErrorForPage(filePath) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
140
|
var _a, _b, _c;
|
|
158
|
-
const defaultErrorPath = getDefaultErrorPath(srcPath);
|
|
159
141
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
160
|
-
const errorModules = import.meta.glob(
|
|
161
|
-
const defaultErrorModules = import.meta.glob(
|
|
142
|
+
const errorModules = import.meta.glob('@/modules/**/_error.tsx', { eager: true });
|
|
143
|
+
const defaultErrorModules = import.meta.glob('@/pages/_error.tsx', { eager: true });
|
|
162
144
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'debug') {
|
|
163
|
-
console.log(`[
|
|
145
|
+
console.log(`[@arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
|
|
164
146
|
filePath,
|
|
165
147
|
errorPath,
|
|
166
148
|
}));
|
|
167
149
|
}
|
|
168
|
-
return ((_b = errorModules[errorPath]) === null || _b === void 0 ? void 0 : _b.default) ||
|
|
169
|
-
((_c = defaultErrorModules[`${defaultErrorPath}.tsx`]) === null || _c === void 0 ? void 0 : _c.default);
|
|
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);
|
|
170
151
|
});
|
|
171
152
|
}
|
|
172
|
-
function findErrorForPageLink(
|
|
173
|
-
return __awaiter(this,
|
|
153
|
+
function findErrorForPageLink(filePath) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
155
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
175
|
-
return cleanPathPage(errorPath
|
|
156
|
+
return cleanPathPage(errorPath).split(SRC_DIR).join('');
|
|
176
157
|
});
|
|
177
158
|
}
|
|
178
159
|
function nearestRoute(targetRoute, routes) {
|
|
@@ -197,20 +178,19 @@ function nearestRoute(targetRoute, routes) {
|
|
|
197
178
|
return possibleLayouts === null || possibleLayouts === void 0 ? void 0 : possibleLayouts[0];
|
|
198
179
|
}
|
|
199
180
|
function getRoutes() {
|
|
200
|
-
return __awaiter(this,
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
182
|
var _a, _b, _c;
|
|
202
|
-
const
|
|
203
|
-
const configs = yield getAllConfig(srcPath);
|
|
183
|
+
const configs = yield getAllConfig();
|
|
204
184
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
|
|
205
|
-
console.log(`[
|
|
185
|
+
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
|
|
206
186
|
}
|
|
207
187
|
let routes = yield Promise.all(Object.entries(pageModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
208
188
|
let layout = (!([
|
|
209
189
|
notFoundPageName
|
|
210
|
-
].map((path) => (cleanPathPage(path
|
|
211
|
-
let erroPage = yield findErrorForPage(filePath
|
|
212
|
-
yield findErrorForPageLink(filePath
|
|
213
|
-
const routePath = filePathToRoutePath(filePath
|
|
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);
|
|
214
194
|
const component = (yield module()).default;
|
|
215
195
|
const routePathParent = routePath.split('/').filter((val, index, arr) => (typeof val === 'string' &&
|
|
216
196
|
val.length > 0 &&
|
|
@@ -234,9 +214,9 @@ function getRoutes() {
|
|
|
234
214
|
const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
|
|
235
215
|
const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
|
|
236
216
|
if (((_b = process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') {
|
|
237
|
-
console.log(`[
|
|
238
|
-
console.log(`[
|
|
239
|
-
console.log(`[
|
|
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);
|
|
240
220
|
}
|
|
241
221
|
routes = routes.map((route) => {
|
|
242
222
|
var _a, _b;
|
|
@@ -253,10 +233,11 @@ function getRoutes() {
|
|
|
253
233
|
return route;
|
|
254
234
|
});
|
|
255
235
|
if (((_c = process.env) === null || _c === void 0 ? void 0 : _c.NODE_ENV) === 'development') {
|
|
256
|
-
console.log(`[
|
|
236
|
+
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
|
|
257
237
|
}
|
|
258
238
|
return routesF;
|
|
259
239
|
});
|
|
260
240
|
}
|
|
241
|
+
const routes = await getRoutes();
|
|
261
242
|
|
|
262
|
-
export { getRoutes };
|
|
243
|
+
export { getRoutes, routes };
|
package/routes-utils.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function __awaiter(
|
|
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}/pages`),"").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
2
|
//# sourceMappingURL=routes-utils.min.js.map
|
package/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ const langCodes = {
|
|
|
4
4
|
'fr': 'fr_FR',
|
|
5
5
|
'en': 'en_US',
|
|
6
6
|
};
|
|
7
|
-
const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.
|
|
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
8
|
|
|
9
9
|
function getLang(lang) {
|
|
10
10
|
let result = lang;
|
package/utils.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _a;let langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"},SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.
|
|
1
|
+
var _a;let langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"},SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.VITE_APP_SRC_DIR)||"/src";function getLang(n){return langs.includes(n)?n:"fr"}function getLangCode(n){return langCodes[getLang(n)]}function getSrcPath(){return SRC_DIR}export{getLang,getLangCode,getSrcPath};
|
|
2
2
|
//# sourceMappingURL=utils.min.js.map
|