@arc-js/core 0.0.40 → 0.0.51
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 +28 -13
- package/minimal-config.min.js +1 -1
- package/package.json +5 -2
- package/rooting.hooks.jsx +1 -1
- package/rooting.hooks.tsx +1 -1
- package/routes-utils.d.ts +2 -3
- package/routes-utils.js +72 -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/vite.config.ts +14 -0
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,44 @@ 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
|
+
return import.meta.glob([
|
|
32
|
+
`${srcPath}/config.json`,
|
|
33
|
+
`${srcPath}/modules/**/config.json`
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
function cleanPathConfig(filePath, srcPath = getSrcPath()) {
|
|
25
37
|
return filePath
|
|
26
|
-
.replace(
|
|
27
|
-
.replace(
|
|
38
|
+
.replace(new RegExp(`^${srcPath}`), '')
|
|
39
|
+
.replace(new RegExp(`^${srcPath}/modules/`), '')
|
|
28
40
|
.replace(/^\/modules\//, '')
|
|
29
41
|
.replace(/config\.json$/, '');
|
|
30
42
|
}
|
|
31
|
-
function filePathToConfigPath(filePath, isParent = false) {
|
|
43
|
+
function filePathToConfigPath(filePath, isParent = false, srcPath = getSrcPath()) {
|
|
32
44
|
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
33
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
45
|
+
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath, srcPath);
|
|
46
|
+
configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
|
|
34
47
|
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
35
48
|
subPath.length > 0)).join('/');
|
|
36
49
|
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
37
50
|
}
|
|
38
51
|
function getAllConfig() {
|
|
39
|
-
return __awaiter(this,
|
|
52
|
+
return __awaiter(this, arguments, void 0, function* (srcPath = getSrcPath()) {
|
|
53
|
+
const configModules = getConfigModules(srcPath);
|
|
40
54
|
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);
|
|
55
|
+
const parentTruePath = filePathToConfigPath(filePath, true, srcPath).split('/').join('/');
|
|
56
|
+
const configPath = filePathToConfigPath(filePath, false, srcPath);
|
|
57
|
+
filePath.replace(new RegExp(`^${srcPath}`), '');
|
|
43
58
|
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
44
59
|
nameConfig = (typeof nameConfig === 'string' &&
|
|
45
60
|
nameConfig.length > 0) ? nameConfig : undefined;
|
|
@@ -86,4 +101,4 @@ function findConfigModuleRoute(route, configDatas) {
|
|
|
86
101
|
return res;
|
|
87
102
|
}
|
|
88
103
|
|
|
89
|
-
export { cleanPathConfig,
|
|
104
|
+
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.51",
|
|
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": [],
|
|
@@ -14,12 +14,15 @@
|
|
|
14
14
|
"login": "npm login"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"
|
|
17
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
18
|
+
"vite": "^6.4.1"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"react-router-dom": "^7.11.0",
|
|
21
22
|
"react": "^19.2.3",
|
|
22
23
|
"react-dom": "^19.2.3",
|
|
24
|
+
"vite-plugin-html": "^3.2.2",
|
|
25
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
23
26
|
"@arc-js/qust": "^0.0.3"
|
|
24
27
|
}
|
|
25
28
|
}
|
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,41 @@ 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
|
+
return import.meta.glob([
|
|
29
|
+
`${srcPath}/config.json`,
|
|
30
|
+
`${srcPath}/modules/**/config.json`
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
function cleanPathConfig(filePath, srcPath = getSrcPath()) {
|
|
25
34
|
return filePath
|
|
26
|
-
.replace(
|
|
27
|
-
.replace(
|
|
35
|
+
.replace(new RegExp(`^${srcPath}`), '')
|
|
36
|
+
.replace(new RegExp(`^${srcPath}/modules/`), '')
|
|
28
37
|
.replace(/^\/modules\//, '')
|
|
29
38
|
.replace(/config\.json$/, '');
|
|
30
39
|
}
|
|
31
|
-
function filePathToConfigPath(filePath, isParent = false) {
|
|
40
|
+
function filePathToConfigPath(filePath, isParent = false, srcPath = getSrcPath()) {
|
|
32
41
|
isParent = (typeof isParent === 'boolean') ? isParent : false;
|
|
33
|
-
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
|
|
42
|
+
let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath, srcPath);
|
|
43
|
+
configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
|
|
34
44
|
configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
|
|
35
45
|
subPath.length > 0)).join('/');
|
|
36
46
|
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
37
47
|
}
|
|
38
48
|
function getAllConfig() {
|
|
39
|
-
return __awaiter(this,
|
|
49
|
+
return __awaiter(this, arguments, void 0, function* (srcPath = getSrcPath()) {
|
|
50
|
+
const configModules = getConfigModules(srcPath);
|
|
40
51
|
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);
|
|
52
|
+
const parentTruePath = filePathToConfigPath(filePath, true, srcPath).split('/').join('/');
|
|
53
|
+
const configPath = filePathToConfigPath(filePath, false, srcPath);
|
|
54
|
+
filePath.replace(new RegExp(`^${srcPath}`), '');
|
|
43
55
|
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
44
56
|
nameConfig = (typeof nameConfig === 'string' &&
|
|
45
57
|
nameConfig.length > 0) ? nameConfig : undefined;
|
|
@@ -86,29 +98,35 @@ function findConfigModuleRoute(route, configDatas) {
|
|
|
86
98
|
return res;
|
|
87
99
|
}
|
|
88
100
|
|
|
101
|
+
function getDefaultErrorPath(srcPath = getSrcPath()) {
|
|
102
|
+
return `${srcPath}/pages/_error`;
|
|
103
|
+
}
|
|
104
|
+
function getDefaultLayoutPath(srcPath = getSrcPath()) {
|
|
105
|
+
return `${srcPath}/pages/_layout`;
|
|
106
|
+
}
|
|
89
107
|
const errorPageName = '_error';
|
|
90
|
-
const defaultErrorPath = './pages/_error';
|
|
91
108
|
const notFoundPageName = '_404';
|
|
92
109
|
const notFoundPagePath = '*';
|
|
93
|
-
const defaultLayoutPath = './pages/_layout';
|
|
94
110
|
const layoutName = '_layout';
|
|
95
111
|
const indexPageName = 'index';
|
|
96
112
|
const indexPageRule = /\/index$/;
|
|
97
113
|
const indexPagePath = '/';
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
function getPageModules(srcPath = getSrcPath()) {
|
|
115
|
+
return import.meta.glob([
|
|
116
|
+
`${srcPath}/pages/**/*.tsx`,
|
|
117
|
+
`${srcPath}/modules/**/pages/**/*.tsx`
|
|
118
|
+
]);
|
|
119
|
+
}
|
|
120
|
+
function cleanPathPage(filePath, srcPath = getSrcPath()) {
|
|
103
121
|
return filePath
|
|
104
|
-
.replace(
|
|
105
|
-
.replace(
|
|
122
|
+
.replace(new RegExp(`^${srcPath}/pages/`), '')
|
|
123
|
+
.replace(new RegExp(`^${srcPath}/modules/`), '')
|
|
106
124
|
.replace(/\/pages\//, '/')
|
|
107
125
|
.replace(/\.tsx$/, '')
|
|
108
126
|
.replace(/\{([^\]]+)\}/g, ':$1');
|
|
109
127
|
}
|
|
110
|
-
function filePathToRoutePath(filePath) {
|
|
111
|
-
let routePath = cleanPathPage(filePath);
|
|
128
|
+
function filePathToRoutePath(filePath, srcPath = getSrcPath()) {
|
|
129
|
+
let routePath = cleanPathPage(filePath, srcPath);
|
|
112
130
|
if (routePath.endsWith(`/${indexPageName}`)) {
|
|
113
131
|
routePath = routePath.replace(indexPageRule, '') || indexPagePath;
|
|
114
132
|
}
|
|
@@ -121,34 +139,38 @@ function filePathToRoutePath(filePath) {
|
|
|
121
139
|
}
|
|
122
140
|
return routePath.startsWith(indexPagePath) ? routePath : `/${routePath}`;
|
|
123
141
|
}
|
|
124
|
-
function findLayoutForPage(
|
|
125
|
-
return __awaiter(this,
|
|
142
|
+
function findLayoutForPage(filePath_1) {
|
|
143
|
+
return __awaiter(this, arguments, void 0, function* (filePath, srcPath = getSrcPath()) {
|
|
126
144
|
var _a, _b;
|
|
145
|
+
const defaultLayoutPath = getDefaultLayoutPath(srcPath);
|
|
127
146
|
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) ||
|
|
147
|
+
const layoutModules = import.meta.glob(`${srcPath}/modules/**/_layout.tsx`, { eager: true });
|
|
148
|
+
const defaultLayoutModules = import.meta.glob(`${srcPath}/pages/_layout.tsx`, { eager: true });
|
|
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);
|
|
131
151
|
});
|
|
132
152
|
}
|
|
133
|
-
function findErrorForPage(
|
|
134
|
-
return __awaiter(this,
|
|
153
|
+
function findErrorForPage(filePath_1) {
|
|
154
|
+
return __awaiter(this, arguments, void 0, function* (filePath, srcPath = getSrcPath()) {
|
|
135
155
|
var _a, _b, _c;
|
|
156
|
+
const defaultErrorPath = getDefaultErrorPath(srcPath);
|
|
136
157
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
137
|
-
const errorModules = import.meta.glob(
|
|
138
|
-
const defaultErrorModules = import.meta.glob(
|
|
158
|
+
const errorModules = import.meta.glob(`${srcPath}/modules/**/_error.tsx`, { eager: true });
|
|
159
|
+
const defaultErrorModules = import.meta.glob(`${srcPath}/pages/_error.tsx`, { eager: true });
|
|
139
160
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'debug') {
|
|
140
|
-
console.log(`[@arc
|
|
161
|
+
console.log(`[src -> @arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
|
|
141
162
|
filePath,
|
|
142
163
|
errorPath,
|
|
143
164
|
}));
|
|
144
165
|
}
|
|
145
|
-
return ((_b = errorModules[errorPath]) === null || _b === void 0 ? void 0 : _b.default) ||
|
|
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);
|
|
146
168
|
});
|
|
147
169
|
}
|
|
148
|
-
function findErrorForPageLink(
|
|
149
|
-
return __awaiter(this,
|
|
170
|
+
function findErrorForPageLink(filePath_1) {
|
|
171
|
+
return __awaiter(this, arguments, void 0, function* (filePath, srcPath = getSrcPath()) {
|
|
150
172
|
const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
|
|
151
|
-
return cleanPathPage(errorPath).split(
|
|
173
|
+
return cleanPathPage(errorPath, srcPath).split(srcPath).join('');
|
|
152
174
|
});
|
|
153
175
|
}
|
|
154
176
|
function nearestRoute(targetRoute, routes) {
|
|
@@ -173,19 +195,20 @@ function nearestRoute(targetRoute, routes) {
|
|
|
173
195
|
return possibleLayouts === null || possibleLayouts === void 0 ? void 0 : possibleLayouts[0];
|
|
174
196
|
}
|
|
175
197
|
function getRoutes() {
|
|
176
|
-
return __awaiter(this,
|
|
198
|
+
return __awaiter(this, arguments, void 0, function* (srcPath = getSrcPath()) {
|
|
177
199
|
var _a, _b, _c;
|
|
178
|
-
const
|
|
200
|
+
const pageModules = getPageModules(srcPath);
|
|
201
|
+
const configs = yield getAllConfig(srcPath);
|
|
179
202
|
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
|
|
180
|
-
console.log(`[@arc
|
|
203
|
+
console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
|
|
181
204
|
}
|
|
182
205
|
let routes = yield Promise.all(Object.entries(pageModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
|
|
183
206
|
let layout = (!([
|
|
184
207
|
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);
|
|
208
|
+
].map((path) => (cleanPathPage(path, srcPath))).includes(cleanPathPage(filePath, srcPath)))) ? yield findLayoutForPage(filePath, srcPath) : undefined;
|
|
209
|
+
let erroPage = yield findErrorForPage(filePath, srcPath);
|
|
210
|
+
yield findErrorForPageLink(filePath, srcPath);
|
|
211
|
+
const routePath = filePathToRoutePath(filePath, srcPath);
|
|
189
212
|
const component = (yield module()).default;
|
|
190
213
|
const routePathParent = routePath.split('/').filter((val, index, arr) => (typeof val === 'string' &&
|
|
191
214
|
val.length > 0 &&
|
|
@@ -209,9 +232,9 @@ function getRoutes() {
|
|
|
209
232
|
const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
|
|
210
233
|
const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
|
|
211
234
|
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
|
|
235
|
+
console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | notFoundRoutes:: `, notFoundRoutes);
|
|
236
|
+
console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | routes:: `, routes);
|
|
237
|
+
console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | layoutRoutes:: `, layoutRoutes);
|
|
215
238
|
}
|
|
216
239
|
routes = routes.map((route) => {
|
|
217
240
|
var _a, _b;
|
|
@@ -228,11 +251,10 @@ function getRoutes() {
|
|
|
228
251
|
return route;
|
|
229
252
|
});
|
|
230
253
|
if (((_c = process.env) === null || _c === void 0 ? void 0 : _c.NODE_ENV) === 'development') {
|
|
231
|
-
console.log(`[@arc
|
|
254
|
+
console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
|
|
232
255
|
}
|
|
233
256
|
return routesF;
|
|
234
257
|
});
|
|
235
258
|
}
|
|
236
|
-
const routes = await getRoutes();
|
|
237
259
|
|
|
238
|
-
export { getRoutes
|
|
260
|
+
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
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [react()],
|
|
6
|
+
optimizeDeps: {
|
|
7
|
+
include: ['@arc-js/qust']
|
|
8
|
+
},
|
|
9
|
+
resolve: {
|
|
10
|
+
alias: {
|
|
11
|
+
'@arc-js/qust': '@arc-js/qust/index.js'
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|