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