5htp 0.6.2 → 0.6.3-2
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/app/index.ts +4 -1
- package/compiler/client/index.ts +2 -2
- package/compiler/common/babel/index.ts +0 -10
- package/compiler/common/babel/plugins/services.ts +263 -13
- package/compiler/common/babel/routes/routes.ts +199 -7
- package/compiler/common/files/autres.ts +1 -1
- package/compiler/common/files/style.ts +24 -7
- package/compiler/common/index.ts +0 -9
- package/compiler/index.ts +24 -11
- package/package.json +8 -3
- package/compiler/common/babel/plugins/form.ts +0 -191
- package/compiler/common/babel/plugins/icones-svg.ts +0 -376
- package/compiler/common/babel/plugins/injection-dependances/index.ts +0 -225
- package/compiler/common/babel/plugins/injection-dependances/remplacerFonction.ts +0 -226
- package/compiler/common/babel/plugins/queries/index.ts +0 -166
- package/compiler/common/plugins/indexage/_utils/Stringify.ts +0 -72
- package/compiler/common/plugins/indexage/_utils/annotations.ts +0 -88
- package/compiler/common/plugins/indexage/_utils/iterateur.ts +0 -52
- package/compiler/common/plugins/indexage/icones-svg/index.ts +0 -207
- package/compiler/common/plugins/indexage/index.ts +0 -134
- package/compiler/common/plugins/indexage/indexeur.ts +0 -13
- package/compiler/common/plugins/indexage/injection-dependances/index.ts +0 -68
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
/*----------------------------------
|
|
2
|
-
- DEPENDANCES
|
|
3
|
-
----------------------------------*/
|
|
4
|
-
|
|
5
|
-
// Npm
|
|
6
|
-
import * as types from '@babel/types'
|
|
7
|
-
import { PluginObj } from '@babel/core';
|
|
8
|
-
|
|
9
|
-
import type { App } from '../../../../app';
|
|
10
|
-
|
|
11
|
-
export type TIndexIcones = { [chemin: string]: { id: string, nom: string, fichier: string } };
|
|
12
|
-
|
|
13
|
-
/*----------------------------------
|
|
14
|
-
- WEBPACK RULE
|
|
15
|
-
----------------------------------*/
|
|
16
|
-
module.exports = (app: App) => ({
|
|
17
|
-
test: /\.(tsx|jsx|ts)$/, // <i src="icon" /> et /* @icon */"icon"
|
|
18
|
-
plugins: [
|
|
19
|
-
[Plugin, { app }]
|
|
20
|
-
]
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const debug = false;
|
|
24
|
-
|
|
25
|
-
/*----------------------------------
|
|
26
|
-
- PLUGIN
|
|
27
|
-
----------------------------------*/
|
|
28
|
-
const ids: string[] = []
|
|
29
|
-
function Plugin (babel, { app }: { app: App }) {
|
|
30
|
-
|
|
31
|
-
const t = babel.types as typeof types;
|
|
32
|
-
|
|
33
|
-
const plugin: PluginObj<{
|
|
34
|
-
referencerIcone: (nomBrut: string) => string | null,
|
|
35
|
-
setNodeAsProcessed: (node: types.Node) => types.Node;
|
|
36
|
-
hasBeenProcessed: (node: types.Node) => boolean | undefined,
|
|
37
|
-
fichier: string,
|
|
38
|
-
traiter: boolean,
|
|
39
|
-
iconeTrouvee: boolean,
|
|
40
|
-
icones: TIndexIcones
|
|
41
|
-
}> = {
|
|
42
|
-
pre(state) {
|
|
43
|
-
|
|
44
|
-
this.fichier = state.opts.filename as string;
|
|
45
|
-
|
|
46
|
-
//console.log('SVG', fichier);
|
|
47
|
-
|
|
48
|
-
this.traiter = true;
|
|
49
|
-
this.iconeTrouvee = false;
|
|
50
|
-
|
|
51
|
-
this.icones = {}; // chemin => { id, nom }
|
|
52
|
-
|
|
53
|
-
this.referencerIcone = (nomBrut: string) => {
|
|
54
|
-
|
|
55
|
-
// Décomposition & dossier par défaut
|
|
56
|
-
let [dossierIcone, nomIcone] = nomBrut.split('/');
|
|
57
|
-
if (nomIcone === undefined) {
|
|
58
|
-
nomIcone = dossierIcone;
|
|
59
|
-
dossierIcone = app.identity.iconsPack || 'regular';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Extraction des infos
|
|
63
|
-
const cheminIconeBrut = dossierIcone + '/' + nomIcone;
|
|
64
|
-
const cheminIcone = cheminIconeBrut + '.svg';
|
|
65
|
-
|
|
66
|
-
// Référencement si pas déjà fait
|
|
67
|
-
if (this.icones[ cheminIconeBrut ] === undefined) {
|
|
68
|
-
|
|
69
|
-
const id = nomBrut.replace(/\//g, '-');
|
|
70
|
-
|
|
71
|
-
this.icones[ cheminIconeBrut ] = {
|
|
72
|
-
//id: dossierIcone.substring(0, 1) + '-' + nomIcone,
|
|
73
|
-
id: id,
|
|
74
|
-
nom: nomBrut,
|
|
75
|
-
fichier: cheminIcone
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this.iconeTrouvee = true;
|
|
81
|
-
|
|
82
|
-
debug && console.log(`[icons]`, nomBrut, '=>', this.icones[cheminIconeBrut].id);
|
|
83
|
-
|
|
84
|
-
ids.push(this.icones[cheminIconeBrut].id);
|
|
85
|
-
|
|
86
|
-
return this.icones[ cheminIconeBrut ].id;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
this.setNodeAsProcessed = (node: types.Node) => {
|
|
90
|
-
node.innerComments = [{ type: 'CommentBlock', 'value': '@iconId' }]
|
|
91
|
-
return node;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.hasBeenProcessed = (node: types.Node) =>
|
|
95
|
-
node.innerComments?.some( c => c.value === '@iconId' )
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
visitor: {
|
|
99
|
-
Program: {
|
|
100
|
-
|
|
101
|
-
enter(path) {
|
|
102
|
-
|
|
103
|
-
if (!this.traiter)
|
|
104
|
-
return;
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
StringLiteral(path) {
|
|
110
|
-
|
|
111
|
-
// Marquage d'une référence à une icon via un /* @icon */"<nom>"
|
|
112
|
-
if (
|
|
113
|
-
path.node.leadingComments
|
|
114
|
-
&&
|
|
115
|
-
path.node.leadingComments.length !== 0
|
|
116
|
-
&&
|
|
117
|
-
path.node.leadingComments[0].value === ' @icon '
|
|
118
|
-
&&
|
|
119
|
-
!this.hasBeenProcessed( path.node )
|
|
120
|
-
) {
|
|
121
|
-
|
|
122
|
-
// Remplacement par id
|
|
123
|
-
const idIcone = this.referencerIcone(path.node.value);
|
|
124
|
-
if (idIcone === null)
|
|
125
|
-
return;
|
|
126
|
-
|
|
127
|
-
path.replaceWith(
|
|
128
|
-
this.setNodeAsProcessed(
|
|
129
|
-
t.stringLiteral(idIcone)
|
|
130
|
-
)
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
path.skip();
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
// { icon: "solid/<nom>" }
|
|
139
|
-
Property(path) {
|
|
140
|
-
if (
|
|
141
|
-
path.node.key.type === 'Identifier'
|
|
142
|
-
&&
|
|
143
|
-
path.node.key.name === 'icon'
|
|
144
|
-
&&
|
|
145
|
-
path.node.value?.type === 'StringLiteral'
|
|
146
|
-
&&
|
|
147
|
-
!this.hasBeenProcessed( path.node )
|
|
148
|
-
) {
|
|
149
|
-
|
|
150
|
-
if (this.fichier.includes("award"))
|
|
151
|
-
console.log( path.node.value.value, path.node.innerComments,path.node.leadingComments, path.node.trailingComments );
|
|
152
|
-
|
|
153
|
-
// Remplacement par id
|
|
154
|
-
const idIcone = this.referencerIcone(path.node.value.value);
|
|
155
|
-
if (idIcone === null)
|
|
156
|
-
return;
|
|
157
|
-
|
|
158
|
-
path.replaceWith(
|
|
159
|
-
this.setNodeAsProcessed(
|
|
160
|
-
t.objectProperty(
|
|
161
|
-
t.identifier('icon'),
|
|
162
|
-
t.stringLiteral( idIcone ),
|
|
163
|
-
)
|
|
164
|
-
)
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
path.skip();
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
|
|
172
|
-
JSXAttribute(path) {
|
|
173
|
-
|
|
174
|
-
// icon="solid/<nom>"
|
|
175
|
-
if (
|
|
176
|
-
path.node.name.type === 'JSXIdentifier'
|
|
177
|
-
&&
|
|
178
|
-
path.node.name.name.startsWith("icon")
|
|
179
|
-
&&
|
|
180
|
-
path.node.value
|
|
181
|
-
&&
|
|
182
|
-
!this.hasBeenProcessed( path.node )
|
|
183
|
-
) {
|
|
184
|
-
|
|
185
|
-
const nomAttr = path.node.name.name;
|
|
186
|
-
const valAttr = path.node.value;
|
|
187
|
-
let remplacement;
|
|
188
|
-
|
|
189
|
-
// icon="solid/<nom>"
|
|
190
|
-
if (valAttr.type === 'StringLiteral') {
|
|
191
|
-
|
|
192
|
-
const idIcone = this.referencerIcone(valAttr.value);
|
|
193
|
-
if (idIcone === null)
|
|
194
|
-
return;
|
|
195
|
-
|
|
196
|
-
remplacement = t.stringLiteral(idIcone)
|
|
197
|
-
|
|
198
|
-
// icon={condition ? "solid/<nom>" : "solid/<nom>"}
|
|
199
|
-
} else if (
|
|
200
|
-
valAttr.type === 'JSXExpressionContainer'
|
|
201
|
-
&&
|
|
202
|
-
valAttr.expression.type === 'ConditionalExpression'
|
|
203
|
-
&&
|
|
204
|
-
valAttr.expression.consequent.type === 'StringLiteral'
|
|
205
|
-
&&
|
|
206
|
-
valAttr.expression.alternate.type === 'StringLiteral'
|
|
207
|
-
) {
|
|
208
|
-
|
|
209
|
-
const idIcone1 = this.referencerIcone(valAttr.expression.consequent.value);
|
|
210
|
-
const idIcone2 = this.referencerIcone(valAttr.expression.alternate.value);
|
|
211
|
-
|
|
212
|
-
remplacement = t.jsxExpressionContainer(
|
|
213
|
-
t.conditionalExpression(
|
|
214
|
-
valAttr.expression.test,
|
|
215
|
-
idIcone1 ? t.stringLiteral(idIcone1) : valAttr.expression.consequent,
|
|
216
|
-
idIcone2 ? t.stringLiteral(idIcone2) : valAttr.expression.alternate,
|
|
217
|
-
|
|
218
|
-
)
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
} else
|
|
222
|
-
return;
|
|
223
|
-
|
|
224
|
-
path.replaceWith(
|
|
225
|
-
this.setNodeAsProcessed(
|
|
226
|
-
t.jsxAttribute(
|
|
227
|
-
t.jsxIdentifier( nomAttr ),
|
|
228
|
-
remplacement
|
|
229
|
-
)
|
|
230
|
-
)
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
path.skip();
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
JSXElement(path) {
|
|
239
|
-
|
|
240
|
-
// <i />
|
|
241
|
-
if (
|
|
242
|
-
this.traiter
|
|
243
|
-
&&
|
|
244
|
-
path.node
|
|
245
|
-
&&
|
|
246
|
-
path.node.openingElement
|
|
247
|
-
&&
|
|
248
|
-
path.node.openingElement.name.type === 'JSXIdentifier'
|
|
249
|
-
&&
|
|
250
|
-
path.node.openingElement.name.name === 'i'
|
|
251
|
-
&&
|
|
252
|
-
!this.hasBeenProcessed( path.node )
|
|
253
|
-
) {
|
|
254
|
-
|
|
255
|
-
// Extraction des attributs src et class
|
|
256
|
-
const attrs: {[prop: string]: types.JSXAttribute["value"]} = {}
|
|
257
|
-
let nouveauxAttributs = path.node.openingElement.attributes.filter((attribut) => {
|
|
258
|
-
|
|
259
|
-
if (attribut.type === 'JSXAttribute' && attribut.name) {
|
|
260
|
-
|
|
261
|
-
if (attribut.name.name === 'src') {
|
|
262
|
-
attrs.src = attribut.value
|
|
263
|
-
return false;
|
|
264
|
-
} else if (attribut.name.name === 'class') {
|
|
265
|
-
attrs.class = attribut.value
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
if (!attrs.src)
|
|
273
|
-
return;
|
|
274
|
-
|
|
275
|
-
// <i src="..." />
|
|
276
|
-
let classeIcone: types.StringLiteral | types.BinaryExpression | undefined = undefined;
|
|
277
|
-
|
|
278
|
-
// Chaine: On référence le nom de l'icon
|
|
279
|
-
if (attrs.src.type === 'StringLiteral') {
|
|
280
|
-
|
|
281
|
-
// <i src="spin" /> => <i class="svg-xxxxx spin" />
|
|
282
|
-
let valSrc = attrs.src.value
|
|
283
|
-
if (valSrc === 'spin') {
|
|
284
|
-
|
|
285
|
-
const idIcone = this.referencerIcone('solid/spinner-third');
|
|
286
|
-
if (idIcone === null)
|
|
287
|
-
return;
|
|
288
|
-
|
|
289
|
-
classeIcone = t.stringLiteral('svg-' + idIcone + ' spin');
|
|
290
|
-
|
|
291
|
-
// <i src="regular/user" /> => <i class="svg-xxxxxx" />
|
|
292
|
-
} else {
|
|
293
|
-
|
|
294
|
-
const idIcone = this.referencerIcone(valSrc);
|
|
295
|
-
if (idIcone === null)
|
|
296
|
-
return;
|
|
297
|
-
|
|
298
|
-
classeIcone = t.stringLiteral('svg-' + idIcone);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Autre: on renomme src en class et contatène le préfixe "svg-"
|
|
302
|
-
// <i src={icon} /> => <i class={"svg-" + icon} />
|
|
303
|
-
} else if (attrs.src.type === 'JSXExpressionContainer' && attrs.src.expression.type !== 'JSXEmptyExpression') {
|
|
304
|
-
|
|
305
|
-
classeIcone = t.binaryExpression(
|
|
306
|
-
'+',
|
|
307
|
-
t.stringLiteral('svg-'),
|
|
308
|
-
attrs.src.expression
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
} else
|
|
312
|
-
throw new Error(`Type de valeur non-géré pour l'attribut src: ${attrs.src.type}`);
|
|
313
|
-
|
|
314
|
-
const origClass = attrs.class?.type !== 'JSXExpressionContainer'
|
|
315
|
-
? attrs.class
|
|
316
|
-
: attrs.class.expression.type !== 'JSXEmptyExpression'
|
|
317
|
-
? attrs.class.expression
|
|
318
|
-
: null
|
|
319
|
-
|
|
320
|
-
path.replaceWith( this.setNodeAsProcessed(
|
|
321
|
-
|
|
322
|
-
// Balise <i>
|
|
323
|
-
t.jsxElement(
|
|
324
|
-
t.jsxOpeningElement(
|
|
325
|
-
t.jsxIdentifier('i'),
|
|
326
|
-
|
|
327
|
-
// Attributs
|
|
328
|
-
[
|
|
329
|
-
...nouveauxAttributs,
|
|
330
|
-
t.jsxAttribute(
|
|
331
|
-
t.jsxIdentifier("class"),
|
|
332
|
-
|
|
333
|
-
// Attribut class
|
|
334
|
-
// concatSrc doit toujours être en premier dans les binary expressions
|
|
335
|
-
// afin que le sélecteur CSS i[class^="svg-"] soit toujours valable
|
|
336
|
-
t.jsxExpressionContainer(
|
|
337
|
-
origClass // Concaténation si attribut déjà défini
|
|
338
|
-
? t.binaryExpression(
|
|
339
|
-
'+',
|
|
340
|
-
classeIcone,
|
|
341
|
-
|
|
342
|
-
t.binaryExpression(
|
|
343
|
-
'+',
|
|
344
|
-
t.stringLiteral(' '),
|
|
345
|
-
origClass
|
|
346
|
-
)
|
|
347
|
-
)
|
|
348
|
-
: classeIcone
|
|
349
|
-
)
|
|
350
|
-
)
|
|
351
|
-
]
|
|
352
|
-
),
|
|
353
|
-
t.jsxClosingElement(
|
|
354
|
-
t.jsxIdentifier('i')
|
|
355
|
-
),
|
|
356
|
-
path.node.children,
|
|
357
|
-
path.node.selfClosing
|
|
358
|
-
)
|
|
359
|
-
));
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
},
|
|
363
|
-
post(state) {
|
|
364
|
-
|
|
365
|
-
if (!this.traiter || !this.iconeTrouvee)
|
|
366
|
-
return;
|
|
367
|
-
|
|
368
|
-
//console.log('@@@@@@ TEST ICONE', this.icones['/home/gaetan/www/Professionnel/Node/framework/kernel/client/assets/img/icones/fa/free/brands/youtube.svg']);
|
|
369
|
-
|
|
370
|
-
state.metadata['icones-svg'] = this.icones;
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
return plugin;
|
|
376
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/*----------------------------------
|
|
2
|
-
- DEPENDANCES
|
|
3
|
-
----------------------------------*/
|
|
4
|
-
|
|
5
|
-
// Npm
|
|
6
|
-
import { PluginObj } from '@babel/core';
|
|
7
|
-
import * as types from '@babel/types'
|
|
8
|
-
var minimatch = require("minimatch")
|
|
9
|
-
|
|
10
|
-
import cli from '@cli';
|
|
11
|
-
|
|
12
|
-
/*----------------------------------
|
|
13
|
-
- WEBPACK RULE
|
|
14
|
-
----------------------------------*/
|
|
15
|
-
const globServices = app.paths.root + '/server/services/**/*.ts';
|
|
16
|
-
const globModuleService = '@app/server/services/**';
|
|
17
|
-
const globRoutes = app.paths.root + '/server/routes/**/*.ts';
|
|
18
|
-
|
|
19
|
-
module.exports = {
|
|
20
|
-
test: [globRoutes, globServices],
|
|
21
|
-
plugins: [
|
|
22
|
-
[Plugin]
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const routerMethods = ['get', 'post', 'put', 'delete', 'patch'];
|
|
27
|
-
|
|
28
|
-
/*----------------------------------
|
|
29
|
-
- PLUGIN
|
|
30
|
-
----------------------------------*/
|
|
31
|
-
function Plugin (babel) {
|
|
32
|
-
|
|
33
|
-
const t = babel.types as typeof types;
|
|
34
|
-
|
|
35
|
-
const remplacerFonction = require('./remplacerFonction').default(t);
|
|
36
|
-
|
|
37
|
-
const plugin: PluginObj<{
|
|
38
|
-
fichier: string,
|
|
39
|
-
cheminApi: string | undefined,
|
|
40
|
-
dependances: {[fichier: string]: { }}
|
|
41
|
-
nbDependances: number,
|
|
42
|
-
servicesImportes: {[nom: string]: string}
|
|
43
|
-
}> = {
|
|
44
|
-
pre(state) {
|
|
45
|
-
|
|
46
|
-
this.fichier = state.opts.filename as string;
|
|
47
|
-
|
|
48
|
-
this.cheminApi = getCheminControleur(this.fichier);
|
|
49
|
-
|
|
50
|
-
//console.log('fichier', fichier);
|
|
51
|
-
|
|
52
|
-
this.dependances = {}; // fichier service => { classe, dependances }
|
|
53
|
-
this.nbDependances = 0;
|
|
54
|
-
|
|
55
|
-
// Permet d'identifier le chemin du module associé à un nom de type
|
|
56
|
-
this.servicesImportes = {};
|
|
57
|
-
|
|
58
|
-
for (const nomBinding in state.scope.bindings) {
|
|
59
|
-
const binding = state.scope.bindings[nomBinding].path;
|
|
60
|
-
// Les services doitvent être importés via un import default
|
|
61
|
-
if (binding.type === 'ImportDefaultSpecifier' && binding.parent.type === 'ImportDeclaration') {
|
|
62
|
-
|
|
63
|
-
const fichier = binding.parent.source.value;
|
|
64
|
-
|
|
65
|
-
if (!minimatch(fichier, globModuleService))
|
|
66
|
-
continue;
|
|
67
|
-
|
|
68
|
-
this.servicesImportes[nomBinding] = fichier;
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
visitor: {
|
|
75
|
-
|
|
76
|
-
// Typescript vire les imports quand ils sont utilisés uniquement comme des types
|
|
77
|
-
// Etant donné que ces derniers sont encore visibles dans pre(state) mais qu'ils le sont plus ici,
|
|
78
|
-
// On les rajoute
|
|
79
|
-
Program(path) {
|
|
80
|
-
for (const nomService in this.servicesImportes) {
|
|
81
|
-
if (!( nomService in path.scope.bindings )) {
|
|
82
|
-
|
|
83
|
-
console.log('Importation forcée de ' + nomService + ' dans ' + this.fichier);
|
|
84
|
-
|
|
85
|
-
path.unshiftContainer(
|
|
86
|
-
'body',
|
|
87
|
-
t.importDeclaration(
|
|
88
|
-
[t.importDefaultSpecifier( t.identifier(nomService) )],
|
|
89
|
-
t.stringLiteral( this.servicesImportes[ nomService ] )
|
|
90
|
-
)
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
// Classe service
|
|
97
|
-
ClassMethod(i) {
|
|
98
|
-
try {
|
|
99
|
-
|
|
100
|
-
const constructeurService = (
|
|
101
|
-
i.node.kind === 'constructor'
|
|
102
|
-
&&
|
|
103
|
-
i.node.params.length !== 0
|
|
104
|
-
);
|
|
105
|
-
if (!constructeurService) return;
|
|
106
|
-
|
|
107
|
-
const classeParent = i.findParent(p => p.node.type === 'ClassDeclaration');
|
|
108
|
-
const parentService = (
|
|
109
|
-
classeParent !== undefined
|
|
110
|
-
&&
|
|
111
|
-
(classeParent.node as types.ClassDeclaration).id.name.endsWith('Service')
|
|
112
|
-
)
|
|
113
|
-
if (!parentService) return;
|
|
114
|
-
|
|
115
|
-
// Extraction de la liste des dépendances
|
|
116
|
-
const remplacement = remplacerFonction.bind(this)(i.node)
|
|
117
|
-
if (remplacement !== null)
|
|
118
|
-
i.replaceWith(remplacement);
|
|
119
|
-
|
|
120
|
-
} catch (e) {
|
|
121
|
-
console.error("[plugin injection-dependances] Erreur traitement constructeur classe", e);
|
|
122
|
-
throw e;
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
// Route
|
|
127
|
-
CallExpression(i) {
|
|
128
|
-
try {
|
|
129
|
-
|
|
130
|
-
if (i.node.loc === undefined) return; // Pas de loc = nouvellement créé = Pas besoin de retraiter
|
|
131
|
-
|
|
132
|
-
// xxx.get('/', ...)
|
|
133
|
-
if (
|
|
134
|
-
i.node.callee.type === 'MemberExpression'
|
|
135
|
-
&&
|
|
136
|
-
i.node.callee.property.type === 'Identifier'
|
|
137
|
-
&&
|
|
138
|
-
routerMethods.includes(i.node.callee.property.name)
|
|
139
|
-
&&
|
|
140
|
-
i.node.arguments.length >= 2 // url + au moins 1 middleware
|
|
141
|
-
&&
|
|
142
|
-
i.node.arguments[0].type === 'StringLiteral'
|
|
143
|
-
) {
|
|
144
|
-
|
|
145
|
-
i.replaceWith(
|
|
146
|
-
t.callExpression(
|
|
147
|
-
i.node.callee,
|
|
148
|
-
i.node.arguments.map((arg) => (
|
|
149
|
-
// async ( ... ) => { ... }
|
|
150
|
-
arg.type === 'ArrowFunctionExpression'
|
|
151
|
-
&&
|
|
152
|
-
arg.async === true
|
|
153
|
-
&&
|
|
154
|
-
arg.params.length !== 0
|
|
155
|
-
) ? remplacerFonction.bind(this)(arg) || arg : arg)
|
|
156
|
-
)
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
} catch (e) {
|
|
162
|
-
console.error("[plugin injection-dependances] Erreur traitement controleur route", e);
|
|
163
|
-
throw e;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
// Injection chemin fichier dans la définition des requetes api
|
|
169
|
-
ExportDefaultDeclaration(instruction) {
|
|
170
|
-
|
|
171
|
-
if (this.cheminApi === undefined)
|
|
172
|
-
return;
|
|
173
|
-
|
|
174
|
-
const declaration = instruction.node.declaration;
|
|
175
|
-
|
|
176
|
-
// Avant: export default Route.api({ ... });
|
|
177
|
-
// Après: export default Route.api({ ... }, 'Earn.Tasks.Missions.Get');
|
|
178
|
-
if (
|
|
179
|
-
declaration.type === 'CallExpression'
|
|
180
|
-
&&
|
|
181
|
-
declaration.callee.type === 'MemberExpression'
|
|
182
|
-
&&
|
|
183
|
-
declaration.callee.object.type === 'Identifier'
|
|
184
|
-
&&
|
|
185
|
-
declaration.callee.object.name === 'Route'
|
|
186
|
-
&&
|
|
187
|
-
declaration.callee.property.type === 'Identifier'
|
|
188
|
-
&&
|
|
189
|
-
declaration.callee.property.name === 'api'
|
|
190
|
-
&&
|
|
191
|
-
declaration.arguments.length === 1
|
|
192
|
-
&&
|
|
193
|
-
declaration.arguments[0].type === 'ObjectExpression'
|
|
194
|
-
) {
|
|
195
|
-
|
|
196
|
-
//console.log('METHODES API', this.cheminApi);
|
|
197
|
-
|
|
198
|
-
const chemin = this.cheminApi;
|
|
199
|
-
|
|
200
|
-
instruction.replaceWith(
|
|
201
|
-
t.exportDefaultDeclaration(
|
|
202
|
-
t.callExpression(
|
|
203
|
-
declaration.callee,
|
|
204
|
-
[
|
|
205
|
-
declaration.arguments[0],
|
|
206
|
-
t.stringLiteral(chemin)
|
|
207
|
-
]
|
|
208
|
-
)
|
|
209
|
-
)
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
post(state) {
|
|
217
|
-
|
|
218
|
-
if (this.nbDependances !== 0)
|
|
219
|
-
state.metadata['injection-dependances'] = this.dependances;
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
return plugin;
|
|
225
|
-
}
|