proteum 1.0.0-1

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 (156) hide show
  1. package/.dockerignore +10 -0
  2. package/Rte.zip +0 -0
  3. package/cli/app/config.ts +54 -0
  4. package/cli/app/index.ts +195 -0
  5. package/cli/bin.js +11 -0
  6. package/cli/commands/build.ts +34 -0
  7. package/cli/commands/deploy/app.ts +29 -0
  8. package/cli/commands/deploy/web.ts +60 -0
  9. package/cli/commands/dev.ts +109 -0
  10. package/cli/commands/init.ts +85 -0
  11. package/cli/compiler/client/identite.ts +72 -0
  12. package/cli/compiler/client/index.ts +334 -0
  13. package/cli/compiler/common/babel/index.ts +170 -0
  14. package/cli/compiler/common/babel/plugins/index.ts +0 -0
  15. package/cli/compiler/common/babel/plugins/services.ts +579 -0
  16. package/cli/compiler/common/babel/routes/imports.ts +127 -0
  17. package/cli/compiler/common/babel/routes/routes.ts +1130 -0
  18. package/cli/compiler/common/files/autres.ts +39 -0
  19. package/cli/compiler/common/files/images.ts +35 -0
  20. package/cli/compiler/common/files/style.ts +78 -0
  21. package/cli/compiler/common/index.ts +154 -0
  22. package/cli/compiler/index.ts +532 -0
  23. package/cli/compiler/server/index.ts +211 -0
  24. package/cli/index.ts +189 -0
  25. package/cli/paths.ts +165 -0
  26. package/cli/print.ts +12 -0
  27. package/cli/tsconfig.json +38 -0
  28. package/cli/utils/index.ts +22 -0
  29. package/cli/utils/keyboard.ts +78 -0
  30. package/client/app/component.tsx +54 -0
  31. package/client/app/index.ts +142 -0
  32. package/client/app/service.ts +34 -0
  33. package/client/app.tsconfig.json +28 -0
  34. package/client/components/Button.tsx +298 -0
  35. package/client/components/Dialog/Manager.tsx +309 -0
  36. package/client/components/Dialog/card.tsx +208 -0
  37. package/client/components/Dialog/index.less +151 -0
  38. package/client/components/Dialog/status.less +176 -0
  39. package/client/components/Dialog/status.tsx +48 -0
  40. package/client/components/index.ts +2 -0
  41. package/client/components/types.d.ts +3 -0
  42. package/client/data/input.ts +32 -0
  43. package/client/global.d.ts +5 -0
  44. package/client/hooks.ts +22 -0
  45. package/client/index.ts +6 -0
  46. package/client/pages/_layout/index.less +6 -0
  47. package/client/pages/_layout/index.tsx +43 -0
  48. package/client/pages/bug.tsx.old +60 -0
  49. package/client/pages/useHeader.tsx +50 -0
  50. package/client/services/captcha/index.ts +67 -0
  51. package/client/services/router/components/Link.tsx +46 -0
  52. package/client/services/router/components/Page.tsx +55 -0
  53. package/client/services/router/components/router.tsx +218 -0
  54. package/client/services/router/index.tsx +521 -0
  55. package/client/services/router/request/api.ts +267 -0
  56. package/client/services/router/request/history.ts +5 -0
  57. package/client/services/router/request/index.ts +53 -0
  58. package/client/services/router/request/multipart.ts +147 -0
  59. package/client/services/router/response/index.tsx +128 -0
  60. package/client/services/router/response/page.ts +86 -0
  61. package/client/services/socket/index.ts +147 -0
  62. package/client/utils/dom.ts +77 -0
  63. package/common/app/index.ts +9 -0
  64. package/common/data/chaines/index.ts +54 -0
  65. package/common/data/dates.ts +179 -0
  66. package/common/data/markdown.ts +73 -0
  67. package/common/data/rte/nodes.ts +83 -0
  68. package/common/data/stats.ts +90 -0
  69. package/common/errors/index.tsx +326 -0
  70. package/common/router/index.ts +213 -0
  71. package/common/router/layouts.ts +93 -0
  72. package/common/router/register.ts +55 -0
  73. package/common/router/request/api.ts +77 -0
  74. package/common/router/request/index.ts +35 -0
  75. package/common/router/response/index.ts +45 -0
  76. package/common/router/response/page.ts +128 -0
  77. package/common/utils/rte.ts +183 -0
  78. package/common/utils.ts +7 -0
  79. package/doc/TODO.md +71 -0
  80. package/doc/front/router.md +27 -0
  81. package/doc/workspace/workspace.png +0 -0
  82. package/doc/workspace/workspace2.png +0 -0
  83. package/doc/workspace/workspace_26.01.22.png +0 -0
  84. package/package.json +171 -0
  85. package/server/app/commands.ts +141 -0
  86. package/server/app/container/config.ts +203 -0
  87. package/server/app/container/console/index.ts +550 -0
  88. package/server/app/container/index.ts +137 -0
  89. package/server/app/index.ts +273 -0
  90. package/server/app/service/container.ts +88 -0
  91. package/server/app/service/index.ts +235 -0
  92. package/server/app.tsconfig.json +28 -0
  93. package/server/context.ts +4 -0
  94. package/server/index.ts +4 -0
  95. package/server/services/auth/index.ts +250 -0
  96. package/server/services/auth/old.ts +277 -0
  97. package/server/services/auth/router/index.ts +95 -0
  98. package/server/services/auth/router/request.ts +54 -0
  99. package/server/services/auth/router/service.json +6 -0
  100. package/server/services/auth/service.json +6 -0
  101. package/server/services/cache/commands.ts +41 -0
  102. package/server/services/cache/index.ts +297 -0
  103. package/server/services/cache/service.json +6 -0
  104. package/server/services/cron/CronTask.ts +86 -0
  105. package/server/services/cron/index.ts +112 -0
  106. package/server/services/cron/service.json +6 -0
  107. package/server/services/disks/driver.ts +103 -0
  108. package/server/services/disks/drivers/local/index.ts +188 -0
  109. package/server/services/disks/drivers/local/service.json +6 -0
  110. package/server/services/disks/drivers/s3/index.ts +301 -0
  111. package/server/services/disks/drivers/s3/service.json +6 -0
  112. package/server/services/disks/index.ts +90 -0
  113. package/server/services/disks/service.json +6 -0
  114. package/server/services/email/index.ts +188 -0
  115. package/server/services/email/utils.ts +53 -0
  116. package/server/services/fetch/index.ts +201 -0
  117. package/server/services/fetch/service.json +7 -0
  118. package/server/services/models.7z +0 -0
  119. package/server/services/prisma/Facet.ts +142 -0
  120. package/server/services/prisma/index.ts +201 -0
  121. package/server/services/prisma/service.json +6 -0
  122. package/server/services/router/http/index.ts +217 -0
  123. package/server/services/router/http/multipart.ts +102 -0
  124. package/server/services/router/http/session.ts.old +40 -0
  125. package/server/services/router/index.ts +801 -0
  126. package/server/services/router/request/api.ts +87 -0
  127. package/server/services/router/request/index.ts +184 -0
  128. package/server/services/router/request/service.ts +21 -0
  129. package/server/services/router/request/validation/zod.ts +180 -0
  130. package/server/services/router/response/index.ts +338 -0
  131. package/server/services/router/response/mask/Filter.ts +323 -0
  132. package/server/services/router/response/mask/index.ts +60 -0
  133. package/server/services/router/response/mask/selecteurs.ts +92 -0
  134. package/server/services/router/response/page/document.tsx +160 -0
  135. package/server/services/router/response/page/index.tsx +196 -0
  136. package/server/services/router/service.json +6 -0
  137. package/server/services/router/service.ts +36 -0
  138. package/server/services/schema/index.ts +44 -0
  139. package/server/services/schema/request.ts +49 -0
  140. package/server/services/schema/router/index.ts +28 -0
  141. package/server/services/schema/router/service.json +6 -0
  142. package/server/services/schema/service.json +6 -0
  143. package/server/services/security/encrypt/aes/index.ts +85 -0
  144. package/server/services/security/encrypt/aes/service.json +6 -0
  145. package/server/services/socket/index.ts +162 -0
  146. package/server/services/socket/scope.ts +226 -0
  147. package/server/services/socket/service.json +6 -0
  148. package/server/services_old/SocketClient.ts +92 -0
  149. package/server/services_old/Token.old.ts +97 -0
  150. package/server/utils/slug.ts +79 -0
  151. package/tsconfig.common.json +45 -0
  152. package/tsconfig.json +3 -0
  153. package/types/aliases.d.ts +54 -0
  154. package/types/global/modules.d.ts +49 -0
  155. package/types/global/utils.d.ts +103 -0
  156. package/types/icons.d.ts +1 -0
