@arc-js/core 0.0.51 → 0.0.53
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 -25
- package/minimal-config.min.js +1 -1
- package/package.json +1 -1
- package/routes-utils.d.ts +3 -2
- package/routes-utils.js +52 -69
- 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: 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,43 +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
|
-
return import.meta.glob([
|
|
32
|
-
`${srcPath}/config.json`,
|
|
33
|
-
`${srcPath}/modules/**/config.json`
|
|
34
|
-
]);
|
|
35
|
-
}
|
|
36
|
-
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;
|
|
37
29
|
return filePath
|
|
38
30
|
.replace(new RegExp(`^${srcPath}`), '')
|
|
39
|
-
.replace(new RegExp(`^${srcPath}/modules
|
|
31
|
+
.replace(new RegExp(`^${srcPath}/modules`), '')
|
|
40
32
|
.replace(/^\/modules\//, '')
|
|
41
33
|
.replace(/config\.json$/, '');
|
|
42
34
|
}
|
|
43
|
-
function filePathToConfigPath(filePath, isParent = false
|
|
35
|
+
function filePathToConfigPath(filePath, isParent = false) {
|
|
44
36
|
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
45
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath
|
|
46
|
-
configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
|
|
37
|
+
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
47
38
|
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
48
39
|
subPath.length > 0)).join('/');
|
|
49
40
|
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
50
41
|
}
|
|
51
42
|
function getAllConfig() {
|
|
52
|
-
return __awaiter(this,
|
|
53
|
-
const configModules = getConfigModules(srcPath);
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
44
|
let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
55
|
-
const parentTruePath = filePathToConfigPath(filePath, true
|
|
56
|
-
const configPath = filePathToConfigPath(filePath
|
|
57
|
-
filePath.replace(new RegExp(`^${srcPath}`), '');
|
|
45
|
+
const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
|
|
46
|
+
const configPath = filePathToConfigPath(filePath);
|
|
58
47
|
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
59
48
|
nameConfig = (typeof nameConfig === 'string' &&
|
|
60
49
|
nameConfig.length > 0) ? nameConfig : undefined;
|
|
@@ -101,4 +90,4 @@ function findConfigModuleRoute(route, configDatas) {
|
|
|
101
90
|
return res;
|
|
102
91
|
}
|
|
103
92
|
|
|
104
|
-
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.53",
|
|
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/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,40 +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
|
-
`${srcPath}/config.json`,
|
|
30
|
-
`${srcPath}/modules/**/config.json`
|
|
31
|
-
]);
|
|
32
|
-
}
|
|
33
|
-
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;
|
|
34
29
|
return filePath
|
|
35
30
|
.replace(new RegExp(`^${srcPath}`), '')
|
|
36
|
-
.replace(new RegExp(`^${srcPath}/modules
|
|
31
|
+
.replace(new RegExp(`^${srcPath}/modules`), '')
|
|
37
32
|
.replace(/^\/modules\//, '')
|
|
38
33
|
.replace(/config\.json$/, '');
|
|
39
34
|
}
|
|
40
|
-
function filePathToConfigPath(filePath, isParent = false
|
|
35
|
+
function filePathToConfigPath(filePath, isParent = false) {
|
|
41
36
|
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
42
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath
|
|
43
|
-
configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
|
|
37
|
+
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
44
38
|
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
45
39
|
subPath.length > 0)).join('/');
|
|
46
40
|
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
47
41
|
}
|
|
48
42
|
function getAllConfig() {
|
|
49
|
-
return __awaiter(this,
|
|
50
|
-
const configModules = getConfigModules(srcPath);
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
44
|
let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
52
|
-
const parentTruePath = filePathToConfigPath(filePath, true
|
|
53
|
-
const configPath = filePathToConfigPath(filePath
|
|
54
|
-
filePath.replace(new RegExp(`^${srcPath}`), '');
|
|
45
|
+
const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
|
|
46
|
+
const configPath = filePathToConfigPath(filePath);
|
|
55
47
|
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
56
48
|
nameConfig = (typeof nameConfig === 'string' &&
|
|
57
49
|
nameConfig.length > 0) ? nameConfig : undefined;
|
|
@@ -98,35 +90,30 @@ function findConfigModuleRoute(route, configDatas) {
|
|
|
98
90
|
return res;
|
|
99
91
|
}
|
|
100
92
|
|
|
101
|
-
function getDefaultErrorPath(srcPath = getSrcPath()) {
|
|
102
|
-
return `${srcPath}/pages/_error`;
|
|
103
|
-
}
|
|
104
|
-
function getDefaultLayoutPath(srcPath = getSrcPath()) {
|
|
105
|
-
return `${srcPath}/pages/_layout`;
|
|
106
|
-
}
|
|
107
93
|
const errorPageName = '_error';
|
|
94
|
+
const defaultErrorPath = `${SRC_DIR}/pages/_error`;
|
|
108
95
|
const notFoundPageName = '_404';
|
|
109
96
|
const notFoundPagePath = '*';
|
|
97
|
+
const defaultLayoutPath = `${SRC_DIR}/pages/_layout`;
|
|
110
98
|
const layoutName = '_layout';
|
|
111
99
|
const indexPageName = 'index';
|
|
112
100
|
const indexPageRule = /\/index$/;
|
|
113
101
|
const indexPagePath = '/';
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
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;
|
|
121
108
|
return filePath
|
|
122
|
-
.replace(new RegExp(`^${srcPath}/pages
|
|
123
|
-
.replace(new RegExp(`^${srcPath}/
|
|
109
|
+
.replace(new RegExp(`^${srcPath}/pages`), '')
|
|
110
|
+
.replace(new RegExp(`^${srcPath}/pages`), '')
|
|
124
111
|
.replace(/\/pages\//, '/')
|
|
125
112
|
.replace(/\.tsx$/, '')
|
|
126
113
|
.replace(/\{([^\]]+)\}/g, ':$1');
|
|
127
114
|
}
|
|
128
|
-
function filePathToRoutePath(filePath
|
|
129
|
-
let routePath = cleanPathPage(filePath
|
|
115
|
+
function filePathToRoutePath(filePath) {
|
|
116
|
+
let routePath = cleanPathPage(filePath);
|
|
130
117
|
if (routePath.endsWith(`/${indexPageName}`)) {
|
|
131
118
|
routePath = routePath.replace(indexPageRule, '') || indexPagePath;
|
|
132
119
|
}
|
|
@@ -139,38 +126,34 @@ function filePathToRoutePath(filePath, srcPath = getSrcPath()) {
|
|
|
139
126
|
}
|
|
140
127
|
return routePath.startsWith(indexPagePath) ? routePath : `/${routePath}`;
|
|
141
128
|
}
|
|
142
|
-
function findLayoutForPage(
|
|
143
|
-
return __awaiter(this,
|
|
129
|
+
function findLayoutForPage(filePath) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
131
|
var _a, _b;
|
|
145
|
-
const defaultLayoutPath = getDefaultLayoutPath(srcPath);
|
|
146
132
|
const layoutPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${layoutName}.tsx`);
|
|
147
|
-
const layoutModules = import.meta.glob(
|
|
148
|
-
const defaultLayoutModules = import.meta.glob(
|
|
149
|
-
return ((_a = layoutModules[layoutPath]) === null || _a === void 0 ? void 0 : _a.default) ||
|
|
150
|
-
((_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);
|
|
151
136
|
});
|
|
152
137
|
}
|
|
153
|
-
function findErrorForPage(
|
|
154
|
-
return __awaiter(this,
|
|
138
|
+
function findErrorForPage(filePath) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
140
|
var _a, _b, _c;
|
|
156
|
-
const defaultErrorPath = getDefaultErrorPath(srcPath);
|
|
157
141
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
158
|
-
const errorModules = import.meta.glob(
|
|
159
|
-
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 });
|
|
160
144
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'debug') {
|
|
161
|
-
console.log(`[
|
|
145
|
+
console.log(`[@arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
|
|
162
146
|
filePath,
|
|
163
147
|
errorPath,
|
|
164
148
|
}));
|
|
165
149
|
}
|
|
166
|
-
return ((_b = errorModules[errorPath]) === null || _b === void 0 ? void 0 : _b.default) ||
|
|
167
|
-
((_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);
|
|
168
151
|
});
|
|
169
152
|
}
|
|
170
|
-
function findErrorForPageLink(
|
|
171
|
-
return __awaiter(this,
|
|
153
|
+
function findErrorForPageLink(filePath) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
155
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
173
|
-
return cleanPathPage(errorPath
|
|
156
|
+
return cleanPathPage(errorPath).split(SRC_DIR).join('');
|
|
174
157
|
});
|
|
175
158
|
}
|
|
176
159
|
function nearestRoute(targetRoute, routes) {
|
|
@@ -195,20 +178,19 @@ function nearestRoute(targetRoute, routes) {
|
|
|
195
178
|
return possibleLayouts === null || possibleLayouts === void 0 ? void 0 : possibleLayouts[0];
|
|
196
179
|
}
|
|
197
180
|
function getRoutes() {
|
|
198
|
-
return __awaiter(this,
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
182
|
var _a, _b, _c;
|
|
200
|
-
const
|
|
201
|
-
const configs = yield getAllConfig(srcPath);
|
|
183
|
+
const configs = yield getAllConfig();
|
|
202
184
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
|
|
203
|
-
console.log(`[
|
|
185
|
+
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
|
|
204
186
|
}
|
|
205
187
|
let routes = yield Promise.all(Object.entries(pageModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
206
188
|
let layout = (!([
|
|
207
189
|
notFoundPageName
|
|
208
|
-
].map((path) => (cleanPathPage(path
|
|
209
|
-
let erroPage = yield findErrorForPage(filePath
|
|
210
|
-
yield findErrorForPageLink(filePath
|
|
211
|
-
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);
|
|
212
194
|
const component = (yield module()).default;
|
|
213
195
|
const routePathParent = routePath.split('/').filter((val, index, arr) => (typeof val === 'string' &&
|
|
214
196
|
val.length > 0 &&
|
|
@@ -232,9 +214,9 @@ function getRoutes() {
|
|
|
232
214
|
const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
|
|
233
215
|
const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
|
|
234
216
|
if (((_b = process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') {
|
|
235
|
-
console.log(`[
|
|
236
|
-
console.log(`[
|
|
237
|
-
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);
|
|
238
220
|
}
|
|
239
221
|
routes = routes.map((route) => {
|
|
240
222
|
var _a, _b;
|
|
@@ -251,10 +233,11 @@ function getRoutes() {
|
|
|
251
233
|
return route;
|
|
252
234
|
});
|
|
253
235
|
if (((_c = process.env) === null || _c === void 0 ? void 0 : _c.NODE_ENV) === 'development') {
|
|
254
|
-
console.log(`[
|
|
236
|
+
console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
|
|
255
237
|
}
|
|
256
238
|
return routesF;
|
|
257
239
|
});
|
|
258
240
|
}
|
|
241
|
+
const routes = await getRoutes();
|
|
259
242
|
|
|
260
|
-
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
|