@@ -4,35 +4,8 @@ const path = require("path");
4
4
import { File , Input , Output } from "./shared/IFile" ;
5
5
import logger from "./shared/logger" ;
6
6
import pathResolver from "./utils/path-resolver" ;
7
+ import { REGEX_SELECTORS } from "./utils/regexSelectors" ;
7
8
8
- // selectors
9
- const componentSelector = / e x p o r t ( \s + ) c l a s s ( \s + ) [ a - z A - Z 0 - 9 - _ ] + / g;
10
- const componentHTMLselector = / s e l e c t o r : ( \s + ) ( \" | ' ) [ a - z A - Z - _ ] + ( \" | ' ) / g;
11
-
12
- // inputs
13
- // @Input () variableName; and @Input() variableName
14
- const regularInputSelector = / @ I n p u t \( \) ( \s + ) [ a - z A - Z 0 - 9 - _ ] + ( ; | ) / g;
15
- // @Input () variableName: type; and @Input() variableName: number = 9;
16
- const regularInputWithTypeSelector = / @ I n p u t \( \) ( \s + ) [ a - z A - Z 0 - 9 - _ ] + : ( \s + ) [ a - z A - Z 0 - 9 - _ ] + ( ( ; | ) | ( \s + ) [ a - z A - Z 0 - 9 - _ ] + ( \s + ) = ( \s + ) [ a - z A - Z 0 - 9 - _ ] + ( ; | ) ) / g;
17
- // @Input ('inputName') varName: type; and @Input("inputName") varName: type
18
- const customNameInputWithTypeSelector = / @ I n p u t \( ( ' | " ) [ a - z A - Z 0 - 9 - _ ] + ( ' | " ) \) ( \s + ) [ a - z A - Z 0 - 9 - _ ] + : ( \s + ) [ a - z A - Z 0 - 9 - _ ] + \; / g;
19
- const regularInputLiteralTypeSelector = / @ I n p u t \( \) ( \s + ) [ a - z A - Z 0 - 9 - _ ] + : ( ( \s + ) ( ( ' | " ) [ a - z A - Z 0 - 9 - _ ] + ( ' | " ) ( ( \s + ) \| ) ) ) + ( \s + ) ( ' | " ) [ a - z A - Z 0 - 9 - _ ] + ( ' | " ) ( ; | : | ) / g;
20
- //@Input () set foo(value) {}
21
- const setterInputSelector = / @ I n p u t \( \) ( \s + ) s e t ( \s + ) [ a - z A - Z 0 - 9 - _ ] + \( [ a - z A - Z 0 - 9 - _ ] + \) ( \s + ) / g;
22
- //@Input () set foo(value: type) {}
23
- const setterInputWithTypeSelector = / @ I n p u t \( \) ( \s + ) s e t ( \s + ) [ a - z A - Z 0 - 9 - _ ] + \( [ a - z A - Z 0 - 9 - _ ] + : ( \s + ) [ a - z A - Z 0 - 9 - _ ] + \) ( \s + ) / g;
24
- // @Input ('inputNameC') varName = 'adv';
25
- const setterInputCustomNameSelector = / @ I n p u t \( ( " | ' ) [ a - z A - Z 0 - 9 - _ ] + ( " | ' ) \) ( \s + ) [ a - z A - Z 0 - 9 - _ ] + ( \s + ) = ( \s + ) [ A - Z a - z 0 - 9 " ' ] + ( ; | ) / g;
26
- //@Input () set foo(value: 'type1' | 'type2') {}
27
- const setterInputLiteralTypeSelector = / @ I n p u t \( \) ( \s + ) s e t ( \s + ) [ a - z A - Z 0 - 9 - _ ] + \( [ a - z A - Z 0 - 9 - _ ] + : ( ( \s + ) ( ' | " ) [ a - z A - Z 0 - 9 - _ ] + ( ' | " ) ( \s + ) \| ) + ( \s ) ( ' | " ) [ a - z A - Z 0 - 9 - _ ] + ( ' | " ) \) / g;
28
-
29
- // outputs
30
- // @Output () buttonClick: EventEmitter<any> = new EventEmitter()
31
- const regularOutputSelector = / @ O u t p u t \( \) ( \s + ) [ a - z A - Z 0 - 9 - _ ] + : ( \s + ) E v e n t E m i t t e r < [ a - z A - Z 0 - 9 - _ ] + > ( \s + ) = ( \s + ) n e w ( \s + ) E v e n t E m i t t e r \( \) ; / g;
32
-
33
- // other
34
- const extendedClassSelector = / e x p o r t ( \s + ) c l a s s ( \s + ) [ a - z A - Z 0 - 9 - _ ] + ( \s + ) e x t e n d s ( \s + ) [ a - z A - Z 0 - 9 - _ ] + / g;
35
- const extendedClassPathSelector = / i m p o r t ( \s + ) { ( \s + ) [ a - z A - Z 0 - 9 - _ ] + ( \s + ) } ( \s + ) f r o m ( \s + ) [ \/ \@ A - Z a - z 0 - 9 . " ' _ - ] + / g;
36
9
// TODO: class implementation with inputs/outputs defined
37
10
38
11
// TODO: Test in other OS (github actions)
@@ -62,7 +35,8 @@ export const parser = (filePaths: Array<string>): Array<File> => {
62
35
continue ;
63
36
}
64
37
65
- let fileNameData : Array < string > = file ?. match ( componentSelector ) || [ ] ;
38
+ let fileNameData : Array < string > =
39
+ file ?. match ( REGEX_SELECTORS . componentSelector ) || [ ] ;
66
40
if ( fileNameData . length === 0 ) {
67
41
logger . warn ( "Component tag not defined by any class." ) ;
68
42
continue ;
@@ -77,7 +51,7 @@ export const parser = (filePaths: Array<string>): Array<File> => {
77
51
if ( containsComponentDef ) {
78
52
// match returns a string not an array
79
53
let componentSelectorData : Array < string > =
80
- file ?. match ( componentHTMLselector ) || [ ] ;
54
+ file ?. match ( REGEX_SELECTORS . componentHTMLselector ) || [ ] ;
81
55
if ( componentSelectorData . length === 0 ) {
82
56
logger . warn (
83
57
"Component doesn't define any selector but contains @Component anotation."
@@ -93,7 +67,7 @@ export const parser = (filePaths: Array<string>): Array<File> => {
93
67
// Input() foo: 'type1' | 'type2'
94
68
let inputs : Array < Input > = [ ] ;
95
69
let inputsData : Array < string > =
96
- file ?. match ( regularInputLiteralTypeSelector ) || [ ] ;
70
+ file ?. match ( REGEX_SELECTORS . regularInputLiteralTypeSelector ) || [ ] ;
97
71
for ( let input of inputsData ) {
98
72
logger . log ( "inputs parsed:" , inputsData ) ;
99
73
let tmp : Array < string > = input . replace ( / ( \s ) + / g, " " ) . split ( " " ) ;
@@ -108,23 +82,25 @@ export const parser = (filePaths: Array<string>): Array<File> => {
108
82
type,
109
83
} ) ;
110
84
}
111
- file = file . replace ( regularInputLiteralTypeSelector , "" ) ;
85
+ file = file . replace ( REGEX_SELECTORS . regularInputLiteralTypeSelector , "" ) ;
112
86
113
87
// @Input () variableName: type; and @Input() variableName: number = 9;
114
88
inputsData = [ ] ;
115
- inputsData = file ?. match ( regularInputWithTypeSelector ) || [ ] ;
89
+ inputsData =
90
+ file ?. match ( REGEX_SELECTORS . regularInputWithTypeSelector ) || [ ] ;
116
91
for ( let input of inputsData ) {
117
92
let tmp : Array < string > = input . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
118
93
inputs . push ( {
119
94
inputName : tmp [ 1 ] . replace ( ":" , "" ) ,
120
95
type : tmp [ 2 ] . replace ( ";" , "" ) ,
121
96
} ) ;
122
97
}
123
- file = file . replace ( regularInputWithTypeSelector , "" ) ;
98
+ file = file . replace ( REGEX_SELECTORS . regularInputWithTypeSelector , "" ) ;
124
99
125
100
inputsData = [ ] ;
126
101
// @Input ('inputName') varName: type; and @Input("inputName") varName: type
127
- inputsData = file ?. match ( customNameInputWithTypeSelector ) || [ ] ;
102
+ inputsData =
103
+ file ?. match ( REGEX_SELECTORS . customNameInputWithTypeSelector ) || [ ] ;
128
104
for ( let input of inputsData ) {
129
105
let tmp : Array < string > = input . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
130
106
const inputName = ( tmp [ 0 ] . match ( / ( ' | " ) [ a - z A - Z 0 - 9 - _ ] + ( ' | " ) / g) ||
@@ -134,12 +110,13 @@ export const parser = (filePaths: Array<string>): Array<File> => {
134
110
type : tmp [ 2 ] . replace ( ";" , "" ) ,
135
111
} ) ;
136
112
}
137
- file = file . replace ( customNameInputWithTypeSelector , "" ) ;
113
+ file = file . replace ( REGEX_SELECTORS . customNameInputWithTypeSelector , "" ) ;
138
114
139
115
// @Input ('inputNameC') varName = 'adv';
140
116
// @Input ("inputNameD") varName = 2354;
141
117
inputsData = [ ] ;
142
- inputsData = file ?. match ( setterInputCustomNameSelector ) || [ ] ;
118
+ inputsData =
119
+ file ?. match ( REGEX_SELECTORS . setterInputCustomNameSelector ) || [ ] ;
143
120
for ( let input of inputsData ) {
144
121
let tmp : Array < string > = input . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
145
122
const inputName = ( tmp [ 0 ] . match ( / ( ' | " ) [ a - z A - Z 0 - 9 - _ ] + ( ' | " ) / g) || [
@@ -150,11 +127,11 @@ export const parser = (filePaths: Array<string>): Array<File> => {
150
127
type : undefined ,
151
128
} ) ;
152
129
}
153
- file = file . replace ( setterInputCustomNameSelector , "" ) ;
130
+ file = file . replace ( REGEX_SELECTORS . setterInputCustomNameSelector , "" ) ;
154
131
155
132
//@Input () set foo(value) {}
156
133
inputsData = [ ] ;
157
- inputsData = file ?. match ( setterInputSelector ) || [ ] ;
134
+ inputsData = file ?. match ( REGEX_SELECTORS . setterInputSelector ) || [ ] ;
158
135
for ( let input of inputsData ) {
159
136
let tmp : Array < string > = input . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
160
137
const inputName = tmp [ 2 ] . replace ( / ( \s + ) / g, "" ) . split ( "(" ) [ 0 ] ;
@@ -163,11 +140,11 @@ export const parser = (filePaths: Array<string>): Array<File> => {
163
140
type : undefined ,
164
141
} ) ;
165
142
}
166
- file = file . replace ( setterInputSelector , "" ) ;
143
+ file = file . replace ( REGEX_SELECTORS . setterInputSelector , "" ) ;
167
144
168
145
//@Input () set foo(value: type) {}
169
146
inputsData = [ ] ;
170
- inputsData = file ?. match ( setterInputWithTypeSelector ) || [ ] ;
147
+ inputsData = file ?. match ( REGEX_SELECTORS . setterInputWithTypeSelector ) || [ ] ;
171
148
for ( let input of inputsData ) {
172
149
let tmp : Array < string > = input . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
173
150
const inputName = tmp [ 2 ] . replace ( / ( \s + ) / g, "" ) . split ( "(" ) [ 0 ] ;
@@ -177,11 +154,12 @@ export const parser = (filePaths: Array<string>): Array<File> => {
177
154
type,
178
155
} ) ;
179
156
}
180
- file = file . replace ( setterInputWithTypeSelector , "" ) ;
157
+ file = file . replace ( REGEX_SELECTORS . setterInputWithTypeSelector , "" ) ;
181
158
182
159
//@Input () set foo(value: 'type1' | 'type2') {}
183
160
inputsData = [ ] ;
184
- inputsData = file ?. match ( setterInputLiteralTypeSelector ) || [ ] ;
161
+ inputsData =
162
+ file ?. match ( REGEX_SELECTORS . setterInputLiteralTypeSelector ) || [ ] ;
185
163
for ( let input of inputsData ) {
186
164
let tmp : Array < string > = input . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
187
165
const inputName = tmp [ 2 ] . replace ( / ( \s + ) / g, "" ) . split ( "(" ) [ 0 ] ;
@@ -195,12 +173,12 @@ export const parser = (filePaths: Array<string>): Array<File> => {
195
173
type,
196
174
} ) ;
197
175
}
198
- file = file . replace ( setterInputLiteralTypeSelector , "" ) ;
176
+ file = file . replace ( REGEX_SELECTORS . setterInputLiteralTypeSelector , "" ) ;
199
177
200
178
// @Input () variableName; and @Input() variableName. Also for now we will parse
201
179
// in this part of the code @Input () variableName = value and @Input() variableName = value;
202
180
inputsData = [ ] ;
203
- inputsData = file ?. match ( regularInputSelector ) || [ ] ;
181
+ inputsData = file ?. match ( REGEX_SELECTORS . regularInputSelector ) || [ ] ;
204
182
for ( let input of inputsData ) {
205
183
let tmp : Array < string > = input . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
206
184
const inputName = tmp [ 1 ] . replace ( ";" , "" ) ;
@@ -212,12 +190,13 @@ export const parser = (filePaths: Array<string>): Array<File> => {
212
190
type : undefined ,
213
191
} ) ;
214
192
}
215
- file = file . replace ( regularInputSelector , "" ) ;
193
+ file = file . replace ( REGEX_SELECTORS . regularInputSelector , "" ) ;
216
194
logger . log ( "Inputs detected:" , inputs ) ;
217
195
218
196
let outputs : Array < Output > = [ ] ;
219
197
// only @Output () buttonClick: EventEmitter<any> = new EventEmitter(); for now
220
- let outputsData : Array < string > = file ?. match ( regularOutputSelector ) || [ ] ;
198
+ let outputsData : Array < string > =
199
+ file ?. match ( REGEX_SELECTORS . regularOutputSelector ) || [ ] ;
221
200
for ( let output of outputsData ) {
222
201
let tmp : Array < string > = output . replace ( / ( \s + ) / g, " " ) . split ( " " ) ;
223
202
outputs . push ( {
@@ -228,27 +207,27 @@ export const parser = (filePaths: Array<string>): Array<File> => {
228
207
. replace ( "<" , "" ) ,
229
208
} ) ;
230
209
}
231
- file = file . replace ( regularOutputSelector , "" ) ;
210
+ file = file . replace ( REGEX_SELECTORS . regularOutputSelector , "" ) ;
232
211
logger . log ( "Outputs detected:" , outputs ) ;
233
212
234
213
let extendedClassPath ;
235
- if ( file ?. match ( extendedClassSelector ) ) {
214
+ if ( file ?. match ( REGEX_SELECTORS . extendedClassSelector ) ) {
236
215
// we should see if the extended class is in tmp and if not extract the inputs defined inside
237
216
let matchExtendedClass : Array < string > =
238
- file ?. match ( extendedClassSelector ) || [ ] ;
217
+ file ?. match ( REGEX_SELECTORS . extendedClassSelector ) || [ ] ;
239
218
// resolve the path of the class
240
219
let extendedClass : string = matchExtendedClass [ 0 ]
241
220
. replace ( / ( \s + ) / g, " " )
242
221
. split ( " " ) [ 4 ] ;
243
222
logger . log ( "extendedClassName:" , extendedClass ) ;
244
223
let matchExtendedClassPath : Array < string > =
245
- file ?. match ( extendedClassPathSelector ) || [ ] ;
224
+ file ?. match ( REGEX_SELECTORS . extendedClassPathSelector ) || [ ] ;
246
225
247
226
extendedClassPath = pathResolver . resolve (
248
227
filePath ,
249
228
matchExtendedClassPath [ 0 ]
250
229
) ;
251
-
230
+
252
231
logger . log ( "path:" , extendedClassPath ) ;
253
232
}
254
233
0 commit comments