@tolgee/cli 1.0.2 → 1.1.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.
- package/README.md +11 -8
- package/dist/client/errors.js +1 -5
- package/dist/client/export.js +1 -4
- package/dist/client/import.js +5 -11
- package/dist/client/index.js +17 -23
- package/dist/client/internal/requester.js +14 -20
- package/dist/client/internal/schema.generated.js +1 -2
- package/dist/client/internal/schema.utils.js +1 -2
- package/dist/client/languages.js +1 -4
- package/dist/client/project.js +1 -4
- package/dist/commands/extract/check.js +11 -13
- package/dist/commands/extract/print.js +10 -12
- package/dist/commands/extract.js +8 -13
- package/dist/commands/login.js +16 -22
- package/dist/commands/pull.js +12 -14
- package/dist/commands/push.js +28 -30
- package/dist/commands/sync/compare.js +18 -23
- package/dist/commands/sync/sync.js +34 -39
- package/dist/commands/sync/syncUtils.js +10 -18
- package/dist/config/credentials.js +16 -25
- package/dist/config/tolgeerc.js +11 -14
- package/dist/constants.js +11 -18
- package/dist/extractor/extractor.js +59 -0
- package/dist/extractor/index.js +1 -2
- package/dist/extractor/machines/comments.js +78 -0
- package/dist/extractor/machines/react.js +37 -42
- package/dist/extractor/machines/shared/comments.js +3 -6
- package/dist/extractor/machines/shared/properties.js +60 -17
- package/dist/extractor/machines/svelte.js +490 -0
- package/dist/extractor/runner.js +8 -16
- package/dist/extractor/tokenizer.js +24 -20
- package/dist/extractor/warnings.js +9 -16
- package/dist/extractor/worker.js +23 -29
- package/dist/index.js +53 -58
- package/dist/options.js +14 -17
- package/dist/utils/ask.js +4 -12
- package/dist/utils/configPath.js +10 -10
- package/dist/utils/deferred.js +1 -5
- package/dist/utils/logger.js +8 -19
- package/dist/utils/moduleLoader.js +7 -14
- package/dist/utils/overwriteDir.js +13 -17
- package/dist/utils/zip.js +11 -16
- package/package.json +37 -28
- package/textmate/Svelte.tmLanguage +1084 -0
- package/textmate/THIRD_PARTY_NOTICE +13 -0
- package/textmate/TypeScript.tmLanguage +98 -90
- package/textmate/TypeScriptReact.tmLanguage +80 -72
- package/dist/extractor/presets/react.js +0 -29
@@ -0,0 +1,490 @@
|
|
1
|
+
import { createMachine, assign, send, forwardTo } from 'xstate';
|
2
|
+
import propertiesMachine from './shared/properties.js';
|
3
|
+
import commentsService from './shared/comments.js';
|
4
|
+
const VOID_KEY = { keyName: '', line: -1 };
|
5
|
+
export default createMachine({
|
6
|
+
predictableActionArguments: true,
|
7
|
+
id: 'svelteExtractor',
|
8
|
+
type: 'parallel',
|
9
|
+
context: {
|
10
|
+
children: '',
|
11
|
+
line: 0,
|
12
|
+
key: VOID_KEY,
|
13
|
+
useTranslate: null,
|
14
|
+
ignore: null,
|
15
|
+
keys: [],
|
16
|
+
warnings: [],
|
17
|
+
},
|
18
|
+
states: {
|
19
|
+
comments: {
|
20
|
+
invoke: {
|
21
|
+
id: 'comments',
|
22
|
+
src: () => commentsService,
|
23
|
+
},
|
24
|
+
on: {
|
25
|
+
// Service messages
|
26
|
+
MAGIC_COMMENT: [
|
27
|
+
{
|
28
|
+
actions: 'ignoreNextLine',
|
29
|
+
cond: (_ctx, evt) => evt.kind === 'ignore',
|
30
|
+
},
|
31
|
+
{
|
32
|
+
actions: 'pushImmediateKey',
|
33
|
+
cond: (_ctx, evt) => evt.kind === 'key',
|
34
|
+
},
|
35
|
+
],
|
36
|
+
WARNING: {
|
37
|
+
actions: 'pushWarning',
|
38
|
+
},
|
39
|
+
// Code messages
|
40
|
+
'comment.line.double-slash.ts': {
|
41
|
+
actions: send((_ctx, evt) => ({
|
42
|
+
type: 'COMMENT',
|
43
|
+
data: evt.token,
|
44
|
+
line: evt.line,
|
45
|
+
}), { to: 'comments' }),
|
46
|
+
},
|
47
|
+
'comment.block.ts': {
|
48
|
+
actions: send((_ctx, evt) => ({
|
49
|
+
type: 'COMMENT',
|
50
|
+
data: evt.token,
|
51
|
+
line: evt.line,
|
52
|
+
}), { to: 'comments' }),
|
53
|
+
},
|
54
|
+
'comment.block.svelte': {
|
55
|
+
actions: send((_ctx, evt) => ({
|
56
|
+
type: 'COMMENT',
|
57
|
+
data: evt.token,
|
58
|
+
line: evt.line,
|
59
|
+
}), { to: 'comments' }),
|
60
|
+
},
|
61
|
+
newline: {
|
62
|
+
actions: 'warnUnusedIgnore',
|
63
|
+
cond: (ctx, evt) => ctx.ignore?.type === 'ignore' && ctx.ignore.line === evt.line,
|
64
|
+
},
|
65
|
+
},
|
66
|
+
},
|
67
|
+
useTranslate: {
|
68
|
+
initial: 'idle',
|
69
|
+
states: {
|
70
|
+
idle: {
|
71
|
+
on: {
|
72
|
+
'entity.name.function.ts': {
|
73
|
+
target: 'func',
|
74
|
+
actions: 'storeLine',
|
75
|
+
cond: (_ctx, evt) => evt.token === 'useTranslate',
|
76
|
+
},
|
77
|
+
},
|
78
|
+
},
|
79
|
+
func: {
|
80
|
+
on: {
|
81
|
+
'*': 'idle',
|
82
|
+
newline: undefined,
|
83
|
+
'meta.block.ts': undefined,
|
84
|
+
'meta.var.expr.ts': undefined,
|
85
|
+
'meta.brace.round.ts': [
|
86
|
+
{
|
87
|
+
target: 'idle',
|
88
|
+
actions: 'consumeIgnoredLine',
|
89
|
+
cond: (ctx, evt) => ctx.ignore?.line === ctx.line &&
|
90
|
+
ctx.ignore.type === 'ignore' &&
|
91
|
+
evt.token === '(',
|
92
|
+
},
|
93
|
+
{
|
94
|
+
target: 'call',
|
95
|
+
cond: (_ctx, evt) => evt.token === '(',
|
96
|
+
},
|
97
|
+
],
|
98
|
+
},
|
99
|
+
},
|
100
|
+
call: {
|
101
|
+
on: {
|
102
|
+
'punctuation.definition.string.begin.ts': 'namespace',
|
103
|
+
'punctuation.definition.string.template.begin.ts': 'namespace',
|
104
|
+
'variable.other.readwrite.ts': {
|
105
|
+
target: 'idle',
|
106
|
+
actions: ['storeUseTranslate', 'markUseTranslateAsDynamic'],
|
107
|
+
},
|
108
|
+
'meta.brace.round.ts': {
|
109
|
+
target: 'idle',
|
110
|
+
cond: (_ctx, evt) => evt.token === ')',
|
111
|
+
actions: 'storeUseTranslate',
|
112
|
+
},
|
113
|
+
},
|
114
|
+
},
|
115
|
+
namespace: {
|
116
|
+
on: {
|
117
|
+
'*': {
|
118
|
+
target: 'namespace_end',
|
119
|
+
actions: 'storeNamespacedUseTranslate',
|
120
|
+
},
|
121
|
+
},
|
122
|
+
},
|
123
|
+
namespace_end: {
|
124
|
+
on: {
|
125
|
+
'punctuation.separator.comma.ts': 'idle',
|
126
|
+
'meta.brace.round.ts': 'idle',
|
127
|
+
'punctuation.definition.template-expression.begin.ts': {
|
128
|
+
target: 'idle',
|
129
|
+
actions: 'markUseTranslateAsDynamic',
|
130
|
+
},
|
131
|
+
'keyword.operator.arithmetic.ts': {
|
132
|
+
target: 'idle',
|
133
|
+
actions: 'markUseTranslateAsDynamic',
|
134
|
+
},
|
135
|
+
},
|
136
|
+
},
|
137
|
+
},
|
138
|
+
},
|
139
|
+
component: {
|
140
|
+
initial: 'idle',
|
141
|
+
states: {
|
142
|
+
idle: {
|
143
|
+
on: {
|
144
|
+
'punctuation.definition.tag.begin.svelte': {
|
145
|
+
target: 'tag',
|
146
|
+
actions: 'storeLine',
|
147
|
+
cond: (_ctx, evt) => evt.token === '<',
|
148
|
+
},
|
149
|
+
},
|
150
|
+
},
|
151
|
+
tag: {
|
152
|
+
on: {
|
153
|
+
'*': 'idle',
|
154
|
+
newline: undefined,
|
155
|
+
'meta.tag.start.svelte': undefined,
|
156
|
+
'support.class.component.svelte': [
|
157
|
+
{
|
158
|
+
target: 'idle',
|
159
|
+
actions: 'consumeIgnoredLine',
|
160
|
+
cond: (ctx, evt) => ctx.ignore?.line === ctx.line && evt.token === 'T',
|
161
|
+
},
|
162
|
+
{
|
163
|
+
target: 'props',
|
164
|
+
cond: (_ctx, evt) => evt.token === 'T',
|
165
|
+
},
|
166
|
+
],
|
167
|
+
},
|
168
|
+
},
|
169
|
+
props: {
|
170
|
+
invoke: {
|
171
|
+
id: 'propertiesMachine',
|
172
|
+
src: propertiesMachine,
|
173
|
+
onDone: [
|
174
|
+
{
|
175
|
+
target: 'idle',
|
176
|
+
actions: 'emitWarningFromParameters',
|
177
|
+
cond: 'isPropertiesDataDynamic',
|
178
|
+
},
|
179
|
+
{
|
180
|
+
target: 'idle',
|
181
|
+
actions: ['consumeParameters', 'pushKey'],
|
182
|
+
cond: (ctx, evt) => evt.data.lastEvent.token !== '/>' &&
|
183
|
+
((!ctx.key.keyName && !evt.data.keyName) ||
|
184
|
+
(!ctx.key.defaultValue && !evt.data.defaultValue)),
|
185
|
+
},
|
186
|
+
{
|
187
|
+
target: 'idle',
|
188
|
+
actions: ['consumeParameters', 'pushKey'],
|
189
|
+
},
|
190
|
+
],
|
191
|
+
},
|
192
|
+
on: {
|
193
|
+
'*': {
|
194
|
+
actions: forwardTo('propertiesMachine'),
|
195
|
+
},
|
196
|
+
},
|
197
|
+
},
|
198
|
+
},
|
199
|
+
},
|
200
|
+
t: {
|
201
|
+
initial: 'idle',
|
202
|
+
states: {
|
203
|
+
idle: {
|
204
|
+
on: {
|
205
|
+
'punctuation.definition.variable.svelte': {
|
206
|
+
target: 'dollar',
|
207
|
+
cond: (ctx, evt) => ctx.useTranslate !== null && evt.token === '$',
|
208
|
+
},
|
209
|
+
},
|
210
|
+
},
|
211
|
+
dollar: {
|
212
|
+
on: {
|
213
|
+
'*': 'idle',
|
214
|
+
'entity.name.function.ts': {
|
215
|
+
target: 'func',
|
216
|
+
actions: 'storeLine',
|
217
|
+
cond: (_ctx, evt) => evt.token === 't',
|
218
|
+
},
|
219
|
+
},
|
220
|
+
},
|
221
|
+
func: {
|
222
|
+
on: {
|
223
|
+
'*': 'idle',
|
224
|
+
newline: undefined,
|
225
|
+
'source.ts': undefined,
|
226
|
+
'meta.brace.round.ts': [
|
227
|
+
{
|
228
|
+
target: 'idle',
|
229
|
+
actions: 'consumeIgnoredLine',
|
230
|
+
cond: (ctx, evt) => ctx.ignore?.line === ctx.line && evt.token === '(',
|
231
|
+
},
|
232
|
+
{
|
233
|
+
target: 'call',
|
234
|
+
cond: (_ctx, evt) => evt.token === '(',
|
235
|
+
},
|
236
|
+
],
|
237
|
+
},
|
238
|
+
},
|
239
|
+
call: {
|
240
|
+
on: {
|
241
|
+
'punctuation.definition.string.begin.ts': 'param_string',
|
242
|
+
'punctuation.definition.string.template.begin.ts': 'param_string',
|
243
|
+
'variable.other.readwrite.ts': [
|
244
|
+
{
|
245
|
+
target: 'idle',
|
246
|
+
actions: 'dynamicOptions',
|
247
|
+
cond: (ctx) => !!ctx.key.keyName,
|
248
|
+
},
|
249
|
+
{
|
250
|
+
target: 'idle',
|
251
|
+
actions: 'dynamicKeyName',
|
252
|
+
},
|
253
|
+
],
|
254
|
+
'punctuation.definition.block.ts': {
|
255
|
+
target: 'param_object',
|
256
|
+
cond: (_ctx, evt) => evt.token === '{',
|
257
|
+
},
|
258
|
+
'meta.brace.round.ts': {
|
259
|
+
target: 'idle',
|
260
|
+
cond: (_ctx, evt) => evt.token === ')',
|
261
|
+
actions: 'pushKey',
|
262
|
+
},
|
263
|
+
},
|
264
|
+
},
|
265
|
+
param_string: {
|
266
|
+
on: {
|
267
|
+
'*': [
|
268
|
+
{
|
269
|
+
target: 'param_end',
|
270
|
+
actions: ['storeKeyName', 'storeKeyCurrentNamespace'],
|
271
|
+
cond: (ctx) => !ctx.key.keyName,
|
272
|
+
},
|
273
|
+
{
|
274
|
+
target: 'param_end',
|
275
|
+
actions: ['storeKeyDefault', 'storeKeyCurrentNamespace'],
|
276
|
+
cond: (ctx) => !!ctx.key.keyName,
|
277
|
+
},
|
278
|
+
],
|
279
|
+
},
|
280
|
+
},
|
281
|
+
param_end: {
|
282
|
+
on: {
|
283
|
+
'punctuation.separator.comma.ts': 'call',
|
284
|
+
'punctuation.definition.template-expression.begin.ts': [
|
285
|
+
{
|
286
|
+
target: 'param_end_warn',
|
287
|
+
actions: 'dynamicKeyDefault',
|
288
|
+
cond: (ctx) => !!ctx.key.defaultValue,
|
289
|
+
},
|
290
|
+
{
|
291
|
+
target: 'idle',
|
292
|
+
actions: 'dynamicKeyName',
|
293
|
+
},
|
294
|
+
],
|
295
|
+
'keyword.operator.arithmetic.ts': [
|
296
|
+
{
|
297
|
+
target: 'param_end_warn',
|
298
|
+
actions: 'dynamicKeyDefault',
|
299
|
+
cond: (ctx) => !!ctx.key.defaultValue,
|
300
|
+
},
|
301
|
+
{
|
302
|
+
target: 'idle',
|
303
|
+
actions: 'dynamicKeyName',
|
304
|
+
},
|
305
|
+
],
|
306
|
+
'meta.brace.round.ts': {
|
307
|
+
target: 'idle',
|
308
|
+
cond: (_ctx, evt) => evt.token === ')',
|
309
|
+
actions: 'pushKey',
|
310
|
+
},
|
311
|
+
},
|
312
|
+
},
|
313
|
+
param_end_warn: {
|
314
|
+
on: {
|
315
|
+
'punctuation.separator.comma.ts': 'call',
|
316
|
+
'meta.brace.round.ts': {
|
317
|
+
target: 'idle',
|
318
|
+
cond: (_ctx, evt) => evt.token === ')',
|
319
|
+
actions: 'pushKey',
|
320
|
+
},
|
321
|
+
},
|
322
|
+
},
|
323
|
+
param_object: {
|
324
|
+
invoke: {
|
325
|
+
id: 'propertiesMachine',
|
326
|
+
src: propertiesMachine,
|
327
|
+
data: {
|
328
|
+
depth: 1,
|
329
|
+
},
|
330
|
+
onDone: [
|
331
|
+
{
|
332
|
+
target: 'idle',
|
333
|
+
actions: 'emitWarningFromParameters',
|
334
|
+
cond: 'isPropertiesDataDynamic',
|
335
|
+
},
|
336
|
+
{
|
337
|
+
target: 'idle',
|
338
|
+
actions: ['consumeParameters', 'pushKey'],
|
339
|
+
},
|
340
|
+
],
|
341
|
+
},
|
342
|
+
on: {
|
343
|
+
'*': {
|
344
|
+
actions: forwardTo('propertiesMachine'),
|
345
|
+
},
|
346
|
+
},
|
347
|
+
},
|
348
|
+
},
|
349
|
+
},
|
350
|
+
},
|
351
|
+
}, {
|
352
|
+
guards: {
|
353
|
+
isPropertiesDataDynamic: (_ctx, evt) => evt.data.keyName === false || evt.data.namespace === false,
|
354
|
+
},
|
355
|
+
actions: {
|
356
|
+
storeLine: assign({
|
357
|
+
line: (_ctx, evt) => evt.line,
|
358
|
+
}),
|
359
|
+
ignoreNextLine: assign({
|
360
|
+
ignore: (_ctx, evt) => ({ type: 'ignore', line: evt.line + 1 }),
|
361
|
+
}),
|
362
|
+
consumeIgnoredLine: assign({
|
363
|
+
ignore: (_ctx, _evt) => null,
|
364
|
+
}),
|
365
|
+
warnUnusedIgnore: assign({
|
366
|
+
warnings: (ctx, evt) => [
|
367
|
+
...ctx.warnings,
|
368
|
+
{ warning: 'W_UNUSED_IGNORE', line: evt.line - 1 },
|
369
|
+
],
|
370
|
+
}),
|
371
|
+
storeUseTranslate: assign({
|
372
|
+
useTranslate: (_ctx, _evt) => '',
|
373
|
+
}),
|
374
|
+
storeNamespacedUseTranslate: assign({
|
375
|
+
useTranslate: (_ctx, evt) => evt.token,
|
376
|
+
}),
|
377
|
+
markUseTranslateAsDynamic: assign({
|
378
|
+
useTranslate: (_ctx, _evt) => false,
|
379
|
+
warnings: (ctx, _evt) => [
|
380
|
+
...ctx.warnings,
|
381
|
+
{ warning: 'W_DYNAMIC_NAMESPACE', line: ctx.line },
|
382
|
+
],
|
383
|
+
}),
|
384
|
+
consumeParameters: assign({
|
385
|
+
key: (ctx, evt) => ({
|
386
|
+
keyName: ctx.key.keyName || evt.data.keyName,
|
387
|
+
defaultValue: ctx.key.defaultValue || evt.data.defaultValue || undefined,
|
388
|
+
namespace: evt.data.namespace ?? ctx.key.namespace,
|
389
|
+
line: ctx.line,
|
390
|
+
}),
|
391
|
+
warnings: (ctx, evt) => {
|
392
|
+
if (evt.data.defaultValue !== false)
|
393
|
+
return ctx.warnings;
|
394
|
+
return [
|
395
|
+
...ctx.warnings,
|
396
|
+
{ warning: 'W_DYNAMIC_DEFAULT_VALUE', line: ctx.line },
|
397
|
+
];
|
398
|
+
},
|
399
|
+
}),
|
400
|
+
emitWarningFromParameters: assign({
|
401
|
+
warnings: (ctx, evt) => [
|
402
|
+
...ctx.warnings,
|
403
|
+
{
|
404
|
+
warning: evt.data.keyName === false
|
405
|
+
? 'W_DYNAMIC_KEY'
|
406
|
+
: 'W_DYNAMIC_NAMESPACE',
|
407
|
+
line: ctx.line,
|
408
|
+
},
|
409
|
+
],
|
410
|
+
key: (_ctx, _evt) => VOID_KEY,
|
411
|
+
}),
|
412
|
+
storeKeyName: assign({
|
413
|
+
key: (ctx, evt) => ({ ...ctx.key, keyName: evt.token }),
|
414
|
+
}),
|
415
|
+
storeKeyDefault: assign({
|
416
|
+
key: (ctx, evt) => ({ ...ctx.key, defaultValue: evt.token }),
|
417
|
+
}),
|
418
|
+
storeKeyCurrentNamespace: assign({
|
419
|
+
key: (ctx, _evt) => ({
|
420
|
+
...ctx.key,
|
421
|
+
namespace: ctx.useTranslate !== null ? ctx.useTranslate : undefined,
|
422
|
+
}),
|
423
|
+
}),
|
424
|
+
dynamicKeyName: assign({
|
425
|
+
warnings: (ctx, _evt) => [
|
426
|
+
...ctx.warnings,
|
427
|
+
{ warning: 'W_DYNAMIC_KEY', line: ctx.line },
|
428
|
+
],
|
429
|
+
key: (_ctx, _evt) => VOID_KEY,
|
430
|
+
}),
|
431
|
+
dynamicKeyDefault: assign({
|
432
|
+
key: (ctx, _evt) => ({ ...ctx.key, defaultValue: undefined }),
|
433
|
+
warnings: (ctx, _evt) => [
|
434
|
+
...ctx.warnings,
|
435
|
+
{ warning: 'W_DYNAMIC_DEFAULT_VALUE', line: ctx.line },
|
436
|
+
],
|
437
|
+
}),
|
438
|
+
dynamicOptions: assign({
|
439
|
+
key: (_ctx, _evt) => VOID_KEY,
|
440
|
+
warnings: (ctx, _evt) => [
|
441
|
+
...ctx.warnings,
|
442
|
+
{ warning: 'W_DYNAMIC_OPTIONS', line: ctx.line },
|
443
|
+
],
|
444
|
+
}),
|
445
|
+
pushKey: assign({
|
446
|
+
warnings: (ctx, _evt) => {
|
447
|
+
if (!ctx.key.keyName || ctx.key.namespace !== false)
|
448
|
+
return ctx.warnings;
|
449
|
+
return [
|
450
|
+
...ctx.warnings,
|
451
|
+
{ warning: 'W_UNRESOLVABLE_NAMESPACE', line: ctx.line },
|
452
|
+
];
|
453
|
+
},
|
454
|
+
keys: (ctx, _evt) => {
|
455
|
+
if (!ctx.key.keyName || ctx.key.namespace === false)
|
456
|
+
return ctx.keys;
|
457
|
+
return [
|
458
|
+
...ctx.keys,
|
459
|
+
{
|
460
|
+
keyName: ctx.key.keyName.trim(),
|
461
|
+
namespace: ctx.key.namespace === ''
|
462
|
+
? undefined
|
463
|
+
: ctx.key.namespace?.trim(),
|
464
|
+
defaultValue: ctx.key.defaultValue?.trim().replace(/\s+/g, ' '),
|
465
|
+
line: ctx.line,
|
466
|
+
},
|
467
|
+
];
|
468
|
+
},
|
469
|
+
key: (_ctx, _evt) => ({ keyName: '', line: 0 }),
|
470
|
+
}),
|
471
|
+
pushImmediateKey: assign({
|
472
|
+
ignore: (_ctx, evt) => ({ type: 'key', line: evt.line + 1 }),
|
473
|
+
keys: (ctx, evt) => [
|
474
|
+
...ctx.keys,
|
475
|
+
{
|
476
|
+
keyName: evt.keyName,
|
477
|
+
namespace: evt.namespace,
|
478
|
+
defaultValue: evt.defaultValue,
|
479
|
+
line: evt.line,
|
480
|
+
},
|
481
|
+
],
|
482
|
+
}),
|
483
|
+
pushWarning: assign({
|
484
|
+
warnings: (ctx, evt) => [
|
485
|
+
...ctx.warnings,
|
486
|
+
{ warning: evt.kind, line: evt.line },
|
487
|
+
],
|
488
|
+
}),
|
489
|
+
},
|
490
|
+
});
|
package/dist/extractor/runner.js
CHANGED
@@ -1,19 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const util_1 = require("util");
|
7
|
-
const glob = (0, util_1.promisify)(glob_1.glob);
|
8
|
-
exports.NullNamespace = Symbol('namespace.null');
|
9
|
-
async function extractKeysFromFile(file, extractor) {
|
10
|
-
return (0, worker_1.callWorker)({
|
1
|
+
import { glob } from 'glob';
|
2
|
+
import { callWorker } from './worker.js';
|
3
|
+
export const NullNamespace = Symbol('namespace.null');
|
4
|
+
export async function extractKeysFromFile(file, extractor) {
|
5
|
+
return callWorker({
|
11
6
|
extractor: extractor,
|
12
7
|
file: file,
|
13
8
|
});
|
14
9
|
}
|
15
|
-
|
16
|
-
async function extractKeysOfFiles(filesPattern, extractor) {
|
10
|
+
export async function extractKeysOfFiles(filesPattern, extractor) {
|
17
11
|
const files = await glob(filesPattern, { nodir: true });
|
18
12
|
const result = new Map();
|
19
13
|
await Promise.all(files.map(async (file) => {
|
@@ -22,12 +16,11 @@ async function extractKeysOfFiles(filesPattern, extractor) {
|
|
22
16
|
}));
|
23
17
|
return result;
|
24
18
|
}
|
25
|
-
|
26
|
-
function filterExtractionResult(data) {
|
19
|
+
export function filterExtractionResult(data) {
|
27
20
|
const result = Object.create(null);
|
28
21
|
for (const { keys } of data.values()) {
|
29
22
|
for (const key of keys) {
|
30
|
-
const namespace = key.namespace ||
|
23
|
+
const namespace = key.namespace || NullNamespace;
|
31
24
|
if (!(namespace in result)) {
|
32
25
|
result[namespace] = new Map();
|
33
26
|
}
|
@@ -36,4 +29,3 @@ function filterExtractionResult(data) {
|
|
36
29
|
}
|
37
30
|
return result;
|
38
31
|
}
|
39
|
-
exports.filterExtractionResult = filterExtractionResult;
|
@@ -1,33 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const
|
7
|
-
const GRAMMAR_PATH = (0, path_1.join)(__dirname, '..', '..', 'textmate');
|
1
|
+
import { extname } from 'path';
|
2
|
+
import { readFile } from 'fs/promises';
|
3
|
+
import { createRequire } from 'module';
|
4
|
+
import TextMate from 'vscode-textmate';
|
5
|
+
import Oniguruma from 'vscode-oniguruma';
|
6
|
+
const GRAMMAR_PATH = new URL('../../textmate/', import.meta.url);
|
8
7
|
const GrammarFiles = {
|
9
|
-
["source.ts" /* Grammar.TYPESCRIPT */]:
|
10
|
-
["source.tsx" /* Grammar.TYPESCRIPT_TSX */]:
|
8
|
+
["source.ts" /* Grammar.TYPESCRIPT */]: new URL('TypeScript.tmLanguage', GRAMMAR_PATH),
|
9
|
+
["source.tsx" /* Grammar.TYPESCRIPT_TSX */]: new URL('TypeScriptReact.tmLanguage', GRAMMAR_PATH),
|
10
|
+
["source.svelte" /* Grammar.SVELTE */]: new URL('Svelte.tmLanguage', GRAMMAR_PATH),
|
11
11
|
};
|
12
12
|
let oniguruma;
|
13
13
|
let registry;
|
14
14
|
async function initializeOniguruma() {
|
15
|
+
const require = createRequire(import.meta.url);
|
15
16
|
const wasmBlobPath = require
|
16
17
|
.resolve('vscode-oniguruma')
|
17
18
|
.replace('main.js', 'onig.wasm');
|
18
|
-
const wasmBlob = await
|
19
|
-
await
|
19
|
+
const wasmBlob = await readFile(wasmBlobPath);
|
20
|
+
await Oniguruma.loadWASM(wasmBlob);
|
20
21
|
return {
|
21
|
-
createOnigScanner: (patterns) => new
|
22
|
-
createOnigString: (s) => new
|
22
|
+
createOnigScanner: (patterns) => new Oniguruma.OnigScanner(patterns),
|
23
|
+
createOnigString: (s) => new Oniguruma.OnigString(s),
|
23
24
|
};
|
24
25
|
}
|
25
26
|
async function loadGrammar(scope) {
|
26
27
|
const file = GrammarFiles[scope];
|
27
28
|
if (!file)
|
28
29
|
return null;
|
29
|
-
const grammar = await
|
30
|
-
return
|
30
|
+
const grammar = await readFile(file, 'utf8');
|
31
|
+
return grammar.startsWith('{')
|
32
|
+
? JSON.parse(grammar)
|
33
|
+
: TextMate.parseRawGrammar(grammar);
|
31
34
|
}
|
32
35
|
function extnameToGrammar(extname) {
|
33
36
|
switch (extname) {
|
@@ -41,10 +44,12 @@ function extnameToGrammar(extname) {
|
|
41
44
|
case '.jsx':
|
42
45
|
case '.tsx':
|
43
46
|
return "source.tsx" /* Grammar.TYPESCRIPT_TSX */;
|
47
|
+
case '.svelte':
|
48
|
+
return "source.svelte" /* Grammar.SVELTE */;
|
44
49
|
}
|
45
50
|
}
|
46
51
|
function tokenize(code, grammar) {
|
47
|
-
let stack =
|
52
|
+
let stack = TextMate.INITIAL;
|
48
53
|
let linePtr = 0;
|
49
54
|
const lines = code.split('\n');
|
50
55
|
const tokens = [];
|
@@ -79,16 +84,16 @@ function tokenize(code, grammar) {
|
|
79
84
|
}
|
80
85
|
return tokens;
|
81
86
|
}
|
82
|
-
async function
|
87
|
+
export default async function (code, fileName) {
|
83
88
|
if (!oniguruma) {
|
84
89
|
// Lazily initialize the WebAssembly runtime
|
85
90
|
oniguruma = initializeOniguruma();
|
86
|
-
registry = new
|
91
|
+
registry = new TextMate.Registry({
|
87
92
|
onigLib: oniguruma,
|
88
93
|
loadGrammar: loadGrammar,
|
89
94
|
});
|
90
95
|
}
|
91
|
-
const fileType =
|
96
|
+
const fileType = extname(fileName);
|
92
97
|
const grammarName = extnameToGrammar(fileType);
|
93
98
|
if (!grammarName) {
|
94
99
|
throw new Error(`Cannot find grammar for file type ${fileType}`);
|
@@ -99,4 +104,3 @@ async function default_1(code, fileName) {
|
|
99
104
|
}
|
100
105
|
return tokenize(code, grammar);
|
101
106
|
}
|
102
|
-
exports.default = default_1;
|
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exports.emitGitHubWarning = exports.dumpWarnings = exports.WarningMessages = void 0;
|
4
|
-
const path_1 = require("path");
|
5
|
-
exports.WarningMessages = {
|
1
|
+
import { relative } from 'path';
|
2
|
+
export const WarningMessages = {
|
6
3
|
W_DYNAMIC_KEY: {
|
7
4
|
name: 'Dynamic key',
|
8
5
|
description: 'The key not static and cannot be extracted automatically. This key will be ignored.\n\nUse @tolgee-key or @tolgee-ignore to suppress this warning.',
|
@@ -42,7 +39,7 @@ exports.WarningMessages = {
|
|
42
39
|
* @param extractionResult Extraction result to dump warnings from.
|
43
40
|
* @returns Count of emitted warnings in the extraction.
|
44
41
|
*/
|
45
|
-
function dumpWarnings(extractionResult) {
|
42
|
+
export function dumpWarnings(extractionResult) {
|
46
43
|
let warningCount = 0;
|
47
44
|
for (const [file, { warnings }] of extractionResult.entries()) {
|
48
45
|
if (warnings.length) {
|
@@ -51,8 +48,8 @@ function dumpWarnings(extractionResult) {
|
|
51
48
|
}
|
52
49
|
console.error(file);
|
53
50
|
for (const warning of warnings) {
|
54
|
-
const warnText = warning.warning in
|
55
|
-
?
|
51
|
+
const warnText = warning.warning in WarningMessages
|
52
|
+
? WarningMessages[warning.warning].name
|
56
53
|
: warning.warning;
|
57
54
|
console.error('\tline %d: %s', warning.line, warnText);
|
58
55
|
emitGitHubWarning(warning.warning, file, warning.line);
|
@@ -65,15 +62,12 @@ function dumpWarnings(extractionResult) {
|
|
65
62
|
}
|
66
63
|
return warningCount;
|
67
64
|
}
|
68
|
-
|
69
|
-
// TODO: Revisit this function and turn it into an actual GitHub Action Annotation?
|
70
|
-
// https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#update-a-check-run
|
71
|
-
function emitGitHubWarning(warning, file, line) {
|
65
|
+
export function emitGitHubWarning(warning, file, line) {
|
72
66
|
if (!process.env.GITHUB_ACTIONS)
|
73
67
|
return;
|
74
|
-
file =
|
75
|
-
if (warning in
|
76
|
-
const { name, description } =
|
68
|
+
file = relative(process.env.GITHUB_WORKSPACE ?? process.cwd(), file);
|
69
|
+
if (warning in WarningMessages) {
|
70
|
+
const { name, description } = WarningMessages[warning];
|
77
71
|
const encodedDescription = description
|
78
72
|
.replaceAll('%', '%25')
|
79
73
|
.replaceAll('\r', '%0D')
|
@@ -86,4 +80,3 @@ function emitGitHubWarning(warning, file, line) {
|
|
86
80
|
}
|
87
81
|
console.log(`::warning file=${file},line=${line}::${warning}`);
|
88
82
|
}
|
89
|
-
exports.emitGitHubWarning = emitGitHubWarning;
|