5htp-core 0.2.9 → 0.3.0

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.
Files changed (75) hide show
  1. package/package.json +7 -5
  2. package/src/client/app/component.tsx +2 -2
  3. package/src/client/assets/css/text/titres.less +4 -0
  4. package/src/client/components/Dialog/card.tsx +1 -1
  5. package/src/client/components/Dialog/index.less +3 -3
  6. package/src/client/components/inputv3/date/index.tsx +1 -1
  7. package/src/client/components/inputv3/index.tsx +14 -4
  8. package/src/client/pages/_layout/index.tsx +3 -3
  9. package/src/client/pages/_messages/400.tsx +2 -2
  10. package/src/client/pages/_messages/401.tsx +2 -2
  11. package/src/client/pages/_messages/403.tsx +2 -2
  12. package/src/client/pages/_messages/404.tsx +2 -2
  13. package/src/client/pages/_messages/500.tsx +2 -2
  14. package/src/client/pages/useHeader.tsx +2 -1
  15. package/src/client/services/router/components/router.tsx +1 -1
  16. package/src/client/services/router/index.tsx +5 -1
  17. package/src/client/services/router/response/index.tsx +5 -2
  18. package/src/common/data/objets.ts +0 -25
  19. package/src/common/router/index.ts +8 -12
  20. package/src/common/router/layouts.ts +3 -1
  21. package/src/common/router/register.ts +5 -3
  22. package/src/common/router/response/index.ts +3 -3
  23. package/src/server/app/commands.ts +2 -11
  24. package/src/server/app/{config.ts → container/config.ts} +4 -1
  25. package/src/server/app/container/index.ts +84 -0
  26. package/src/server/app/index.ts +73 -136
  27. package/src/server/app/instance.ts +3 -0
  28. package/src/server/app/service/container.ts +136 -0
  29. package/src/server/app/service/index.ts +219 -0
  30. package/src/server/index.ts +9 -3
  31. package/src/server/services/cache/index.ts +42 -16
  32. package/src/server/services/cache/service.json +6 -0
  33. package/src/server/services/console/index.ts +35 -22
  34. package/src/server/services/console/service.json +6 -0
  35. package/src/server/services/cron/index.ts +11 -11
  36. package/src/server/services/cron/service.json +6 -0
  37. package/src/server/services/database/connection.ts +26 -34
  38. package/src/server/services/database/index.ts +41 -21
  39. package/src/server/services/database/metas.ts +12 -7
  40. package/src/server/services/database/repository.ts +0 -9
  41. package/src/server/services/database/service.json +6 -0
  42. package/src/server/services/database/stats.ts +3 -3
  43. package/src/server/services/disks/driver.ts +9 -7
  44. package/src/server/services/disks/drivers/local/index.ts +199 -0
  45. package/src/server/services/disks/drivers/local/service.json +6 -0
  46. package/src/server/services/disks/drivers/s3/index.ts +282 -0
  47. package/src/server/services/disks/drivers/s3/service.json +6 -0
  48. package/src/server/services/disks/index.ts +47 -16
  49. package/src/server/services/disks/service.json +6 -0
  50. package/src/server/services/email/index.ts +16 -4
  51. package/src/server/services/email/service.json +6 -0
  52. package/src/server/services/fetch/index.ts +52 -8
  53. package/src/server/services/fetch/service.json +6 -0
  54. package/src/server/services/router/http/index.ts +12 -9
  55. package/src/server/services/router/index.ts +95 -68
  56. package/src/server/services/router/request/api.ts +1 -1
  57. package/src/server/services/router/response/index.ts +13 -19
  58. package/src/server/services/router/service.json +6 -0
  59. package/src/server/services/router/service.ts +16 -29
  60. package/src/server/services/schema/{router.ts → router/index.ts} +19 -7
  61. package/src/server/services/schema/router/service.json +6 -0
  62. package/src/server/services/schema/service.json +6 -0
  63. package/src/server/services/security/encrypt/{aes.ts → aes/index.ts} +16 -3
  64. package/src/server/services/security/encrypt/aes/service.json +6 -0
  65. package/src/server/services/socket/index.ts +39 -13
  66. package/src/server/services/socket/service.json +6 -0
  67. package/src/server/services/users/index.ts +16 -4
  68. package/src/server/services/users/old.ts +1 -1
  69. package/src/server/services/users/router/index.ts +21 -14
  70. package/src/server/services/users/router/service.json +6 -0
  71. package/src/server/services/users/service.json +6 -0
  72. package/src/types/aliases.d.ts +5 -0
  73. package/tsconfig.common.json +2 -0
  74. package/src/server/app/service.ts +0 -109
  75. /package/src/server/{patch.ts → app/container/patch.ts} +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp-core",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.2.9",
