@xyd-js/sources 0.0.0-build

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 (97) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/ISSUES.md +10 -0
  3. package/LICENSE +21 -0
  4. package/README.md +3 -0
  5. package/TODO.md +9 -0
  6. package/__fixtures__/-1.typescript/package.json +5 -0
  7. package/__fixtures__/-1.typescript/src/index.ts +0 -0
  8. package/__fixtures__/-1.typescript/src/settings.ts +592 -0
  9. package/__fixtures__/-1.typescript/tsconfig.json +8 -0
  10. package/__fixtures__/-2.react.basic/1.flat-interface.output.json +114 -0
  11. package/__fixtures__/-2.react.basic/2.file-connect-interface.output.json +60 -0
  12. package/__fixtures__/-2.react.basic/2a.file-connect-interface-advanced.output.json +92 -0
  13. package/__fixtures__/-2.react.basic/3.props-as-variants.output.json +166 -0
  14. package/__fixtures__/-2.react.basic/4.outside-interface.output.json +60 -0
  15. package/__fixtures__/-2.react.basic/5.inline-props.output.json +60 -0
  16. package/__fixtures__/-2.react.basic/5.outside-inline-props.output.json +60 -0
  17. package/__fixtures__/-2.react.basic/5a.inline-props+outside.output.json +60 -0
  18. package/__fixtures__/-2.react.basic/5b.inline-props+interfaces.output.json +92 -0
  19. package/__fixtures__/-2.react.basic/package.json +4 -0
  20. package/__fixtures__/-2.react.basic/src/1.flat-interface.tsx +41 -0
  21. package/__fixtures__/-2.react.basic/src/2.file-connect-interface.tsx +28 -0
  22. package/__fixtures__/-2.react.basic/src/2a.file-connect-interace+advanced.tsx +54 -0
  23. package/__fixtures__/-2.react.basic/src/3.props-as-variants.tsx +67 -0
  24. package/__fixtures__/-2.react.basic/src/4.outside-interface.tsx +13 -0
  25. package/__fixtures__/-2.react.basic/src/4.outside-interface2.ts +15 -0
  26. package/__fixtures__/-2.react.basic/src/5.inline-props.tsx +19 -0
  27. package/__fixtures__/-2.react.basic/src/5a.inline-props+outside.tsx +19 -0
  28. package/__fixtures__/-2.react.basic/src/5b.inline-props+interfaces.tsx +62 -0
  29. package/__fixtures__/-2.react.basic/src/index.ts +0 -0
  30. package/__fixtures__/-2.react.basic/tsconfig.json +8 -0
  31. package/__tests__/sourcesToUniform.test.ts +167 -0
  32. package/__tests__/testResolvePropertySymbol.ts +838 -0
  33. package/__tests__/types.ts +12 -0
  34. package/__tests__/utils.ts +108 -0
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +2 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/react.cjs +237 -0
  42. package/dist/react.cjs.map +1 -0
  43. package/dist/react.d.cts +6 -0
  44. package/dist/react.d.ts +6 -0
  45. package/dist/react.js +212 -0
  46. package/dist/react.js.map +1 -0
  47. package/dist/ts.cjs +1794 -0
  48. package/dist/ts.cjs.map +1 -0
  49. package/dist/ts.d.cts +14 -0
  50. package/dist/ts.d.ts +14 -0
  51. package/dist/ts.js +1760 -0
  52. package/dist/ts.js.map +1 -0
  53. package/package.json +41 -0
  54. package/packages/react/index.ts +1 -0
  55. package/packages/react/uniformToReactUniform.ts +275 -0
  56. package/packages/ts/SignatureText.ts +233 -0
  57. package/packages/ts/TypeDocTransformer.ts +1519 -0
  58. package/packages/ts/__fixtures__/packages/package-a/package.json +4 -0
  59. package/packages/ts/__fixtures__/packages/package-a/src/index.ts +56 -0
  60. package/packages/ts/__fixtures__/packages/package-a/tsconfig.json +23 -0
  61. package/packages/ts/__fixtures__/packages/package-b/package.json +7 -0
  62. package/packages/ts/__fixtures__/packages/package-b/src/billing.ts +193 -0
  63. package/packages/ts/__fixtures__/packages/package-b/src/index.ts +8 -0
  64. package/packages/ts/__fixtures__/packages/package-b/tsconfig.json +20 -0
  65. package/packages/ts/__fixtures__/packages2/package-a/package.json +4 -0
  66. package/packages/ts/__fixtures__/packages2/package-a/src/index.ts +496 -0
  67. package/packages/ts/__fixtures__/packages2/package-a/tsconfig.json +6 -0
  68. package/packages/ts/__fixtures__/packages3/package-a/package.json +4 -0
  69. package/packages/ts/__fixtures__/packages3/package-a/src/index.ts +488 -0
  70. package/packages/ts/__fixtures__/packages3/package-a/tsconfig.json +6 -0
  71. package/packages/ts/__fixtures__/packages3/project.json +171 -0
  72. package/packages/ts/__fixtures__/react/react-a/package.json +5 -0
  73. package/packages/ts/__fixtures__/react/react-a/src/TestAbc.tsx +90 -0
  74. package/packages/ts/__fixtures__/react/react-a/src/TestBasic.tsx +27 -0
  75. package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters.tsx +27 -0
  76. package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters2.tsx +26 -0
  77. package/packages/ts/__fixtures__/react/react-a/src/TestUnion.tsx +32 -0
  78. package/packages/ts/__fixtures__/react/react-a/src/index.ts +1 -0
  79. package/packages/ts/__fixtures__/react/react-a/tsconfig.json +8 -0
  80. package/packages/ts/__fixtures__/references-output-project.json +344 -0
  81. package/packages/ts/__fixtures__/references-output-react.json +68 -0
  82. package/packages/ts/__fixtures__/references-output.json +129 -0
  83. package/packages/ts/__tests__/sourcesToUniform.test.ts +106 -0
  84. package/packages/ts/context.ts +0 -0
  85. package/packages/ts/converterts/ts-class.ts +0 -0
  86. package/packages/ts/converterts/ts-enum.ts +0 -0
  87. package/packages/ts/converterts/ts-function.ts +0 -0
  88. package/packages/ts/converterts/ts-interface.ts +0 -0
  89. package/packages/ts/converterts/ts-type.ts +0 -0
  90. package/packages/ts/index.ts +129 -0
  91. package/packages/ts/ts-core.ts +0 -0
  92. package/packages/ts/uniformToMiniUniform.ts +486 -0
  93. package/src/index.ts +0 -0
  94. package/test-cmd/index.ts +62 -0
  95. package/tsconfig.json +38 -0
  96. package/tsup.config.ts +39 -0
  97. package/vitest.config.ts +34 -0
