@arc-js/core 0.0.50 → 0.0.52

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