@spyglassmc/mcdoc-cli 0.1.8 → 0.1.10

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.
@@ -1,5 +1,4 @@
1
- import type { AstNode } from '@spyglassmc/core';
2
- import type { Service } from '@spyglassmc/core';
1
+ import type { AstNode, Service } from '@spyglassmc/core';
3
2
  import type walk from 'klaw';
4
3
  import type { Logger } from '../index.js';
5
4
  type Args = {
@@ -16,8 +16,9 @@ export async function generate(project_path, generated_path, args, doc_file, ser
16
16
  const path = parse(fileURLToPath(doc.uri));
17
17
  let resource = join(path.dir.replace(`${project_path}`, ''), path.name).replace(/^[\/\\]/, '');
18
18
  // remove windows cruft
19
- if (resource.includes('\\'))
19
+ if (resource.includes('\\')) {
20
20
  resource = resource.replaceAll('\\', '/');
21
+ }
21
22
  logger.info(`parsing ${resource}\n`);
22
23
  if (node.children[0]) {
23
24
  const children = node.children;
@@ -27,11 +28,13 @@ export async function generate(project_path, generated_path, args, doc_file, ser
27
28
  /* @ts-ignore */
28
29
  child.self = self;
29
30
  /* @ts-ignore */
30
- if (_child.parent)
31
+ if (_child.parent) {
31
32
  child.parent = parent;
33
+ }
32
34
  /* @ts-ignore */
33
- if (_child.parentMap)
35
+ if (_child.parentMap) {
34
36
  child.parentMap = parent;
37
+ }
35
38
  if (_child.children) {
36
39
  child.children = [];
37
40
  for (const [i, __child] of Object.entries(_child.children)) {
@@ -71,9 +74,7 @@ export async function generate(project_path, generated_path, args, doc_file, ser
71
74
  switch (fourBack?.type) {
72
75
  case 'mcdoc:struct/field/pair':
73
76
  {
74
- const key = fourBack.children?.find(child => child.type === 'mcdoc:identifier'
75
- /* @ts-ignore */
76
- )?.value;
77
+ const key = fourBack.children?.find(child => child.type === 'mcdoc:identifier')?.value;
77
78
  const sixBack = fourBack.parent?.parent;
78
79
  const foundRoot = sixBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
79
80
  if (key) {
@@ -83,30 +84,19 @@ export async function generate(project_path, generated_path, args, doc_file, ser
83
84
  else {
84
85
  // This is another nested anonymous struct
85
86
  // TODO: Yeah this should be recursive and smarter but I'm lazy
86
- const parentKey = sixBack?.parent
87
- ?.children?.find(child => child.type === 'mcdoc:identifier'
88
- /* @ts-ignore */
89
- )?.value;
90
- const actualRoot = sixBack?.parent
91
- ?.parent?.parent?.children?.find(child => child.type ===
92
- 'mcdoc:identifier')?.value;
93
- container =
94
- `${actualRoot}.${parentKey}.${key}`;
87
+ const parentKey = sixBack?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
88
+ const actualRoot = sixBack?.parent?.parent?.parent?.children
89
+ ?.find(child => child.type === 'mcdoc:identifier')?.value;
90
+ container = `${actualRoot}.${parentKey}.${key}`;
95
91
  }
96
92
  }
97
93
  else {
98
94
  // This is another nested anonymous struct
99
95
  // TODO: Yeah this should be recursive and smarter but I'm lazy
100
- const parentKey = sixBack?.parent?.children
101
- ?.find(child => child.type === 'mcdoc:identifier'
102
- /* @ts-ignore */
103
- )?.value;
104
- const actualRoot = sixBack?.parent?.parent
105
- ?.parent?.children?.find(child => child.type === 'mcdoc:identifier'
106
- /* @ts-ignore */
107
- )?.value;
108
- container =
109
- `${actualRoot}.${parentKey}.__map_key.__struct`;
96
+ const parentKey = sixBack?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
97
+ const actualRoot = sixBack?.parent?.parent?.parent?.children
98
+ ?.find(child => child.type === 'mcdoc:identifier')?.value;
99
+ container = `${actualRoot}.${parentKey}.__map_key.__struct`;
110
100
  }
111
101
  }
112
102
  break;
@@ -115,16 +105,12 @@ export async function generate(project_path, generated_path, args, doc_file, ser
115
105
  switch (fourBack?.parent?.type) {
116
106
  case 'mcdoc:struct/field/spread':
117
107
  {
118
- const root = fourBack?.parent?.parent
119
- ?.parent?.children?.find(child => child.type ===
120
- 'mcdoc:identifier'
121
- /* @ts-ignore */
122
- )?.value;
108
+ const root = fourBack?.parent?.parent?.parent?.children
109
+ ?.find(child => child.type === 'mcdoc:identifier')?.value;
123
110
  // java/server/world/entity/mob/breedable/llama.[0][2][4][2][9][0][0][1][0][0][0]
124
111
  // java/server/world/entity/mob/breedable/llama.[0][2][4][2][9][0][1][1][0][0][0]
125
112
  if (root) {
126
- container =
127
- `${root}.__spread.__union.__struct_${self.split('][').slice(-4)[0]}`; // THIS IS REALLY REALLY BAD
113
+ container = `${root}.__spread.__union.__struct_${self.split('][').slice(-4)[0]}`; // THIS IS REALLY REALLY BAD
128
114
  }
129
115
  else {
130
116
  logger.warn('Could not find root for union spread');
@@ -133,32 +119,16 @@ export async function generate(project_path, generated_path, args, doc_file, ser
133
119
  break;
134
120
  case 'mcdoc:struct/field/pair':
135
121
  {
136
- const parentKey = fourBack?.parent
137
- ?.children?.find(child => child.type ===
138
- 'mcdoc:identifier'
139
- /* @ts-ignore */
140
- )?.value;
141
- const root = fourBack?.parent?.parent
142
- ?.parent?.children?.find(child => child.type ===
143
- 'mcdoc:identifier'
144
- /* @ts-ignore */
145
- )?.value;
146
- container =
147
- `${root}.${parentKey}.__union.__struct_${self.split('][').slice(-2)[0]}`; // THIS IS REALLY REALLY BAD
122
+ const parentKey = fourBack?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
123
+ const root = fourBack?.parent?.parent?.parent?.children
124
+ ?.find(child => child.type === 'mcdoc:identifier')?.value;
125
+ container = `${root}.${parentKey}.__union.__struct_${self.split('][').slice(-2)[0]}`; // THIS IS REALLY REALLY BAD
148
126
  }
149
127
  break;
150
128
  case 'mcdoc:dispatch_statement':
151
129
  {
152
- const registry = fourBack.parent
153
- .children?.find(child => child.type ===
154
- 'resource_location'
155
- /* @ts-ignore */
156
- )?.path?.join('_');
157
- const key = fourBack.parent.children
158
- ?.find(child => child.type ===
159
- 'mcdoc:index_body'
160
- /* @ts-ignore */
161
- )?.children?.[0]?.value;
130
+ const registry = fourBack.parent.children?.find(child => child.type === 'resource_location')?.path?.join('_');
131
+ const key = fourBack.parent.children?.find(child => child.type === 'mcdoc:index_body')?.children?.[0]?.value;
162
132
  const indexGuess = self.split('][').slice(-6)[0]; // THIS IS REALLY REALLY BAD
163
133
  if (indexGuess === '45') {
164
134
  container =
@@ -172,11 +142,7 @@ export async function generate(project_path, generated_path, args, doc_file, ser
172
142
  break;
173
143
  case 'mcdoc:type_alias':
174
144
  {
175
- container = fourBack?.parent?.children
176
- ?.find(child => child.type ===
177
- 'mcdoc:identifier'
178
- /* @ts-ignore */
179
- )?.value;
145
+ container = fourBack?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
180
146
  }
181
147
  break;
182
148
  default: {
@@ -192,38 +158,23 @@ export async function generate(project_path, generated_path, args, doc_file, ser
192
158
  switch (fiveBack?.type) {
193
159
  case 'mcdoc:struct/field/pair':
194
160
  {
195
- const key = fiveBack.children?.find(child => child.type ===
196
- 'mcdoc:identifier')?.value;
197
- const sevenBack = fiveBack.parent
198
- ?.parent;
199
- const foundRoot = sevenBack?.children
200
- ?.find(child => child.type ===
201
- 'mcdoc:identifier'
202
- /* @ts-ignore */
203
- )?.value;
161
+ const key = fiveBack.children?.find(child => child.type === 'mcdoc:identifier')?.value;
162
+ const sevenBack = fiveBack.parent?.parent;
163
+ const foundRoot = sevenBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
204
164
  if (foundRoot) {
205
- container =
206
- `${foundRoot}.${key}.__struct_list`;
165
+ container = `${foundRoot}.${key}.__struct_list`;
207
166
  }
208
167
  else {
209
168
  // This is another nested anonymous struct
210
169
  switch (sevenBack?.parent?.type) {
211
170
  case 'mcdoc:type/list':
212
171
  {
213
- const nineBack = sevenBack
214
- .parent?.parent;
172
+ const nineBack = sevenBack.parent?.parent;
215
173
  /* @ts-ignore */
216
- const parentKey = nineBack
217
- ?.children?.find(child => child.type ===
218
- 'mcdoc:identifier')?.value;
174
+ const parentKey = nineBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
219
175
  // Credits husk
220
- const actualRoot = nineBack?.parent
221
- ?.parent?.parent
222
- ?.parent?.children
223
- ?.find(child => child.type ===
224
- 'mcdoc:identifier'
225
- /* @ts-ignore */
226
- )?.value;
176
+ const actualRoot = nineBack?.parent?.parent
177
+ ?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
227
178
  if (actualRoot) {
228
179
  container =
229
180
  `${actualRoot}.__struct_list.${parentKey}.__struct_list.${key}.__struct_list`;
@@ -234,12 +185,8 @@ export async function generate(project_path, generated_path, args, doc_file, ser
234
185
  }
235
186
  break;
236
187
  case 'mcdoc:type/union': {
237
- const actualRoot = sevenBack
238
- .parent?.parent?.children
239
- ?.find(child => child.type ===
240
- 'mcdoc:identifier'
241
- /* @ts-ignore */
242
- )?.value;
188
+ const actualRoot = sevenBack.parent?.parent
189
+ ?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
243
190
  // block state definition, this is fragile
244
191
  if (actualRoot) {
245
192
  container =
@@ -255,8 +202,7 @@ export async function generate(project_path, generated_path, args, doc_file, ser
255
202
  break;
256
203
  case 'mcdoc:type_alias':
257
204
  {
258
- const root = fiveBack?.children?.find(child => child.type ===
259
- 'mcdoc:identifier')?.value;
205
+ const root = fiveBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
260
206
  container = `${root}.__struct_list`;
261
207
  }
262
208
  break;
@@ -265,15 +211,12 @@ export async function generate(project_path, generated_path, args, doc_file, ser
265
211
  break;
266
212
  case 'mcdoc:type_alias':
267
213
  {
268
- const root = fourBack?.children?.find(child => child.type === 'mcdoc:identifier'
269
- /* @ts-ignore */
270
- )?.value;
214
+ const root = fourBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
271
215
  if (root) {
272
216
  container = root;
273
217
  }
274
218
  else {
275
- logger.warn('Could not find root for type alias, hint:' +
276
- self);
219
+ logger.warn('Could not find root for type alias, hint:' + self);
277
220
  }
278
221
  }
279
222
  break;
@@ -288,9 +231,7 @@ export async function generate(project_path, generated_path, args, doc_file, ser
288
231
  switch (fourBack?.type) {
289
232
  case 'mcdoc:struct/field/pair':
290
233
  {
291
- const key = fourBack.children?.find(child => child.type === 'mcdoc:identifier'
292
- /* @ts-ignore */
293
- )?.value;
234
+ const key = fourBack.children?.find(child => child.type === 'mcdoc:identifier')?.value;
294
235
  const sixBack = fourBack.parent?.parent;
295
236
  const parentKey = sixBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
296
237
  if (key) {
@@ -299,29 +240,17 @@ export async function generate(project_path, generated_path, args, doc_file, ser
299
240
  }
300
241
  else {
301
242
  // memories
302
- const actualParentKey = sixBack?.parent
303
- ?.children?.find(child => child.type === 'mcdoc:identifier'
304
- /* @ts-ignore */
305
- )?.value;
306
- const root = sixBack?.parent?.parent
307
- ?.parent?.children?.find(child => child.type === 'mcdoc:identifier'
308
- /* @ts-ignore */
309
- )?.value;
310
- container =
311
- `${root}.${actualParentKey}.${key}`;
243
+ const actualParentKey = sixBack?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
244
+ const root = sixBack?.parent?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
245
+ container = `${root}.${actualParentKey}.${key}`;
312
246
  }
313
247
  }
314
248
  else {
315
249
  // advancement criteria trigger
316
- const sevenBack = fourBack?.parent?.parent
317
- ?.parent;
250
+ const sevenBack = fourBack?.parent?.parent?.parent;
318
251
  const parentKey = sevenBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
319
- const root = sevenBack?.parent?.parent
320
- ?.children?.find(child => child.type === 'mcdoc:identifier'
321
- /* @ts-ignore */
322
- )?.value;
323
- container =
324
- `${root}.${parentKey}.__map_key.__struct`;
252
+ const root = sevenBack?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
253
+ container = `${root}.${parentKey}.__map_key.__struct`;
325
254
  }
326
255
  }
327
256
  break;
@@ -331,28 +260,15 @@ export async function generate(project_path, generated_path, args, doc_file, ser
331
260
  switch (fourBack?.parent?.type) {
332
261
  case 'mcdoc:type_alias':
333
262
  {
334
- const root = fourBack?.parent
335
- ?.children?.find(child => child.type ===
336
- 'mcdoc:identifier'
337
- /* @ts-ignore */
338
- )?.value;
339
- container =
340
- `${root}.__union.__struct_${self.split('][').slice(-4)[0]}`; // THIS IS REALLY REALLY BAD
263
+ const root = fourBack?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
264
+ container = `${root}.__union.__struct_${self.split('][').slice(-4)[0]}`; // THIS IS REALLY REALLY BAD
341
265
  }
342
266
  break;
343
267
  case 'mcdoc:struct/field/pair':
344
268
  {
345
- const parentKey = fourBack?.parent
346
- .children?.find(child => child.type ===
347
- 'mcdoc:identifier'
348
- /* @ts-ignore */
349
- )?.value;
350
- const root = fourBack?.parent
351
- ?.parent?.parent?.children
352
- ?.find(child => child.type ===
353
- 'mcdoc:identifier'
354
- /* @ts-ignore */
355
- )?.value;
269
+ const parentKey = fourBack?.parent.children?.find(child => child.type === 'mcdoc:identifier')?.value;
270
+ const root = fourBack?.parent?.parent?.parent?.children
271
+ ?.find(child => child.type === 'mcdoc:identifier')?.value;
356
272
  container = `${root}.${parentKey}`;
357
273
  }
358
274
  break;
@@ -361,28 +277,19 @@ export async function generate(project_path, generated_path, args, doc_file, ser
361
277
  // kill
362
278
  const indexGuess = self.split('][').slice(-6)[0];
363
279
  if (indexGuess === '45') {
364
- container =
365
- `__dispatch.__struct_${self.split('][').slice(-4)[0]}`;
280
+ container = `__dispatch.__struct_${self.split('][').slice(-4)[0]}`;
366
281
  }
367
282
  else {
368
- container =
369
- `__dispatch.__struct_${indexGuess}`; // THIS IS REALLY REALLY BAD
283
+ container = `__dispatch.__struct_${indexGuess}`; // THIS IS REALLY REALLY BAD
370
284
  }
371
285
  }
372
286
  break;
373
287
  case 'mcdoc:type/union':
374
288
  {
375
289
  // book lines
376
- const sevenBack = fourBack?.parent
377
- ?.parent?.parent;
378
- const parentKey = sevenBack
379
- ?.children?.find(child => child.type ===
380
- 'mcdoc:identifier'
381
- /* @ts-ignore */
382
- )?.value;
383
- const root = sevenBack?.parent
384
- ?.parent?.children?.find(child => child.type ===
385
- 'mcdoc:identifier')?.value;
290
+ const sevenBack = fourBack?.parent?.parent?.parent;
291
+ const parentKey = sevenBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
292
+ const root = sevenBack?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
386
293
  container =
387
294
  `${root}.${parentKey}.__union_list.__struct`;
388
295
  }
@@ -390,24 +297,12 @@ export async function generate(project_path, generated_path, args, doc_file, ser
390
297
  case 'mcdoc:type/list':
391
298
  {
392
299
  // texture meta
393
- const parentKey = fourBack?.parent
394
- .parent?.children?.find(child => child.type ===
395
- 'mcdoc:identifier'
396
- /* @ts-ignore */
397
- )?.value;
398
- const rootKey = fourBack?.parent
399
- ?.parent?.parent?.parent?.parent
400
- ?.children?.find(child => child.type ===
401
- 'mcdoc:identifier'
402
- /* @ts-ignore */
403
- )?.value;
404
- const root = fourBack?.parent
405
- ?.parent?.parent?.parent?.parent
406
- ?.parent?.parent?.children
407
- ?.find(child => child.type ===
408
- 'mcdoc:identifier'
409
- /* @ts-ignore */
410
- )?.value;
300
+ const parentKey = fourBack?.parent.parent?.children
301
+ ?.find(child => child.type === 'mcdoc:identifier')?.value;
302
+ const rootKey = fourBack?.parent?.parent?.parent
303
+ ?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
304
+ const root = fourBack?.parent?.parent?.parent?.parent
305
+ ?.parent?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
411
306
  container =
412
307
  `${root}.${rootKey}.${parentKey}.__union_list.__struct`;
413
308
  }
@@ -424,37 +319,23 @@ export async function generate(project_path, generated_path, args, doc_file, ser
424
319
  switch (threeBack?.type) {
425
320
  case 'mcdoc:enum':
426
321
  {
427
- const root = threeBack?.children?.find(child => child.type === 'mcdoc:identifier'
428
- /* @ts-ignore */
429
- )?.value;
322
+ const root = threeBack?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
430
323
  if (root) {
431
324
  container = root;
432
325
  }
433
326
  else {
434
327
  // inline enum
435
- const parentKey = threeBack?.parent?.children
436
- ?.find(child => child.type === 'mcdoc:identifier'
437
- /* @ts-ignore */
438
- )?.value;
439
- const root = threeBack?.parent?.parent?.parent
440
- ?.children?.find(child => child.type === 'mcdoc:identifier'
441
- /* @ts-ignore */
442
- )?.value;
328
+ const parentKey = threeBack?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
329
+ const root = threeBack?.parent?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
443
330
  if (root) {
444
331
  container = `${root}.${parentKey}`;
445
332
  }
446
333
  else {
447
- const rootKey = threeBack?.parent?.parent
448
- ?.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier'
449
- /* @ts-ignore */
450
- )?.value;
451
- const root = threeBack?.parent?.parent
452
- ?.parent?.parent?.parent?.parent
453
- ?.children?.find(child => child.type === 'mcdoc:identifier'
454
- /* @ts-ignore */
455
- )?.value;
456
- container =
457
- `${root}.${rootKey}.${parentKey}`;
334
+ const rootKey = threeBack?.parent?.parent?.parent?.parent
335
+ ?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
336
+ const root = threeBack?.parent?.parent?.parent?.parent?.parent
337
+ ?.parent?.children?.find(child => child.type === 'mcdoc:identifier')?.value;
338
+ container = `${root}.${rootKey}.${parentKey}`;
458
339
  }
459
340
  }
460
341
  }
@@ -470,8 +351,7 @@ export async function generate(project_path, generated_path, args, doc_file, ser
470
351
  case 'mcdoc:dispatch_statement':
471
352
  {
472
353
  if (_parent?.children) {
473
- container = _parent?.children?.find(child => child.type ===
474
- 'resource_location')?.path?.join('_');
354
+ container = _parent?.children?.find(child => child.type === 'resource_location')?.path?.join('_');
475
355
  }
476
356
  }
477
357
  break;
@@ -489,13 +369,10 @@ export async function generate(project_path, generated_path, args, doc_file, ser
489
369
  }
490
370
  break;
491
371
  case 'mcdoc:struct/field/pair': {
492
- const key = threeBack.children?.find(child => child.type === 'mcdoc:identifier'
372
+ const key = threeBack.children?.find(child => child.type === 'mcdoc:identifier')?.value;
373
+ const root = threeBack.parent?.parent?.children?.find(child => child.type === 'mcdoc:identifier'
493
374
  /* @ts-ignore */
494
375
  )?.value;
495
- const root = threeBack.parent?.parent?.children
496
- ?.find(child => child.type === 'mcdoc:identifier')
497
- /* @ts-ignore */
498
- ?.value;
499
376
  container = `${root}.${key}`;
500
377
  }
501
378
  }
@@ -504,8 +381,9 @@ export async function generate(project_path, generated_path, args, doc_file, ser
504
381
  const key = `mcdoc.${resource.replace(/\//g, '.')}${container ? `.${container}` : ''}.${end}`;
505
382
  let value = internal_locales[parent].join('').trimEnd();
506
383
  /// remove windows cruft
507
- if (value.includes('\r'))
384
+ if (value.includes('\r')) {
508
385
  value = value.replaceAll('\r', '');
386
+ }
509
387
  locales[key] = value;
510
388
  }
511
389
  /* @ts-ignore */
@@ -530,8 +408,7 @@ export async function generate(project_path, generated_path, args, doc_file, ser
530
408
  else {
531
409
  const key = `${
532
410
  /* @ts-ignore */
533
- _parent?.children?.[3]?.children?.[0].value}`
534
- .replace(/[\%\, ]/, '__'); // should be sanitized enough
411
+ _parent?.children?.[3]?.children?.[0].value}`.replace(/[\%\, ]/, '__'); // should be sanitized enough
535
412
  setLocale(`__dispatch.${key}`);
536
413
  }
537
414
  }
@@ -542,12 +419,10 @@ export async function generate(project_path, generated_path, args, doc_file, ser
542
419
  delete internal_locales[parent];
543
420
  }
544
421
  }
545
- if (child.type === 'mcdoc:struct/map_key' &&
546
- internal_locales[parent]) {
422
+ if (child.type === 'mcdoc:struct/map_key' && internal_locales[parent]) {
547
423
  const attributes = _child.children?.[0]?.children?.[0]?.children;
548
- if (attributes && attributes.length === 1 &&
549
- /* @ts-ignore */
550
- !attributes[0].children && attributes[0].value === 'id') {
424
+ if (attributes && attributes.length === 1 /* @ts-ignore */
425
+ && !attributes[0].children && attributes[0].value === 'id') {
551
426
  /* @ts-ignore */
552
427
  setLocale(_child.children?.[0].children?.[1].value);
553
428
  }
@@ -561,8 +436,7 @@ export async function generate(project_path, generated_path, args, doc_file, ser
561
436
  /* @ts-ignore */
562
437
  const comment = _child.comment;
563
438
  child.comment = comment;
564
- if (!args.dry && args.locale &&
565
- _parent?.type === 'mcdoc:doc_comments') {
439
+ if (!args.dry && args.locale && _parent?.type === 'mcdoc:doc_comments') {
566
440
  const key = parent.replace(/\[\d+\]$/, '');
567
441
  if (!internal_locales[key]) {
568
442
  internal_locales[key] = [];
@@ -570,12 +444,15 @@ export async function generate(project_path, generated_path, args, doc_file, ser
570
444
  internal_locales[key].push(comment.slice(1));
571
445
  }
572
446
  }
573
- if (_child.hover)
447
+ if (_child.hover) {
574
448
  child.hover = _child.hover;
575
- if (_child.color)
449
+ }
450
+ if (_child.color) {
576
451
  child.color = _child.color;
577
- if (child.type !== 'error')
452
+ }
453
+ if (child.type !== 'error') {
578
454
  return child;
455
+ }
579
456
  else {
580
457
  errors++;
581
458
  const lc = lineColumn(doc_contents);
@@ -611,15 +488,13 @@ export async function generate(project_path, generated_path, args, doc_file, ser
611
488
  /* @ts-ignore */
612
489
  children[i] = flattenChild(resource, `${resource}.[${i}]`, undefined, child);
613
490
  });
614
- const symbol = {
615
- resource,
616
- children,
617
- };
491
+ const symbol = { resource, children };
618
492
  symbols.push(symbol);
619
493
  if (!args.dry && args.module) {
620
494
  const dir = parse(join(generated_path, 'module', resource)).dir;
621
- if (dir !== '')
495
+ if (dir !== '') {
622
496
  await fs.ensureDir(dir);
497
+ }
623
498
  await fs.writeFile(join(generated_path, 'module', `${resource}.mcdoc.json`), JSON.stringify(symbol));
624
499
  if (args.pretty) {
625
500
  await fs.writeFile(join(generated_path, 'module', `${resource}.pretty.mcdoc.json`), JSON.stringify(symbol, undefined, 3));
package/lib/index.js CHANGED
@@ -5,15 +5,14 @@ import fs from 'fs-extra';
5
5
  import walk from 'klaw';
6
6
  import yargs from 'yargs';
7
7
  import { hideBin } from 'yargs/helpers';
8
- import { ConfigService, fileUtil, Service, VanillaConfig, } from '@spyglassmc/core';
8
+ import { ConfigService, fileUtil, Service, VanillaConfig } from '@spyglassmc/core';
9
9
  import { NodeJsExternals } from '@spyglassmc/core/lib/nodejs.js';
10
10
  import * as mcdoc from '@spyglassmc/mcdoc';
11
11
  import { generate } from './generate/index.js';
12
12
  import { update_locales } from './update_locales/index.js';
13
13
  const cache_root = join(dirname(fileURLToPath(import.meta.url)), 'cache');
14
14
  const CLI = yargs(hideBin(process.argv));
15
- await CLI.scriptName('mcdoc')
16
- .command('generate [source]', 'Generate JSON files', () => CLI.positional('source', {
15
+ await CLI.scriptName('mcdoc').command('generate [source]', 'Generate JSON files', () => CLI.positional('source', {
17
16
  describe: 'path to directory containing mcdoc source.',
18
17
  type: 'string',
19
18
  default: '.',
@@ -28,29 +27,18 @@ await CLI.scriptName('mcdoc')
28
27
  description: 'file tree mirroring definitions; to optimize for web.',
29
28
  default: false,
30
29
  },
31
- 'pretty': {
32
- alias: 'p',
33
- description: 'pretty printed variants.',
34
- default: false,
35
- },
36
- 'verbose': {
37
- alias: 'v',
38
- default: false,
39
- },
40
- 'dry': {
41
- alias: 'd',
42
- description: 'will not write to disk.',
43
- default: false,
44
- },
30
+ 'pretty': { alias: 'p', description: 'pretty printed variants.', default: false },
31
+ 'verbose': { alias: 'v', default: false },
32
+ 'dry': { alias: 'd', description: 'will not write to disk.', default: false },
45
33
  }).boolean('locale').boolean('module').boolean('pretty').boolean('verbose').boolean('dry'), async (args) => {
46
34
  const include = [];
47
- if (args.locale)
35
+ if (args.locale) {
48
36
  include.push('locales');
49
- if (args.module)
37
+ }
38
+ if (args.module) {
50
39
  include.push('modules');
51
- console.info(`Generating JSON files${args.locale || args.module
52
- ? `, including ${include.join(', ')}`
53
- : ''}`);
40
+ }
41
+ console.info(`Generating JSON files${args.locale || args.module ? `, including ${include.join(', ')}` : ''}`);
54
42
  const logger = {
55
43
  log: (...log_args) => args.verbose ? console.log(...log_args) : false,
56
44
  warn: (...log_args) => console.warn(...log_args),
@@ -64,9 +52,7 @@ await CLI.scriptName('mcdoc')
64
52
  logger,
65
53
  project: {
66
54
  cacheRoot: fileUtil.ensureEndingSlash(pathToFileURL(cache_root).toString()),
67
- defaultConfig: ConfigService.merge(VanillaConfig, {
68
- env: { dependencies: [] },
69
- }),
55
+ defaultConfig: ConfigService.merge(VanillaConfig, { env: { dependencies: [] } }),
70
56
  externals: NodeJsExternals,
71
57
  initializers: [mcdoc.initialize],
72
58
  projectRoot: fileUtil.ensureEndingSlash(pathToFileURL(project_path).toString()),
@@ -120,9 +106,6 @@ await CLI.scriptName('mcdoc')
120
106
  }
121
107
  console.log(`Generated JSON files with ${errors} errors.`);
122
108
  await service.project.close();
123
- })
124
- .command('update_locales', 'Attempt automatic upgrade of locales.', update_locales)
125
- .strict()
126
- .demandCommand(1)
127
- .parse();
109
+ }).command('update_locales', 'Attempt automatic upgrade of locales.', update_locales).strict()
110
+ .demandCommand(1).parse();
128
111
  //# sourceMappingURL=index.js.map
@@ -26,8 +26,7 @@ export async function update_locales() {
26
26
  removed_keys.push([locales.old_keys[i], locales.old_values[i]]);
27
27
  }
28
28
  else if (keyRemoved && !valueRemoved) {
29
- if (locales.new_values.filter(value => value === locales.old_values[i])
30
- .length > 1) {
29
+ if (locales.new_values.filter(value => value === locales.old_values[i]).length > 1) {
31
30
  removed_keys.push([locales.old_keys[i], locales.old_values[i]]);
32
31
  console.log('Duplicate key removed:', locales.old_keys[i]);
33
32
  }
@@ -47,8 +46,7 @@ export async function update_locales() {
47
46
  }
48
47
  }
49
48
  for (let i = 0; i < locales.new_keys.length; i++) {
50
- if (!moved_keys[locales.new_keys[i]] &&
51
- !locales.old_keys.includes(locales.new_keys[i])) {
49
+ if (!moved_keys[locales.new_keys[i]] && !locales.old_keys.includes(locales.new_keys[i])) {
52
50
  added_keys.push([locales.new_keys[i], locales.new_values[i]]);
53
51
  }
54
52
  }
@@ -83,21 +81,18 @@ export async function update_locales() {
83
81
  for (const [key, [from, to]] of changed_values) {
84
82
  const isPeriod = to.slice(-1);
85
83
  if (isPeriod !== '.' && from.slice(0, -1) !== to) {
86
- description +=
87
- `- \`${key}\` changed, before/after:\n - \`${from}\`\n - \`${to}\`\n`;
84
+ description += `- \`${key}\` changed, before/after:\n - \`${from}\`\n - \`${to}\`\n`;
88
85
  }
89
86
  }
90
87
  await ofetch(webhook, {
91
88
  method: 'POST',
92
89
  body: {
93
90
  content: '',
94
- embeds: [
95
- {
91
+ embeds: [{
96
92
  color: 1863349,
97
93
  title: 'mcdoc translation key values changed in en-us.json',
98
94
  description,
99
- },
100
- ],
95
+ }],
101
96
  },
102
97
  });
103
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/mcdoc-cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -33,8 +33,8 @@
33
33
  "line-column": "^1.0.2",
34
34
  "ofetch": "^1.3.4",
35
35
  "yargs": "17.6.2",
36
- "@spyglassmc/core": "0.4.5",
37
- "@spyglassmc/mcdoc": "0.3.8"
36
+ "@spyglassmc/core": "0.4.7",
37
+ "@spyglassmc/mcdoc": "0.3.10"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/fs-extra": "^11.0.2",