@arc-js/core 0.0.51 → 0.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/auto-rooting.jsx CHANGED
@@ -1,12 +1,9 @@
1
+ import * as autoRoutes from './routes-utils';
1
2
  import { useRootingActions } from './rooting.hooks';
2
- import { getSrcPath } from "./utils";
3
- import { getRoutes } from "./routes-utils";
4
3
  import React from "react";
5
4
 
6
-
7
- export default async (srcPath = getSrcPath()) => {
8
- const autoRoutes = await getRoutes(srcPath);
9
- let routes = autoRoutes.map(route => ({
5
+ export default () => {
6
+ let routes = autoRoutes.routes.map(route => ({
10
7
  path: route.path,
11
8
  element: route.layout ? React.createElement(route.layout, null, React.createElement(route.component, null)) : React.createElement(route.component, null),
12
9
  ...(!!route.error ? {
package/auto-rooting.tsx CHANGED
@@ -1,17 +1,13 @@
1
1
  import { Navigate, RouteObject } from "react-router-dom";
2
2
  import { lazy } from 'react';
3
+ import * as autoRoutes from './routes-utils';
3
4
  import { useRootingActions } from './rooting.hooks';
4
5
  import { RouteDefinition } from './types';
5
- import { getSrcPath } from "./utils";
6
- import { getRoutes } from "./routes-utils";
7
6
 
8
7
 
9
8
 
10
- export default async (
11
- srcPath = getSrcPath(),
12
- ) => {
13
- const autoRoutes: RouteDefinition[] = await getRoutes(srcPath);
14
- let routes: RouteObject[] = autoRoutes.map((route) => ({
9
+ export default () => {
10
+ let routes: RouteObject[] = autoRoutes.routes.map((route) => ({
15
11
  path: route.path,
16
12
  element: route.layout ? (
17
13
  <route.layout>
package/config.js CHANGED
@@ -8,6 +8,6 @@ const langCodes = {
8
8
  const PATH_CONFIG = {
9
9
  SRC_DIR: '/src',
10
10
  };
11
- const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.APP_SRC_DIR) || '/src';
11
+ const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
12
12
 
13
13
  export { NODEENV, PATH_CONFIG, SRC_DIR, langCodes, langs };
package/config.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var _a;let NODEENV="development",langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"},PATH_CONFIG={SRC_DIR:"/src"},SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.APP_SRC_DIR)||"/src";export{NODEENV,PATH_CONFIG,SRC_DIR,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.VITE_APP_SRC_DIR)||"/src";export{NODEENV,PATH_CONFIG,SRC_DIR,langCodes,langs};
2
2
  //# sourceMappingURL=config.min.js.map
@@ -24,11 +24,10 @@ interface ConfigDatasDefinition {
24
24
  isEnabled: boolean;
25
25
  }
26
26
 
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[]>;
27
+ declare const configModules: any;
28
+ declare function cleanPathConfig(filePath: string): string;
29
+ declare function filePathToConfigPath(filePath: string, isParent?: boolean): string;
30
+ declare function getAllConfig(): Promise<ConfigDefinition[]>;
32
31
  declare function findConfigModuleRoute(route: RouteDefinition, configDatas: ConfigDefinition[]): ConfigDatasDefinition | undefined;
33
32
 
34
- export { cleanPathConfig, filePathToConfigPath, findConfigModuleRoute, getAllConfig, getConfigModules, normalizePath };
33
+ export { cleanPathConfig, configModules, filePathToConfigPath, findConfigModuleRoute, getAllConfig };
package/minimal-config.js CHANGED
@@ -18,43 +18,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
18
18
  };
19
19
 
20
20
  var _a;
21
- const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.APP_SRC_DIR) || '/src';
21
+ const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
22
22
 
23
- 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()) {
23
+ const configModules = import.meta.glob([
24
+ '@/config.json',
25
+ '@/modules/**/config.json'
26
+ ]);
27
+ function cleanPathConfig(filePath) {
28
+ const srcPath = SRC_DIR;
37
29
  return filePath
38
30
  .replace(new RegExp(`^${srcPath}`), '')
39
- .replace(new RegExp(`^${srcPath}/modules/`), '')
31
+ .replace(new RegExp(`^${srcPath}/modules`), '')
40
32
  .replace(/^\/modules\//, '')
41
33
  .replace(/config\.json$/, '');
42
34
  }
43
- function filePathToConfigPath(filePath, isParent = false, srcPath = getSrcPath()) {
35
+ function filePathToConfigPath(filePath, isParent = false) {
44
36
  isParent = (typeof isParent === 'boolean') ? isParent : false;
45
- let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath, srcPath);
46
- configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
37
+ let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
47
38
  configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
48
39
  subPath.length > 0)).join('/');
49
40
  return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
50
41
  }
51
42
  function getAllConfig() {
52
- return __awaiter(this, arguments, void 0, function* (srcPath = getSrcPath()) {
53
- const configModules = getConfigModules(srcPath);
43
+ return __awaiter(this, void 0, void 0, function* () {
54
44
  let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
55
- const parentTruePath = filePathToConfigPath(filePath, true, srcPath).split('/').join('/');
56
- const configPath = filePathToConfigPath(filePath, false, srcPath);
57
- filePath.replace(new RegExp(`^${srcPath}`), '');
45
+ const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
46
+ const configPath = filePathToConfigPath(filePath);
58
47
  let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
59
48
  nameConfig = (typeof nameConfig === 'string' &&
60
49
  nameConfig.length > 0) ? nameConfig : undefined;
@@ -101,4 +90,4 @@ function findConfigModuleRoute(route, configDatas) {
101
90
  return res;
102
91
  }
103
92
 
104
- export { cleanPathConfig, filePathToConfigPath, findConfigModuleRoute, getAllConfig, getConfigModules, normalizePath };
93
+ export { cleanPathConfig, configModules, filePathToConfigPath, findConfigModuleRoute, getAllConfig };
@@ -1,2 +1,2 @@
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};
1
+ function __awaiter(n,a,r,u){return new(r=r||Promise)(function(e,t){function o(n){try{l(u.next(n))}catch(n){t(n)}}function i(n){try{l(u.throw(n))}catch(n){t(n)}}function l(n){var t;n.done?e(n.value):((t=n.value)instanceof r?t:new r(function(n){n(t)})).then(o,i)}l((u=u.apply(n,a||[])).next())})}var _a;let SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.VITE_APP_SRC_DIR)||"/src",configModules=import.meta.glob(["@/config.json","@/modules/**/config.json"]);function cleanPathConfig(n){var t=SRC_DIR;return n.replace(new RegExp("^"+t),"").replace(new RegExp(`^${t}/modules`),"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(n,t=!1){let e=(t="boolean"==typeof t&&t)?n.replace(/config\.json$/,""):cleanPathConfig(n);return(e=e.split("/").filter(n=>"string"==typeof n&&0<n.length).join("/")).startsWith("/")?e:("/"+e).split("//").join("/")}function getAllConfig(){return __awaiter(this,void 0,void 0,function*(){return yield Promise.all(Object.entries(configModules).map(n=>__awaiter(this,[n],void 0,function*([n,t]){var e=filePathToConfigPath(n,!0).split("/").join("/"),o=filePathToConfigPath(n),i="string"==typeof(i=o.split("/").filter((n,t,e)=>0<t).join("/"))&&0<i.length?i:void 0,t=(yield t()).default;return{parentTruePath:e,truePath:n,path:o,name:i,description:void 0,config:"object"==typeof t&&!Array.isArray(t)&&0<Object.keys(t).length?{path:"string"==typeof(null==t?void 0:t.path)&&0<(null==t?void 0:t.path.length)?null==t?void 0:t.path:o,name:"string"==typeof(null==t?void 0:t.name)&&0<(null==t?void 0:t.name.length)?null==t?void 0:t.name:i,description:!("string"==typeof(null==t?void 0:t.description)&&0<(null==t?void 0:t.description.length))||null==t?void 0:t.description,author:!("string"==typeof(null==t?void 0:t.author)&&0<(null==t?void 0:t.author.length))||null==t?void 0:t.author,isEnabled:"boolean"!=typeof(null==t?void 0:t.isEnabled)||(null==t?void 0:t.isEnabled)}:{path:o,name:i,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(t,n){return null==(n=n.sort((n,t)=>n.truePath.split("/").length>t.truePath.split("/").length?-1:n.truePath.split("/").length<t.truePath.split("/").length?1:0).find(n=>0===t.truePath.indexOf(n.parentTruePath)))?void 0:n.config}export{cleanPathConfig,configModules,filePathToConfigPath,findConfigModuleRoute,getAllConfig};
2
2
  //# sourceMappingURL=minimal-config.min.js.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.51",
6
+ "version": "0.0.53",
7
7
  "description": "CORE est un module de routage intelligent et auto-configuré pour les applications React avec TypeScript/Javascript. Il fournit un système de routage basé sur la structure de fichiers, des hooks de navigation avancés et une configuration minimale pour les applications modulaires.",
8
8
  "main": "index.js",
9
9
  "keywords": [],
package/routes-utils.d.ts CHANGED
@@ -11,6 +11,7 @@ interface RouteDefinition {
11
11
  error?: React.ComponentType<{}>;
12
12
  }
13
13
 
14
- declare function getRoutes(srcPath?: string): Promise<RouteDefinition[]>;
14
+ declare function getRoutes(): Promise<RouteDefinition[]>;
15
+ declare const routes: RouteDefinition[];
15
16
 
16
- export { getRoutes };
17
+ export { getRoutes, routes };
package/routes-utils.js CHANGED
@@ -18,40 +18,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
18
18
  };
19
19
 
20
20
  var _a;
21
- const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.APP_SRC_DIR) || '/src';
21
+ const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
22
22
 
23
- 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()) {
23
+ const configModules = import.meta.glob([
24
+ '@/config.json',
25
+ '@/modules/**/config.json'
26
+ ]);
27
+ function cleanPathConfig(filePath) {
28
+ const srcPath = SRC_DIR;
34
29
  return filePath
35
30
  .replace(new RegExp(`^${srcPath}`), '')
36
- .replace(new RegExp(`^${srcPath}/modules/`), '')
31
+ .replace(new RegExp(`^${srcPath}/modules`), '')
37
32
  .replace(/^\/modules\//, '')
38
33
  .replace(/config\.json$/, '');
39
34
  }
40
- function filePathToConfigPath(filePath, isParent = false, srcPath = getSrcPath()) {
35
+ function filePathToConfigPath(filePath, isParent = false) {
41
36
  isParent = (typeof isParent === 'boolean') ? isParent : false;
42
- let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath, srcPath);
43
- configPath = configPath.replace(new RegExp(`^${srcPath}`), '');
37
+ let configPath = !!isParent ? filePath.replace(/config\.json$/, '') : cleanPathConfig(filePath);
44
38
  configPath = configPath.split('/').filter((subPath) => (typeof subPath === 'string' &&
45
39
  subPath.length > 0)).join('/');
46
40
  return configPath.startsWith('/') ? configPath : `/${configPath}`.split('//').join('/');
47
41
  }
48
42
  function getAllConfig() {
49
- return __awaiter(this, arguments, void 0, function* (srcPath = getSrcPath()) {
50
- const configModules = getConfigModules(srcPath);
43
+ return __awaiter(this, void 0, void 0, function* () {
51
44
  let configs = yield Promise.all(Object.entries(configModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
52
- const parentTruePath = filePathToConfigPath(filePath, true, srcPath).split('/').join('/');
53
- const configPath = filePathToConfigPath(filePath, false, srcPath);
54
- filePath.replace(new RegExp(`^${srcPath}`), '');
45
+ const parentTruePath = filePathToConfigPath(filePath, true).split('/').join('/');
46
+ const configPath = filePathToConfigPath(filePath);
55
47
  let nameConfig = configPath.split('/').filter((subPath, indexSubPath, pathArr) => (indexSubPath > 0)).join('/');
56
48
  nameConfig = (typeof nameConfig === 'string' &&
57
49
  nameConfig.length > 0) ? nameConfig : undefined;
@@ -98,35 +90,30 @@ function findConfigModuleRoute(route, configDatas) {
98
90
  return res;
99
91
  }
100
92
 
101
- function getDefaultErrorPath(srcPath = getSrcPath()) {
102
- return `${srcPath}/pages/_error`;
103
- }
104
- function getDefaultLayoutPath(srcPath = getSrcPath()) {
105
- return `${srcPath}/pages/_layout`;
106
- }
107
93
  const errorPageName = '_error';
94
+ const defaultErrorPath = `${SRC_DIR}/pages/_error`;
108
95
  const notFoundPageName = '_404';
109
96
  const notFoundPagePath = '*';
97
+ const defaultLayoutPath = `${SRC_DIR}/pages/_layout`;
110
98
  const layoutName = '_layout';
111
99
  const indexPageName = 'index';
112
100
  const indexPageRule = /\/index$/;
113
101
  const indexPagePath = '/';
114
- 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()) {
102
+ const pageModules = import.meta.glob([
103
+ '@/pages/**/*.tsx',
104
+ '@/modules/**/pages/**/*.tsx'
105
+ ]);
106
+ function cleanPathPage(filePath) {
107
+ const srcPath = SRC_DIR;
121
108
  return filePath
122
- .replace(new RegExp(`^${srcPath}/pages/`), '')
123
- .replace(new RegExp(`^${srcPath}/modules/`), '')
109
+ .replace(new RegExp(`^${srcPath}/pages`), '')
110
+ .replace(new RegExp(`^${srcPath}/pages`), '')
124
111
  .replace(/\/pages\//, '/')
125
112
  .replace(/\.tsx$/, '')
126
113
  .replace(/\{([^\]]+)\}/g, ':$1');
127
114
  }
128
- function filePathToRoutePath(filePath, srcPath = getSrcPath()) {
129
- let routePath = cleanPathPage(filePath, srcPath);
115
+ function filePathToRoutePath(filePath) {
116
+ let routePath = cleanPathPage(filePath);
130
117
  if (routePath.endsWith(`/${indexPageName}`)) {
131
118
  routePath = routePath.replace(indexPageRule, '') || indexPagePath;
132
119
  }
@@ -139,38 +126,34 @@ function filePathToRoutePath(filePath, srcPath = getSrcPath()) {
139
126
  }
140
127
  return routePath.startsWith(indexPagePath) ? routePath : `/${routePath}`;
141
128
  }
142
- function findLayoutForPage(filePath_1) {
143
- return __awaiter(this, arguments, void 0, function* (filePath, srcPath = getSrcPath()) {
129
+ function findLayoutForPage(filePath) {
130
+ return __awaiter(this, void 0, void 0, function* () {
144
131
  var _a, _b;
145
- const defaultLayoutPath = getDefaultLayoutPath(srcPath);
146
132
  const layoutPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${layoutName}.tsx`);
147
- const layoutModules = import.meta.glob(`${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);
133
+ const layoutModules = import.meta.glob('@/modules/**/_layout.tsx', { eager: true });
134
+ const defaultLayoutModules = import.meta.glob('@/pages/_layout.tsx', { eager: true });
135
+ return ((_a = layoutModules[layoutPath]) === null || _a === void 0 ? void 0 : _a.default) || ((_b = defaultLayoutModules[`${defaultLayoutPath}.tsx`]) === null || _b === void 0 ? void 0 : _b.default);
151
136
  });
152
137
  }
153
- function findErrorForPage(filePath_1) {
154
- return __awaiter(this, arguments, void 0, function* (filePath, srcPath = getSrcPath()) {
138
+ function findErrorForPage(filePath) {
139
+ return __awaiter(this, void 0, void 0, function* () {
155
140
  var _a, _b, _c;
156
- const defaultErrorPath = getDefaultErrorPath(srcPath);
157
141
  const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
158
- const errorModules = import.meta.glob(`${srcPath}/modules/**/_error.tsx`, { eager: true });
159
- const defaultErrorModules = import.meta.glob(`${srcPath}/pages/_error.tsx`, { eager: true });
142
+ const errorModules = import.meta.glob('@/modules/**/_error.tsx', { eager: true });
143
+ const defaultErrorModules = import.meta.glob('@/pages/_error.tsx', { eager: true });
160
144
  if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'debug') {
161
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
145
+ console.log(`[@arc -> core -> rooter -> routes-utils] findErrorForPage | datas:: `, JSON.stringify({
162
146
  filePath,
163
147
  errorPath,
164
148
  }));
165
149
  }
166
- return ((_b = errorModules[errorPath]) === null || _b === void 0 ? void 0 : _b.default) ||
167
- ((_c = defaultErrorModules[`${defaultErrorPath}.tsx`]) === null || _c === void 0 ? void 0 : _c.default);
150
+ return ((_b = errorModules[errorPath]) === null || _b === void 0 ? void 0 : _b.default) || ((_c = defaultErrorModules[`${defaultErrorPath}.tsx`]) === null || _c === void 0 ? void 0 : _c.default);
168
151
  });
169
152
  }
170
- function findErrorForPageLink(filePath_1) {
171
- return __awaiter(this, arguments, void 0, function* (filePath, srcPath = getSrcPath()) {
153
+ function findErrorForPageLink(filePath) {
154
+ return __awaiter(this, void 0, void 0, function* () {
172
155
  const errorPath = filePath.replace(/\/pages\/.*\.tsx$/, `/pages/${errorPageName}.tsx`);
173
- return cleanPathPage(errorPath, srcPath).split(srcPath).join('');
156
+ return cleanPathPage(errorPath).split(SRC_DIR).join('');
174
157
  });
175
158
  }
176
159
  function nearestRoute(targetRoute, routes) {
@@ -195,20 +178,19 @@ function nearestRoute(targetRoute, routes) {
195
178
  return possibleLayouts === null || possibleLayouts === void 0 ? void 0 : possibleLayouts[0];
196
179
  }
197
180
  function getRoutes() {
198
- return __awaiter(this, arguments, void 0, function* (srcPath = getSrcPath()) {
181
+ return __awaiter(this, void 0, void 0, function* () {
199
182
  var _a, _b, _c;
200
- const pageModules = getPageModules(srcPath);
201
- const configs = yield getAllConfig(srcPath);
183
+ const configs = yield getAllConfig();
202
184
  if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
203
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
185
+ console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | configs:: `, configs);
204
186
  }
205
187
  let routes = yield Promise.all(Object.entries(pageModules).map((_a) => __awaiter(this, [_a], void 0, function* ([filePath, module]) {
206
188
  let layout = (!([
207
189
  notFoundPageName
208
- ].map((path) => (cleanPathPage(path, 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);
190
+ ].map((path) => (cleanPathPage(path))).includes(cleanPathPage(filePath)))) ? yield findLayoutForPage(filePath) : undefined;
191
+ let erroPage = yield findErrorForPage(filePath);
192
+ yield findErrorForPageLink(filePath);
193
+ const routePath = filePathToRoutePath(filePath);
212
194
  const component = (yield module()).default;
213
195
  const routePathParent = routePath.split('/').filter((val, index, arr) => (typeof val === 'string' &&
214
196
  val.length > 0 &&
@@ -232,9 +214,9 @@ function getRoutes() {
232
214
  const layoutRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_layout') !== -1)));
233
215
  const errorRoutes = routes.filter((route) => (!!route.path && (route.path.indexOf('/_error') !== -1)));
234
216
  if (((_b = process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') {
235
- console.log(`[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);
217
+ console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | notFoundRoutes:: `, notFoundRoutes);
218
+ console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | routes:: `, routes);
219
+ console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | layoutRoutes:: `, layoutRoutes);
238
220
  }
239
221
  routes = routes.map((route) => {
240
222
  var _a, _b;
@@ -251,10 +233,11 @@ function getRoutes() {
251
233
  return route;
252
234
  });
253
235
  if (((_c = process.env) === null || _c === void 0 ? void 0 : _c.NODE_ENV) === 'development') {
254
- console.log(`[src -> @arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
236
+ console.log(`[@arc -> core -> rooter -> routes-utils] getRoutes | routesF:: `, routesF);
255
237
  }
256
238
  return routesF;
257
239
  });
258
240
  }
241
+ const routes = await getRoutes();
259
242
 
260
- export { getRoutes };
243
+ export { getRoutes, routes };
@@ -1,2 +1,2 @@
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};
1
+ function __awaiter(e,l,r,u){return new(r=r||Promise)(function(n,t){function a(e){try{o(u.next(e))}catch(e){t(e)}}function i(e){try{o(u.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(a,i)}o((u=u.apply(e,l||[])).next())})}var _a;let SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.VITE_APP_SRC_DIR)||"/src",configModules=import.meta.glob(["@/config.json","@/modules/**/config.json"]);function cleanPathConfig(e){var t=SRC_DIR;return e.replace(new RegExp("^"+t),"").replace(new RegExp(`^${t}/modules`),"").replace(/^\/modules\//,"").replace(/config\.json$/,"")}function filePathToConfigPath(e,t=!1){let n=(t="boolean"==typeof t&&t)?e.replace(/config\.json$/,""):cleanPathConfig(e);return(n=n.split("/").filter(e=>"string"==typeof e&&0<e.length).join("/")).startsWith("/")?n:("/"+n).split("//").join("/")}function getAllConfig(){return __awaiter(this,void 0,void 0,function*(){return yield Promise.all(Object.entries(configModules).map(e=>__awaiter(this,[e],void 0,function*([e,t]){var n=filePathToConfigPath(e,!0).split("/").join("/"),a=filePathToConfigPath(e),i="string"==typeof(i=a.split("/").filter((e,t,n)=>0<t).join("/"))&&0<i.length?i:void 0,t=(yield t()).default;return{parentTruePath:n,truePath:e,path:a,name:i,description:void 0,config:"object"==typeof t&&!Array.isArray(t)&&0<Object.keys(t).length?{path:"string"==typeof(null==t?void 0:t.path)&&0<(null==t?void 0:t.path.length)?null==t?void 0:t.path:a,name:"string"==typeof(null==t?void 0:t.name)&&0<(null==t?void 0:t.name.length)?null==t?void 0:t.name:i,description:!("string"==typeof(null==t?void 0:t.description)&&0<(null==t?void 0:t.description.length))||null==t?void 0:t.description,author:!("string"==typeof(null==t?void 0:t.author)&&0<(null==t?void 0:t.author.length))||null==t?void 0:t.author,isEnabled:"boolean"!=typeof(null==t?void 0:t.isEnabled)||(null==t?void 0:t.isEnabled)}:{path:a,name:i,author:void 0,isEnabled:!0}}})))})}function findConfigModuleRoute(t,e){return null==(e=e.sort((e,t)=>e.truePath.split("/").length>t.truePath.split("/").length?-1:e.truePath.split("/").length<t.truePath.split("/").length?1:0).find(e=>0===t.truePath.indexOf(e.parentTruePath)))?void 0:e.config}let errorPageName="_error",defaultErrorPath=SRC_DIR+"/pages/_error",notFoundPageName="_404",notFoundPagePath="*",defaultLayoutPath=SRC_DIR+"/pages/_layout",layoutName="_layout",indexPageName="index",indexPageRule=/\/index$/,indexPagePath="/",pageModules=import.meta.glob(["@/pages/**/*.tsx","@/modules/**/pages/**/*.tsx"]);function cleanPathPage(e){var t=SRC_DIR;return e.replace(new RegExp(`^${t}/pages`),"").replace(new RegExp(`^${t}/pages`),"").replace(/\/pages\//,"/").replace(/\.tsx$/,"").replace(/\{([^\]]+)\}/g,":$1")}function filePathToRoutePath(e){let t=cleanPathPage(e);if(t.endsWith("/"+indexPageName))t=t.replace(indexPageRule,"")||indexPagePath;else if(t===""+indexPageName)t=indexPagePath;else if(t===notFoundPageName)return t=notFoundPagePath;return t.startsWith(indexPagePath)?t:"/"+t}function findLayoutForPage(a){return __awaiter(this,void 0,void 0,function*(){var e=a.replace(/\/pages\/.*\.tsx$/,`/pages/${layoutName}.tsx`),t=import.meta.glob("@/modules/**/_layout.tsx",{eager:!0}),n=import.meta.glob("@/pages/_layout.tsx",{eager:!0});return(null==(t=t[e])?void 0:t.default)||(null==(e=n[defaultLayoutPath+".tsx"])?void 0:e.default)})}function findErrorForPage(i){return __awaiter(this,void 0,void 0,function*(){var e,t=i.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`),n=import.meta.glob("@/modules/**/_error.tsx",{eager:!0}),a=import.meta.glob("@/pages/_error.tsx",{eager:!0});return null!=(e=process.env)&&e.NODE_ENV,(null==(e=n[t])?void 0:e.default)||(null==(n=a[defaultErrorPath+".tsx"])?void 0:n.default)})}function findErrorForPageLink(e){return __awaiter(this,void 0,void 0,function*(){return cleanPathPage(e.replace(/\/pages\/.*\.tsx$/,`/pages/${errorPageName}.tsx`)).split(SRC_DIR).join("")})}function nearestRoute(n,e){e=e.map(e=>Object.assign(Object.assign({},e),{path:(e.path||"").split("/").filter((e,t,n)=>2<=n.length&&"string"==typeof(null==n?void 0:n[n.length-2])&&(null==n?void 0:n[n.length-2].length)<=0&&t<n.length-2||!(2<=n.length&&"string"==typeof(null==n?void 0:n[n.length-2])&&(null==n?void 0:n[n.length-2].length)<=0)&&t<n.length-1).join("/")})).filter(e=>0===n.path.indexOf(e.path)).sort((e,t)=>e.path.indexOf(n.path)>t.path.indexOf(n.path)?-1:e.path.indexOf(n.path)<t.path.indexOf(n.path)?1:e.path.split("/").length>t.path.split("/").length?-1:e.path.split("/").length<t.path.split("/").length?1:0);return null==e?void 0:e[0]}function getRoutes(){return __awaiter(this,void 0,void 0,function*(){let e,t,n,a=yield getAllConfig(),i=(null==(e=process.env)||e.NODE_ENV,yield Promise.all(Object.entries(pageModules).map(e=>__awaiter(this,[e],void 0,function*([e,t]){var n=[notFoundPageName].map(e=>cleanPathPage(e)).includes(cleanPathPage(e))?void 0:yield findLayoutForPage(e),a=yield findErrorForPage(e),i=(yield findErrorForPageLink(e),filePathToRoutePath(e)),t=(yield t()).default,o=i.split("/").filter((e,t,n)=>"string"==typeof e&&0<e.length&&t<n.length-1).join("/");return{truePath:e,path:i,component:t,layout:n,error:a,pathParent:o}}))));var o=i.filter(e=>!!e.truePath&&0<e.truePath.split("/").filter(e=>-1!==e.indexOf("_404.tsx")).length).map(e=>Object.assign(Object.assign({},e),{path:e.path.split("/").map(e=>e.split("_404").join(notFoundPagePath)).join("/")}));let l=(i=[...i.filter(e=>!(e.truePath&&0<e.truePath.split("/").filter(e=>-1!==e.indexOf("_404.tsx")).length)),...o]).filter(e=>!!e.path&&-1!==e.path.indexOf("/_layout")),r=i.filter(e=>!!e.path&&-1!==e.path.indexOf("/_error"));null!=(t=process.env)&&t.NODE_ENV;o=(i=i.map(e=>{var t;return Object.assign(Object.assign({},e),{layout:(null==(t=nearestRoute(e,l))?void 0:t.component)||e.layout,error:(null==(t=nearestRoute(e,r))?void 0:t.component)||e.error})})).map((e,t)=>{var n=findConfigModuleRoute(e,a);return"string"==typeof(null==n?void 0:n.path)&&0<(null==n?void 0:n.path.length)&&"/"!=(null==n?void 0:n.path)&&(e.path=e.path.split("/").filter((e,t,n)=>1<t).join("/"),e.path=(`${null==n?void 0:n.path}/`+e.path).split("//").join("/")),e});return null!=(n=process.env)&&n.NODE_ENV,o})}let routes=await getRoutes();export{getRoutes,routes};
2
2
  //# sourceMappingURL=routes-utils.min.js.map
package/utils.js CHANGED
@@ -4,7 +4,7 @@ const langCodes = {
4
4
  'fr': 'fr_FR',
5
5
  'en': 'en_US',
6
6
  };
7
- const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.APP_SRC_DIR) || '/src';
7
+ const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
8
8
 
9
9
  function getLang(lang) {
10
10
  let result = lang;
package/utils.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var _a;let langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"},SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.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};
1
+ var _a;let langs=["en","fr"],langCodes={fr:"fr_FR",en:"en_US"},SRC_DIR=(null==(_a=null==process?void 0:process.env)?void 0:_a.VITE_APP_SRC_DIR)||"/src";function getLang(n){return langs.includes(n)?n:"fr"}function getLangCode(n){return langCodes[getLang(n)]}function getSrcPath(){return SRC_DIR}export{getLang,getLangCode,getSrcPath};
2
2
  //# sourceMappingURL=utils.min.js.map