@kubb/fabric-core 0.1.1 → 0.1.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.
Files changed (90) hide show
  1. package/dist/App-DZuROf6f.d.ts +292 -0
  2. package/dist/App-zyf9KG3p.d.cts +292 -0
  3. package/dist/chunk-CUT6urMc.cjs +30 -0
  4. package/dist/defineApp-D3B0bU-z.d.cts +14 -0
  5. package/dist/defineApp-DJVMk9lc.d.ts +14 -0
  6. package/dist/index.cjs +165 -88
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +4 -8
  9. package/dist/index.d.ts +4 -8
  10. package/dist/index.js +154 -77
  11. package/dist/index.js.map +1 -1
  12. package/dist/parsers/typescript.cjs +5 -6
  13. package/dist/parsers/typescript.d.cts +3 -51
  14. package/dist/parsers/typescript.d.ts +3 -51
  15. package/dist/parsers/typescript.js +2 -3
  16. package/dist/parsers.cjs +7 -0
  17. package/dist/parsers.d.cts +14 -0
  18. package/dist/parsers.d.ts +14 -0
  19. package/dist/parsers.js +4 -0
  20. package/dist/plugins.cjs +76 -0
  21. package/dist/plugins.cjs.map +1 -0
  22. package/dist/plugins.d.cts +28 -0
  23. package/dist/plugins.d.ts +28 -0
  24. package/dist/plugins.js +71 -0
  25. package/dist/plugins.js.map +1 -0
  26. package/dist/tsxParser-C741ZKCN.js +26 -0
  27. package/dist/tsxParser-C741ZKCN.js.map +1 -0
  28. package/dist/tsxParser-HDf_3TMc.cjs +37 -0
  29. package/dist/tsxParser-HDf_3TMc.cjs.map +1 -0
  30. package/dist/types.d.cts +2 -2
  31. package/dist/types.d.ts +2 -2
  32. package/dist/{typescript-C60gWBu8.js → typescriptParser-BBGeFKlP.js} +52 -69
  33. package/dist/typescriptParser-BBGeFKlP.js.map +1 -0
  34. package/dist/{typescript-Z90jN87k.cjs → typescriptParser-BBbbmG5W.cjs} +61 -108
  35. package/dist/typescriptParser-BBbbmG5W.cjs.map +1 -0
  36. package/dist/typescriptParser-C-sBy1iR.d.cts +50 -0
  37. package/dist/typescriptParser-CtMmz0UV.d.ts +50 -0
  38. package/package.json +13 -13
  39. package/src/App.ts +91 -0
  40. package/src/FileManager.ts +12 -12
  41. package/src/FileProcessor.ts +49 -46
  42. package/src/createFile.ts +1 -1
  43. package/src/defineApp.ts +47 -72
  44. package/src/index.ts +1 -1
  45. package/src/parsers/createParser.ts +8 -0
  46. package/src/parsers/defaultParser.ts +10 -0
  47. package/src/parsers/index.ts +5 -0
  48. package/src/parsers/tsxParser.ts +11 -0
  49. package/src/parsers/types.ts +12 -2
  50. package/src/parsers/{typescript.ts → typescriptParser.ts} +8 -4
  51. package/src/plugins/createPlugin.ts +10 -0
  52. package/src/plugins/fsPlugin.ts +112 -0
  53. package/src/plugins/index.ts +3 -0
  54. package/src/plugins/types.ts +15 -0
  55. package/src/types.ts +4 -1
  56. package/src/utils/AsyncEventEmitter.ts +37 -0
  57. package/src/utils/getRelativePath.ts +32 -0
  58. package/src/utils/trimExtName.ts +3 -0
  59. package/dist/KubbFile-BrN7Wwp6.d.cts +0 -119
  60. package/dist/KubbFile-BzVkcu9M.d.ts +0 -119
  61. package/dist/createFileParser-BD8yn0LT.cjs +0 -14
  62. package/dist/createFileParser-BD8yn0LT.cjs.map +0 -1
  63. package/dist/createFileParser-Cix3AMLd.js +0 -8
  64. package/dist/createFileParser-Cix3AMLd.js.map +0 -1
  65. package/dist/default-DCpuPmrL.js +0 -10
  66. package/dist/default-DCpuPmrL.js.map +0 -1
  67. package/dist/default-DNBu_jsL.cjs +0 -15
  68. package/dist/default-DNBu_jsL.cjs.map +0 -1
  69. package/dist/defineApp-CZYKsxTp.d.ts +0 -95
  70. package/dist/defineApp-c9lWJ96_.d.cts +0 -95
  71. package/dist/parsers/default.cjs +0 -4
  72. package/dist/parsers/default.d.cts +0 -8
  73. package/dist/parsers/default.d.ts +0 -8
  74. package/dist/parsers/default.js +0 -4
  75. package/dist/parsers/tsx.cjs +0 -5
  76. package/dist/parsers/tsx.d.cts +0 -8
  77. package/dist/parsers/tsx.d.ts +0 -8
  78. package/dist/parsers/tsx.js +0 -5
  79. package/dist/tsx-BSUaIML3.cjs +0 -16
  80. package/dist/tsx-BSUaIML3.cjs.map +0 -1
  81. package/dist/tsx-DBAk9dqS.js +0 -11
  82. package/dist/tsx-DBAk9dqS.js.map +0 -1
  83. package/dist/types-CkbelZaS.d.ts +0 -15
  84. package/dist/types-GueHciQ3.d.cts +0 -15
  85. package/dist/typescript-C60gWBu8.js.map +0 -1
  86. package/dist/typescript-Z90jN87k.cjs.map +0 -1
  87. package/src/fs.ts +0 -167
  88. package/src/parsers/createFileParser.ts +0 -5
  89. package/src/parsers/default.ts +0 -7
  90. package/src/parsers/tsx.ts +0 -8
