@luna-park/plugin 1.4.1 → 1.5.0

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/bin/preview.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "node:util";
3
+
4
+ import { resolve } from "path";
5
+
6
+ import { startPreviewServer } from "../dist/preview.mjs";
7
+
8
+ const cwd = process.cwd();
9
+
10
+ // Parse CLI arguments
11
+ const { values } = parseArgs({
12
+ options: {
13
+ dist: {
14
+ default: "dist",
15
+ short: "d",
16
+ type: "string"
17
+ },
18
+ help: {
19
+ default: false,
20
+ short: "h",
21
+ type: "boolean"
22
+ },
23
+ port: {
24
+ default: "2084",
25
+ short: "p",
26
+ type: "string"
27
+ }
28
+ }
29
+ });
30
+
31
+ if (values.help) {
32
+ console.log(`
33
+ Usage: luna-preview [options]
34
+
35
+ Options:
36
+ -p, --port <port> Port to run the server on (default: 2084)
37
+ -d, --dist <dir> Distribution directory to serve (default: dist)
38
+ -h, --help Show this help message
39
+ `);
40
+ process.exit(0);
41
+ }
42
+
43
+ const dist = resolve(cwd, values.dist);
44
+ const port = parseInt(values.port);
45
+
46
+ startPreviewServer({
47
+ dist,
48
+ externals: ["vue", "vue-router", "@luna-park/design"],
49
+ port
50
+ });
@@ -92,99 +92,99 @@ const LogicType = {
92
92
  return {
93
93
  ...args,
94
94
  items,
95
- type: EVarType.array
95
+ type: "array"
96
96
  };
97
97
  },
98
98
  boolean: (args = {}) => {
99
99
  return {
100
100
  ...args,
101
- type: EVarType.boolean
101
+ type: "boolean"
102
102
  };
103
103
  },
104
104
  exec: (args = {}) => {
105
105
  return {
106
106
  ...args,
107
- type: EVarType.exec
108
- };
109
- },
110
- function: (inputs = {
111
- properties: {},
112
- type: EVarType.object
113
- }, output = { type: EVarType.void }, args = {}) => {
114
- return {
115
- ...args,
116
- inputs,
117
- output,
118
- type: EVarType.function
107
+ type: "exec"
119
108
  };
120
109
  },
110
+ function: createFunction,
121
111
  interface: (interfaceClass, args = {}) => {
122
112
  return {
123
113
  ...args,
124
114
  className: typeof interfaceClass === "string" ? interfaceClass : interfaceClass.name,
125
- type: EVarType.interface
115
+ type: "interface"
126
116
  };
127
117
  },
128
118
  number: (args = {}) => {
129
119
  return {
130
120
  ...args,
131
- type: EVarType.number
121
+ type: "number"
132
122
  };
133
123
  },
134
124
  object: (properties = {}, args = {}) => {
135
125
  return {
136
126
  ...args,
137
127
  properties,
138
- type: EVarType.object
128
+ type: "object"
139
129
  };
140
130
  },
141
131
  record: (key, value, args = {}) => {
142
132
  return {
143
133
  ...args,
144
134
  key,
145
- type: EVarType.record,
135
+ type: "record",
146
136
  value
147
137
  };
148
138
  },
149
139
  string: (args = {}) => {
150
140
  return {
151
141
  ...args,
152
- type: EVarType.string
153
- };
154
- },
155
- type: (target, args = {}) => {
156
- return {
157
- ...args,
158
- target,
159
- type: EVarType.type
142
+ type: "string"
160
143
  };
161
144
  },
145
+ type: createType,
162
146
  undefined: (args = {}) => {
163
147
  return {
164
148
  ...args,
165
- type: EVarType.undefined
149
+ type: "undefined"
166
150
  };
167
151
  },
168
152
  union: (elements, args = {}) => {
169
153
  return {
170
154
  ...args,
171
155
  elements,
172
- type: EVarType.union
156
+ type: "union"
173
157
  };
174
158
  },
175
159
  unknown: (args = {}) => {
176
160
  return {
177
161
  ...args,
178
- type: EVarType.unknown
162
+ type: "unknown"
179
163
  };
180
164
  },
181
165
  void: (args = {}) => {
182
166
  return {
183
167
  ...args,
184
- type: EVarType.void
168
+ type: "void"
185
169
  };
186
170
  }
187
171
  };