@@ -0,0 +1,532 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ // Npm
6
+ import path from 'path';
7
+ import webpack from 'webpack';
8
+ import fs from 'fs-extra';
9
+ import serialize from 'serialize-javascript';
10
+
11
+ import SpeedMeasurePlugin from "speed-measure-webpack-plugin";
12
+ const smp = new SpeedMeasurePlugin({ disable: true });
13
+
14
+ // Core
15
+ import app from '../app';
16
+ import cli from '..';
17
+ import createServerConfig from './server';
18
+ import createClientConfig from './client';
19
+ import { TCompileMode } from './common';
20
+
21
+ type TCompilerCallback = (compiler: webpack.Compiler) => void
22
+
23
+ type TServiceMetas = {
24
+ id: string,
25
+ name: string,
26
+ parent: string,
27
+ dependences: string,
28
+ importationPath: string,
29
+ priority: number
30
+ }
31
+
32
+ type TRegisteredService = {
33
+ id?: string,
34
+ name: string,
35
+ className: string,
36
+ instanciation: (parentRef?: string) => string,
37
+ priority: number,
38
+ }
39
+
40
+ /*----------------------------------
41
+ - FONCTION
42
+ ----------------------------------*/
43
+ export default class Compiler {
44
+
45
+ public compiling: { [compiler: string]: Promise<void> } = {};
46
+
47
+ public constructor(
48
+ private mode: TCompileMode,
49
+ private callbacks: {
50
+ before?: TCompilerCallback,
51
+ after?: TCompilerCallback,
52
+ } = {},
53
+ private debug: boolean = false
54
+ ) {
55
+
56
+ }
57
+
58
+ public cleanup() {
59
+
60
+ fs.emptyDirSync( app.paths.bin );
61
+ fs.ensureDirSync( path.join(app.paths.bin, 'public') )
62
+ const publicFiles = fs.readdirSync(app.paths.public);
63
+ for (const publicFile of publicFiles) {
64
+ // Dev: faster to use symlink
65
+ if (this.mode === 'dev')
66
+ fs.symlinkSync(
67
+ path.join(app.paths.public, publicFile),
68
+ path.join(app.paths.bin, 'public', publicFile)
69
+ );
70
+ // Prod: Symlink not always supported by CI / Containers solutions
71
+ else
72
+ fs.copySync(
73
+ path.join(app.paths.public, publicFile),
74
+ path.join(app.paths.bin, 'public', publicFile)
75
+ );
76
+ }
77
+ }
78
+ /* FIX issue with npm link
79
+ When we install a module with npm link, this module's deps are not installed in the parent project scope
80
+ Which causes some issues:
81
+ - The module's deps are not found by Typescript
82
+ - Including React, so VSCode shows that JSX is missing
83
+ */
84
+ public fixNpmLinkIssues() {
85
+ const corePath = path.join(app.paths.root, '/node_modules/proteum');
86
+ if (!fs.lstatSync( corePath ).isSymbolicLink())
87
+ return console.info("Not fixing npm issue because proteum wasn't installed with npm link.");
88
+
89
+ this.debug && console.info(`Fix NPM link issues ...`);
90
+
91
+ const appModules = path.join(app.paths.root, 'node_modules');
92
+ const coreModules = path.join(corePath, 'node_modules');
93
+
94
+ // When the 5htp package is installed from npm link,
95
+ // Modules are installed locally and not glbally as with with the 5htp package from NPM.
96
+ // So we need to symbilnk the http-core node_modules in one of the parents of server.js.
97
+ // It avoids errors like: "Error: Cannot find module 'intl'"
98
+ fs.symlinkSync( coreModules, path.join(app.paths.bin, 'node_modules') );
99
+
100
+ // Same problem: when 5htp-core is installed via npm link,
101
+ // Typescript doesn't detect React and shows mission JSX errors
102
+ const preactCoreModule = path.join(coreModules, 'preact');
103
+ const preactAppModule = path.join(appModules, 'preact');
104
+ const reactAppModule = path.join(appModules, 'react');
105
+
106
+ if (!fs.existsSync( preactAppModule ))
107
+ fs.symlinkSync( preactCoreModule, preactAppModule );
108
+ if (!fs.existsSync( reactAppModule ))
109
+ fs.symlinkSync( path.join(preactCoreModule, 'compat'), reactAppModule );
110
+ }
111
+
112
+ private findServices( dir: string ) {
113
+
114
+ const blacklist = ['node_modules', 'proteum']
115
+ const files: string[] = [];
116
+ const dirents = fs.readdirSync(dir, { withFileTypes: true });
117
+
118
+ for (let dirent of dirents) {
119
+
120
+ let fileName = dirent.name;
121
+ let filePath = path.resolve(dir, fileName);
122
+
123
+ if (blacklist.includes( fileName ))
124
+ continue;
125
+
126
+ // Define is we should recursively find service in the current item
127
+ let iterate: boolean = false;
128
+ if (dirent.isSymbolicLink()) {
129
+
130
+ const realPath = path.resolve( dir, fs.readlinkSync(filePath) );
131
+ const destinationInfos = fs.lstatSync( realPath );
132
+ if (destinationInfos.isDirectory())
133
+ iterate = true;
134
+
135
+ } else if (dirent.isDirectory())
136
+ iterate = true;
137
+
138
+ // Update the list of found services
139
+ if (iterate) {
140
+ files.push( ...this.findServices(filePath) );
141
+ } else if (dirent.name === 'service.json') {
142
+ files.push( path.dirname(filePath) );
143
+ }
144
+ }
145
+ return files;
146
+ }
147
+
148
+ private indexServices() {
149
+
150
+
151
+ // Index services
152
+ const searchDirs = [
153
+ // The less priority is the first
154
+ {
155
+ path: '@server/services/',
156
+ priority: -1,
157
+ root: path.join(cli.paths.core.root, 'server', 'services')
158
+ },
159
+ {
160
+ path: '@/server/services/',
161
+ priority: 0,
162
+ root: path.join(app.paths.root, 'server', 'services')
163
+ },
164
+ // Temp disabled because compile issue on vercel
165
+ //'': path.join(app.paths.root, 'node_modules'),
166
+ ]
167
+
168
+ // Generate app class file
169
+ const servicesAvailable: {[id: string]: TServiceMetas} = {};
170
+ for (const searchDir of searchDirs) {
171
+
172
+ const services = this.findServices(searchDir.root);
173
+
174
+ for (const serviceDir of services) {
175
+ const metasFile = path.join( serviceDir, 'service.json');
176
+
177
+ // The +1 is to remove the slash
178
+ const importationPath = searchDir.path + serviceDir.substring( searchDir.root.length + 1 );
179
+
180
+ const serviceMetas = require(metasFile);
181
+
182
+ servicesAvailable[ serviceMetas.id ] = {
183
+ importationPath,
184
+ priority: searchDir.priority,
185
+ ...serviceMetas,
186
+ };
187
+ }
188
+ }
189
+
190
+ // Read app services
191
+ const imported: string[] = []
192
+ const referencedNames: {[serviceId: string]: string} = {} // ID to Name
193
+
194
+ const refService = (serviceName: string, serviceConfig: any, level: number = 0): TRegisteredService => {
195
+
196
+ if (serviceConfig.refTo !== undefined) {
197
+ const refTo = serviceConfig.refTo;
198
+ return {
199
+ name: serviceName,
200
+ instanciation: () => `this.${refTo}`,
201
+ priority: 0
202
+ }
203
+ }
204
+
205
+ const serviceMetas = servicesAvailable[ serviceConfig.id ];
206
+ if (serviceMetas === undefined)
207
+ throw new Error(`Service ${serviceConfig.id} not found. Referenced services: ${Object.keys(servicesAvailable).join('\n')}`);
208
+
209
+ const referencedName = referencedNames[serviceConfig.id];
210
+ if (referencedName !== undefined)
211
+ throw new Error(`Service ${serviceConfig.id} is already setup as ${referencedName}`);
212
+
213
+ // Generate index & typings
214
+ imported.push(`import ${serviceMetas.name} from "${serviceMetas.importationPath}";`);
215
+
216
+ if (serviceConfig.name !== undefined)
217
+ referencedNames[serviceConfig.id] = serviceConfig.name;
218
+
219
+ const processConfig = (config: any, level: number = 0) => {
220
+
221
+ let propsStr = '';
222
+ for (const key in config) {
223
+ const value = config[key];
224
+
225
+ if (!value || typeof value !== 'object')
226
+ propsStr += `"${key}":${serialize(value, { space: 4 })},\n`;
227
+
228
+ // Reference to a service
229
+ else if (value.type === 'service.setup' || value.type === 'service.ref') // TODO: more reliable way to detect a service reference
230
+ propsStr += `${key}:`+ refService(key, value, level + 1).instanciation() + ',\n'
231
+
232
+ // Recursion
233
+ else if (level <= 4 && !Array.isArray(value))
234
+ propsStr += `"${key}":` + processConfig(value, level + 1) + ',\n';
235
+
236
+ else
237
+ propsStr += `"${key}":${serialize(value, { space: 4 })},\n`;
238
+
239
+ }
240
+
241
+ return `{ ${propsStr} }`;
242
+ }
243
+ const config = processConfig(serviceConfig.config || {});
244
+
245
+ // Generate the service instance
246
+ const instanciation = (parentRef?: string) =>
247
+ `new ${serviceMetas.name}(
248
+ ${parentRef ? `${parentRef},` : ''}
249
+ ${config},
250
+ this
251
+ )`
252
+
253
+ return {
254
+ id: serviceConfig.id,
255
+ name: serviceName,
256
+ instanciation,
257
+ className: serviceMetas.name,
258
+ priority: serviceConfig.config?.priority || serviceMetas.priority || 0,
259
+ };
260
+ }
261
+
262
+ const servicesCode = Object.values(app.registered).map( s => refService(s.name, s, 0));
263
+ const sortedServices = servicesCode.sort((a, b) => a.priority - b.priority);
264
+
265
+ // Define the app class identifier
266
+ const appClassIdentifier = app.identity.identifier;
267
+ const containerServices = app.containerServices.map( s => "'" + s + "'").join('|');
268
+
269
+ // @/client/.generated/services.d.ts
270
+ fs.outputFileSync(
271
+ path.join( app.paths.client.generated, 'services.d.ts'),
272
+ `declare module "@app" {
273
+
274
+ import { ${appClassIdentifier} as ${appClassIdentifier}Client } from "@/client";
275
+ import ${appClassIdentifier}Server from "@/server/.generated/app";
276
+
277
+ export const Router: ${appClassIdentifier}Client['Router'];
278
+
279
+ ${sortedServices.map(service => service.name !== 'Router'
280
+ ? `export const ${service.name}: ${appClassIdentifier}Server["${service.name}"];`
281
+ : ''
282
+ ).join('\n')}
283
+
284
+ }
285
+
286
+ declare module '@models/types' {
287
+ export * from '@/var/prisma/index';
288
+ }
289
+
290
+ declare module '@request' {
291
+
292
+ }
293
+
294
+ declare namespace preact.JSX {
295
+ interface HTMLAttributes {
296
+ src?: string;
297
+ }
298
+ }
299
+ `
300
+ );
301
+
302
+ // @/client/.generated/context.ts
303
+ fs.outputFileSync(
304
+ path.join( app.paths.client.generated, 'context.ts'),
305
+ `// TODO: move it into core (but how to make sure usecontext returns ${appClassIdentifier}'s context ?)
306
+ import React from 'react';
307
+
308
+ import type ${appClassIdentifier}Server from '@/server/.generated/app';
309
+ import type { TRouterContext as TServerRouterRequestContext } from '@server/services/router/response';
310
+ import type { TRouterContext as TClientRouterRequestContext } from '@client/services/router/response';
311
+ import type ${appClassIdentifier}Client from '.';
312
+
313
+ // TO Fix: TClientRouterRequestContext is unable to get the right type of ${appClassIdentifier}Client["router"]
314
+ // (it gets ClientApplication instead of ${appClassIdentifier}Client)
315
+ type ClientRequestContext = TClientRouterRequestContext<${appClassIdentifier}Client["Router"], ${appClassIdentifier}Client>;
316
+ type ServerRequestContext = TServerRouterRequestContext<${appClassIdentifier}Server["Router"]>
317
+ type UniversalServices = ClientRequestContext | ServerRequestContext
318
+
319
+ // Non-universla services are flagged as potentially undefined
320
+ export type ClientContext = (
321
+ UniversalServices
322
+ &
323
+ Partial<Omit<ClientRequestContext, keyof UniversalServices>>
324
+ &
325
+ {
326
+ Router: ${appClassIdentifier}Client["Router"],
327
+ }
328
+ )
329
+
330
+ export const ReactClientContext = React.createContext<ClientContext>({} as ClientContext);
331
+ export default (): ClientContext => React.useContext<ClientContext>(ReactClientContext);`);
332
+
333
+ // @/common/.generated/services.d.ts
334
+ fs.outputFileSync(
335
+ path.join( app.paths.common.generated, 'services.d.ts'),
336
+ `declare module '@models/types' {
337
+ export * from '@/var/prisma/index';
338
+ }`
339
+ );
340
+
341
+ // @/server/.generated/app.ts
342
+ fs.outputFileSync(
343
+ path.join( app.paths.server.generated, 'app.ts'),
344
+ `
345
+ import { Application } from '@server/app/index';
346
+ import { ServicesContainer } from '@server/app/service/container';
347
+
348
+ ${imported.join('\n')}
349
+
350
+ export default class ${appClassIdentifier} extends Application<ServicesContainer, CurrentUser> {
351
+
352
+ // Make sure the services typigs are reflecting the config and referring to the app
353
+ ${sortedServices.map(service =>
354
+ `public ${service.name}!: ReturnType<${appClassIdentifier}["registered"]["${service.id}"]["start"]>;`
355
+ ).join('\n')}
356
+
357
+ protected registered = {
358
+ ${sortedServices.map(service =>
359
+ `"${service.id}": {
360
+ name: "${service.name}",
361
+ priority: ${service.priority},
362
+ start: () => ${service.instanciation('this')}
363
+ }`
364
+ ).join(',\n')}
365
+ } as const;
366
+ }
367
+
368
+
369
+ `);
370
+
371
+ // @/server/.generated/services.d.ts
372
+ fs.outputFileSync(
373
+ path.join( app.paths.server.generated, 'services.d.ts'),
374
+ `type InstalledServices = import('./services').Services;
375
+
376
+ declare type ${appClassIdentifier} = import("@/server/.generated/app").default;
377
+
378
+ declare module '@cli/app' {
379
+
380
+ type App = {
381
+
382
+ env: TEnvConfig;
383
+
384
+ use: (referenceName: string) => TServiceRef;
385
+
386
+ setup: <TServiceName extends keyof ${appClassIdentifier}>(...args: [
387
+ // { user: app.setup('Core/User') }
388
+ servicePath: string,
389
+ serviceConfig?: {}
390
+ ] | [
391
+ // app.setup('User', 'Core/User')
392
+ serviceName: TServiceName,
393
+ servicePath: string,
394
+ serviceConfig?: ${appClassIdentifier}[TServiceName]["config"]
395
+ ]) => TServiceSetup;
396
+ }
397
+ const app: App;
398
+ export = app;
399
+ }
400
+
401
+ declare module "@app" {
402
+
403
+ import { ApplicationContainer } from '@server/app/container';
404
+
405
+ const ServerServices: (
406
+ Pick<
407
+ ApplicationContainer<InstalledServices>,
408
+ ${containerServices}
409
+ >
410
+ &
411
+ ${appClassIdentifier}
412
+ )
413
+
414
+ export = ServerServices
415
+ }
416
+
417
+ declare module '@server/app' {
418
+
419
+ import { Application } from "@server/app";
420
+ import { Environment } from "@server/app";
421
+ import { ServicesContainer } from "@server/app/service/container";
422
+
423
+ abstract class ApplicationWithServices extends Application<
424
+ ServicesContainer<InstalledServices>
425
+ > {}
426
+
427
+ export interface Exported {
428
+ Application: typeof ApplicationWithServices,
429
+ Environment: Environment,
430
+ }
431
+
432
+ const foo: Exported;
433
+
434
+ export = foo;
435
+ }
436
+
437
+ declare module '@request' {
438
+ import type { TRouterContext } from '@server/services/router/response';
439
+ const routerContext: TRouterContext<CrossPath["Router"]>;
440
+ export = routerContext;
441
+ }
442
+
443
+ declare module '@models' {
444
+ import { Prisma, PrismaClient } from '@/var/prisma/index';
445
+
446
+ type ModelNames = Prisma.ModelName;
447
+
448
+ type ModelDelegates = {
449
+ [K in ModelNames]: PrismaClient[Uncapitalize<K>];
450
+ };
451
+
452
+ const models: ModelDelegates;
453
+
454
+ export = models;
455
+ }
456
+
457
+ declare module '@models/types' {
458
+ export * from '@/var/prisma/index';
459
+ }`
460
+ );
461
+ }
462
+
463
+ public async create() {
464
+
465
+ await app.warmup();
466
+
467
+ this.cleanup();
468
+
469
+ this.fixNpmLinkIssues();
470
+
471
+ this.indexServices();
472
+
473
+ // Create compilers
474
+ const multiCompiler = webpack([
475
+ smp.wrap( createServerConfig(app, this.mode) ),
476
+ smp.wrap( createClientConfig(app, this.mode) )
477
+ ]);
478
+
479
+ for (const compiler of multiCompiler.compilers) {
480
+
481
+ const name = compiler.name;
482
+ if (name === undefined)
483
+ throw new Error(`A name must be specified to each compiler.`);
484
+
485
+ let timeStart = new Date();
486
+
487
+ let finished: (() => void);
488
+ this.compiling[name] = new Promise((resolve) => finished = resolve);
489
+
490
+ compiler.hooks.compile.tap(name, (compilation) => {
491
+
492
+ this.callbacks.before && this.callbacks.before( compiler );
493
+
494
+ this.compiling[name] = new Promise((resolve) => finished = resolve);
495
+
496
+ timeStart = new Date();
497
+ console.info(`[${name}] Compiling ...`);
498
+ });
499
+
500
+ /* TODO: Ne pas résoudre la promise tant que la recompilation des données indexées (icones, identité, ...)
501
+ n'a pas été achevée */
502
+ compiler.hooks.done.tap(name, stats => {
503
+
504
+ // Shiow status
505
+ const timeEnd = new Date();
506
+ const time = timeEnd.getTime() - timeStart.getTime();
507
+ if (stats.hasErrors()) {
508
+
509
+ console.info(stats.toString(compiler.options.stats));
510
+ console.error(`[${name}] Failed to compile after ${time} ms`);
511
+
512
+ // Exit process with code 0, so the CI container can understand building failed
513
+ // Only in prod, because in dev, we want the compiler watcher continue running
514
+ if (this.mode === 'prod')
515
+ process.exit(0);
516
+
517
+ } else {
518
+ this.debug && console.info(stats.toString(compiler.options.stats));
519
+ console.info(`[${name}] Finished compilation after ${time} ms`);
520
+ }
521
+
522
+ // Mark as finished
523
+ finished();
524
+ delete this.compiling[name];
525
+ });
526
+ }
527
+
528
+ return multiCompiler;
529
+
530
+ }
531
+
532
+ }