@@ -1,77 +1,31 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- const require_createFileParser = require('./createFileParser-BD8yn0LT.cjs');
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
25
2
  let node_path = require("node:path");
26
- node_path = __toESM(node_path);
27
- let fs_extra = require("fs-extra");
28
- fs_extra = __toESM(fs_extra);
29
- let js_runtime = require("js-runtime");
30
- js_runtime = __toESM(js_runtime);
3
+ node_path = require_chunk.__toESM(node_path);
31
4
  let typescript = require("typescript");
32
- typescript = __toESM(typescript);
5
+ typescript = require_chunk.__toESM(typescript);
33
6
 
34
- //#region src/fs.ts
35
- async function write(path$1, data, options = {}) {
36
- if (data.trim() === "") return;
37
- return (0, js_runtime.switcher)({
38
- node: async (path$2, data$1, { sanity }) => {
39
- try {
40
- const oldContent = await fs_extra.default.readFile((0, node_path.resolve)(path$2), { encoding: "utf-8" });
41
- if ((oldContent === null || oldContent === void 0 ? void 0 : oldContent.toString()) === (data$1 === null || data$1 === void 0 ? void 0 : data$1.toString())) return;
42
- } catch (_err) {}
43
- await fs_extra.default.outputFile((0, node_path.resolve)(path$2), data$1, { encoding: "utf-8" });
44
- if (sanity) {
45
- const savedData = await fs_extra.default.readFile((0, node_path.resolve)(path$2), { encoding: "utf-8" });
46
- if ((savedData === null || savedData === void 0 ? void 0 : savedData.toString()) !== (data$1 === null || data$1 === void 0 ? void 0 : data$1.toString())) throw new Error(`Sanity check failed for ${path$2}\n\nData[${data$1.length}]:\n${data$1}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
47
- return savedData;
48
- }
49
- return data$1;
50
- },
51
- bun: async (path$2, data$1, { sanity }) => {
52
- try {
53
- await Bun.write((0, node_path.resolve)(path$2), data$1);
54
- if (sanity) {
55
- const savedData = await Bun.file((0, node_path.resolve)(path$2)).text();
56
- if ((savedData === null || savedData === void 0 ? void 0 : savedData.toString()) !== (data$1 === null || data$1 === void 0 ? void 0 : data$1.toString())) throw new Error(`Sanity check failed for ${path$2}\n\nData[${path$2.length}]:\n${path$2}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
57
- return savedData;
58
- }
59
- return data$1;
60
- } catch (e) {
61
- console.error(e);
62
- }
63
- }
64
- }, "node")(path$1, data.trim(), options);
7
+ //#region src/utils/trimExtName.ts
8
+ function trimExtName(text) {
9
+ return text.replace(/\.[^/.]+$/, "");
10
+ }
11
+
12
+ //#endregion
13
+ //#region src/parsers/createParser.ts
14
+ function createParser(parser) {
15
+ return {
16
+ type: "parser",
17
+ ...parser
18
+ };
65
19
  }
20
+
21
+ //#endregion
22
+ //#region src/utils/getRelativePath.ts
66
23
  function slash(path$1, platform = "linux") {
67
24
  const isWindowsPath = /^\\\\\?\\/.test(path$1);
68
25
  const normalizedPath = (0, node_path.normalize)(path$1);
69
26
  if (["linux", "mac"].includes(platform) && !isWindowsPath) return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
70
27
  return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
71
28
  }
72
- function trimExtName(text) {
73
- return text.replace(/\.[^/.]+$/, "");
74
- }
75
29
  function getRelativePath(rootDir, filePath, platform = "linux") {
76
30
  if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
77
31
  const slashedPath = slash((0, node_path.relative)(rootDir, filePath), platform);
@@ -80,7 +34,7 @@ function getRelativePath(rootDir, filePath, platform = "linux") {
80
34
  }
81
35
 
82
36
  //#endregion
83
- //#region src/parsers/typescript.ts
37
+ //#region src/parsers/typescriptParser.ts
84
38
  const { factory } = typescript.default;
85
39
  /**
86
40
  * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}
@@ -143,42 +97,41 @@ function createExport({ path: path$1, asAlias, isTypeOnly = false, name }) {
143
97
  return factory.createExportSpecifier(false, void 0, typeof propertyName === "string" ? factory.createIdentifier(propertyName) : propertyName);
144
98
  })), factory.createStringLiteral(path$1), void 0);
145
99
  }
146
- const typeScriptParser = require_createFileParser.createFileParser({ async print(file, options = { extname: ".ts" }) {
147
- const source = file.sources.map((item) => item.value).join("\n\n");
148
- const importNodes = file.imports.map((item) => {
149
- const importPath = item.root ? getRelativePath(item.root, item.path) : item.path;
150
- const hasExtname = !!node_path.default.extname(importPath);
151
- return createImport({
152
- name: item.name,
153
- path: options.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,
154
- isTypeOnly: item.isTypeOnly
155
- });
156
- }).filter(Boolean);
157
- const exportNodes = file.exports.map((item) => {
158
- const exportPath = item.path;
159
- const hasExtname = !!node_path.default.extname(exportPath);
160
- return createExport({
161
- name: item.name,
162
- path: options.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),
163
- isTypeOnly: item.isTypeOnly,
164
- asAlias: item.asAlias
165
- });
166
- }).filter(Boolean);
167
- return [
168
- file.banner,
169
- print([...importNodes, ...exportNodes]),
170
- source,
171
- file.footer
172
- ].join("\n");
173
- } });
100
+ const typescriptParser = createParser({
101
+ name: "typescript",
102
+ extNames: [".ts", ".js"],
103
+ install() {},
104
+ async parse(file, options = { extname: ".ts" }) {
105
+ const source = file.sources.map((item) => item.value).join("\n\n");
106
+ const importNodes = file.imports.map((item) => {
107
+ const importPath = item.root ? getRelativePath(item.root, item.path) : item.path;
108
+ const hasExtname = !!node_path.default.extname(importPath);
109
+ return createImport({
110
+ name: item.name,
111
+ path: options.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,
112
+ isTypeOnly: item.isTypeOnly
113
+ });
114
+ }).filter(Boolean);
115
+ const exportNodes = file.exports.map((item) => {
116
+ const exportPath = item.path;
117
+ const hasExtname = !!node_path.default.extname(exportPath);
118
+ return createExport({
119
+ name: item.name,
120
+ path: options.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),
121
+ isTypeOnly: item.isTypeOnly,
122
+ asAlias: item.asAlias
123
+ });
124
+ }).filter(Boolean);
125
+ return [
126
+ file.banner,
127
+ print([...importNodes, ...exportNodes]),
128
+ source,
129
+ file.footer
130
+ ].join("\n");
131
+ }
132
+ });
174
133
 
175
134
  //#endregion
176
- Object.defineProperty(exports, '__toESM', {
177
- enumerable: true,
178
- get: function () {
179
- return __toESM;
180
- }
181
- });
182
135
  Object.defineProperty(exports, 'createExport', {
183
136
  enumerable: true,
184
137
  get: function () {
@@ -191,28 +144,28 @@ Object.defineProperty(exports, 'createImport', {
191
144
  return createImport;
192
145
  }
193
146
  });
194
- Object.defineProperty(exports, 'print', {
147
+ Object.defineProperty(exports, 'createParser', {
195
148
  enumerable: true,
196
149
  get: function () {
197
- return print;
150
+ return createParser;
198
151
  }
199
152
  });
200
- Object.defineProperty(exports, 'trimExtName', {
153
+ Object.defineProperty(exports, 'print', {
201
154
  enumerable: true,
202
155
  get: function () {
203
- return trimExtName;
156
+ return print;
204
157
  }
205
158
  });
206
- Object.defineProperty(exports, 'typeScriptParser', {
159
+ Object.defineProperty(exports, 'trimExtName', {
207
160
  enumerable: true,
208
161
  get: function () {
209
- return typeScriptParser;
162
+ return trimExtName;
210
163
  }
211
164
  });
212
- Object.defineProperty(exports, 'write', {
165
+ Object.defineProperty(exports, 'typescriptParser', {
213
166
  enumerable: true,
214
167
  get: function () {
215
- return write;
168
+ return typescriptParser;
216
169
  }
217
170
  });
218
- //# sourceMappingURL=typescript-Z90jN87k.cjs.map
171
+ //# sourceMappingURL=typescriptParser-BBbbmG5W.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescriptParser-BBbbmG5W.cjs","names":["path","ts","output: string","path","importPropertyName: ts.Identifier | undefined","importName: ts.NamedImportBindings | undefined"],"sources":["../src/utils/trimExtName.ts","../src/parsers/createParser.ts","../src/utils/getRelativePath.ts","../src/parsers/typescriptParser.ts"],"sourcesContent":["export function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import type { Parser, UserParser } from './types.ts'\n\nexport function createParser<TOptions = any[], TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {\n return {\n type: 'parser',\n ...parser,\n }\n}\n","import { normalize, relative } from 'node:path'\n\nfunction slash(path: string, platform: 'windows' | 'mac' | 'linux' = 'linux') {\n const isWindowsPath = /^\\\\\\\\\\?\\\\/.test(path)\n const normalizedPath = normalize(path)\n\n if (['linux', 'mac'].includes(platform) && !isWindowsPath) {\n // linux and mac\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n }\n\n // windows\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null, platform: 'windows' | 'mac' | 'linux' = 'linux'): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const slashedPath = slash(relativePath, platform)\n\n if (slashedPath.startsWith('../')) {\n return slashedPath\n }\n\n return `./${slashedPath}`\n}\n","import ts from 'typescript'\nimport { getRelativePath } from '../utils/getRelativePath.ts'\nimport { trimExtName } from '../utils/trimExtName.ts'\nimport path from 'node:path'\nimport { createParser } from './createParser.ts'\n\nconst { factory } = ts\n\ntype PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n}\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\n/**\n * Convert AST TypeScript/TSX nodes to a string based on the TypeScript printer.\n * Ensures consistent output across environments.\n * Also works as a formatter when `source` is provided without `elements`.\n */\nexport function print(elements: Array<ts.Node> = [], { source = '', baseName = 'print.tsx', scriptKind = ts.ScriptKind.TSX }: PrintOptions = {}): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, true, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n })\n\n let output: string\n\n if (elements.length > 0) {\n // Print only provided nodes\n const nodes = elements.filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n } else {\n // Format the whole file\n output = printer.printFile(sourceFile)\n }\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n\nexport function createImport({\n name,\n path,\n root,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n root?: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n const resolvePath = root ? getRelativePath(root, path) : path\n\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n}\n\nexport function createExport({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n console.warn(`When using name as string, asAlias should be true ${name}`)\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport const typescriptParser = createParser({\n name: 'typescript',\n extNames: ['.ts', '.js'],\n install() {},\n async parse(file, options = { extname: '.ts' }) {\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n\n const importNodes = file.imports\n .map((item) => {\n const importPath = item.root ? getRelativePath(item.root, item.path) : item.path\n const hasExtname = !!path.extname(importPath)\n\n return createImport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,\n isTypeOnly: item.isTypeOnly,\n })\n })\n .filter(Boolean)\n\n const exportNodes = file.exports\n .map((item) => {\n const exportPath = item.path\n\n const hasExtname = !!path.extname(exportPath)\n\n return createExport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),\n isTypeOnly: item.isTypeOnly,\n asAlias: item.asAlias,\n })\n })\n .filter(Boolean)\n\n return [file.banner, print([...importNodes, ...exportNodes]), source, file.footer].join('\\n')\n },\n})\n"],"mappings":";;;;;;;AAAA,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG;;;;;ACCtC,SAAgB,aAA2D,QAA8D;AACvI,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACJH,SAAS,MAAM,QAAc,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAKA,OAAK;CAC5C,MAAM,0CAA2BA,OAAK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O,CAAC,KAAK,KAAK;;CAEhG,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { o as Parser } from "./App-zyf9KG3p.cjs";
2
+ import ts from "typescript";
3
+
4
+ //#region src/parsers/typescriptParser.d.ts
5
+ type PrintOptions = {
6
+ source?: string;
7
+ baseName?: string;
8
+ scriptKind?: ts.ScriptKind;
9
+ };
10
+ /**
11
+ * Convert AST TypeScript/TSX nodes to a string based on the TypeScript printer.
12
+ * Ensures consistent output across environments.
13
+ * Also works as a formatter when `source` is provided without `elements`.
14
+ */
15
+ declare function print(elements?: Array<ts.Node>, {
16
+ source,
17
+ baseName,
18
+ scriptKind
19
+ }?: PrintOptions): string;
20
+ declare function createImport({
21
+ name,
22
+ path,
23
+ root,
24
+ isTypeOnly,
25
+ isNameSpace
26
+ }: {
27
+ name: string | Array<string | {
28
+ propertyName: string;
29
+ name?: string;
30
+ }>;
31
+ path: string;
32
+ root?: string;
33
+ isTypeOnly?: boolean;
34
+ isNameSpace?: boolean;
35
+ }): ts.ImportDeclaration;
36
+ declare function createExport({
37
+ path,
38
+ asAlias,
39
+ isTypeOnly,
40
+ name
41
+ }: {
42
+ path: string;
43
+ asAlias?: boolean;
44
+ isTypeOnly?: boolean;
45
+ name?: string | Array<ts.Identifier | string>;
46
+ }): ts.ExportDeclaration;
47
+ declare const typescriptParser: Parser<[], any>;
48
+ //#endregion
49
+ export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
+ //# sourceMappingURL=typescriptParser-C-sBy1iR.d.cts.map
@@ -0,0 +1,50 @@
1
+ import { o as Parser } from "./App-DZuROf6f.js";
2
+ import ts from "typescript";
3
+
4
+ //#region src/parsers/typescriptParser.d.ts
5
+ type PrintOptions = {
6
+ source?: string;
7
+ baseName?: string;
8
+ scriptKind?: ts.ScriptKind;
9
+ };
10
+ /**
11
+ * Convert AST TypeScript/TSX nodes to a string based on the TypeScript printer.
12
+ * Ensures consistent output across environments.
13
+ * Also works as a formatter when `source` is provided without `elements`.
14
+ */
15
+ declare function print(elements?: Array<ts.Node>, {
16
+ source,
17
+ baseName,
18
+ scriptKind
19
+ }?: PrintOptions): string;
20
+ declare function createImport({
21
+ name,
22
+ path,
23
+ root,
24
+ isTypeOnly,
25
+ isNameSpace
26
+ }: {
27
+ name: string | Array<string | {
28
+ propertyName: string;
29
+ name?: string;
30
+ }>;
31
+ path: string;
32
+ root?: string;
33
+ isTypeOnly?: boolean;
34
+ isNameSpace?: boolean;
35
+ }): ts.ImportDeclaration;
36
+ declare function createExport({
37
+ path,
38
+ asAlias,
39
+ isTypeOnly,
40
+ name
41
+ }: {
42
+ path: string;
43
+ asAlias?: boolean;
44
+ isTypeOnly?: boolean;
45
+ name?: string | Array<ts.Identifier | string>;
46
+ }): ts.ExportDeclaration;
47
+ declare const typescriptParser: Parser<[], any>;
48
+ //#endregion
49
+ export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
+ //# sourceMappingURL=typescriptParser-CtMmz0UV.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,18 +26,18 @@
26
26
  "import": "./dist/index.js",
27
27
  "require": "./dist/index.cjs"
28
28
  },
