@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 CHANGED
@@ -1,33 +1,29 @@
1
- import { j as jsxRuntimeExports } from './_virtual/jsx-runtime';
2
- import * as routesUtils_js from './routes-utils.js';
3
- import { routes } from './routes-utils.js';
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
- var autoRooting = () => {
7
- let routes$1 = routes.map((route) => ({
8
- path: route.path,
9
- element: route.layout ? (jsxRuntimeExports.jsx(route.layout, { children: jsxRuntimeExports.jsx(route.component, {}) })) : (jsxRuntimeExports.jsx(route.component, {})),
10
- ...(!!route.error ? {
11
- errorElement: jsxRuntimeExports.jsx(route.error, {}),
12
- } : {}),
13
- }));
14
- let homeRoute = undefined;
15
- let notFoundRoute = undefined;
16
- homeRoute = routes$1.find((a) => a.path === '/');
17
- notFoundRoute = routes$1.find((a) => a.path === '*');
18
- routes$1 = [
19
- ...(!!homeRoute ? [homeRoute] : []),
20
- ...routes$1.filter((route) => !(!!route.path &&
21
- ['/', '*'].includes(route.path))),
22
- ...(!!notFoundRoute ? [notFoundRoute] : []),
23
- ].filter((route) => (!!route.path && (route.path.indexOf('/_404') === -1 &&
24
- route.path.indexOf('/_layout') === -1)));
25
- if (process.env?.NODE_ENV === 'development') {
26
- console.log(`[router -> routes.tsx] notFoundRoute:: `, notFoundRoute);
27
- console.log(`[router -> routes.tsx] autoRoutes:: `, routesUtils_js);
28
- console.log(`[router -> routes.tsx] routes:: `, routes$1);
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 };
@@ -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
@@ -0,0 +1,8 @@
1
+ declare const NODEENV: 'development' | 'production' | 'debug';
2
+ declare const langs: string[];
3
+ declare const langCodes: {
4
+ fr: string;
5
+ en: string;
6
+ };
7
+
8
+ export { NODEENV, langCodes, langs };
package/config.js ADDED
@@ -0,0 +1,8 @@
1
+ const NODEENV = 'development';
2
+ const langs = ['en', 'fr'];
3
+ const langCodes = {
4
+ 'fr': 'fr_FR',
5
+ 'en': 'en_US',
6
+ };
7
+
8
+ export { NODEENV, langCodes, langs };
package/config.min.js ADDED
@@ -0,0 +1,2 @@
1
+ let NODEENV="development",langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"};export{NODEENV,langCodes,langs};
2
+ //# sourceMappingURL=config.min.js.map
@@ -1,5 +1,28 @@
1
- import { ConfigDefinition, RouteDefinition, ConfigDatasDefinition } from './types.js';
2
- import 'react';
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
- async function getAllConfig() {
20
- let configs = await Promise.all(Object.entries(configModules).map(async ([filePath, module]) => {
21
- const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
22
- const configPath = filePathToConfigPath(filePath);
23
- let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
24
- nameConfig = (typeof nameConfig === 'string' &&
25
- nameConfig.length > 0) ? nameConfig : undefined;
26
- let config = (await module()).default;
27
- config = (typeof config === 'object' &&
28
- !Array.isArray(config) &&
29
- Object.keys(config).length > 0) ? {
30
- path: ((typeof config?.path === 'string' &&
31
- config?.path.length > 0) ? config?.path : configPath),
32
- name: ((typeof config?.name === 'string' &&
33
- config?.name.length > 0) ? config?.name : nameConfig),
34
- description: ((typeof config?.description === 'string' &&
35
- config?.description.length > 0) ? config?.description : undefined),
36
- author: ((typeof config?.author === 'string' &&
37
- config?.author.length > 0) ? config?.author : undefined),
38
- isEnabled: ((typeof config?.isEnabled === 'boolean') ? config?.isEnabled : true),
39
- } : {
40
- path: configPath,
41
- name: nameConfig,
42
- author: undefined,
43
- isEnabled: true,
44
- };
45
- return {
46
- parentTruePath,
47
- truePath: filePath,
48
- path: configPath,
49
- name: nameConfig,
50
- description: undefined,
51
- config,
52
- };
53
- }));
54
- return configs;
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
- const res = configDatas.sort((a, b) => {
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))?.config;
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
 
@@ -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,e=!1){let n=(e="boolean"==typeof e&&e)?t.replace(/config\.json$/,""):cleanPathConfig(t);return(n=n.split("/").filter(t=>"string"==typeof t&&0<t.length).join("/")).startsWith("/")?n:("/"+n).split("//").join("/")}async function getAllConfig(){return await Promise.all(Object.entries(configModules).map(async([t,e])=>{var n=filePathToConfigPath(t,!0).split("/").join("/"),o=filePathToConfigPath(t),i="string"==typeof(i=o.split("/").filter((t,e,n)=>0<e).join("/"))&&0<i.length?i:void 0,e=(await 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 e?.path&&0<e?.path.length?e?.path:o,name:"string"==typeof e?.name&&0<e?.name.length?e?.name:i,description:"string"==typeof e?.description&&0<e?.description.length?e?.description:void 0,author:"string"==typeof e?.author&&0<e?.author.length?e?.author:void 0,isEnabled:"boolean"!=typeof e?.isEnabled||e?.isEnabled}:{path:o,name:i,author:void 0,isEnabled:!0}}}))}function findConfigModuleRoute(e,t){return 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))?.config}export{cleanPathConfig,configModules,filePathToConfigPath,findConfigModuleRoute,getAllConfig};
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.11",
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": [],