@kubb/fabric-core 0.0.0-canary-20251021185909 → 0.0.0-canary-20251022200241

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-DUFbq4lD.d.ts +292 -0
  2. package/dist/App-DoQNlnGL.d.cts +292 -0
  3. package/dist/chunk-CUT6urMc.cjs +30 -0
  4. package/dist/defineApp-C6WnoREI.d.ts +14 -0
  5. package/dist/defineApp-D1-njmtr.d.cts +14 -0
  6. package/dist/index.cjs +127 -93
  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 +116 -82
  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-C9WJrwRd.d.ts +50 -0
  37. package/dist/typescriptParser-DOD1_QTe.d.cts +50 -0
  38. package/package.json +13 -13
  39. package/src/App.ts +91 -0
  40. package/src/FileManager.ts +10 -3
  41. package/src/FileProcessor.ts +48 -49
  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-CpGKyn6q.d.cts +0 -100
  70. package/dist/defineApp-ms3Tog4-.d.ts +0 -100
  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
@@ -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;AAEtC,KAAI,CAAC,SAAS,MAAM,CAAC,SAAS,SAAS,IAAI,CAAC,cAE1C,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;AAIjE,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;;AAGjE,SAAgB,gBAAgB,SAAyB,UAA0B,WAAwC,SAAiB;AAC1I,KA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OACD;;AAGH,MAAa,mBAAmB,aAAa;CAC3C,MAAM;CACN,UAAU,CAAC,OAAO,MAAM;CACxB,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,OAAO,EAAE;EAC9C,MAAM,SAAS,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;EAElE,MAAM,cAAc,KAAK,QACtB,KAAK,SAAS;GACb,MAAM,aAAa,KAAK,OAAO,gBAAgB,KAAK,MAAM,KAAK,KAAK,GAAG,KAAK;GAC5E,MAAM,aAAa,CAAC,CAACA,kBAAK,QAAQ,WAAW;AAE7C,UAAO,aAAa;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAG,YAAY,WAAW,GAAG,QAAQ,YAAY,KAAK,OAAO,YAAY,WAAW,GAAG;IAC7H,YAAY,KAAK;IAClB,CAAC;IACF,CACD,OAAO,QAAQ;EAElB,MAAM,cAAc,KAAK,QACtB,KAAK,SAAS;GACb,MAAM,aAAa,KAAK;GAExB,MAAM,aAAa,CAAC,CAACA,kBAAK,QAAQ,WAAW;AAE7C,UAAO,aAAa;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAG,YAAY,KAAK,KAAK,GAAG,QAAQ,YAAY,YAAY,KAAK,KAAK;IAC5G,YAAY,KAAK;IACjB,SAAS,KAAK;IACf,CAAC;IACF,CACD,OAAO,QAAQ;AAElB,SAAO;GAAC,KAAK;GAAQ,MAAM,CAAC,GAAG,aAAa,GAAG,YAAY,CAAC;GAAE;GAAQ,KAAK;GAAO,CAAC,KAAK,KAAK;;CAEhG,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { o as Parser } from "./App-DUFbq4lD.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-C9WJrwRd.d.ts.map
@@ -0,0 +1,50 @@
1
+ import { o as Parser } from "./App-DoQNlnGL.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-DOD1_QTe.d.cts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.0.0-canary-20251021185909",
3
+ "version": "0.0.0-canary-20251022200241",
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
 
@@ -1,85 +1,84 @@
1
1
  import type * as KubbFile from './KubbFile.ts'
2
- import { EventEmitter } from './utils/EventEmitter.ts'
3
- import { write } from './fs.ts'
4
2
  import pLimit from 'p-limit'
3
+ import path from 'node:path'
4
+
5
5
  import type { Parser } from './parsers/types.ts'
6
- import { typeScriptParser } from './parsers/typescript.ts'
7
- import { tsxParser } from './parsers/tsx.ts'
8
- import { defaultParser } from './parsers/default.ts'
9
-
10
- type FileProcessorEvents = {
11
- start: [{ files: KubbFile.ResolvedFile[] }]
12
- finish: [{ files: KubbFile.ResolvedFile[] }]
13
- 'file:start': [{ file: KubbFile.ResolvedFile }]
14
- 'file:finish': [{ file: KubbFile.ResolvedFile }]
15
- }
6
+ import { defaultParser } from './parsers/defaultParser.ts'
7
+ import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
8
+ import type { AppEvents } from './App.ts'
9
+ import { typescriptParser } from './parsers/typescriptParser.ts'
10
+ import { tsxParser } from './parsers/tsxParser.ts'
16
11
 