29
- "./parsers/default": {
30
- "import": "./dist/parsers/default.js",
31
- "require": "./dist/parsers/default.cjs"
32
- },
33
- "./parsers/tsx": {
34
- "import": "./dist/parsers/tsx.js",
35
- "require": "./dist/parsers/tsx.cjs"
29
+ "./parsers": {
30
+ "import": "./dist/parsers.js",
31
+ "require": "./dist/parsers.cjs"
36
32
  },
37
33
  "./parsers/typescript": {
38
34
  "import": "./dist/parsers/typescript.js",
39
35
  "require": "./dist/parsers/typescript.cjs"
40
36
  },
37
+ "./plugins": {
38
+ "import": "./dist/plugins.js",
39
+ "require": "./dist/plugins.cjs"
40
+ },
41
41
  "./types": {
42
42
  "import": "./dist/types.js",
43
43
  "require": "./dist/types.cjs"
@@ -49,14 +49,14 @@
49
49
  "types": "./dist/index.d.cts",
50
50
  "typesVersions": {
51
51
  "*": {
52
+ "parsers": [
53
+ "./dist/parsers.d.ts"
54
+ ],
52
55
  "parsers/typescript": [
53
56
  "./dist/parsers/typescript.d.ts"
54
57
  ],
55
- "parsers/tsx": [
56
- "./dist/parsers/tsx.d.ts"
57
- ],
58
- "parsers/default": [
59
- "./dist/parsers/default.d.ts"
58
+ "plugins": [
59
+ "./dist/plugins.d.ts"
60
60
  ],
61
61
  "types": [
62
62
  "./dist/types.d.ts"
package/src/App.ts ADDED
@@ -0,0 +1,91 @@
1
+ import type * as KubbFile from './KubbFile.ts'
2
+ import type { Plugin } from './plugins/types.ts'
3
+ import type { Parser } from './parsers/types.ts'
4
+ import type { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
5
+ import type { FileManager } from './FileManager.ts'
6
+
7
+ export type Component = any
8
+
9
+ export type AppEvents = {
10
+ /**
11
+ * Called in the beginning of the app lifecycle.
12
+ */
13
+ start: [{ app: App }]
14
+ /**
15
+ * Called in the end of the app lifecycle.
16
+ */
17
+ end: [{ app: App }]
18
+ /**
19
+ * Called when being rendered
20
+ */
21
+ render: [{ app: App }]
22
+ /**
23
+ * Called once before processing any files.
24
+ */
25
+ 'process:start': [{ files: KubbFile.ResolvedFile[] }]
26
+
27
+ /**
28
+ * Called for each file when processing begins.
29
+ */
30
+ 'file:start': [{ file: KubbFile.ResolvedFile; index: number; total: number }]
31
+
32
+ /**
33
+ * Called for each file when processing finishes.
34
+ */
35
+ 'file:end': [{ file: KubbFile.ResolvedFile; index: number; total: number }]
36
+
37
+ /**
38
+ * Called periodically (or after each file) to indicate progress.
39
+ * Useful for progress bars or logging.
40
+ */
41
+ 'process:progress': [
42
+ {
43
+ processed: number
44
+ total: number
45
+ percentage: number
46
+ source: string
47
+ file: KubbFile.ResolvedFile
48
+ },
49
+ ]
50
+
51
+ /**
52
+ * Called once all files have been processed successfully.
53
+ */
54
+ 'process:end': [{ files: KubbFile.ResolvedFile[] }]
55
+ }
56
+
57
+ export type AppContext<TOptions = unknown> = {
58
+ options?: TOptions
59
+ events: AsyncEventEmitter<AppEvents>
60
+ fileManager: FileManager
61
+ installedPlugins: Set<Plugin>
62
+ installedParsers: Set<Parser>
63
+ }
64
+
65
+ export type Install<TOptions = any[] | object | undefined> = TOptions extends any[]
66
+ ? (app: App, context: AppContext, ...options: TOptions) => void
67
+ : TOptions extends object
68
+ ? (app: App, context: AppContext, options?: TOptions) => void
69
+ : (app: App, context: AppContext) => void
70
+
71
+ export type Override<TOptions = any[] | object | undefined, TAppExtension extends Record<string, any> = {}> = TOptions extends any[]
72
+ ? (app: App, context: AppContext, ...options: TOptions) => Partial<TAppExtension>
73
+ : TOptions extends object
74
+ ? (app: App, context: AppContext, options?: TOptions) => Partial<TAppExtension>
75
+ : (app: App, context: AppContext) => Partial<TAppExtension>
76
+
77
+ export interface App {
78
+ _component: Component
79
+ render(): Promise<void>
80
+ renderToString(): Promise<string>
81
+ files: Array<KubbFile.ResolvedFile>
82
+ use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
83
+ pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
84
+ ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]
85
+ ): this & TAppExtension
86
+ use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
87
+ pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
88
+ ): this & TAppExtension
89
+ addFile(...files: Array<KubbFile.File>): Promise<void>
90
+ waitUntilExit(): Promise<void>
91
+ }
@@ -1,9 +1,11 @@
1
1
  import type * as KubbFile from './KubbFile.ts'
2
2
  import { Cache } from './utils/Cache.ts'
3
- import { trimExtName } from './fs.ts'
3
+ import { trimExtName } from './utils/trimExtName.ts'
4
4
  import { orderBy } from 'natural-orderby'
5
5
  import { createFile } from './createFile.ts'
6
6
  import { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'
7
+ import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
8
+ import type { AppEvents } from './App.ts'
7
9
 
8
10
  function mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {
9
11
  return {
@@ -14,11 +16,16 @@ function mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: Ku
14
16
  }
15
17
  }
16
18
 
19
+ type Options = {
20
+ events?: AsyncEventEmitter<AppEvents>
21
+ }
22
+
17
23
  export class FileManager {
18
24
  #cache = new Cache<KubbFile.ResolvedFile>()
19
- #processor = new FileProcessor()
25
+ processor: FileProcessor
20
26
 
21
- constructor() {
27
+ constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {
28
+ this.processor = new FileProcessor({ events })
22
29
  return this
23
30
  }
24
31
 
@@ -78,14 +85,7 @@ export class FileManager {
78
85
  return files.filter(Boolean)
79
86
  }
80
87
 
81
- get processor() {
82
- const files = this.files
83
- const processor = this.#processor
84
-
85
- return {
86
- async run(options: ProcessFilesProps) {
87
- return processor.run(files, options)
88
- },
89
- }
88
+ async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {
89
+ return this.processor.run(this.files, options)
90
90
  }
91
91
  }