@arc-js/core 0.0.11 → 0.0.13
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 +27 -31
- package/auto-rooting.tsx +55 -0
- package/config.d.ts +8 -0
- package/config.js +8 -0
- package/config.min.js +2 -0
- package/minimal-config.d.ts +25 -2
- package/minimal-config.js +60 -38
- package/minimal-config.min.js +1 -1
- package/package.json +1 -1
- package/rooting.hooks.jsx +268 -194
- package/rooting.hooks.tsx +400 -0
- package/routes-utils.d.ts +12 -2
- package/routes-utils.js +179 -89
- package/routes-utils.min.js +1 -1
- package/utils.d.ts +4 -0
- package/utils.js +16 -0
- package/utils.min.js +2 -0
- package/auto-rooting.d.ts +0 -10
- package/auto-rooting.min.jsx +0 -1
- package/auto-rooting.min.jsx.map +0 -1
- package/rooting.hooks.d.ts +0 -87
- package/rooting.hooks.min.jsx +0 -1
- package/rooting.hooks.min.jsx.map +0 -1
package/auto-rooting.jsx
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
export { useRootingActions } from './rooting.hooks.jsx';
|
|
1
|
+
import * as autoRoutes from './routes-utils';
|
|
2
|
+
import { useRootingActions } from './rooting.hooks';
|
|
3
|
+
import React from "react";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return routes$1;
|
|
5
|
+
/**
|
|
6
|
+
* Permet d'initialiser toutes les routes de l'application
|
|
7
|
+
* @returns RouteObject[]
|
|
8
|
+
*/
|
|
9
|
+
export default () => {
|
|
10
|
+
let routes = autoRoutes.routes.map(route => ({
|
|
11
|
+
path: route.path,
|
|
12
|
+
element: route.layout ? /*#__PURE__*/React.createElement(route.layout, null, /*#__PURE__*/React.createElement(route.component, null)) : /*#__PURE__*/React.createElement(route.component, null),
|
|
13
|
+
...(!!route.error ? {
|
|
14
|
+
errorElement: /*#__PURE__*/React.createElement(route.error, null)
|
|
15
|
+
} : {})
|
|
16
|
+
}));
|
|
17
|
+
let homeRoute = undefined;
|
|
18
|
+
let notFoundRoute = undefined;
|
|
19
|
+
homeRoute = routes.find(a => a.path === '/');
|
|
20
|
+
notFoundRoute = routes.find(a => a.path === '*');
|
|
21
|
+
routes = [...(!!homeRoute ? [homeRoute] : []), ...routes.filter(route => !(!!route.path && ['/', '*'].includes(route.path))), ...(!!notFoundRoute ? [notFoundRoute] : [])].filter(route => !!route.path && route.path.indexOf('/_404') === -1 && route.path.indexOf('/_layout') === -1);
|
|
22
|
+
if (process.env?.NODE_ENV === 'development') {
|
|
23
|
+
console.log(`[router -> routes.tsx] notFoundRoute:: `, notFoundRoute);
|
|
24
|
+
console.log(`[router -> routes.tsx] autoRoutes:: `, autoRoutes);
|
|
25
|
+
console.log(`[router -> routes.tsx] routes:: `, routes);
|
|
26
|
+
}
|
|
27
|
+
return routes;
|
|
31
28
|
};
|
|
32
|
-
|
|
33
|
-
export { autoRooting as default };
|
|
29
|
+
export { useRootingActions };
|
package/auto-rooting.tsx
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Navigate, RouteObject } from "react-router-dom";
|
|
2
|
+
import { lazy } from 'react';
|
|
3
|
+
import * as autoRoutes from './routes-utils';
|
|
4
|
+
import { useRootingActions } from './rooting.hooks';
|
|
5
|
+
import { RouteDefinition } from './types';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Permet d'initialiser toutes les routes de l'application
|
|
10
|
+
* @returns RouteObject[]
|
|
11
|
+
*/
|
|
12
|
+
export default () => {
|
|
13
|
+
let routes: RouteObject[] = autoRoutes.routes.map((route) => ({
|
|
14
|
+
path: route.path,
|
|
15
|
+
element: route.layout ? (
|
|
16
|
+
<route.layout>
|
|
17
|
+
<route.component />
|
|
18
|
+
</route.layout>
|
|
19
|
+
) : (
|
|
20
|
+
<route.component />
|
|
21
|
+
),
|
|
22
|
+
...(!!route.error ? {
|
|
23
|
+
errorElement: <route.error />,
|
|
24
|
+
} : {}),
|
|
25
|
+
}));
|
|
26
|
+
let homeRoute: RouteObject | undefined = undefined;
|
|
27
|
+
let notFoundRoute: RouteObject | undefined = undefined;
|
|
28
|
+
homeRoute = routes.find((a) => a.path === '/');
|
|
29
|
+
notFoundRoute = routes.find((a) => a.path === '*');
|
|
30
|
+
routes = [
|
|
31
|
+
...(!!homeRoute ? [homeRoute] : []),
|
|
32
|
+
...routes.filter((route) => !(
|
|
33
|
+
!!route.path &&
|
|
34
|
+
['/', '*'].includes(route.path)
|
|
35
|
+
)),
|
|
36
|
+
...(!!notFoundRoute ? [notFoundRoute] : []),
|
|
37
|
+
].filter((route) => (
|
|
38
|
+
!!route.path && (
|
|
39
|
+
route.path.indexOf('/_404') === -1 &&
|
|
40
|
+
route.path.indexOf('/_layout') === -1
|
|
41
|
+
)
|
|
42
|
+
));
|
|
43
|
+
|
|
44
|
+
if(process.env?.NODE_ENV === 'development') {
|
|
45
|
+
console.log(`[router -> routes.tsx] notFoundRoute:: `, notFoundRoute);
|
|
46
|
+
console.log(`[router -> routes.tsx] autoRoutes:: `, autoRoutes);
|
|
47
|
+
console.log(`[router -> routes.tsx] routes:: `, routes);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return routes;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
useRootingActions,
|
|
55
|
+
};
|
package/config.d.ts
ADDED
package/config.js
ADDED
package/config.min.js
ADDED
package/minimal-config.d.ts
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface RouteDefinition {
|
|
4
|
+
truePath: string;
|
|
5
|
+
pathParent?: string;
|
|
6
|
+
path: string;
|
|
7
|
+
component: React.ComponentType<any>;
|
|
8
|
+
layout?: React.ComponentType<{
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}>;
|
|
11
|
+
error?: React.ComponentType<{}>;
|
|
12
|
+
}
|
|
13
|
+
interface ConfigDefinition {
|
|
14
|
+
parentTruePath: string;
|
|
15
|
+
truePath: string;
|
|
16
|
+
path: string;
|
|
17
|
+
name: string | undefined;
|
|
18
|
+
config: ConfigDatasDefinition;
|
|
19
|
+
}
|
|
20
|
+
interface ConfigDatasDefinition {
|
|
21
|
+
path: string;
|
|
22
|
+
name: string | undefined;
|
|
23
|
+
author: string | undefined;
|
|
24
|
+
isEnabled: boolean;
|
|
25
|
+
}
|
|
3
26
|
|
|
4
27
|
declare const configModules: any;
|
|
5
28
|
declare function cleanPathConfig(filePath: string): string;
|
package/minimal-config.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
16
|
+
var e = new Error(message);
|
|
17
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
18
|
+
};
|
|
19
|
+
|
|
1
20
|
const configModules = import.meta.glob([
|
|
2
21
|
'/src/config.json',
|
|
3
22
|
'/src/modules/**/config.json'
|
|
@@ -16,51 +35,54 @@ function filePathToConfigPath(filePath, isParent = false) {
|
|
|
16
35
|
subPath.length > 0)).join('/');
|
|
17
36
|
return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
|
|
18
37
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
nameConfig
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
function getAllConfig() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
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);
|
|
43
|
+
let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
|
|
44
|
+
nameConfig = (typeof nameConfig === 'string' &&
|
|
45
|
+
nameConfig.length > 0) ? nameConfig : undefined;
|
|
46
|
+
let config = (yield module()).default;
|
|
47
|
+
config = (typeof config === 'object' &&
|
|
48
|
+
!Array.isArray(config) &&
|
|
49
|
+
Object.keys(config).length > 0) ? {
|
|
50
|
+
path: ((typeof (config === null || config === void 0 ? void 0 : config.path) === 'string' &&
|
|
51
|
+
(config === null || config === void 0 ? void 0 : config.path.length) > 0) ? config === null || config === void 0 ? void 0 : config.path : configPath),
|
|
52
|
+
name: ((typeof (config === null || config === void 0 ? void 0 : config.name) === 'string' &&
|
|
53
|
+
(config === null || config === void 0 ? void 0 : config.name.length) > 0) ? config === null || config === void 0 ? void 0 : config.name : nameConfig),
|
|
54
|
+
description: ((typeof (config === null || config === void 0 ? void 0 : config.description) === 'string' &&
|
|
55
|
+
(config === null || config === void 0 ? void 0 : config.description.length) > 0) ? config === null || config === void 0 ? void 0 : config.description : undefined),
|
|
56
|
+
author: ((typeof (config === null || config === void 0 ? void 0 : config.author) === 'string' &&
|
|
57
|
+
(config === null || config === void 0 ? void 0 : config.author.length) > 0) ? config === null || config === void 0 ? void 0 : config.author : undefined),
|
|
58
|
+
isEnabled: ((typeof (config === null || config === void 0 ? void 0 : config.isEnabled) === 'boolean') ? config === null || config === void 0 ? void 0 : config.isEnabled : true),
|
|
59
|
+
} : {
|
|
60
|
+
path: configPath,
|
|
61
|
+
name: nameConfig,
|
|
62
|
+
author: undefined,
|
|
63
|
+
isEnabled: true,
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
parentTruePath,
|
|
67
|
+
truePath: filePath,
|
|
68
|
+
path: configPath,
|
|
69
|
+
name: nameConfig,
|
|
70
|
+
description: undefined,
|
|
71
|
+
config,
|
|
72
|
+
};
|
|
73
|
+
})));
|
|
74
|
+
return configs;
|
|
75
|
+
});
|
|
55
76
|
}
|
|
56
77
|
function findConfigModuleRoute(route, configDatas) {
|
|
57
|
-
|
|
78
|
+
var _a;
|
|
79
|
+
const res = (_a = configDatas.sort((a, b) => {
|
|
58
80
|
if (a.truePath.split('/').length > b.truePath.split('/').length)
|
|
59
81
|
return -1;
|
|
60
82
|
if (a.truePath.split('/').length < b.truePath.split('/').length)
|
|
61
83
|
return 1;
|
|
62
84
|
return 0;
|
|
63
|
-
}).find((config) => (route.truePath.indexOf(config.parentTruePath) === 0))
|
|
85
|
+
}).find((config) => (route.truePath.indexOf(config.parentTruePath) === 0))) === null || _a === void 0 ? void 0 : _a.config;
|
|
64
86
|
return res;
|
|
65
87
|
}
|
|
66
88
|
|
package/minimal-config.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let configModules=import.meta.glob(["/src/config.json","/src/modules/**/config.json"]);function cleanPathConfig(t){return t.replace(/^\/src/,"").replace(/^\/src\/modules\//,"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(t,
|
|
1
|
+
function __awaiter(t,a,r,u){return new(r=r||Promise)(function(e,n){function i(t){try{l(u.next(t))}catch(t){n(t)}}function o(t){try{l(u.throw(t))}catch(t){n(t)}}function l(t){var n;t.done?e(t.value):((n=t.value)instanceof r?n:new r(function(t){t(n)})).then(i,o)}l((u=u.apply(t,a||[])).next())})}let configModules=import.meta.glob(["/src/config.json","/src/modules/**/config.json"]);function cleanPathConfig(t){return t.replace(/^\/src/,"").replace(/^\/src\/modules\//,"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(t,n=!1){let e=(n="boolean"==typeof n&&n)?t.replace(/config\.json$/,""):cleanPathConfig(t);return(e=e.split("/").filter(t=>"string"==typeof t&&0<t.length).join("/")).startsWith("/")?e:("/"+e).split("//").join("/")}function getAllConfig(){return __awaiter(this,void 0,void 0,function*(){return yield Promise.all(Object.entries(configModules).map(t=>__awaiter(this,[t],void 0,function*([t,n]){var e=filePathToConfigPath(t,!0).split("/").join("/"),i=filePathToConfigPath(t),o="string"==typeof(o=i.split("/").filter((t,n,e)=>0<n).join("/"))&&0<o.length?o:void 0,n=(yield n()).default;return{parentTruePath:e,truePath:t,path:i,name:o,description:void 0,config:"object"==typeof n&&!Array.isArray(n)&&0<Object.keys(n).length?{path:"string"==typeof(null==n?void 0:n.path)&&0<(null==n?void 0:n.path.length)?null==n?void 0:n.path:i,name:"string"==typeof(null==n?void 0:n.name)&&0<(null==n?void 0:n.name.length)?null==n?void 0:n.name:o,description:!("string"==typeof(null==n?void 0:n.description)&&0<(null==n?void 0:n.description.length))||null==n?void 0:n.description,author:!("string"==typeof(null==n?void 0:n.author)&&0<(null==n?void 0:n.author.length))||null==n?void 0:n.author,isEnabled:"boolean"!=typeof(null==n?void 0:n.isEnabled)||(null==n?void 0:n.isEnabled)}:{path:i,name:o,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(n,t){return null==(t=t.sort((t,n)=>t.truePath.split("/").length>n.truePath.split("/").length?-1:t.truePath.split("/").length<n.truePath.split("/").length?1:0).find(t=>0===n.truePath.indexOf(t.parentTruePath)))?void 0:t.config}export{cleanPathConfig,configModules,filePathToConfigPath,findConfigModuleRoute,getAllConfig};
|
|
2
2
|
//# sourceMappingURL=minimal-config.min.js.map
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.13",
|
|
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": [],
|