4
+ "version": "0.3.0",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-core.git",
7
7
  "license": "MIT",
@@ -13,11 +13,12 @@
13
13
  "framework"
14
14
  ],
15
15
  "dependencies": {
16
- "@wojtekmaj/react-daterange-picker": "^4.2.0",
16
+ "@wojtekmaj/react-daterange-picker": "^5.0.2",
17
17
  "accepts": "^1.3.7",
18
18
  "activity-detector": "^3.0.0",
19
19
  "ansi-to-html": "^0.7.1",
20
20
  "array-move": "^3.0.1",
21
+ "aws-sdk": "^2.1415.0",
21
22
  "axios": "^1.2.1",
22
23
  "bowser": "^2.11.0",
23
24
  "chart.js": "^3.6.2",
@@ -60,10 +61,12 @@
60
61
  "mysql2": "^2.3.0",
61
62
  "nodemailer": "^6.6.3",
62
63
  "object-sizeof": "^1.6.3",
64
+ "ololog": "^1.1.175",
63
65
  "path-to-regexp": "^6.2.0",
64
66
  "picomatch": "^2.3.1",
65
67
  "preact": "^10.5.15",
66
68
  "preact-render-to-string": "^5.1.19",
69
+ "react-datetime-picker": "^5.0.3",
67
70
  "react-scrollbars-custom": "^4.0.27",
68
71
  "react-slider": "^2.0.1",
69
72
  "react-textarea-autosize": "^8.3.3",
@@ -72,7 +75,6 @@
72
75
  "request": "^2.88.2",
73
76
  "sharp": "^0.29.1",
74
77
  "sql-formatter": "^4.0.2",
75
- "tslog": "^3.2.2",
76
78
  "uuid": "^8.3.2",
77
79
  "uuid-by-string": "^3.0.4",
78
80
  "validator": "^13.7.0",
@@ -92,9 +94,9 @@
92
94
  "@types/webpack-env": "^1.16.2",
93
95
  "@types/ws": "^7.4.7",
94
96
  "@types/yargs-parser": "^21.0.0",
95
- "babel-plugin-glob-import": "^0.0.6-2"
97
+ "babel-plugin-glob-import": "^0.0.7"
96
98
  },
97
99
  "peerDependencies": {
98
- "5htp": "0.2.3"
100
+ "5htp": "0.3.0"
99
101
  }
100
102
  }
@@ -11,7 +11,7 @@ import { ReactClientContext } from '@/client/context';
11
11
  import DialogManager from '@client/components/Dialog/Manager'
12
12
 
13
13
  // Core components
14
- import Router from '@client/services/router/components/router';
14
+ import RouterComponent from '@client/services/router/components/router';
15
15
  import type { TClientOrServerContext } from '@common/router';
16
16
 
17
17
  /*----------------------------------
@@ -35,7 +35,7 @@ export default function App ({ context }: {
35
35
 
36
36
  {!layout ? <>
37
37
  {/* TODO: move to app, because here, we're not aware that the router service has been defined */}
38
- <Router service={context.router} />
38
+ <RouterComponent service={context.Router} />
39
39
  </> : <>
40
40
  <layout.Component context={context} />
41
41
  </>}
@@ -19,6 +19,10 @@ h3 {
19
19
  strong {
20
20
  color: var(--cAccent);
21
21
  font-weight: inherit;
22
+
23
+ .bg.img & {
24
+ color: var(--cTxtImportant);
25
+ }
22
26
  }
23
27
  }
