5htp 0.4.6 → 0.5.9
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/{src/app → app}/config.ts +7 -7
- package/app/index.ts +196 -0
- package/{src/commands → commands}/dev.ts +2 -2
- package/{src/commands → commands}/init.ts +1 -1
- package/{src/compiler → compiler}/client/identite.ts +1 -1
- package/{src/compiler → compiler}/client/index.ts +6 -6
- package/{src/compiler → compiler}/common/babel/index.ts +20 -2
- package/{src/compiler → compiler}/common/babel/plugins/injection-dependances/index.ts +2 -2
- package/{src/compiler → compiler}/common/babel/plugins/queries/index.ts +1 -1
- package/compiler/common/babel/plugins/services.ts +247 -0
- package/{src/compiler → compiler}/common/babel/routes/imports.ts +1 -1
- package/{src/compiler → compiler}/common/babel/routes/routes.ts +148 -39
- package/{src/compiler → compiler}/common/files/style.ts +3 -3
- package/{src/compiler → compiler}/common/plugins/indexage/icones-svg/index.ts +2 -2
- package/{src/compiler → compiler}/index.ts +150 -37
- package/{src/compiler → compiler}/server/index.ts +18 -11
- package/package.json +7 -5
- package/{src/paths.ts → paths.ts} +3 -4
- package/tsconfig.json +3 -2
- package/src/app/index.ts +0 -111
- package/src/compiler/common/babel/plugins/services.ts +0 -209
- /package/{src/commands → commands}/build.ts +0 -0
- /package/{src/commands → commands}/deploy/app.ts +0 -0
- /package/{src/commands → commands}/deploy/web.ts +0 -0
- /package/{src/compiler → compiler}/common/babel/plugins/form.ts +0 -0
- /package/{src/compiler → compiler}/common/babel/plugins/icones-svg.ts +0 -0
- /package/{src/compiler → compiler}/common/babel/plugins/index.ts +0 -0
- /package/{src/compiler → compiler}/common/babel/plugins/injection-dependances/remplacerFonction.ts +0 -0
- /package/{src/compiler → compiler}/common/files/autres.ts +0 -0
- /package/{src/compiler → compiler}/common/files/images.ts +0 -0
- /package/{src/compiler → compiler}/common/index.ts +0 -0
- /package/{src/compiler → compiler}/common/plugins/indexage/_utils/Stringify.ts +0 -0
- /package/{src/compiler → compiler}/common/plugins/indexage/_utils/annotations.ts +0 -0
- /package/{src/compiler → compiler}/common/plugins/indexage/_utils/iterateur.ts +0 -0
- /package/{src/compiler → compiler}/common/plugins/indexage/index.ts +0 -0
- /package/{src/compiler → compiler}/common/plugins/indexage/indexeur.ts +0 -0
- /package/{src/compiler → compiler}/common/plugins/indexage/injection-dependances/index.ts +0 -0
- /package/{src/index.ts → index.ts} +0 -0
- /package/{src/print.ts → print.ts} +0 -0
- /package/{src/utils → utils}/index.ts +0 -0
- /package/{src/utils → utils}/keyboard.ts +0 -0
|
@@ -39,11 +39,16 @@ module.exports = (options: TOptions) => (
|
|
|
39
39
|
[Plugin, options]
|
|
40
40
|
)
|
|
41
41
|
|
|
42
|
+
const clientServices = ['Router'];
|
|
43
|
+
// Others will be called via app.<Service> (backend) or api.post(<path>, <params>) (frontend)
|
|
44
|
+
|
|
42
45
|
/*----------------------------------
|
|
43
46
|
- PLUGIN
|
|
44
47
|
----------------------------------*/
|
|
45
48
|
function Plugin(babel, { app, side, debug }: TOptions) {
|
|
46
49
|
|
|
50
|
+
debug = true;
|
|
51
|
+
|
|
47
52
|
const t = babel.types as typeof types;
|
|
48
53
|
|
|
49
54
|
/*
|
|
@@ -78,7 +83,8 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
78
83
|
// Replace by: nothing
|
|
79
84
|
ImportDeclaration(path) {
|
|
80
85
|
|
|
81
|
-
|
|
86
|
+
const shouldTransformImports = this.file.process && this.file.side === 'front';
|
|
87
|
+
if (!shouldTransformImports)
|
|
82
88
|
return;
|
|
83
89
|
|
|
84
90
|
if (path.node.source.value !== '@app')
|
|
@@ -92,7 +98,12 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
92
98
|
if (specifier.imported.type !== 'Identifier')
|
|
93
99
|
continue;
|
|
94
100
|
|
|
95
|
-
|
|
101
|
+
const serviceName = specifier.imported.name;
|
|
102
|
+
|
|
103
|
+
if (clientServices.includes(serviceName))
|
|
104
|
+
this.file.importedServices[ specifier.local.name ] = serviceName;
|
|
105
|
+
else
|
|
106
|
+
this.file.importedServices[ specifier.local.name ] = 'app';
|
|
96
107
|
}
|
|
97
108
|
|
|
98
109
|
// Remove this import
|
|
@@ -100,9 +111,7 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
100
111
|
|
|
101
112
|
},
|
|
102
113
|
|
|
103
|
-
//
|
|
104
|
-
// Test: Router.xxx()
|
|
105
|
-
// Replace by: nothing
|
|
114
|
+
// Transform services service calls
|
|
106
115
|
CallExpression(path) {
|
|
107
116
|
|
|
108
117
|
if (!this.file.process)
|
|
@@ -112,36 +121,121 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
112
121
|
const callee = path.node.callee
|
|
113
122
|
if (!(
|
|
114
123
|
callee.type === 'MemberExpression'
|
|
115
|
-
&&
|
|
116
|
-
callee.object.type === 'Identifier'
|
|
117
|
-
&&
|
|
118
|
-
callee.property.type === 'Identifier'
|
|
119
|
-
&&
|
|
120
|
-
// Should be at the root of the document
|
|
121
|
-
path.parent.type === 'ExpressionStatement'
|
|
122
|
-
&&
|
|
123
|
-
path.parentPath.parent.type === 'Program'
|
|
124
|
-
// And make reference to a service
|
|
125
|
-
&&
|
|
126
|
-
(callee.object.name in this.file.importedServices)
|
|
127
124
|
))
|
|
128
125
|
return;
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
// Create full path
|
|
128
|
+
const completePath: string[] = [];
|
|
129
|
+
let currCallee: types.MemberExpression = callee;
|
|
130
|
+
while (1) {
|
|
131
|
+
|
|
132
|
+
if (currCallee.property.type === 'Identifier')
|
|
133
|
+
completePath.unshift(currCallee.property.name);
|
|
134
|
+
|
|
135
|
+
if (currCallee.object.type === 'MemberExpression')
|
|
136
|
+
currCallee = currCallee.object;
|
|
137
|
+
else {
|
|
134
138
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
if (currCallee.object.type === 'Identifier')
|
|
140
|
+
completePath.unshift(currCallee.object.name);
|
|
141
|
+
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
138
144
|
}
|
|
145
|
+
|
|
146
|
+
// If we actually call a service
|
|
147
|
+
const serviceName = completePath[0];
|
|
148
|
+
|
|
149
|
+
/*
|
|
150
|
+
Router.page: wrap with export const __register = ({ Router }) => Router.page(...)
|
|
151
|
+
*/
|
|
152
|
+
if (
|
|
153
|
+
serviceName === 'Router'
|
|
154
|
+
&&
|
|
155
|
+
callee.property.type === 'Identifier'
|
|
156
|
+
&&
|
|
157
|
+
['page', 'error', 'get', 'post', 'put', 'delete'].includes(callee.property.name)
|
|
158
|
+
) {
|
|
159
|
+
|
|
160
|
+
// Should be at the root of the document
|
|
161
|
+
if (!(
|
|
162
|
+
path.parent.type === 'ExpressionStatement'
|
|
163
|
+
&&
|
|
164
|
+
path.parentPath.parent.type === 'Program'
|
|
165
|
+
))
|
|
166
|
+
return;
|
|
167
|
+
|
|
168
|
+
const routeDef: TRouteDefinition = {
|
|
169
|
+
definition: path.node,
|
|
170
|
+
dataFetchers: []
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Adjust
|
|
174
|
+
if (this.file.side === 'front') {
|
|
175
|
+
transformDataFetchers(path, this, routeDef);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Add to the list of route definitons to wrap
|
|
179
|
+
this.file.routeDefinitions.push(routeDef);
|
|
180
|
+
|
|
181
|
+
// Delete the route def since it will be replaced by a wrapper
|
|
182
|
+
path.replaceWithMultiple([]);
|
|
183
|
+
|
|
184
|
+
/* [client] Backend Service calls: Transform to api.post( <method path>, <params> )
|
|
185
|
+
|
|
186
|
+
Events.Create( form.data ).then(res => toast.success(res.message))
|
|
187
|
+
=>
|
|
188
|
+
api.post( '/api/events/create', form.data ).then(res => toast.success(res.message))
|
|
189
|
+
*/
|
|
190
|
+
} else if (this.file.side === 'front') {
|
|
139
191
|
|
|
140
|
-
|
|
141
|
-
|
|
192
|
+
const isAService = (
|
|
193
|
+
serviceName in this.file.importedServices
|
|
194
|
+
&&
|
|
195
|
+
serviceName[0] === serviceName[0].toUpperCase()
|
|
196
|
+
);
|
|
197
|
+
if(!isAService)
|
|
198
|
+
return;
|
|
199
|
+
|
|
200
|
+
if (side === 'client') {
|
|
142
201
|
|
|
143
|
-
|
|
144
|
-
|
|
202
|
+
// Get complete call path
|
|
203
|
+
const apiPath = '/api/' + completePath.join('/');
|
|
204
|
+
|
|
205
|
+
// Replace by api.post( <method path>, <params> )
|
|
206
|
+
const apiPostArgs: types.CallExpression["arguments"] = [t.stringLiteral(apiPath)];
|
|
207
|
+
if (path.node.arguments.length === 1)
|
|
208
|
+
apiPostArgs.push( path.node.arguments[0] );
|
|
209
|
+
|
|
210
|
+
path.replaceWith(
|
|
211
|
+
t.callExpression(
|
|
212
|
+
t.memberExpression(
|
|
213
|
+
t.identifier('api'), t.identifier('post')
|
|
214
|
+
), apiPostArgs
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
} else {
|
|
218
|
+
|
|
219
|
+
// Rebuild member expression from completePath, adding a api prefix
|
|
220
|
+
let newCallee = t.memberExpression(
|
|
221
|
+
t.identifier('app'),
|
|
222
|
+
t.identifier(completePath[0])
|
|
223
|
+
);
|
|
224
|
+
for (let i = 1; i < completePath.length; i++) {
|
|
225
|
+
newCallee = t.memberExpression(
|
|
226
|
+
newCallee,
|
|
227
|
+
t.identifier(completePath[i])
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Replace by app.<service>.<method>(...)
|
|
232
|
+
path.replaceWith(
|
|
233
|
+
t.callExpression(
|
|
234
|
+
newCallee, [...path.node.arguments]
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
145
239
|
|
|
146
240
|
},
|
|
147
241
|
Program: {
|
|
@@ -153,7 +247,6 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
153
247
|
const wrappedrouteDefs = wrapRouteDefs( this.file );
|
|
154
248
|
if (wrappedrouteDefs)
|
|
155
249
|
path.pushContainer('body', [wrappedrouteDefs])
|
|
156
|
-
|
|
157
250
|
}
|
|
158
251
|
}
|
|
159
252
|
}
|
|
@@ -185,9 +278,9 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
185
278
|
}
|
|
186
279
|
|
|
187
280
|
// Differenciate back / front
|
|
188
|
-
if (relativeFileName.startsWith('/
|
|
281
|
+
if (relativeFileName.startsWith('/client/pages')) {
|
|
189
282
|
file.side = 'front';
|
|
190
|
-
} else if (relativeFileName.startsWith('/
|
|
283
|
+
} else if (relativeFileName.startsWith('/server/routes')) {
|
|
191
284
|
file.side = 'back';
|
|
192
285
|
} else
|
|
193
286
|
file.process = false;
|
|
@@ -201,12 +294,13 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
201
294
|
routeDef: TRouteDefinition
|
|
202
295
|
) {
|
|
203
296
|
path.traverse({
|
|
297
|
+
// api.load => move data fetchers to route.options.data
|
|
298
|
+
// So the router is able to load data before rendering the component
|
|
204
299
|
CallExpression(path) {
|
|
205
300
|
|
|
206
301
|
const callee = path.node.callee
|
|
207
302
|
|
|
208
|
-
// api.
|
|
209
|
-
// So the router is able to load data before rendering the component
|
|
303
|
+
// Detect api.fetch
|
|
210
304
|
if (!(
|
|
211
305
|
callee.type === 'MemberExpression'
|
|
212
306
|
&&
|
|
@@ -220,11 +314,23 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
220
314
|
))
|
|
221
315
|
return;
|
|
222
316
|
|
|
317
|
+
/* Reference data fetchers
|
|
318
|
+
{
|
|
319
|
+
stats: api.get(...)
|
|
320
|
+
}
|
|
321
|
+
*/
|
|
223
322
|
routeDef.dataFetchers.push(
|
|
224
323
|
...path.node.arguments[0].properties
|
|
225
324
|
);
|
|
226
325
|
|
|
227
|
-
|
|
326
|
+
/* Replace the:
|
|
327
|
+
const { stats } = api.fetch({
|
|
328
|
+
stats: api.get(...)
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
by:
|
|
332
|
+
const { stats } = context.data.stats;
|
|
333
|
+
*/
|
|
228
334
|
path.replaceWith(
|
|
229
335
|
t.memberExpression(
|
|
230
336
|
t.identifier( routeDef.contextName || 'context' ),
|
|
@@ -235,7 +341,7 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
235
341
|
}, routerDefContext);
|
|
236
342
|
}
|
|
237
343
|
|
|
238
|
-
function
|
|
344
|
+
function enrichRouteOptions(
|
|
239
345
|
routeDef: TRouteDefinition,
|
|
240
346
|
routeArgs: types.CallExpression["arguments"],
|
|
241
347
|
filename: string
|
|
@@ -366,7 +472,9 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
366
472
|
|
|
367
473
|
// Limit to one route def per file
|
|
368
474
|
const routesDefCount = file.routeDefinitions.length;
|
|
369
|
-
if (routesDefCount
|
|
475
|
+
if (routesDefCount === 0)
|
|
476
|
+
return;
|
|
477
|
+
else if (routesDefCount > 1)
|
|
370
478
|
throw new Error(`Frontend route definition files (/client/pages/**/**.ts) can contain only one route definition.
|
|
371
479
|
${routesDefCount} were given in ${file.path}.`);
|
|
372
480
|
|
|
@@ -379,7 +487,7 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
379
487
|
if (callee.object.name === 'Router') {
|
|
380
488
|
|
|
381
489
|
// Inject chunk id in options (2nd arg)
|
|
382
|
-
const newRouteArgs =
|
|
490
|
+
const newRouteArgs = enrichRouteOptions(routeDef, routeArgs, file.path);
|
|
383
491
|
if (newRouteArgs === 'ALREADY_PROCESSED')
|
|
384
492
|
return;
|
|
385
493
|
|
|
@@ -426,9 +534,10 @@ function Plugin(babel, { app, side, debug }: TOptions) {
|
|
|
426
534
|
)
|
|
427
535
|
])
|
|
428
536
|
);
|
|
537
|
+
|
|
429
538
|
|
|
430
|
-
|
|
431
|
-
|
|
539
|
+
(file.side === 'front' && file.path.includes('/server/routes/events.ts'))
|
|
540
|
+
&& console.log( file.path, generate(exportDeclaration).code );
|
|
432
541
|
|
|
433
542
|
return exportDeclaration;
|
|
434
543
|
}
|
|
@@ -18,16 +18,16 @@ module.exports = (app: App, dev: Boolean, client: boolean) => {
|
|
|
18
18
|
|
|
19
19
|
// Process external/third-party styles
|
|
20
20
|
{
|
|
21
|
-
exclude: [
|
|
21
|
+
exclude: [app.paths.root],
|
|
22
22
|
loader: 'css-loader',
|
|
23
23
|
options: {
|
|
24
24
|
sourceMap: dev
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
|
|
28
|
-
// Process internal/project styles (from
|
|
28
|
+
// Process internal/project styles (from root folder)
|
|
29
29
|
{
|
|
30
|
-
include: [
|
|
30
|
+
include: [app.paths.root],
|
|
31
31
|
loader: 'css-loader',
|
|
32
32
|
options: {
|
|
33
33
|
// CSS Loader https://github.com/webpack/css-loader
|
|
@@ -38,10 +38,10 @@ export default class IconesSVG extends Indexeur {
|
|
|
38
38
|
super();
|
|
39
39
|
|
|
40
40
|
this.formats = ['woff2'];
|
|
41
|
-
this.dossierIcones = cli.paths.core.
|
|
41
|
+
this.dossierIcones = cli.paths.core.root + '/client/assets/icons/';
|
|
42
42
|
this.dossierSortie = app.paths.bin + '/public/';
|
|
43
43
|
|
|
44
|
-
this.cacheTypes = cli.paths.core.
|
|
44
|
+
this.cacheTypes = cli.paths.core.root + '/types/icons.d.ts';
|
|
45
45
|
this.cacheIndex = this.dossierIcones + 'index.json';
|
|
46
46
|
|
|
47
47
|
if (fs.existsSync(this.cacheIndex)) {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import webpack from 'webpack';
|
|
8
8
|
import fs from 'fs-extra';
|
|
9
|
+
import serialize from 'serialize-javascript';
|
|
9
10
|
|
|
10
11
|
import SpeedMeasurePlugin from "speed-measure-webpack-plugin";
|
|
11
12
|
const smp = new SpeedMeasurePlugin({ disable: true });
|
|
@@ -137,20 +138,19 @@ export default class Compiler {
|
|
|
137
138
|
|
|
138
139
|
private indexServices() {
|
|
139
140
|
|
|
140
|
-
const imported: string[] = []
|
|
141
|
-
const exportedType: string[] = []
|
|
142
|
-
const exportedMetas: string[] = []
|
|
143
141
|
|
|
144
142
|
// Index services
|
|
145
143
|
const searchDirs = {
|
|
146
144
|
// The less priority is the first
|
|
147
145
|
// The last override the first if there are duplicates
|
|
148
|
-
'@server/services/': path.join(cli.paths.core.
|
|
149
|
-
'@/server/services/': path.join(app.paths.
|
|
150
|
-
|
|
146
|
+
'@server/services/': path.join(cli.paths.core.root, 'server', 'services'),
|
|
147
|
+
'@/server/services/': path.join(app.paths.root, 'server', 'services'),
|
|
148
|
+
// Temp disabled because compile issue on vercel
|
|
149
|
+
//'': path.join(app.paths.root, 'node_modules'),
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
|
|
152
|
+
// Generate app class file
|
|
153
|
+
const servicesAvailable: {[id: string]: TServiceMetas} = {};
|
|
154
154
|
for (const importationPrefix in searchDirs) {
|
|
155
155
|
|
|
156
156
|
const searchDir = searchDirs[ importationPrefix ];
|
|
@@ -164,32 +164,88 @@ export default class Compiler {
|
|
|
164
164
|
|
|
165
165
|
const serviceMetas = require(metasFile);
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
servicesAvailable[ serviceMetas.id ] = {
|
|
168
168
|
...serviceMetas,
|
|
169
169
|
importationPath
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
//
|
|
175
|
-
|
|
174
|
+
// Read app services
|
|
175
|
+
const imported: string[] = []
|
|
176
|
+
const referencedNames: {[serviceId: string]: string} = {} // ID to Name
|
|
177
|
+
|
|
178
|
+
const refService = (serviceName: string, serviceConfig: any, level: number = 0) => {
|
|
176
179
|
|
|
177
|
-
|
|
180
|
+
if (serviceConfig.refTo !== undefined) {
|
|
181
|
+
const refTo = serviceConfig.refTo;
|
|
182
|
+
return {
|
|
183
|
+
name: serviceName,
|
|
184
|
+
code: `${serviceName}: this.${refTo},`,
|
|
185
|
+
priority: 0
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const serviceMetas = servicesAvailable[ serviceConfig.id ];
|
|
190
|
+
if (serviceMetas === undefined)
|
|
191
|
+
throw new Error(`Service ${serviceConfig.id} not found. Referenced services: ${Object.keys(servicesAvailable).join('\n')}`);
|
|
192
|
+
|
|
193
|
+
const referencedName = referencedNames[serviceConfig.id];
|
|
194
|
+
if (referencedName !== undefined)
|
|
195
|
+
throw new Error(`Service ${serviceConfig.id} is already setup as ${referencedName}`);
|
|
178
196
|
|
|
179
197
|
// Generate index & typings
|
|
180
|
-
imported.push(`import
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
198
|
+
imported.push(`import ${serviceMetas.name} from "${serviceMetas.importationPath}";`);
|
|
199
|
+
|
|
200
|
+
if (serviceConfig.name !== undefined)
|
|
201
|
+
referencedNames[serviceConfig.id] = serviceConfig.name;
|
|
202
|
+
|
|
203
|
+
// Subservices
|
|
204
|
+
let subservices = '';
|
|
205
|
+
if (serviceConfig.subservices) {
|
|
206
|
+
|
|
207
|
+
const subservicesList = serviceConfig.subservices;
|
|
208
|
+
const subservicesCode = Object.entries(subservicesList).map(([name, service]) =>
|
|
209
|
+
refService(name, service, level + 1)
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Sort by priority
|
|
213
|
+
const sortedSubservices = subservicesCode.sort((a, b) => a.priority - b.priority);
|
|
214
|
+
|
|
215
|
+
// Generate code
|
|
216
|
+
subservices = sortedSubservices.map(s => s.code).join('\n');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Generate the service instance
|
|
220
|
+
const instanciation = `new ${serviceMetas.name}(
|
|
221
|
+
this,
|
|
222
|
+
${serialize(serviceConfig.config || {}) || '{}'},
|
|
223
|
+
() => ({
|
|
224
|
+
${subservices}
|
|
225
|
+
}),
|
|
226
|
+
this
|
|
227
|
+
)`
|
|
228
|
+
|
|
229
|
+
if (level === 0)
|
|
230
|
+
return {
|
|
231
|
+
name: serviceName,
|
|
232
|
+
code: `public ${serviceName} = ${instanciation};`,
|
|
233
|
+
priority: serviceConfig.config?.priority || 0
|
|
234
|
+
};
|
|
235
|
+
else
|
|
236
|
+
return {
|
|
237
|
+
name: serviceName,
|
|
238
|
+
code: `${serviceName}: ${instanciation},`,
|
|
239
|
+
priority: serviceConfig.config?.priority || 0
|
|
240
|
+
};
|
|
191
241
|
}
|
|
192
242
|
|
|
243
|
+
const servicesCode = Object.values(app.registered).map( s => refService(s.name, s, 0));
|
|
244
|
+
const sortedServices = servicesCode.sort((a, b) => a.priority - b.priority);
|
|
245
|
+
|
|
246
|
+
const services = sortedServices.map(s => s.code).join('\n');
|
|
247
|
+
const servicesNames = sortedServices.map(s => s.name);
|
|
248
|
+
|
|
193
249
|
// Define the app class identifier
|
|
194
250
|
const appClassIdentifier = app.identity.identifier;
|
|
195
251
|
const containerServices = app.containerServices.map( s => "'" + s + "'").join('|');
|
|
@@ -199,30 +255,70 @@ dependences: ${JSON.stringify(dependences)},
|
|
|
199
255
|
path.join( app.paths.client.generated, 'services.d.ts'),
|
|
200
256
|
`declare module "@app" {
|
|
201
257
|
|
|
202
|
-
import {
|
|
258
|
+
import { RouenEvents as RouenEventsClient } from "@/client";
|
|
259
|
+
import RouenEventsServer from "@/server/.generated/app";
|
|
260
|
+
|
|
261
|
+
import { ApplicationProperties as ClientApplicationProperties } from "@client/app";
|
|
262
|
+
import { ApplicationProperties as ServerApplicationProperties } from "@server/app";
|
|
263
|
+
|
|
264
|
+
type ClientServices = Omit<RouenEventsClient, ClientApplicationProperties>;
|
|
265
|
+
type ServerServices = Omit<RouenEventsServer, ServerApplicationProperties | keyof ClientServices>;
|
|
266
|
+
|
|
267
|
+
type CombinedServices = ClientServices & ServerServices;
|
|
268
|
+
|
|
269
|
+
const appClass: CombinedServices;
|
|
270
|
+
export = appClass;
|
|
271
|
+
}
|
|
203
272
|
|
|
204
|
-
const appClass: ${appClassIdentifier};
|
|
205
273
|
|
|
206
|
-
|
|
207
|
-
|
|
274
|
+
// Temporary
|
|
275
|
+
/*declare module '@models' {
|
|
276
|
+
export * from '@/var/prisma/index';
|
|
277
|
+
}*/
|
|
278
|
+
|
|
279
|
+
declare module '@models' {
|
|
280
|
+
import { Prisma, PrismaClient } from '@/var/prisma/index';
|
|
281
|
+
|
|
282
|
+
type ModelNames = Prisma.ModelName;
|
|
283
|
+
|
|
284
|
+
type ModelDelegates = {
|
|
285
|
+
[K in ModelNames]: PrismaClient[Uncapitalize<K>];
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const models: ModelDelegates;
|
|
289
|
+
|
|
290
|
+
export = models;
|
|
291
|
+
}
|
|
292
|
+
`
|
|
208
293
|
);
|
|
209
294
|
|
|
210
295
|
fs.outputFileSync(
|
|
211
|
-
path.join( app.paths.server.generated, '
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
296
|
+
path.join( app.paths.server.generated, 'app.ts'),
|
|
297
|
+
`import { Application } from '@server/app/index';
|
|
298
|
+
|
|
299
|
+
${imported.join('\n')}
|
|
300
|
+
|
|
301
|
+
export default class ${appClassIdentifier} extends Application {
|
|
302
|
+
|
|
303
|
+
protected serviceNames = [
|
|
304
|
+
${Object.values(servicesNames).map(name => `"${name}"`).join(',\n')}
|
|
305
|
+
] as const;
|
|
306
|
+
|
|
307
|
+
protected servicesIdToName = {
|
|
308
|
+
${Object.entries(referencedNames).map(([id, name]) => `"${id}": "${name}"`).join(',\n')}
|
|
309
|
+
} as const;
|
|
310
|
+
|
|
311
|
+
${services}
|
|
215
312
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
);
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
`);
|
|
220
316
|
|
|
221
317
|
fs.outputFileSync(
|
|
222
318
|
path.join( app.paths.server.generated, 'services.d.ts'),
|
|
223
319
|
`type InstalledServices = import('./services').Services;
|
|
224
320
|
|
|
225
|
-
declare type ${appClassIdentifier} = import("@/server").default;
|
|
321
|
+
declare type ${appClassIdentifier} = import("@/server/.generated/app").default;
|
|
226
322
|
|
|
227
323
|
declare module "@app" {
|
|
228
324
|
|
|
@@ -242,7 +338,8 @@ declare module "@app" {
|
|
|
242
338
|
|
|
243
339
|
declare module '@server/app' {
|
|
244
340
|
|
|
245
|
-
import { Application } from "@server/app
|
|
341
|
+
import { Application } from "@server/app";
|
|
342
|
+
import { Environment } from "@server/app";
|
|
246
343
|
import { ServicesContainer } from "@server/app/service/container";
|
|
247
344
|
|
|
248
345
|
abstract class ApplicationWithServices extends Application<
|
|
@@ -251,18 +348,34 @@ declare module '@server/app' {
|
|
|
251
348
|
|
|
252
349
|
export interface Exported {
|
|
253
350
|
Application: typeof ApplicationWithServices,
|
|
254
|
-
|
|
351
|
+
Environment: Environment,
|
|
255
352
|
}
|
|
256
353
|
|
|
257
354
|
const foo: Exported;
|
|
258
355
|
|
|
259
356
|
export = foo;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
declare module '@models' {
|
|
360
|
+
import { Prisma, PrismaClient } from '@/var/prisma/index';
|
|
361
|
+
|
|
362
|
+
type ModelNames = Prisma.ModelName;
|
|
363
|
+
|
|
364
|
+
type ModelDelegates = {
|
|
365
|
+
[K in ModelNames]: PrismaClient[Uncapitalize<K>];
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const models: ModelDelegates;
|
|
369
|
+
|
|
370
|
+
export = models;
|
|
260
371
|
}`
|
|
261
372
|
);
|
|
262
373
|
}
|
|
263
374
|
|
|
264
375
|
public async create() {
|
|
265
376
|
|
|
377
|
+
await app.warmup();
|
|
378
|
+
|
|
266
379
|
this.cleanup();
|
|
267
380
|
|
|
268
381
|
this.fixNpmLinkIssues();
|
|
@@ -17,7 +17,7 @@ import createCommonConfig, { TCompileMode, regex } from '../common';
|
|
|
17
17
|
// Type
|
|
18
18
|
import type App from '../../app';
|
|
19
19
|
|
|
20
|
-
const getCorePluginsList = (app: App,) => {
|
|
20
|
+
/*const getCorePluginsList = (app: App,) => {
|
|
21
21
|
|
|
22
22
|
const corePlugins: string[] = [];
|
|
23
23
|
|
|
@@ -32,7 +32,7 @@ const getCorePluginsList = (app: App,) => {
|
|
|
32
32
|
corePlugins.push(cli.paths.core.root + '/node_modules/' + moduleName + '/src');
|
|
33
33
|
|
|
34
34
|
return corePlugins;
|
|
35
|
-
}
|
|
35
|
+
}*/
|
|
36
36
|
|
|
37
37
|
const debug = false;
|
|
38
38
|
|
|
@@ -63,7 +63,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
|
|
|
63
63
|
target: 'node',
|
|
64
64
|
entry: {
|
|
65
65
|
server: [
|
|
66
|
-
cli.paths.coreRoot + '/
|
|
66
|
+
cli.paths.coreRoot + '/server/index.ts'
|
|
67
67
|
],
|
|
68
68
|
},
|
|
69
69
|
|
|
@@ -101,8 +101,14 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
|
|
|
101
101
|
// Aliased modules
|
|
102
102
|
app.aliases.server.containsAlias(request)
|
|
103
103
|
||
|
|
104
|
+
// TODO: 5htp.conf: compile: include
|
|
104
105
|
// Compile 5HTP modules
|
|
105
106
|
request.startsWith('5htp-')
|
|
107
|
+
||
|
|
108
|
+
// Compile 5HTP modules
|
|
109
|
+
request.startsWith('@mantine/') ||
|
|
110
|
+
request.startsWith('react-number-format') ||
|
|
111
|
+
request.startsWith('@floating-ui')
|
|
106
112
|
)
|
|
107
113
|
|
|
108
114
|
//console.log('isNodeModule', request, isNodeModule);
|
|
@@ -124,7 +130,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
|
|
|
124
130
|
|
|
125
131
|
alias: aliases,
|
|
126
132
|
|
|
127
|
-
extensions: ['.ts', '.tsx', ".json", ".sql"],
|
|
133
|
+
extensions: ['.ts', '.tsx', ".json", ".sql", ".js"],
|
|
128
134
|
},
|
|
129
135
|
|
|
130
136
|
module: {
|
|
@@ -136,18 +142,19 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
|
|
|
136
142
|
test: regex.scripts,
|
|
137
143
|
include: [
|
|
138
144
|
|
|
139
|
-
app.paths.root + '/
|
|
140
|
-
cli.paths.core.root + '/
|
|
145
|
+
app.paths.root + '/client',
|
|
146
|
+
cli.paths.core.root + '/client',
|
|
141
147
|
|
|
142
|
-
app.paths.root + '/
|
|
143
|
-
cli.paths.core.root + '/
|
|
148
|
+
app.paths.root + '/common',
|
|
149
|
+
cli.paths.core.root + '/common',
|
|
144
150
|
|
|
145
151
|
// Dossiers server uniquement pour le bundle server
|
|
146
|
-
app.paths.root + '/
|
|
147
|
-
cli.paths.core.root + '/
|
|
152
|
+
app.paths.root + '/server',
|
|
153
|
+
cli.paths.core.root + '/server',
|
|
148
154
|
|
|
149
155
|
// Complle 5HTP modules so they can refer to the framework instance and aliases
|
|
150
|
-
|
|
156
|
+
// Temp disabled because compile issue on vercel
|
|
157
|
+
//...getCorePluginsList(app)
|
|
151
158
|
],
|
|
152
159
|
rules: require('../common/babel')(app, 'server', dev)
|
|
153
160
|
},
|