172
+ function createFunction(inputs = [], output = LogicType.void(), args = {}) {
173
+ if (Array.isArray(inputs)) return createFunction(LogicType.object(Object.fromEntries(inputs)), output, args);
174
+ return {
175
+ ...args,
176
+ inputs,
177
+ output,
178
+ type: "function"
179
+ };
180
+ }
181
+ function createType(target, args = {}) {
182
+ return {
183
+ ...args,
184
+ target,
185
+ type: "type"
186
+ };
187
+ }
188
188
  const LogicUtil = {
189
189
  omit(target, keys) {
190
190
  return {
@@ -239,44 +239,6 @@ let ELogicScope = /* @__PURE__ */ function(ELogicScope) {
239
239
  function makeLogicNode(node) {
240
240
  return node;
241
241
  }
242
- function scanner(input) {
243
- const elements = [];
244
- input = input.replaceAll(/ +/g, " ");
245
- input = input.replaceAll(/\s*\n\s*/g, "\n");
246
- while (input.length) {
247
- if ([" ", "\n"].includes(input[0])) {
248
- input = input.slice(1);
249
- continue;
250
- }
251
- if (input.startsWith("/*")) {
252
- const commentEnd = input.indexOf("*/");
253
- elements.push(input.slice(0, commentEnd + 2));
254
- input = input.slice(commentEnd + 2);
255
- continue;
256
- }
257
- const startingWord = input.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];
258
- if (startingWord) {
259
- input = input.slice(startingWord.length);
260
- elements.push(startingWord);
261
- continue;
262
- }
263
- const startingNumber = input.match(/^([0-9]+)/)?.[0];
264
- if (startingNumber) {
265
- input = input.slice(startingNumber.length);
266
- elements.push(startingNumber);
267
- continue;
268
- }
269
- if (input[0] === ">" && elements.at(-1) === "=") {
270
- elements.pop();
271
- elements.push("=>");
272
- input = input.slice(1);
273
- continue;
274
- }
275
- elements.push(input[0]);
276
- input = input.slice(1);
277
- }
278
- return elements;
279
- }
280
242
  const wrappers = [
281
243
  ["(", ")"],
282
244
  ["[", "]"],
@@ -332,8 +294,8 @@ function getFirstElement(scan) {
332
294
  exportFlag = true;
333
295
  element = scan.shift();
334
296
  if (element === "=") return {
335
- type: "export",
336
- content: scan.shift()
297
+ content: scan.shift(),
298
+ type: "export"
337
299
  };
338
300
  if (element === "as") {
339
301
  eraseUntil(scan, ";");
@@ -347,10 +309,10 @@ function getFirstElement(scan) {
347
309
  const content = splitUntil(getUntil(scan, "}", 0), ";");
348
310
  scan.unshift(";");
349
311
  return {
350
- name,
351
- type: element,
352
312
  content,
353
- export: exportFlag
313
+ export: exportFlag,
314
+ name,
315
+ type: element
354
316
  };
355
317
  }
356
318
  if (element === "function") {
@@ -380,9 +342,9 @@ function getFirstElement(scan) {
380
342
  const content = splitUntil(getUntil(scan, "}", 0), ";");
381
343
  scan.unshift(";");
382
344
  return {
345
+ content,
383
346
  name,
384
- type: "interface",
385
- content
347
+ type: "interface"
386
348
  };
387
349
  }
388
350
  if (element === "type" && /^[A-Za-z0-9]*$/.test(scan[0])) {
@@ -407,24 +369,24 @@ function getFirstElement(scan) {
407
369
  scan.unshift(";");
408
370
  return {
409
371
  name,
410
- type: "enum",
411
372
  options: Object.fromEntries(content.join("").split(",").filter((item) => item.trim()).map((item) => {
412
373
  if (item.includes("=")) {
413
374
  const [name, value] = item.split("=");
414
375
  return [JSON.parse(value), name];
415
376
  }
416
377
  return [name, name];
417
- }))
378
+ })),
379
+ type: "enum"
418
380
  };
419
381
  }
420
382
  if (typeof element === "string" && element.startsWith("/*")) return {
421
- type: "comment",
422
- content: cleanComment(element)
383
+ content: cleanComment(element),
384
+ type: "comment"
423
385
  };
424
386
  for (const wrapper of wrappers) if (element === wrapper[0]) return {
425
- type: "wrap",
426
387
  content: splitUntil(getUntil(scan, wrapper[1]), ";").map((item) => splitUntil(item, ",")).map((item) => splitUntil(item, "|")),
427
- style: wrapper.join("")
388
+ style: wrapper.join(""),
389
+ type: "wrap"
428
390
  };
429
391
  return element;
430
392
  }
@@ -447,32 +409,32 @@ function cleanComment(comment) {
447
409
  return comment.trim();
448
410
  }
449
411
  function cleanUnion(schema) {
450
- if (schema.elements.find((element) => [EVarType.undefined, EVarType.void].includes(element.type))) {
412
+ if (schema.elements.find((element) => ["undefined", "void"].includes(element.type))) {
451
413
  schema.optional = true;
452
- schema.elements = schema.elements.filter((element) => ![EVarType.undefined, EVarType.void].includes(element.type));
414
+ schema.elements = schema.elements.filter((element) => !["undefined", "void"].includes(element.type));
453
415
  }
454
- const childUnions = schema.elements.filter((element) => element.type === EVarType.union);
416
+ const childUnions = schema.elements.filter((element) => element.type === "union");
455
417
  if (childUnions.length > 0) {
456
- schema.elements = schema.elements.filter((element) => element.type !== EVarType.union);
418
+ schema.elements = schema.elements.filter((element) => element.type !== "union");
457
419
  for (const childUnion of childUnions) schema.elements.push(...childUnion.elements);
458
420
  }
459
- const stringElements = schema.elements.filter((element) => element.type === EVarType.string);
421
+ const stringElements = schema.elements.filter((element) => element.type === "string");
460
422
  if (stringElements.length > 1) {
461
423
  const enumValues = [];
462
424
  let anyFlag = false;
463
425
  for (const element of stringElements) if (element.enum) enumValues.push(...element.enum);
464
426
  else anyFlag = true;
465
- schema.elements = schema.elements.filter((element) => element.type !== EVarType.string);
427
+ schema.elements = schema.elements.filter((element) => element.type !== "string");
466
428
  if (anyFlag) schema.elements.push(LogicType.string());
467
429
  else schema.elements.push(LogicType.string({ enum: enumValues }));
468
430
  }
469
- const numberElements = schema.elements.filter((element) => element.type === EVarType.number);
431
+ const numberElements = schema.elements.filter((element) => element.type === "number");
470
432
  if (numberElements.length > 1) {
471
433
  const enumValues = [];
472
434
  let anyFlag = false;
473
435
  for (const element of numberElements) if (element.enum) enumValues.push(...element.enum);
474
436
  else anyFlag = true;
475
- schema.elements = schema.elements.filter((element) => element.type !== EVarType.number);
437
+ schema.elements = schema.elements.filter((element) => element.type !== "number");
476
438
  if (anyFlag) schema.elements.push(LogicType.number());
477
439
  else schema.elements.push(LogicType.number({ enum: enumValues }));
478
440
  }
@@ -497,6 +459,44 @@ function cleanInterface(schema) {
497
459
  if (["Omit", "Pick"].includes(schema.className)) return LogicUtil[schema.className.toLocaleLowerCase()](schema.options.template[0], schema.options.template[1]?.enum);
498
460
  return schema;
499
461
  }
462
+ function scanner(input) {
463
+ const elements = [];
464
+ input = input.replaceAll(/ +/g, " ");
465
+ input = input.replaceAll(/\s*\n\s*/g, "\n");
466
+ while (input.length) {
467
+ if ([" ", "\n"].includes(input[0])) {
468
+ input = input.slice(1);
469
+ continue;
470
+ }
471
+ if (input.startsWith("/*")) {
472
+ const commentEnd = input.indexOf("*/");
473
+ elements.push(input.slice(0, commentEnd + 2));
474
+ input = input.slice(commentEnd + 2);
475
+ continue;
476
+ }
477
+ const startingWord = input.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];
478
+ if (startingWord) {
479
+ input = input.slice(startingWord.length);
480
+ elements.push(startingWord);
481
+ continue;
482
+ }
483
+ const startingNumber = input.match(/^([0-9]+)/)?.[0];
484
+ if (startingNumber) {
485
+ input = input.slice(startingNumber.length);
486
+ elements.push(startingNumber);
487
+ continue;
488
+ }
489
+ if (input[0] === ">" && elements.at(-1) === "=") {
490
+ elements.pop();
491
+ elements.push("=>");
492
+ input = input.slice(1);
493
+ continue;
494
+ }
495
+ elements.push(input[0]);
496
+ input = input.slice(1);
497
+ }
498
+ return elements;
499
+ }
500
500
  function parser(element, options = {}) {
501
501
  if (typeof element === "string") {
502
502
  if (element === "string") return LogicType.string(options);
@@ -519,8 +519,10 @@ function parser(element, options = {}) {
519
519
  if (element[1].style === "<>") {
520
520
  let template = element[1].content;
521
521
  if (!Array.isArray(template)) template = [template];
522
- if (!Array.isArray(template[0])) if (template.some((element) => element.type === "wrap" && element.style === "[]") || template.some((element) => element.type === "wrap" && element.style === "<>") || template.includes("&") || template.includes("|")) template = [template];
523
- else template = template.map((element) => [element]);
522
+ if (!Array.isArray(template[0])) {
523
+ if (template.some((element) => element.type === "wrap" && element.style === "[]") || template.some((element) => element.type === "wrap" && element.style === "<>") || template.includes("&") || template.includes("|")) template = [template];
524
+ else template = template.map((element) => [element]);
525
+ }
524
526
  template = template.map((element) => parser(element));
525
527
  return cleanInterface(LogicType.interface(element[0], {
526
528
  ...options,
@@ -587,13 +589,13 @@ function schemaLoop(schema, func, key) {
587
589
  key,
588
590
  schema
589
591
  }) || schema;
590
- if (schema.type === EVarType.object) for (const key in schema.properties) schema.properties[key] = schemaLoop(schema.properties[key], func, key);
591
- if (schema.type === EVarType.array) schema.items = schemaLoop(schema.items, func);
592
- if (schema.type === EVarType.function) {
592
+ if (schema.type === "object") for (const key in schema.properties) schema.properties[key] = schemaLoop(schema.properties[key], func, key);
593
+ if (schema.type === "array") schema.items = schemaLoop(schema.items, func);
594
+ if (schema.type === "function") {
593
595
  schema.inputs = schemaLoop(schema.inputs, func);
594
596
  schema.output = schemaLoop(schema.output, func);
595
597
  }
596
- if (schema.type === EVarType.union) for (const key in schema.elements) schema.elements[key] = schemaLoop(schema.elements[key], func);
598
+ if (schema.type === "union") for (const key in schema.elements) schema.elements[key] = schemaLoop(schema.elements[key], func);
597
599
  return schema;
598
600
  }
599
601
  //#endregion
@@ -1,7 +1,6 @@
1
- import { l as TSchema } from "./index-X3hhfmWd.mjs";
1
+ import { l as TSchema } from "./index-DwEOlEBY.mjs";
2
2
  import * as ts$1 from "typescript";
3
3
  import ts from "typescript";
4
-
5
4
  //#region src/extractor/export/type.d.ts
6
5
  type TExportResult = {
7
6
  components: Record<string, TExportComponent>;
@@ -38,7 +37,7 @@ type TExportType = {
38
37
  };
39
38
  //#endregion
40
39
  //#region src/extractor/export/index.d.ts
41
- declare class CTypeExport {
40
+ export declare class CTypeExport {
42
41
  program: ts.Program;
43
42
  checker: ts.TypeChecker;
44
43
  index?: ts.SourceFile;
@@ -71,15 +70,14 @@ type TExportLogicResult = {
71
70
  functions: Record<string, TExportNodeFunction>;
72
71
  types: Record<string, TSchema>;
73
72
  };
74
- declare function generateNodes(exportResult: TExportResult, packageName?: string): TExportLogicResult;
73
+ export declare function generateNodes(exportResult: TExportResult, packageName?: string): TExportLogicResult;
75
74
  //#endregion
76
75
  //#region src/extractor/source.d.ts
77
- declare function getSourceFile(moduleName: string): {
76
+ export declare function getSourceFile(moduleName: string): {
78
77
  program: ts$1.Program;
79
78
  sourceFile: ts$1.SourceFile;
80
79
  };
81
80
  //#endregion
82
81
  //#region src/extractor/index.d.ts
83
- declare function extractFile(filePath: string, target: string): Promise<void>;
84
- //#endregion
85
- export { CTypeExport, extractFile, generateNodes, getSourceFile };
82
+ export declare function extractFile(filePath: string, target: string): Promise<void>;
83
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { c as typeToSchema, d as objectMap, i as LogicType, l as cleanObject, r as EVarType, s as schemaLoop } from "./dist-hc-SHkAg.mjs";
1
+ import { c as typeToSchema, d as objectMap, i as LogicType, l as cleanObject, r as EVarType, s as schemaLoop } from "./dist-JzydDdZn.mjs";
2
2
  import fs from "node:fs";
3
3
  import * as ts$1 from "typescript";
4
4
  import ts from "typescript";
@@ -233,6 +233,7 @@ function isUserType(type) {
233
233
  //#region src/extractor/export/index.ts
234
234
  const FLAGS = ts.TypeFormatFlags.WriteArrowStyleSignature | ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType;
235
235
  var CTypeExport = class {
236
+ program;
236
237
  checker;
237
238
  index;
238
239
  cache = /* @__PURE__ */ new Set();
@@ -493,9 +494,7 @@ function generateNodes(exportResult, packageName = "unknown") {
493
494
  case EVarType.number:
494
495
  schema.default = Number(type.default);
495
496
  break;
496
- case EVarType.string:
497
- schema.default = type.default;
498
- break;
497
+ case EVarType.string: schema.default = type.default;
499
498
  }
500
499
  if (schema.type === EVarType.object && !Object.keys(schema.properties).length) schema.customizable = true;
501
500
  return schema;