17
12
  export type ProcessFilesProps = {
13
+ parsers?: Set<Parser>
18
14
  extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
19
15
  dryRun?: boolean
20
16
  }
21
17
 
22
- type GetSourceOptions = {
23
- extname?: KubbFile.Extname
18
+ type GetParseOptions = {
19
+ parsers?: Set<Parser>
20
+ extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
24
21
  }
25
22
 
26
- async function getParser<TMeta extends object = object>(extname: KubbFile.Extname | undefined): Promise<Parser<TMeta>> {
27
- const parsers: Record<KubbFile.Extname, Parser<any>> = {
28
- '.ts': typeScriptParser,
29
- '.js': typeScriptParser,
30
- '.jsx': tsxParser,
31
- '.tsx': tsxParser,
32
- '.json': defaultParser,
33
- }
23
+ type Options = {
24
+ events?: AsyncEventEmitter<AppEvents>
25
+ }
34
26
 
35
- if (!extname) {
36
- return defaultParser
37
- }
27
+ export class FileProcessor {
28
+ #limit = pLimit(100)
29
+ events: AsyncEventEmitter<AppEvents>
38
30
 
39
- const parser = parsers[extname]
31
+ constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {
32
+ this.events = events
40
33
 
41
- if (!parser) {
42
- console.warn(`[parser] No parser found for ${extname}, default parser will be used`)
34
+ return this
43
35
  }
44
36
 
45
- return parser || defaultParser
46
- }
37
+ get #defaultParser(): Set<Parser> {
38
+ return new Set<Parser>([typescriptParser, tsxParser, defaultParser])
39
+ }
47
40
 
48
- export class FileProcessor extends EventEmitter<FileProcessorEvents> {
49
- #limit = pLimit(100)
41
+ async parse(file: KubbFile.ResolvedFile, { parsers = this.#defaultParser, extension }: GetParseOptions = {}): Promise<string> {
42
+ const extname = path.extname(file.path) as KubbFile.Extname
43
+ const parseExtName = extension?.[file.extname] || undefined
50
44
 
51
- constructor(maxListener = 1000) {
52
- super(maxListener)
53
- return this
54
- }
45
+ if (!extname) {
46
+ return defaultParser.parse(file, { extname: parseExtName })
47
+ }
55
48
 
56
- async parse(file: KubbFile.ResolvedFile, { extname }: GetSourceOptions = {}): Promise<string> {
57
- const parser = await getParser(file.extname)
49
+ const parser = [...parsers].find((item) => item.extNames?.includes(extname))
58
50
 
59
- return parser.print(file, { extname })
51
+ if (!parser) {
52
+ return defaultParser.parse(file, { extname: parseExtName })
53
+ }
54
+
55
+ return parser.parse(file, { extname: parseExtName })
60
56
  }
61
57
 
62
- async run(files: Array<KubbFile.ResolvedFile>, { dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {
63
- this.emit('start', { files })
58
+ async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {
59
+ await this.events.emit('process:start', { files })
64
60
 
65
- const promises = files.map((resolvedFile) =>
66
- this.#limit(async () => {
67
- const extname = extension?.[resolvedFile.extname] || undefined
61
+ let processed = 0
62
+ const total = files.length
68
63
 
69
- this.emit('file:start', { file: resolvedFile })
64
+ const promises = files.map((resolvedFile, index) =>
65
+ this.#limit(async () => {
66
+ await this.events.emit('file:start', { file: resolvedFile, index, total })
70
67
 
71
68
  if (!dryRun) {
72
- const source = await this.parse(resolvedFile, { extname })
73
- await write(resolvedFile.path, source, { sanity: false })
69
+ const source = await this.parse(resolvedFile, { extension, parsers })
70
+ await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage: (processed / total) * 100, total })
74
71
  }
75
72
 
76
- this.emit('file:finish', { file: resolvedFile })
73
+ await this.events.emit('file:end', { file: resolvedFile, index, total })
74
+
75
+ processed++
77
76
  }),
78
77
  )
79
78
 
80
79
  await Promise.all(promises)
81
80
 
82
- this.emit('finish', { files })
81
+ await this.events.emit('process:end', { files })
83
82
 
84
83
  return files
85
84
  }
package/src/createFile.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type * as KubbFile from './KubbFile.ts'
2
- import { trimExtName } from './fs.ts'
2
+ import { trimExtName } from './utils/trimExtName.ts'
3
3
  import { createHash } from 'node:crypto'
4
4
  import path from 'node:path'
5
5
  import { isDeepEqual, uniqueBy } from 'remeda'
package/src/defineApp.ts CHANGED
@@ -1,17 +1,9 @@
1
- import type * as KubbFile from './KubbFile.ts'
2
1
  import { FileManager } from './FileManager.ts'
3
- import { isPromise } from 'remeda'
4
-
5
- const isFunction = (val: unknown): val is Function => typeof val === 'function'
6
-
7
- type Component = any
8
-
9
- type PluginInstallFunction<Options = any[]> = Options extends unknown[] ? (app: App, ...options: Options) => any : (app: App, options: Options) => any
10
-
11
- export type ObjectPlugin<Options = any[]> = {
12
- install: PluginInstallFunction<Options>
13
- }
14
- export type FunctionPlugin<Options = any[]> = PluginInstallFunction<Options> & Partial<ObjectPlugin<Options>>
2
+ import { isFunction, isPromise } from 'remeda'
3
+ import type { Plugin } from './plugins/types.ts'
4
+ import type { Parser } from './parsers/types.ts'
5
+ import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
6
+ import type { App, AppContext, Component, AppEvents } from './App.ts'
15
7
 
16
8
  type AppRenderer = {
17
9
  render(): Promise<void> | void
@@ -19,57 +11,27 @@ type AppRenderer = {
19
11
  waitUntilExit(): Promise<void>
20
12
  }
21
13
 
22
- export type AppContext<TOptions = unknown> = {
23
- options?: TOptions
24
- fileManager: FileManager
25
- addFile(...files: Array<KubbFile.File>): Promise<void>
26
- files: Array<KubbFile.ResolvedFile>
27
- clear: () => void
28
- }
29
-
30
14
  type RootRenderFunction<THostElement, TContext extends AppContext> = (this: TContext, container: THostElement, context: TContext) => AppRenderer
31
15
 
32
- type Plugin<Options = any[], P extends unknown[] = Options extends unknown[] ? Options : [Options]> = FunctionPlugin<P> | ObjectPlugin<P>
33
-
34
- type WriteOptions = {
35
- extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
36
- dryRun?: boolean
37
- }
38
-
39
- export interface App {
40
- _component: Component
41
- render(): Promise<void>
42
- renderToString(): Promise<string>
43
- files: Array<KubbFile.ResolvedFile>
44
- use<Options>(plugin: Plugin<Options>, options: NoInfer<Options>): this
45
- write(options?: WriteOptions): Promise<void>
46
- addFile(...files: Array<KubbFile.File>): Promise<void>
47
- waitUntilExit(): Promise<void>
48
- }
49
-
50
16
  export type DefineApp<TContext extends AppContext> = (rootComponent?: Component, options?: TContext['options']) => App
51
17
 
52
18
  export function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext> {
53
19
  function createApp(rootComponent: Component, options?: TContext['options']): App {
54
- const installedPlugins = new WeakSet()
55
- const fileManager = new FileManager()
20
+ const events = new AsyncEventEmitter<AppEvents>()
21
+ const installedPlugins = new Set<Plugin>()
22
+ const installedParsers = new Set<Parser>()
23
+ const fileManager = new FileManager({ events })
56
24
  const context = {
25
+ events,
57
26
  options,
58
27
  fileManager,
59
- async addFile(...newFiles) {
60
- await fileManager.add(...newFiles)
61
- },
62
- clear() {
63
- context.fileManager.clear()
64
- },
65
- get files() {
66
- return fileManager.files
67
- },
28
+ installedPlugins,
29
+ installedParsers,
68
30
  } as TContext
69
31
 
70
32
  const { render, renderToString, waitUntilExit } = instance.call(context, rootComponent, context)
71
33
 
72
- const app: App = {
34
+ const app = {
73
35
  _component: rootComponent,
74
36
  async render() {
75
37
  if (isPromise(render)) {
@@ -85,32 +47,45 @@ export function defineApp<THostElement, TContext extends AppContext>(instance: R
85
47
  return fileManager.files
86
48
  },
87
49
  waitUntilExit,
88
- addFile: context.addFile,
89
- async write(
90
- options = {
91
- extension: { '.ts': '.ts' },
92
- dryRun: false,
93
- },
94
- ) {
95
- await fileManager.write({
96
- extension: options.extension,
97
- dryRun: options.dryRun,
98
- })
50
+ async addFile(...newFiles) {
51
+ await fileManager.add(...newFiles)
99
52
  },
100
- use(plugin: Plugin, ...options: any[]) {
101
- if (installedPlugins.has(plugin)) {
102
- console.warn('Plugin has already been applied to target app.')
103
- } else if (plugin && isFunction(plugin.install)) {
104
- installedPlugins.add(plugin)
105
- plugin.install(app, ...options)
106
- } else if (isFunction(plugin)) {
107
- installedPlugins.add(plugin)
108
- plugin(app, ...options)
53
+ use(pluginOrParser, ...options) {
54
+ const args = Array.isArray(options) ? options : [options[0]]
55
+
56
+ if (pluginOrParser.type === 'plugin') {
57
+ if (installedPlugins.has(pluginOrParser)) {
58
+ console.warn('Plugin has already been applied to target app.')
59
+ } else {
60
+ installedPlugins.add(pluginOrParser)
61
+ }
62
+
63
+ if (pluginOrParser.override && isFunction(pluginOrParser.override)) {
64
+ const overrider = pluginOrParser.override
65
+
66
+ const extraApp = (overrider as any)(app, context, ...args)
67
+ Object.assign(app, extraApp)
68
+ }
69
+ }
70
+ if (pluginOrParser.type === 'parser') {
71
+ if (installedParsers.has(pluginOrParser)) {
72
+ console.warn('Parser has already been applied to target app.')
73
+ } else {
74
+ installedParsers.add(pluginOrParser)
75
+ }
76
+ }
77
+
78
+ if (pluginOrParser && isFunction(pluginOrParser.install)) {
79
+ const installer = pluginOrParser.install
80
+
81
+ ;(installer as any)(app, context, ...args)
109
82
  }
110
83
 
111
84
  return app
112
85
  },
113
- }
86
+ } as App
87
+
88
+ events.emit('start', { app })
114
89
 
115
90
  return app
116
91
  }
package/src/index.ts CHANGED
@@ -3,4 +3,4 @@ export { defineApp } from './defineApp.ts'
3
3
  export { FileManager } from './FileManager.ts'
4
4
  export { createFile } from './createFile.ts'
5
5
  export { FileProcessor } from './FileProcessor.ts'
6
- export { createFileParser } from './parsers/createFileParser.ts'
6
+ export type { App } from './App.ts'
@@ -0,0 +1,8 @@
1
+ import type { Parser, UserParser } from './types.ts'
2
+
3
+ export function createParser<TOptions = any[], TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {
4
+ return {
5
+ type: 'parser',
6
+ ...parser,
7
+ }
8
+ }
@@ -0,0 +1,10 @@
1
+ import { createParser } from './createParser.ts'
2
+
3
+ export const defaultParser = createParser({
4
+ name: 'default',
5
+ extNames: ['.json'],
6
+ install() {},
7
+ async parse(file) {
8
+ return file.sources.map((item) => item.value).join('\n\n')
9
+ },
10
+ })
@@ -0,0 +1,5 @@
1
+ export { createParser } from './createParser.ts'
2
+
3
+ export { defaultParser } from './defaultParser.ts'
4
+ export { tsxParser } from './tsxParser.ts'
5
+ export { typescriptParser } from './typescriptParser.ts'
@@ -0,0 +1,11 @@
1
+ import { typescriptParser } from './typescriptParser.ts'
2
+ import { createParser } from './createParser.ts'
3
+
4
+ export const tsxParser = createParser({
5
+ name: 'tsx',
6
+ extNames: ['.tsx', '.jsx'],
7
+ install() {},
8
+ async parse(file, options = { extname: '.tsx' }) {
9
+ return typescriptParser.parse(file, options)
10
+ },
11
+ })