@@ -0,0 +1,129 @@
1
+ [
2
+ {
3
+ "title": "Interface Props",
4
+ "canonical": "@xyd-sources-examples/react/interfaces/Props",
5
+ "description": "The props type for \nTestBasicComponent\n.\n",
6
+ "context": {
7
+ "symbolId": "4",
8
+ "symbolName": "Props",
9
+ "symbolKind": 256,
10
+ "packageName": "@xyd-sources-examples/react",
11
+ "fileName": "TestBasic.tsx",
12
+ "fileFullPath": "src/TestBasic.tsx",
13
+ "line": 6,
14
+ "col": 17,
15
+ "signatureText": {
16
+ "code": "export interface Props extends PropsWithChildren {\n}",
17
+ "lang": "ts"
18
+ },
19
+ "sourcecode": {
20
+ "code": "export interface Props extends PropsWithChildren {\n /** The name of the person. */\n name: string\n\n /** The age of the person. */\n age: number\n\n /** Whether the person is active. */\n isActive: boolean\n\n /** The date the person was created. */\n createdAt: Date\n}",
21
+ "lang": "ts"
22
+ },
23
+ "group": [
24
+ "@xyd-sources-examples",
25
+ "react",
26
+ "Interfaces"
27
+ ]
28
+ },
29
+ "examples": {
30
+ "groups": []
31
+ },
32
+ "definitions": [
33
+ {
34
+ "title": "Properties",
35
+ "properties": [
36
+ {
37
+ "name": "name",
38
+ "type": "string",
39
+ "description": "The name of the person.\n"
40
+ },
41
+ {
42
+ "name": "age",
43
+ "type": "number",
44
+ "description": "The age of the person.\n"
45
+ },
46
+ {
47
+ "name": "isActive",
48
+ "type": "boolean",
49
+ "description": "Whether the person is active.\n"
50
+ },
51
+ {
52
+ "name": "createdAt",
53
+ "type": "Date",
54
+ "description": "The date the person was created.\n"
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ },
60
+ {
61
+ "title": "Function TestBasicComponent",
62
+ "canonical": "@xyd-sources-examples/react/functions/TestBasicComponent",
63
+ "description": "TestBasicComponent is a React component that uses a basic props type.\n",
64
+ "context": {
65
+ "symbolId": "1",
66
+ "symbolName": "TestBasicComponent",
67
+ "symbolKind": 64,
68
+ "packageName": "@xyd-sources-examples/react",
69
+ "fileName": "TestBasic.tsx",
70
+ "fileFullPath": "src/TestBasic.tsx",
71
+ "line": 25,
72
+ "col": 16,
73
+ "signatureText": {
74
+ "code": "export function TestBasicComponent(props: Props): ReactElement;",
75
+ "lang": "ts"
76
+ },
77
+ "sourcecode": {
78
+ "code": "export function TestBasicComponent(props: Props): ReactElement {\n return <div>{props.children}</div>;\n}",
79
+ "lang": "ts"
80
+ },
81
+ "category": "Component",
82
+ "group": [
83
+ "@xyd-sources-examples",
84
+ "react",
85
+ "Component"
86
+ ]
87
+ },
88
+ "examples": {
89
+ "groups": []
90
+ },
91
+ "definitions": [
92
+ {
93
+ "title": "Returns",
94
+ "properties": [
95
+ {
96
+ "name": "",
97
+ "type": "React.ReactElement",
98
+ "description": ""
99
+ }
100
+ ],
101
+ "meta": [
102
+ {
103
+ "name": "type",
104
+ "value": "returns"
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "title": "Parameters",
110
+ "properties": [
111
+ {
112
+ "name": "props",
113
+ "type": "Props",
114
+ "description": "",
115
+ "symbolDef": {
116
+ "id": "4"
117
+ }
118
+ }
119
+ ],
120
+ "meta": [
121
+ {
122
+ "name": "type",
123
+ "value": "parameters"
124
+ }
125
+ ]
126
+ }
127
+ ]
128
+ }
129
+ ]
@@ -0,0 +1,106 @@
1
+ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2
+ import { SignatureTextLoader, MultiSignatureLoader } from '../SignatureText';
3
+ import * as path from 'node:path';
4
+ import * as fs from 'node:fs';
5
+ import { sourcesToUniformV2 } from '..';
6
+ import { uniformToReactUniform } from '../../react/uniformToReactUniform';
7
+ import { TypeDocReferenceContext } from '@xyd-js/uniform';
8
+ import { Reference } from '@xyd-js/uniform';
9
+
10
+ describe('SignatureText TODO', () => {
11
+ it("TODO", async () => {
12
+ expect(true).toBe(true)
13
+ })
14
+ })
15
+
16
+ // describe('SignatureText', () => {
17
+ // const fixturesBasePath = path.resolve(__dirname, "../__fixtures__")
18
+
19
+ // const testFilePath = path.join(fixturesBasePath, 'test-file.ts');
20
+ // const outputFilePath = path.join(fixturesBasePath, 'references-output.json');
21
+ // const outputFilePathReact = path.join(fixturesBasePath, 'references-output-react.json');
22
+ // const outputFilePathProject = path.join(fixturesBasePath, 'references-output-project.json');
23
+
24
+ // // Create a temporary test file
25
+ // beforeAll(() => {
26
+ // const testContent = `
27
+ // export class TestClass {
28
+ // constructor() {}
29
+
30
+ // public testMethod(param: string): void {
31
+ // console.log(param);
32
+ // }
33
+ // }
34
+ // `;
35
+ // fs.writeFileSync(testFilePath, testContent);
36
+ // });
37
+
38
+ // // Clean up after tests
39
+ // afterAll(() => {
40
+ // if (fs.existsSync(testFilePath)) {
41
+ // fs.unlinkSync(testFilePath);
42
+ // }
43
+ // });
44
+
45
+ // describe('sourcesToUniform', () => {
46
+ // expect(true).toBe(true)
47
+ // // TODO: finish
48
+ // return
49
+ // // it('should return a reference to the test class', async () => {
50
+ // // const basePath = path.resolve(fixturesBasePath, "packages2")
51
+
52
+ // // const references = await sourcesToUniformV2(basePath,
53
+ // // [
54
+ // // path.resolve(basePath, "package-a"),
55
+ // // // path.resolve(basePath, "package-b"),
56
+ // // ]
57
+ // // );
58
+
59
+ // // fs.writeFileSync(outputFilePath, JSON.stringify(references, null, 2));
60
+ // // // Save references to a file for inspection
61
+ // // console.log(`References saved to: ${outputFilePath}`);
62
+ // // });
63
+
64
+ // it('should return a reference to react component', async () => {
65
+ // const packagePath = path.resolve(fixturesBasePath, "react/react-a")
66
+
67
+ // const resp = await sourcesToUniformV2(packagePath,
68
+ // [
69
+ // "src/TestBasic.tsx",
70
+ // ]
71
+ // );
72
+ // if (!resp || !resp.references || !resp.projectJson) {
73
+ // throw new Error("Failed to generate documentation.")
74
+ // }
75
+
76
+ // const references = resp.references as Reference<TypeDocReferenceContext>[]
77
+ // const reactUniform = uniformToReactUniform(references, resp.projectJson)
78
+
79
+ // fs.writeFileSync(outputFilePath, JSON.stringify(resp?.references, null, 2));
80
+ // fs.writeFileSync(outputFilePathProject, JSON.stringify(resp?.projectJson, null, 2));
81
+
82
+ // fs.writeFileSync(outputFilePathReact, JSON.stringify(reactUniform, null, 2));
83
+
84
+ // // Save references to a file for inspection
85
+ // console.log(`References saved to: ${outputFilePath}`);
86
+ // console.log(`React Uniform saved to: ${outputFilePathReact}`);
87
+ // });
88
+
89
+ // it('should return a reference to react component', async () => {
90
+ // expect(true).toBe(true)
91
+ // // TODO: finish
92
+ // return
93
+ // const packagePath = path.resolve(fixturesBasePath, "packages3")
94
+
95
+ // const resp = await sourcesToUniformV2(packagePath,
96
+ // [
97
+ // path.join(packagePath, "package-a"),
98
+ // ]
99
+ // );
100
+
101
+ // fs.writeFileSync(outputFilePath, JSON.stringify(resp?.references, null, 2));
102
+ // fs.writeFileSync(outputFilePathProject, JSON.stringify(resp?.projectJson, null, 2));
103
+ // });
104
+ // });
105
+
106
+ // });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,129 @@
1
+ import * as path from 'node:path';
2
+ import {resolve} from "path";
3
+ import ts from "typescript";
4
+
5
+ import * as TypeDoc from 'typedoc';
6
+ import type {NormalizedPath, TypeDocOptions} from "typedoc";
7
+
8
+ import type {Reference, ReferenceContext} from "@xyd-js/uniform";
9
+ import {
10
+ typedocToUniform
11
+ } from "./TypeDocTransformer"
12
+
13
+ export {
14
+ uniformToMiniUniform
15
+ } from "./uniformToMiniUniform"
16
+
17
+ const importedFiles = new Set<string>();
18
+
19
+ // TODO: SUPPORT GET FROM URL + VIRTUAL FS (OR NO FS JUST SET NEEDED OPTIONS VIA CODE)
20
+ // TODO: in the future typedoc options?
21
+ export async function sourcesToUniformV2(
22
+ root: string,
23
+ entryPoints: string[]
24
+ ): Promise<{
25
+ references: Reference<ReferenceContext>[];
26
+ projectJson: TypeDoc.JSONOutput.ProjectReflection;
27
+ } | undefined> {
28
+ // TODO: support another strategies
29
+ // TODO: support entry points from github?
30
+ const commonOptions: Partial<TypeDocOptions> = {
31
+ // entryPoints,
32
+ // entryPointStrategy: TypeDoc.EntryPointStrategy.Packages,
33
+ exclude: ["**/*.test.ts", "**/*.test.tsx"],
34
+ // @ts-ignore // TODO: for some reason on build types mismatch
35
+ excludePrivate: true,
36
+ // @ts-ignore
37
+ excludeProtected: true,
38
+ // @ts-ignore
39
+ excludeExternals: true,
40
+ // @ts-ignore
41
+ includeVersion: true,
42
+ // @ts-ignore
43
+ // hideGenerator: true,
44
+ // @ts-ignore
45
+ skipErrorChecking: true,
46
+
47
+ // @ts-ignore
48
+ sort: ['source-order'],
49
+ // @ts-ignore
50
+ sortEntryPoints: false,
51
+ }
52
+
53
+ const options = {
54
+ ...commonOptions,
55
+ }
56
+ const everySingleFile = entryPoints?.every(ep => !!path.extname(ep))
57
+
58
+ if (everySingleFile) {
59
+ entryPoints.map(ep => {
60
+ findImports(root, path.resolve(root, ep));
61
+ })
62
+ const fileImported = Array.from(importedFiles) || []
63
+ options.entryPoints = [
64
+ ...[
65
+ ...entryPoints,
66
+ ...fileImported
67
+ ]?.map(ep => path.resolve(root, ep))
68
+ ]
69
+ } else {
70
+ options.entryPointStrategy = TypeDoc.EntryPointStrategy.Packages
71
+ options.entryPoints = entryPoints
72
+ options.packageOptions = {
73
+ ...commonOptions,
74
+ }
75
+ }
76
+
77
+ // TOOD: if react will not work then add []
78
+ const app = await TypeDoc.Application.bootstrapWithPlugins(options);
79
+ const project = await app.convert()
80
+ if (!project) {
81
+ console.error('Failed to generate documentation.');
82
+ return
83
+ }
84
+
85
+ const jsonOutput = await app.serializer.projectToObject(project, root as NormalizedPath);
86
+ const projectJson = jsonOutput as unknown as TypeDoc.JSONOutput.ProjectReflection;
87
+
88
+ if (!projectJson.schemaVersion || !projectJson.children || !projectJson.children.length) {
89
+ console.error('Failed to generate documentation.');
90
+ return
91
+ }
92
+
93
+ const references = typedocToUniform(root, projectJson)
94
+ if (!references) {
95
+ console.error('Failed to generate documentation.');
96
+ return
97
+ }
98
+ return {
99
+ references,
100
+ projectJson
101
+ }
102
+ }
103
+
104
+ // TODO: nested strategy
105
+ // TODO: better mechanism?
106
+ function findImports(root: string, file: string, seen = new Set()) {
107
+ if (seen.has(file)) return;
108
+ seen.add(file);
109
+
110
+ const source = ts.createSourceFile(
111
+ file,
112
+ ts.sys.readFile(file) || "",
113
+ ts.ScriptTarget.Latest,
114
+ true
115
+ );
116
+
117
+ for (const stmt of source.statements) {
118
+ if (ts.isImportDeclaration(stmt) && stmt.moduleSpecifier) {
119
+ const importPath = stmt.moduleSpecifier.getText().replace(/['"]/g, "");
120
+ if (importPath.startsWith(".")) {
121
+ const resolved = resolve(file, "..", importPath + ".ts"); // TODO: support .tsx also + aliases
122
+ const relativePath = path.relative(root, resolved);
123
+ importedFiles.add(relativePath);
124
+ findImports(root, resolved, seen);
125
+ }
126
+ }
127
+ }
128
+ }
129
+
File without changes