24
28
 
@@ -169,7 +169,7 @@ export default ({
169
169
  ) : title}
170
170
 
171
171
  {(!prison && close) && (
172
- <Button class="close" icon="solid/times" size="s" shape="pill" onClick={async () => {
172
+ <Button class="close" icon="times" size="s" shape="pill" onClick={async () => {
173
173
  if (typeof close === "function") {
174
174
 
175
175
  if (onClose !== undefined)
@@ -1,6 +1,7 @@
1
1
  @toast-zindex: 999;
2
2
 
3
- #modals, #toasts {
3
+ #modals,
4
+ #toasts {
4
5
 
5
6
  z-index: @toast-zindex;
6
7
 
@@ -60,7 +61,7 @@
60
61
  // Desktop = vertically center the modal
61
62
  @media (min-width: 900px) {
62
63
  justify-content: center;
63
- padding: @spacing;
64
+ //padding: @spacing;
64
65
  }
65
66
 
66
67
  // Pour les animations (ex: conffetis
@@ -79,7 +80,6 @@
79
80
  min-width: 300px;
80
81
  max-height: 100vh;
81
82
  box-shadow: none;
82
- padding: @spacing * 2;
83
83
  overflow-y: auto;
84
84
 
85
85
  // Pas d'anim quand pas card,
@@ -5,7 +5,7 @@
5
5
  // Npm
6
6
  import React from 'react';
7
7
  import type { StateUpdater } from 'preact/hooks';
8
- import DateRangePicker from '@wojtekmaj/react-daterange-picker/dist/entry.nostyle';
8
+ import DateRangePicker from '@wojtekmaj/react-daterange-picker';
9
9
 
10
10
  // Core
11
11
 
@@ -58,7 +58,7 @@ export default ({
58
58
  - INIT
59
59
  ----------------------------------*/
60
60
 
61
- const [{ value, focus, fieldProps }, setValue, commitValue, setState] = useInput(props, '');
61
+ const [{ value, focus, fieldProps }, setValue, commitValue, setState] = useInput(props, '' );
62
62
 
63
63
  // Trigger onchange oly when finished typing
64
64
  const refCommit = React.useRef<NodeJS.Timeout | null>(null);
@@ -71,7 +71,17 @@ export default ({
71
71
 
72
72
  }, [value]);
73
73
 
74
- const updateValue = v => setValue( type === 'number' ? parseFloat(v) : v );
74
+ const updateValue = v => {
75
+ if (type === 'number') {
76
+
77
+ // Fix on Safari: the browser allows to input text in input number
78
+ const numberValue = parseFloat(v);
79
+ if (!Number.isNaN( numberValue ))
80
+ setValue(numberValue);
81
+
82
+ } else
83
+ setValue(v);
84
+ }
75
85
 
76
86
  const refInput = inputRef || React.useRef<HTMLInputElement>();
77
87
 
@@ -154,12 +164,12 @@ export default ({
154
164
  // @ts-ignore: Property 'ref' does not exist on type 'IntrinsicAttributes'
155
165
  ref={refInput}
156
166
  value={value}
157
-
158
167
  onFocus={() => setState({ focus: true })}
159
168
  onBlur={() => setState({ focus: false })}
160
169
  onChange={(e) => updateValue(e.target.value)}
161
170
 
162
- onKeyDown={(e) => {
171
+ onKeyDown={(e: KeyboardEvent) => {
172
+
163
173
  if (onPressEnter && e.key === 'Enter' && value !== undefined) {
164
174
  commitValue();
165
175
  onPressEnter(value)
@@ -7,7 +7,7 @@ import React from 'react';
7
7
  import type { ComponentChild } from 'preact';
8
8
 
9
9
  // Core
10
- import Router from '@client/services/router/components/router';
10
+ import RouterComponent from '@client/services/router/components/router';
11
11
  import { ClientContext } from '@/client/context';
12
12
 
13
13
  // Core components
@@ -28,14 +28,14 @@ export default function App ({ context, menu }: {
28
28
  menu: ComponentChild
29
29
  }) {
30
30
 
31
- const { router, page, toast } = context;
31
+ const { Router, page, toast } = context;
32
32
 
33
33
  return (
34
34
  <div id="internaLlayout">
35
35
 
36
36
  <div class="center row al-fill">
37
37
 
38
- <Router service={router} />
38
+ <RouterComponent service={Router} />
39
39
 
40
40
  </div>
41
41
  </div>
@@ -6,7 +6,7 @@
6
6
  import React from 'react';
7
7
 
8
8
  // Core
9
- import { router } from '@app';
9
+ import { Router } from '@app';
10
10
  import { Button } from '@client/components';
11
11
 
12
12
  // App
@@ -15,7 +15,7 @@ import useHeader from '@client/pages/useHeader';
15
15
  /*----------------------------------
16
16
  - CONTROLEUR
17
17
  ----------------------------------*/
18
- router.error( 400, ({ message, modal }) => {
18
+ Router.error( 400, ({ message, modal }) => {
19
19
 
20
20
  useHeader({
21
21
  title: 'Bad request',
@@ -6,7 +6,7 @@
6
6
  import React from 'react';
7
7
 
8
8
  // Core
9
- import { router } from '@app';
9
+ import { Router } from '@app';
10
10
  import { Button } from '@client/components';
11
11
 
12
12
  // App
@@ -19,7 +19,7 @@ import useHeader from '@client/pages/useHeader';
19
19
  /*----------------------------------
20
20
  - CONTROLEUR
21
21
  ----------------------------------*/
22
- router.error( 401, ({ message, request, page }) => {
22
+ Router.error( 401, ({ message, request, page }) => {
23
23
 
24
24
  request.response?.redirect('/');
25
25
 
@@ -6,7 +6,7 @@
6
6
  import React from 'react';
7
7
 
8
8
  // Core
9
- import { router } from '@app';
9
+ import { Router } from '@app';
10
10
  import { Button } from '@client/components';
11
11
 
12
12
  // App
@@ -15,7 +15,7 @@ import useHeader from '@client/pages/useHeader';
15
15
  /*----------------------------------
16
16
  - CONTROLEUR
17
17
  ----------------------------------*/
18
- router.error( 403, ({ message, modal }) => {
18
+ Router.error( 403, ({ message, modal }) => {
19
19
 
20
20
  useHeader({
21
21
  title: 'Access Denied.',
@@ -6,7 +6,7 @@
6
6
  import React from 'react';
7
7
 
8
8
  // Core
9
- import { router } from '@app';
9
+ import { Router } from '@app';
10
10
  import { Button } from '@client/components';
11
11
 
12
12
  // App
@@ -15,7 +15,7 @@ import useHeader from '@client/pages/useHeader';
15
15
  /*----------------------------------
16
16
  - CONTROLEUR
17
17
  ----------------------------------*/
18
- router.error( 404, ({ message, modal }) => {
18
+ Router.error( 404, ({ message, modal }) => {
19
19
 
20
20
  useHeader({
21
21
  title: 'Page Not Found',
@@ -6,7 +6,7 @@
6
6
  import React from 'react';
7
7
 
8
8
  // Core
9
- import { router } from '@app';
9
+ import { Router } from '@app';
10
10
  import { Button } from '@client/components';
11
11
 
12
12
  // App
@@ -15,7 +15,7 @@ import useHeader from '@client/pages/useHeader';
15
15
  /*----------------------------------
16
16
  - CONTROLEUR
17
17
  ----------------------------------*/
18
- router.error( 500, ({ message }) => {
18
+ Router.error( 500, ({ message }) => {
19
19
 
20
20
  useHeader({
21
21
  title: 'Technical Error',
@@ -15,7 +15,8 @@ export type Props = {
15
15
  error?: boolean,
16
16
 
17
17
  title: string,
18
- subtitle: string,
18
+ subtitle?: string,
19
+ description?: string,
19
20
  }
20
21
 
21
22
  /*----------------------------------
@@ -127,7 +127,7 @@ export default ({ service: router }: { service: Router }) => {
127
127
  return history?.listen(async (locationUpdate) => {
128
128
 
129
129
  // Load the concerned route
130
- const request = new ClientRequest(locationUpdate.location, context.router);
130
+ const request = new ClientRequest(locationUpdate.location, context.Router);
131
131
  await resolvePage(request);
132
132
 
133
133
  // Scroll to the selected content via url hash
@@ -65,6 +65,10 @@ export type TRegisterPageArgs<TProvidedData extends TFetcherList = {}, TRouter e
65
65
  path: string,
66
66
  controller: TDataProvider<TProvidedData> | null,
67
67
  renderer: TFrontRenderer<TProvidedData>
68
+ ] | [
69
+ path: string,
70
+ options: Partial<TRoute["options"]>,
71
+ renderer: TFrontRenderer<TProvidedData>
68
72
  ] | [
69
73
  path: string,
70
74
  options: Partial<TRoute["options"]>,
@@ -119,7 +123,7 @@ type THookName = 'location.change' | 'page.changed'
119
123
 
120
124
  type Config<TAdditionnalContext extends {} = {}> = {
121
125
  preload: string[], // List of globs
122
- context: () => TAdditionnalContext
126
+ context: (router: ClientRouter) => TAdditionnalContext
123
127
  }
124
128
 
125
129
  /*----------------------------------
@@ -27,13 +27,16 @@ export type TPageResponse<TRouter extends ClientRouter> = (
27
27
  ServerResponse<ServerRouter, ClientPage>
28
28
  );
29
29
 
30
- export type TRouterContext<TRouter extends ClientRouter = ClientRouter, TApplication extends ClientApplication = ClientApplication> = (
30
+ export type TRouterContext<
31
+ TRouter extends ClientRouter = ClientRouter,
32
+ TApplication extends ClientApplication = ClientApplication
33
+ > = (
31
34
  // ClientPage context
32
35
  {
33
36
  app: TApplication,
34
37
  context: TRouterContext<TRouter, TApplication>,
35
38
  request: ClientRequest<TRouter>,
36
- route: TRoute<TRouter>,
39
+ route: TRoute<TRouterContext>,
37
40
  api: ClientRequest<TRouter>["api"],
38
41
  page: ClientPage<TRouter>,
39
42
  user: User
@@ -117,29 +117,4 @@ export const chemin = {
117
117
  valA[ brancheVal ] = val;
118
118
 
119
119
  }
120
- }
121
-
122
- export const callableInstance = <TInstance extends object, TCallableName extends keyof TInstance>(
123
- instance: TInstance,
124
- funcName: TCallableName
125
- ): TInstance[TCallableName] & TInstance => {
126
-
127
- const callableFunc = instance[funcName];
128
- if (typeof callableFunc !== 'function')
129
- throw new Error(`instance[funcName] isn't callable.`);
130
-
131
- const callable = callableFunc.bind(instance);
132
-
133
- const methods = [
134
- ...Object.getOwnPropertyNames( Object.getPrototypeOf( instance )),
135
- ...Object.getOwnPropertyNames( instance )
136
- ];
137
-
138
- for (const method of methods)
139
- if (method !== 'constructor')
140
- callable[ method ] = typeof instance[ method ] === 'function'
141
- ? instance[ method ].bind( instance )
142
- : instance[ method ];
143
-
144
- return callable as TInstance[TCallableName] & TInstance;
145
120
  }
@@ -2,8 +2,6 @@
2
2
  - DEPENDANCES
3
3
  ----------------------------------*/
4
4
 
5
- import { Layout } from './layouts';
6
-
7
5
  // types
8
6
  import type {
9
7
  default as ClientRouter,
@@ -22,9 +20,6 @@ import type { TUserRole } from '@server/services/users';
22
20
  import type { TAppArrowFunction } from '@common/app';
23
21
 
24
22
  // Specfic
25
- import type ApiClient from './request/api';
26
- import type Request from './request';
27
- import type Response from './response';
28
23
  import type { default as Page, TFrontRenderer } from './response/page';
29
24
 
30
25
  /*----------------------------------
@@ -57,12 +52,13 @@ export type TErrorRoute<RouterContext extends TClientOrServerContext = TClientOr
57
52
  options: TRouteOptions
58
53
  }
59
54
 
60
- export type TClientOrServerContext<
61
- TClientOnlyContextKeys extends keyof ClientRouterContext = keyof (ClientRouterContext | ServerRouterContext)
62
- > = (
55
+ export type TAnyRoute<RouterContext extends TClientOrServerContext = TClientOrServerContext> =
56
+ TRoute<RouterContext> | TErrorRoute<RouterContext>
57
+
58
+ export type TClientOrServerContext = (
63
59
  (
64
- {[serverContextKey in keyof ServerRouterContext/*Omit<ClientRouterContext, TClientOnlyContextKeys>*/]: undefined}
65
- &
60
+ //{[serverContextKey in keyof ServerRouterContext/*Omit<ClientRouterContext, TClientOnlyContextKeys>*/]: undefined}
61
+ //&
66
62
  ClientRouterContext
67
63
  )
68
64
  |
@@ -72,8 +68,8 @@ export type TClientOrServerContext<
72
68
  // When we destructure the context from the page controller
73
69
  // While making reference to a key only available in client context
74
70
  // So here, we put the
75
- {[clientContextKey in keyof ClientRouterContext/*Omit<ClientRouterContext, TClientOnlyContextKeys>*/]: undefined}
76
- &
71
+ //{[clientContextKey in keyof ClientRouterContext/*Omit<ClientRouterContext, TClientOnlyContextKeys>*/]: undefined}
72
+ //&
77
73
  ServerRouterContext
78
74
  )
79
75
  )
@@ -42,8 +42,10 @@ export const getLayout = (routePath: string, routeOptions?: TRouteOptions): Layo
42
42
 
43
43
  // options.id has been injected via the babel plugon
44
44
  const chunkId = routeOptions["id"];
45
- if (chunkId === undefined)
45
+ if (chunkId === undefined) {
46
+ console.error("Route informations where ID cas not injected:", routeOptions);
46
47
  throw new Error(`ID has not injected for the following page route: ${routePath}`);
48
+ }
47
49
 
48
50
  // Layout via name
49
51
  if (routeOptions.layout !== undefined) {
@@ -24,10 +24,12 @@ export const getRegisterPageArgs = (...args: TRegisterPageArgs) => {
24
24
  let controller: TDataProvider|null;
25
25
  let renderer: TFrontRenderer;
26
26
 
27
- if (args.length === 3)
28
- ([path, controller, renderer] = args)
29
- else
27
+ if (args.length === 4)
30
28
  ([path, options, controller, renderer] = args)
29
+ else if (typeof args[1] === 'object')
30
+ ([path, options, renderer] = args)
31
+ else
32
+ ([path, controller, renderer] = args)
31
33
 
32
34
  // Automatic layout form the nearest _layout folder
33
35
  const layout = getLayout(path, options);
@@ -6,7 +6,7 @@
6
6
  import { FunctionalComponent } from "preact";
7
7
 
8
8
  // Core
9
- import { TRoute } from "..";
9
+ import { TAnyRoute } from "..";
10
10
  import type ClientRequest from '@client/services/router';
11
11
  import Page from '@client/services/router/response/page'
12
12
 
@@ -26,7 +26,7 @@ export default abstract class BaseResponse<
26
26
 
27
27
  public data?: TData;
28
28
  public request: TRequest;
29
- public route?: TRoute;
29
+ public route?: TAnyRoute;
30
30
 
31
31
  public constructor(
32
32
  request: TRequest,
@@ -36,7 +36,7 @@ export default abstract class BaseResponse<
36
36
  this.request = request as TRequest;
37
37
  }
38
38
 
39
- public setRoute(route: TRoute) {
39
+ public setRoute(route: TAnyRoute) {
40
40
  this.route = route;
41
41
  return this;
42
42
  }
@@ -6,7 +6,8 @@
6
6
  import yargsParser from 'yargs-parser';
7
7
 
8
8
  // Core
9
- import Application, { Service } from '@server/app';
9
+ import type { Application } from '@server/app';
10
+ import Service from '@server/app/service';
10
11
  import { NotFound } from '@common/errors';
11
12
 
12
13
  /*----------------------------------
@@ -49,16 +50,6 @@ export default class CommandsManager extends Service<Config, Hooks, Application>
49
50
 
50
51
  public commandsIndex: CommandsList = {}
51
52
 
52
- public async register() {
53
-
54
-
55
-
56
- }
57
-
58
- public async start() {
59
-
60
- }
61
-
62
53
  /*----------------------------------
63
54
  - DEFINITIONS
64
55
  ----------------------------------*/
@@ -63,6 +63,8 @@ export type AppConfig = {
63
63
  identity: Config.Identity,
64
64
  }
65
65
 
66
+ const debug = false;
67
+
66
68
  /*----------------------------------
67
69
  - LOADE
68
70
  ----------------------------------*/
@@ -76,7 +78,7 @@ export default class ConfigParser {
76
78
  }
77
79
 
78
80
  private loadYaml( filepath: string ) {
79
- console.info(`Loading config ${filepath}`);
81
+ debug && console.info(`Loading config ${filepath}`);
80
82
  const rawConfig = fs.readFileSync(filepath, 'utf-8');
81
83
  return yaml.parse(rawConfig);
82
84
  }
@@ -96,6 +98,7 @@ export default class ConfigParser {
96
98
 
97
99
  public identity() {
98
100
  const identityFile = this.appDir + '/identity.yaml';
101
+ debug && console.info(`Loading identity ${identityFile}`);
99
102
  return this.loadYaml( identityFile );
100
103
  }
101
104
  }
@@ -0,0 +1,84 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ import './patch';
6
+
7
+ // Npm
8
+ import path from 'path';
9
+
10
+ // Core
11
+ import Services from '../service/container';
12
+ import ConfigParser, { TEnvConfig } from './config';
13
+
14
+ /*----------------------------------
15
+ - CLASS
16
+ ----------------------------------*/
17
+ export class ApplicationContainer {
18
+
19
+ /*----------------------------------
20
+ - INIT
21
+ ----------------------------------*/
22
+
23
+ public Services = Services;
24
+ public Environment: TEnvConfig;
25
+ public Identity: Config.Identity;
26
+
27
+ public constructor() {
28
+
29
+ // Load config files
30
+ const configParser = new ConfigParser( this.path.root );
31
+ this.Environment = configParser.env();
32
+ this.Identity = configParser.identity();
33
+ }
34
+
35
+ // Context
36
+ public hmr: __WebpackModuleApi.Hot | undefined = module.hot;
37
+
38
+ public path = {
39
+ root: process.cwd(),
40
+ public: path.join( process.cwd(), '/public'),
41
+ var: path.join( process.cwd(), '/var'),
42
+
43
+ client: {
44
+ generated: path.join( process.cwd(), 'src', 'client', '.generated')
45
+ },
46
+ server: {
47
+ generated: path.join( process.cwd(), 'src', 'server', '.generated')
48
+ },
49
+ }
50
+
51
+ /*----------------------------------
52
+ - HMR
53
+ - TODO: move in dev server
54
+ ----------------------------------*/
55
+ private activateHMR() {
56
+
57
+ if (!module.hot) return;
58
+
59
+ console.info(`Activating HMR ...`);
60
+
61
+ module.hot.accept();
62
+ module.hot.accept( this.path.root + '/.cache/commun/routes.ts' );
63
+
64
+ module.hot.addDisposeHandler((data) => {
65
+
66
+ console.info(`Cleaning application ...`);
67
+
68
+ // Services hooks
69
+ //this.app.shutdown();
70
+
71
+ /*
72
+ console.log("[nettoyage] Arrêt serveur socket ...");
73
+ if (socket !== undefined)
74
+ socket.serveur.close()
75
+
76
+ console.log("[nettoyage] Reset du cache requêtes JSQL ...");
77
+ QueryParser.clearCache();*/
78
+
79
+ });
80
+ }
81
+
82
+ }
83
+
84
+ export default new ApplicationContainer;