crankscript 0.9.6 → 0.9.8
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/assets/plugin.ts +0 -1
- package/package.json +1 -1
- package/src/commands/GenerateTypes/fn/getApiDefinitions.d.ts +2 -6
- package/src/commands/GenerateTypes/fn/getApiDefinitions.js +22 -73
- package/src/commands/GenerateTypes/fn/getApiDefinitions.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js +90 -10
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useGetVersion.d.ts +1 -0
- package/src/commands/GenerateTypes/hooks/useParseDocumentation.d.ts +1 -5
- package/src/commands/GenerateTypes/utils/createTypeProvider.d.ts +1 -0
- package/src/commands/GenerateTypes/utils/createTypeProvider.js +7 -0
- package/src/commands/GenerateTypes/utils/createTypeProvider.js.map +1 -1
- package/src/types.d.ts +5 -17
- package/src/types.js.map +1 -1
- package/src/commands/GenerateTypes/fn/generateFunction.d.ts +0 -4
- package/src/commands/GenerateTypes/fn/generateFunction.js +0 -27
- package/src/commands/GenerateTypes/fn/generateFunction.js.map +0 -1
- package/src/commands/GenerateTypes/fn/generateNamespace.d.ts +0 -4
- package/src/commands/GenerateTypes/fn/generateNamespace.js +0 -81
- package/src/commands/GenerateTypes/fn/generateNamespace.js.map +0 -1
package/assets/plugin.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,2 @@
|
|
1
|
-
import {
|
2
|
-
export declare const getApiDefinitions: (functions: FunctionDescription[], properties: PropertyDescription[]) =>
|
3
|
-
rootNamespace: PlaydateNamespace;
|
4
|
-
namespaces: Record<string, PlaydateNamespace>;
|
5
|
-
types: Record<string, PlaydateType>;
|
6
|
-
};
|
1
|
+
import { ApiDefinitions, FunctionDescription, PropertyDescription } from '../../../types.js';
|
2
|
+
export declare const getApiDefinitions: (functions: FunctionDescription[], properties: PropertyDescription[]) => ApiDefinitions;
|
@@ -1,88 +1,37 @@
|
|
1
1
|
export const getApiDefinitions = (functions, properties)=>{
|
2
|
-
const
|
2
|
+
const global = {
|
3
3
|
functions: [],
|
4
4
|
methods: [],
|
5
|
-
properties: []
|
5
|
+
properties: [],
|
6
|
+
namespaces: {}
|
6
7
|
};
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
const realNamespaceName = currentNamespace.trim();
|
17
|
-
if (!realNamespaces.has(realNamespaceName)) {
|
18
|
-
realNamespaces.add(realNamespaceName);
|
19
|
-
}
|
20
|
-
});
|
21
|
-
}
|
22
|
-
});
|
23
|
-
properties.forEach((prop)=>{
|
24
|
-
let currentNamespace = '';
|
25
|
-
prop.namespaces.forEach((ns)=>{
|
26
|
-
currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
|
27
|
-
const realNamespaceName = currentNamespace.trim();
|
28
|
-
if (!realNamespaces.has(realNamespaceName)) {
|
29
|
-
realNamespaces.add(realNamespaceName);
|
8
|
+
const getOrCreateNamespace = (path, root)=>{
|
9
|
+
return path.reduce((currentNamespace, ns)=>{
|
10
|
+
if (!currentNamespace.namespaces[ns]) {
|
11
|
+
currentNamespace.namespaces[ns] = {
|
12
|
+
functions: [],
|
13
|
+
methods: [],
|
14
|
+
properties: [],
|
15
|
+
namespaces: {}
|
16
|
+
};
|
30
17
|
}
|
31
|
-
|
32
|
-
|
18
|
+
return currentNamespace.namespaces[ns];
|
19
|
+
}, root);
|
20
|
+
};
|
33
21
|
functions.forEach((func)=>{
|
22
|
+
const targetNamespace = getOrCreateNamespace(func.namespaces, global);
|
34
23
|
if (func.hasSelf) {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if (!potentialNamespaces.has(currentNamespace)) {
|
39
|
-
potentialNamespaces.add(currentNamespace);
|
40
|
-
}
|
41
|
-
});
|
42
|
-
}
|
43
|
-
});
|
44
|
-
realNamespaces.forEach((ns)=>{
|
45
|
-
namespaces[ns] = {
|
46
|
-
functions: [],
|
47
|
-
methods: [],
|
48
|
-
properties: []
|
49
|
-
};
|
50
|
-
});
|
51
|
-
functions.forEach((func)=>{
|
52
|
-
const fullNamespacePath = func.namespaces.join('.');
|
53
|
-
if (realNamespaces.has(fullNamespacePath)) {
|
54
|
-
if (func.hasSelf) {
|
55
|
-
namespaces[fullNamespacePath].methods.push(func);
|
56
|
-
} else {
|
57
|
-
namespaces[fullNamespacePath].functions.push(func);
|
58
|
-
}
|
59
|
-
} else if (potentialNamespaces.has(fullNamespacePath)) {
|
60
|
-
if (!types[fullNamespacePath]) {
|
61
|
-
types[fullNamespacePath] = {
|
62
|
-
methods: []
|
63
|
-
};
|
64
|
-
}
|
65
|
-
types[fullNamespacePath].methods.push(func);
|
66
|
-
} else if (fullNamespacePath === '') {
|
67
|
-
if (func.hasSelf) {
|
68
|
-
rootNamespace.methods.push(func);
|
69
|
-
} else {
|
70
|
-
rootNamespace.functions.push(func);
|
71
|
-
}
|
24
|
+
targetNamespace.methods.push(func);
|
25
|
+
} else {
|
26
|
+
targetNamespace.functions.push(func);
|
72
27
|
}
|
73
28
|
});
|
74
29
|
properties.forEach((prop)=>{
|
75
|
-
const
|
76
|
-
|
77
|
-
namespaces[fullNamespacePath].properties.push(prop);
|
78
|
-
} else if (fullNamespacePath === '') {
|
79
|
-
rootNamespace.properties.push(prop);
|
80
|
-
}
|
30
|
+
const targetNamespace = getOrCreateNamespace(prop.namespaces, global);
|
31
|
+
targetNamespace.properties.push(prop);
|
81
32
|
});
|
82
33
|
return {
|
83
|
-
|
84
|
-
namespaces,
|
85
|
-
types
|
34
|
+
global
|
86
35
|
};
|
87
36
|
};
|
88
37
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getApiDefinitions.ts"],"sourcesContent":["import {\n ApiDefinitions,\n FunctionDescription,\n
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getApiDefinitions.ts"],"sourcesContent":["import {\n ApiDefinitions,\n FunctionDescription,\n ApiObject,\n PropertyDescription,\n} from '@/cli/types.js';\n\nexport const getApiDefinitions = (\n functions: FunctionDescription[],\n properties: PropertyDescription[]\n): ApiDefinitions => {\n const global: ApiObject = {\n functions: [],\n methods: [],\n properties: [],\n namespaces: {},\n };\n\n const getOrCreateNamespace = (\n path: string[],\n root: ApiObject\n ): ApiObject => {\n return path.reduce((currentNamespace, ns) => {\n if (!currentNamespace.namespaces[ns]) {\n currentNamespace.namespaces[ns] = {\n functions: [],\n methods: [],\n properties: [],\n namespaces: {},\n };\n }\n return currentNamespace.namespaces[ns];\n }, root);\n };\n\n functions.forEach((func) => {\n const targetNamespace = getOrCreateNamespace(func.namespaces, global);\n if (func.hasSelf) {\n targetNamespace.methods.push(func);\n } else {\n targetNamespace.functions.push(func);\n }\n });\n\n properties.forEach((prop) => {\n const targetNamespace = getOrCreateNamespace(prop.namespaces, global);\n targetNamespace.properties.push(prop);\n });\n\n return { global };\n};\n"],"names":["getApiDefinitions","functions","properties","global","methods","namespaces","getOrCreateNamespace","path","root","reduce","currentNamespace","ns","forEach","func","targetNamespace","hasSelf","push","prop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAOA,OAAO,MAAMA,oBAAoB,CAC7BC,WACAC;IAEA,MAAMC,SAAoB;QACtBF,WAAW,EAAE;QACbG,SAAS,EAAE;QACXF,YAAY,EAAE;QACdG,YAAY,CAAC;IACjB;IAEA,MAAMC,uBAAuB,CACzBC,MACAC;QAEA,OAAOD,KAAKE,MAAM,CAAC,CAACC,kBAAkBC;YAClC,IAAI,CAACD,iBAAiBL,UAAU,CAACM,GAAG,EAAE;gBAClCD,iBAAiBL,UAAU,CAACM,GAAG,GAAG;oBAC9BV,WAAW,EAAE;oBACbG,SAAS,EAAE;oBACXF,YAAY,EAAE;oBACdG,YAAY,CAAC;gBACjB;YACJ;YACA,OAAOK,iBAAiBL,UAAU,CAACM,GAAG;QAC1C,GAAGH;IACP;IAEAP,UAAUW,OAAO,CAAC,CAACC;QACf,MAAMC,kBAAkBR,qBAAqBO,KAAKR,UAAU,EAAEF;QAC9D,IAAIU,KAAKE,OAAO,EAAE;YACdD,gBAAgBV,OAAO,CAACY,IAAI,CAACH;QACjC,OAAO;YACHC,gBAAgBb,SAAS,CAACe,IAAI,CAACH;QACnC;IACJ;IAEAX,WAAWU,OAAO,CAAC,CAACK;QAChB,MAAMH,kBAAkBR,qBAAqBW,KAAKZ,UAAU,EAAEF;QAC9DW,gBAAgBZ,UAAU,CAACc,IAAI,CAACC;IACpC;IAEA,OAAO;QAAEd;IAAO;AACpB,EAAE"}
|
@@ -1,7 +1,8 @@
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
1
2
|
import { writeFileSync } from 'node:fs';
|
2
3
|
import { useMemo } from 'react';
|
3
4
|
import { Project } from 'ts-morph';
|
4
|
-
import {
|
5
|
+
import { TypescriptReservedNamed } from '../../../constants.js';
|
5
6
|
export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
|
6
7
|
const generateTypeFile = useMemo(()=>{
|
7
8
|
return {
|
@@ -20,16 +21,9 @@ export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
|
|
20
21
|
const typeFile = project.createSourceFile(path, '', {
|
21
22
|
overwrite: true
|
22
23
|
});
|
24
|
+
const globalNamespace = definitions.global;
|
23
25
|
typeFile.addStatements(typeProvider.getGlobalStatements());
|
24
|
-
|
25
|
-
const typeSubjects = new Map();
|
26
|
-
subjects.set('root', typeFile);
|
27
|
-
generateNamespace(definitions.rootNamespace, [], subjects, typeSubjects, typeProvider, definitions.types);
|
28
|
-
Object.keys(definitions.namespaces).forEach((namespace)=>{
|
29
|
-
const namespaceDescription = definitions.namespaces[namespace];
|
30
|
-
const namespaces = namespace.split('.');
|
31
|
-
generateNamespace(namespaceDescription, namespaces, subjects, typeSubjects, typeProvider, definitions.types);
|
32
|
-
});
|
26
|
+
generateNamespace(globalNamespace, typeFile, typeProvider, '');
|
33
27
|
writeFileSync(path, typeFile.getFullText().replace('/**', '\n/**'));
|
34
28
|
},
|
35
29
|
ready: definitions !== null && typeProvider !== null
|
@@ -42,5 +36,91 @@ export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
|
|
42
36
|
generateTypeFile
|
43
37
|
};
|
44
38
|
};
|
39
|
+
const generateNamespace = (apiObject, incomingSubject, typeProvider, namespace, name)=>{
|
40
|
+
let subject = incomingSubject;
|
41
|
+
const fullNamespaceName = [
|
42
|
+
namespace,
|
43
|
+
name
|
44
|
+
].filter(Boolean).join('.');
|
45
|
+
if (name) {
|
46
|
+
subject = incomingSubject.addModule({
|
47
|
+
name
|
48
|
+
});
|
49
|
+
}
|
50
|
+
if (name === 'playdate') {
|
51
|
+
subject.addStatements(typeProvider.getStatements());
|
52
|
+
}
|
53
|
+
for (const func of apiObject.functions){
|
54
|
+
const isFunctionNameReserved = TypescriptReservedNamed.includes(func.name);
|
55
|
+
const resolvedName = `_${func.name}`;
|
56
|
+
const parameters = typeProvider.getParameters(func);
|
57
|
+
subject.addFunction(_extends({
|
58
|
+
name: isFunctionNameReserved ? resolvedName : func.name,
|
59
|
+
docs: [
|
60
|
+
func.docs
|
61
|
+
],
|
62
|
+
parameters,
|
63
|
+
returnType: typeProvider.getFunctionReturnType(func),
|
64
|
+
isExported: !!name
|
65
|
+
}, typeProvider.getFunctionOverrideOptions(func)));
|
66
|
+
if (isFunctionNameReserved) {
|
67
|
+
subject.addExportDeclaration({
|
68
|
+
namedExports: [
|
69
|
+
{
|
70
|
+
name: resolvedName,
|
71
|
+
alias: func.name
|
72
|
+
}
|
73
|
+
]
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
let propertiesSubject = null;
|
78
|
+
if (name && apiObject.methods.length > 0) {
|
79
|
+
const typeClass = incomingSubject.addClass(_extends({
|
80
|
+
name
|
81
|
+
}, typeProvider.getClassOptions(fullNamespaceName)));
|
82
|
+
propertiesSubject = typeClass;
|
83
|
+
for (const method of apiObject.methods){
|
84
|
+
const parameters = typeProvider.getParameters(method);
|
85
|
+
typeClass.addMethod(_extends({
|
86
|
+
name: method.name,
|
87
|
+
docs: [
|
88
|
+
method.docs
|
89
|
+
],
|
90
|
+
parameters,
|
91
|
+
returnType: typeProvider.getFunctionReturnType(method)
|
92
|
+
}, typeProvider.getFunctionOverrideOptions(method)));
|
93
|
+
}
|
94
|
+
}
|
95
|
+
for (const property of apiObject.properties){
|
96
|
+
const propertyDetails = typeProvider.getPropertyDetails(property);
|
97
|
+
if (propertiesSubject) {
|
98
|
+
propertiesSubject.addProperty({
|
99
|
+
name: property.name,
|
100
|
+
docs: [
|
101
|
+
property.docs
|
102
|
+
],
|
103
|
+
type: propertyDetails.type,
|
104
|
+
isStatic: propertyDetails.isStatic,
|
105
|
+
isReadonly: propertyDetails.isReadOnly
|
106
|
+
});
|
107
|
+
} else {
|
108
|
+
subject.addVariableStatement({
|
109
|
+
docs: [
|
110
|
+
property.docs
|
111
|
+
],
|
112
|
+
declarations: [
|
113
|
+
{
|
114
|
+
name: property.name,
|
115
|
+
type: propertyDetails.type
|
116
|
+
}
|
117
|
+
]
|
118
|
+
});
|
119
|
+
}
|
120
|
+
}
|
121
|
+
for (const eachNamespace of Object.entries(apiObject.namespaces)){
|
122
|
+
generateNamespace(eachNamespace[1], subject, typeProvider, fullNamespaceName, eachNamespace[0]);
|
123
|
+
}
|
124
|
+
};
|
45
125
|
|
46
126
|
//# sourceMappingURL=useGenerateTypeFile.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGenerateTypeFile.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { useMemo } from 'react';\nimport {\n ClassDeclaration,\n ModuleDeclaration,\n Project,\n SourceFile,\n} from 'ts-morph';\nimport {
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGenerateTypeFile.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { useMemo } from 'react';\nimport {\n ClassDeclaration,\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ModuleDeclaration,\n Project,\n SourceFile,\n} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport { ApiDefinitions, ApiObject, CheckListItem } from '@/cli/types.js';\n\nexport const useGenerateTypeFile = (\n path: string,\n definitions: ApiDefinitions | null,\n typeProvider: ReturnType<typeof createTypeProvider> | null\n) => {\n const generateTypeFile = useMemo(() => {\n return {\n waitingDescription: 'Waiting to generate the type file...',\n errorDescription: 'Failed to generate the type file',\n finishedDescription: () => 'Type file generated',\n runningDescription: 'Generating the type file...',\n runner: async () => {\n if (!definitions) {\n throw new Error('Definitions are not set');\n }\n\n if (!typeProvider) {\n throw new Error('Type provider is not set');\n }\n\n const project = new Project();\n const typeFile = project.createSourceFile(path, '', {\n overwrite: true,\n });\n\n const globalNamespace = definitions.global;\n\n typeFile.addStatements(typeProvider.getGlobalStatements());\n\n generateNamespace(globalNamespace, typeFile, typeProvider, '');\n\n writeFileSync(\n path,\n typeFile.getFullText().replace('/**', '\\n/**')\n );\n },\n ready: definitions !== null && typeProvider !== null,\n } satisfies CheckListItem<void>;\n }, [definitions, typeProvider]);\n\n return {\n generateTypeFile,\n };\n};\n\nconst generateNamespace = (\n apiObject: ApiObject,\n incomingSubject: SourceFile | ModuleDeclaration,\n typeProvider: ReturnType<typeof createTypeProvider>,\n namespace: string,\n name?: string\n) => {\n let subject = incomingSubject;\n const fullNamespaceName = [namespace, name].filter(Boolean).join('.');\n\n if (name) {\n subject = incomingSubject.addModule({\n name,\n });\n }\n\n if (name === 'playdate') {\n subject.addStatements(typeProvider.getStatements());\n }\n\n for (const func of apiObject.functions) {\n const isFunctionNameReserved = TypescriptReservedNamed.includes(\n func.name\n );\n const resolvedName = `_${func.name}`;\n const parameters = typeProvider.getParameters(func);\n\n subject.addFunction({\n name: isFunctionNameReserved ? resolvedName : func.name,\n docs: [func.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(func),\n isExported: !!name,\n ...(typeProvider.getFunctionOverrideOptions(\n func\n ) as FunctionDeclarationStructure),\n });\n\n if (isFunctionNameReserved) {\n subject.addExportDeclaration({\n namedExports: [\n {\n name: resolvedName,\n alias: func.name,\n },\n ],\n });\n }\n }\n\n let propertiesSubject: ClassDeclaration | null = null;\n\n if (name && apiObject.methods.length > 0) {\n const typeClass = incomingSubject.addClass({\n name,\n ...typeProvider.getClassOptions(fullNamespaceName),\n });\n propertiesSubject = typeClass;\n\n for (const method of apiObject.methods) {\n const parameters = typeProvider.getParameters(method);\n\n typeClass.addMethod({\n name: method.name,\n docs: [method.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(method),\n ...(typeProvider.getFunctionOverrideOptions(\n method\n ) as Partial<MethodDeclarationStructure>),\n });\n }\n }\n\n for (const property of apiObject.properties) {\n const propertyDetails = typeProvider.getPropertyDetails(property);\n\n if (propertiesSubject) {\n propertiesSubject.addProperty({\n name: property.name,\n docs: [property.docs],\n type: propertyDetails.type,\n isStatic: propertyDetails.isStatic,\n isReadonly: propertyDetails.isReadOnly,\n });\n } else {\n subject.addVariableStatement({\n docs: [property.docs],\n declarations: [\n {\n name: property.name,\n type: propertyDetails.type,\n },\n ],\n });\n }\n }\n\n for (const eachNamespace of Object.entries(apiObject.namespaces)) {\n generateNamespace(\n eachNamespace[1],\n subject,\n typeProvider,\n fullNamespaceName,\n eachNamespace[0]\n );\n }\n};\n"],"names":["writeFileSync","useMemo","Project","TypescriptReservedNamed","useGenerateTypeFile","path","definitions","typeProvider","generateTypeFile","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","project","typeFile","createSourceFile","overwrite","globalNamespace","global","addStatements","getGlobalStatements","generateNamespace","getFullText","replace","ready","apiObject","incomingSubject","namespace","name","subject","fullNamespaceName","filter","Boolean","join","addModule","getStatements","func","functions","isFunctionNameReserved","includes","resolvedName","parameters","getParameters","addFunction","docs","returnType","getFunctionReturnType","isExported","getFunctionOverrideOptions","addExportDeclaration","namedExports","alias","propertiesSubject","methods","length","typeClass","addClass","getClassOptions","method","addMethod","property","properties","propertyDetails","getPropertyDetails","addProperty","type","isStatic","isReadonly","isReadOnly","addVariableStatement","declarations","eachNamespace","Object","entries","namespaces"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAKIC,OAAO,QAEJ,WAAW;AAElB,SAASC,uBAAuB,QAAQ,qBAAqB;AAG7D,OAAO,MAAMC,sBAAsB,CAC/BC,MACAC,aACAC;IAEA,MAAMC,mBAAmBP,QAAQ;QAC7B,OAAO;YACHQ,oBAAoB;YACpBC,kBAAkB;YAClBC,qBAAqB,IAAM;YAC3BC,oBAAoB;YACpBC,QAAQ;gBACJ,IAAI,CAACP,aAAa;oBACd,MAAM,IAAIQ,MAAM;gBACpB;gBAEA,IAAI,CAACP,cAAc;oBACf,MAAM,IAAIO,MAAM;gBACpB;gBAEA,MAAMC,UAAU,IAAIb;gBACpB,MAAMc,WAAWD,QAAQE,gBAAgB,CAACZ,MAAM,IAAI;oBAChDa,WAAW;gBACf;gBAEA,MAAMC,kBAAkBb,YAAYc,MAAM;gBAE1CJ,SAASK,aAAa,CAACd,aAAae,mBAAmB;gBAEvDC,kBAAkBJ,iBAAiBH,UAAUT,cAAc;gBAE3DP,cACIK,MACAW,SAASQ,WAAW,GAAGC,OAAO,CAAC,OAAO;YAE9C;YACAC,OAAOpB,gBAAgB,QAAQC,iBAAiB;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;YAE9CH,UAAUI,SAAS,CAAC;gBAChB/B,MAAM8B,OAAO9B,IAAI;gBACjBgB,MAAM;oBAACc,OAAOd,IAAI;iBAAC;gBACnBH;gBACAI,YAAYxC,aAAayC,qBAAqB,CAACY;eAC3CrD,aAAa2C,0BAA0B,CACvCU;QAGZ;IACJ;IAEA,KAAK,MAAME,YAAYnC,UAAUoC,UAAU,CAAE;QACzC,MAAMC,kBAAkBzD,aAAa0D,kBAAkB,CAACH;QAExD,IAAIR,mBAAmB;YACnBA,kBAAkBY,WAAW,CAAC;gBAC1BpC,MAAMgC,SAAShC,IAAI;gBACnBgB,MAAM;oBAACgB,SAAShB,IAAI;iBAAC;gBACrBqB,MAAMH,gBAAgBG,IAAI;gBAC1BC,UAAUJ,gBAAgBI,QAAQ;gBAClCC,YAAYL,gBAAgBM,UAAU;YAC1C;QACJ,OAAO;YACHvC,QAAQwC,oBAAoB,CAAC;gBACzBzB,MAAM;oBAACgB,SAAShB,IAAI;iBAAC;gBACrB0B,cAAc;oBACV;wBACI1C,MAAMgC,SAAShC,IAAI;wBACnBqC,MAAMH,gBAAgBG,IAAI;oBAC9B;iBACH;YACL;QACJ;IACJ;IAEA,KAAK,MAAMM,iBAAiBC,OAAOC,OAAO,CAAChD,UAAUiD,UAAU,EAAG;QAC9DrD,kBACIkD,aAAa,CAAC,EAAE,EAChB1C,SACAxB,cACAyB,mBACAyC,aAAa,CAAC,EAAE;IAExB;AACJ"}
|
@@ -12,6 +12,7 @@ export declare const useGetVersion: (version: PlaydateSdkVersion) => {
|
|
12
12
|
typeProvider: {
|
13
13
|
getGlobalStatements: () => string[];
|
14
14
|
getStatements: () => string[];
|
15
|
+
getClassOptions: (className: string) => Partial<import("ts-morph").ClassDeclarationStructure>;
|
15
16
|
getPropertyDetails: (property: import("../../../types.js").PropertyDescription) => import("../../../types.js").PropertyDetails;
|
16
17
|
getFunctionReturnType: (func: import("../../../types.js").FunctionDescription) => string;
|
17
18
|
getParameterDetails: (func: import("../../../types.js").FunctionDescription, parameter: string) => import("../../../types.js").ParameterDetails;
|
@@ -6,11 +6,7 @@ export declare const useParseDocumentation: (html: string | null, version: strin
|
|
6
6
|
errorDescription: string;
|
7
7
|
finishedDescription: () => string;
|
8
8
|
runningDescription: string;
|
9
|
-
runner: () => Promise<
|
10
|
-
rootNamespace: import("../../../types.js").PlaydateNamespace;
|
11
|
-
namespaces: Record<string, import("../../../types.js").PlaydateNamespace>;
|
12
|
-
types: Record<string, import("../../../types.js").PlaydateType>;
|
13
|
-
}>;
|
9
|
+
runner: () => Promise<ApiDefinitions>;
|
14
10
|
onFinish: (result: ApiDefinitions) => void;
|
15
11
|
ready: boolean;
|
16
12
|
};
|
@@ -3,6 +3,7 @@ import { FunctionDescription, ParameterDetails, PropertyDescription, PropertyDet
|
|
3
3
|
export declare const createTypeProvider: (version: string) => {
|
4
4
|
getGlobalStatements: () => string[];
|
5
5
|
getStatements: () => string[];
|
6
|
+
getClassOptions: (className: string) => Partial<import("ts-morph").ClassDeclarationStructure>;
|
6
7
|
getPropertyDetails: (property: PropertyDescription) => PropertyDetails;
|
7
8
|
getFunctionReturnType: (func: FunctionDescription) => string;
|
8
9
|
getParameterDetails: (func: FunctionDescription, parameter: string) => ParameterDetails;
|
@@ -12,17 +12,23 @@ export const createTypeProvider = (version)=>{
|
|
12
12
|
const fallbackProvider = existsSync(path) ? JSON.parse(readFileSync(path, 'utf-8')) : {
|
13
13
|
globalStatements: [],
|
14
14
|
statements: [],
|
15
|
+
classes: {},
|
15
16
|
properties: {},
|
16
17
|
functions: {}
|
17
18
|
};
|
18
19
|
const provider = {
|
19
20
|
globalStatements: fallbackProvider.globalStatements,
|
20
21
|
statements: fallbackProvider.statements,
|
22
|
+
classes: fallbackProvider.classes,
|
21
23
|
properties: {},
|
22
24
|
functions: {}
|
23
25
|
};
|
24
26
|
const visitedProperties = new Map();
|
25
27
|
const visitedFunctions = new Map();
|
28
|
+
const getClassOptions = (className)=>{
|
29
|
+
var _provider_classes_className;
|
30
|
+
return (_provider_classes_className = provider.classes[className]) != null ? _provider_classes_className : {};
|
31
|
+
};
|
26
32
|
const getPropertyDetails = (property)=>{
|
27
33
|
if (visitedProperties.has(property.signature)) {
|
28
34
|
return visitedProperties.get(property.signature);
|
@@ -127,6 +133,7 @@ export const createTypeProvider = (version)=>{
|
|
127
133
|
return {
|
128
134
|
getGlobalStatements,
|
129
135
|
getStatements,
|
136
|
+
getClassOptions,
|
130
137
|
getPropertyDetails,
|
131
138
|
getFunctionReturnType,
|
132
139
|
getParameterDetails,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/utils/createTypeProvider.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { existsSync, writeFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport {\n FunctionDeclarationStructure,\n ParameterDeclarationStructure,\n StructureKind,\n} from 'ts-morph';\nimport { DataFolder } from '@/cli/constants.js';\nimport {\n FunctionDescription,\n FunctionDetails,\n ParameterDetails,\n PropertyDescription,\n PropertyDetails,\n TypeProviderData,\n} from '@/cli/types.js';\n\nfunction kebabToCamelCase(str: string): string {\n return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\nexport const createTypeProvider = (version: string) => {\n const path = join(DataFolder, `${version}.json`);\n const fallbackProvider = existsSync(path)\n ? (JSON.parse(readFileSync(path, 'utf-8')) as TypeProviderData)\n : ({\n globalStatements: [],\n statements: [],\n properties: {},\n functions: {},\n } satisfies TypeProviderData);\n const provider = {\n globalStatements: fallbackProvider.globalStatements,\n statements: fallbackProvider.statements,\n properties: {},\n functions: {},\n } as TypeProviderData;\n const visitedProperties = new Map<string, PropertyDetails>();\n const visitedFunctions = new Map<string, FunctionDetails>();\n\n const getPropertyDetails = (property: PropertyDescription) => {\n if (visitedProperties.has(property.signature)) {\n return visitedProperties.get(property.signature) as PropertyDetails;\n }\n\n let result: PropertyDetails;\n let prop = provider.properties[property.signature];\n\n if (!prop) {\n prop = fallbackProvider.properties[property.signature];\n }\n\n if (!prop) {\n const details = {\n signature: property.signature,\n type: 'any',\n } satisfies PropertyDetails;\n\n provider.properties[property.signature] = details;\n\n result = details;\n } else {\n provider.properties[property.signature] = prop;\n\n result = prop;\n }\n\n visitedProperties.set(property.signature, result);\n\n return result;\n };\n\n const getFunctionDetails = (func: FunctionDescription): FunctionDetails => {\n if (visitedFunctions.has(func.signature)) {\n return visitedFunctions.get(func.signature) as FunctionDetails;\n }\n\n let result: FunctionDetails;\n let fn = provider.functions[func.signature];\n\n if (!fn) {\n fn = fallbackProvider.functions[func.signature];\n }\n\n if (!fn) {\n const details = {\n signature: func.signature,\n parameters: func.parameters.map((p) => ({\n name: p.name,\n type: 'any',\n })),\n returnType: 'any',\n } satisfies FunctionDetails;\n\n provider.functions[func.signature] = details;\n\n result = details;\n } else {\n provider.functions[func.signature] = fn;\n\n result = fn;\n }\n\n visitedFunctions.set(func.signature, result);\n\n return result;\n };\n\n const getGlobalStatements = () => {\n return provider.globalStatements;\n };\n\n const getStatements = () => {\n return provider.statements;\n };\n\n const getFunctionReturnType = (func: FunctionDescription) => {\n const { returnType } = getFunctionDetails(func);\n\n return returnType;\n };\n\n const getParameterDetails = (\n func: FunctionDescription,\n parameter: string\n ) => {\n const { parameters } = getFunctionDetails(func);\n const param = parameters.find((p) => p.name === parameter);\n\n if (!param) {\n return {\n name: parameter,\n type: 'any',\n } satisfies ParameterDetails;\n }\n\n return param;\n };\n\n const getParameters = (\n func: FunctionDescription\n ): FunctionDeclarationStructure['parameters'] => {\n const { overrideParameters = false, parameters } =\n getFunctionDetails(func);\n const getParameterFromDetails = (parameter: ParameterDetails) => {\n return {\n kind: StructureKind.Parameter,\n name: kebabToCamelCase(parameter.name),\n type: parameter.type,\n ...(parameter.overrideOptions ?? {}),\n } satisfies ParameterDeclarationStructure;\n };\n\n if (overrideParameters) {\n return parameters.map((details) => {\n return getParameterFromDetails(details);\n });\n }\n\n return func.parameters.map((parameter) => {\n const details = getParameterDetails(func, parameter.name);\n\n return {\n hasQuestionToken: !parameter.required,\n ...getParameterFromDetails(details),\n } satisfies ParameterDeclarationStructure;\n });\n };\n\n const getFunctionOverrideOptions = (func: FunctionDescription) => {\n return getFunctionDetails(func).overrideOptions ?? {};\n };\n\n const save = () => {\n const contents = JSON.stringify(provider, null, 4) + '\\n';\n\n writeFileSync(path, contents, 'utf-8');\n };\n\n return {\n getGlobalStatements,\n getStatements,\n getPropertyDetails,\n getFunctionReturnType,\n getParameterDetails,\n getParameters,\n getFunctionOverrideOptions,\n save,\n };\n};\n"],"names":["readFileSync","existsSync","writeFileSync","join","StructureKind","DataFolder","kebabToCamelCase","str","replace","_","letter","toUpperCase","createTypeProvider","version","path","fallbackProvider","JSON","parse","globalStatements","statements","properties","functions","provider","visitedProperties","Map","visitedFunctions","getPropertyDetails","property","has","signature","get","result","prop","details","type","set","getFunctionDetails","func","fn","parameters","map","p","name","returnType","getGlobalStatements","getStatements","getFunctionReturnType","getParameterDetails","parameter","param","find","getParameters","overrideParameters","getParameterFromDetails","kind","Parameter","overrideOptions","hasQuestionToken","required","getFunctionOverrideOptions","save","contents","stringify"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,YAAY,QAAQ,KAAK;AAClC,SAASC,UAAU,EAAEC,aAAa,QAAQ,UAAU;AACpD,SAASC,IAAI,QAAQ,YAAY;AACjC,SAGIC,aAAa,QACV,WAAW;AAClB,SAASC,UAAU,QAAQ,qBAAqB;AAUhD,SAASC,iBAAiBC,GAAW;IACjC,OAAOA,IAAIC,OAAO,CAAC,aAAa,CAACC,GAAGC,SAAWA,OAAOC,WAAW;AACrE;AAEA,OAAO,MAAMC,qBAAqB,CAACC;IAC/B,MAAMC,OAAOX,KAAKE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6B,CAAC;QAE1C;QAEA,IAAII,oBAAoB;YACpB,OAAOb,WAAWC,GAAG,CAAC,CAACP;gBACnB,OAAOoB,wBAAwBpB;YACnC;QACJ;QAEA,OAAOI,KAAKE,UAAU,CAACC,GAAG,CAAC,CAACQ;YACxB,MAAMf,UAAUc,oBAAoBV,MAAMW,UAAUN,IAAI;YAExD,OAAO;gBACHe,kBAAkB,CAACT,UAAUU,QAAQ;eAClCL,wBAAwBpB;QAEnC;IACJ;IAEA,MAAM0B,6BAA6B,CAACtB;YACzBD;QAAP,OAAOA,CAAAA,sCAAAA,mBAAmBC,MAAMmB,eAAe,YAAxCpB,sCAA4C,CAAC;IACxD;IAEA,MAAMwB,OAAO;QACT,MAAMC,WAAW7C,KAAK8C,SAAS,CAACxC,UAAU,MAAM,KAAK;QAErDpB,cAAcY,MAAM+C,UAAU;IAClC;IAEA,OAAO;QACHjB;QACAC;QACAnB;QACAoB;QACAC;QACAI;QACAQ;QACAC;IACJ;AACJ,EAAE"}
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/utils/createTypeProvider.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { existsSync, writeFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport {\n FunctionDeclarationStructure,\n ParameterDeclarationStructure,\n StructureKind,\n} from 'ts-morph';\nimport { DataFolder } from '@/cli/constants.js';\nimport {\n FunctionDescription,\n FunctionDetails,\n ParameterDetails,\n PropertyDescription,\n PropertyDetails,\n TypeProviderData,\n} from '@/cli/types.js';\n\nfunction kebabToCamelCase(str: string): string {\n return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\nexport const createTypeProvider = (version: string) => {\n const path = join(DataFolder, `${version}.json`);\n const fallbackProvider = existsSync(path)\n ? (JSON.parse(readFileSync(path, 'utf-8')) as TypeProviderData)\n : ({\n globalStatements: [],\n statements: [],\n classes: {},\n properties: {},\n functions: {},\n } satisfies TypeProviderData);\n const provider = {\n globalStatements: fallbackProvider.globalStatements,\n statements: fallbackProvider.statements,\n classes: fallbackProvider.classes,\n properties: {},\n functions: {},\n } as TypeProviderData;\n const visitedProperties = new Map<string, PropertyDetails>();\n const visitedFunctions = new Map<string, FunctionDetails>();\n\n const getClassOptions = (className: string) => {\n return provider.classes[className] ?? {};\n };\n\n const getPropertyDetails = (property: PropertyDescription) => {\n if (visitedProperties.has(property.signature)) {\n return visitedProperties.get(property.signature) as PropertyDetails;\n }\n\n let result: PropertyDetails;\n let prop = provider.properties[property.signature];\n\n if (!prop) {\n prop = fallbackProvider.properties[property.signature];\n }\n\n if (!prop) {\n const details = {\n signature: property.signature,\n type: 'any',\n } satisfies PropertyDetails;\n\n provider.properties[property.signature] = details;\n\n result = details;\n } else {\n provider.properties[property.signature] = prop;\n\n result = prop;\n }\n\n visitedProperties.set(property.signature, result);\n\n return result;\n };\n\n const getFunctionDetails = (func: FunctionDescription): FunctionDetails => {\n if (visitedFunctions.has(func.signature)) {\n return visitedFunctions.get(func.signature) as FunctionDetails;\n }\n\n let result: FunctionDetails;\n let fn = provider.functions[func.signature];\n\n if (!fn) {\n fn = fallbackProvider.functions[func.signature];\n }\n\n if (!fn) {\n const details = {\n signature: func.signature,\n parameters: func.parameters.map((p) => ({\n name: p.name,\n type: 'any',\n })),\n returnType: 'any',\n } satisfies FunctionDetails;\n\n provider.functions[func.signature] = details;\n\n result = details;\n } else {\n provider.functions[func.signature] = fn;\n\n result = fn;\n }\n\n visitedFunctions.set(func.signature, result);\n\n return result;\n };\n\n const getGlobalStatements = () => {\n return provider.globalStatements;\n };\n\n const getStatements = () => {\n return provider.statements;\n };\n\n const getFunctionReturnType = (func: FunctionDescription) => {\n const { returnType } = getFunctionDetails(func);\n\n return returnType;\n };\n\n const getParameterDetails = (\n func: FunctionDescription,\n parameter: string\n ) => {\n const { parameters } = getFunctionDetails(func);\n const param = parameters.find((p) => p.name === parameter);\n\n if (!param) {\n return {\n name: parameter,\n type: 'any',\n } satisfies ParameterDetails;\n }\n\n return param;\n };\n\n const getParameters = (\n func: FunctionDescription\n ): FunctionDeclarationStructure['parameters'] => {\n const { overrideParameters = false, parameters } =\n getFunctionDetails(func);\n const getParameterFromDetails = (parameter: ParameterDetails) => {\n return {\n kind: StructureKind.Parameter,\n name: kebabToCamelCase(parameter.name),\n type: parameter.type,\n ...(parameter.overrideOptions ?? {}),\n } satisfies ParameterDeclarationStructure;\n };\n\n if (overrideParameters) {\n return parameters.map((details) => {\n return getParameterFromDetails(details);\n });\n }\n\n return func.parameters.map((parameter) => {\n const details = getParameterDetails(func, parameter.name);\n\n return {\n hasQuestionToken: !parameter.required,\n ...getParameterFromDetails(details),\n } satisfies ParameterDeclarationStructure;\n });\n };\n\n const getFunctionOverrideOptions = (func: FunctionDescription) => {\n return getFunctionDetails(func).overrideOptions ?? {};\n };\n\n const save = () => {\n const contents = JSON.stringify(provider, null, 4) + '\\n';\n\n writeFileSync(path, contents, 'utf-8');\n };\n\n return {\n getGlobalStatements,\n getStatements,\n getClassOptions,\n getPropertyDetails,\n getFunctionReturnType,\n getParameterDetails,\n getParameters,\n getFunctionOverrideOptions,\n save,\n };\n};\n"],"names":["readFileSync","existsSync","writeFileSync","join","StructureKind","DataFolder","kebabToCamelCase","str","replace","_","letter","toUpperCase","createTypeProvider","version","path","fallbackProvider","JSON","parse","globalStatements","statements","classes","properties","functions","provider","visitedProperties","Map","visitedFunctions","getClassOptions","className","getPropertyDetails","property","has","signature","get","result","prop","details","type","set","getFunctionDetails","func","fn","parameters","map","p","name","returnType","getGlobalStatements","getStatements","getFunctionReturnType","getParameterDetails","parameter","param","find","getParameters","overrideParameters","getParameterFromDetails","kind","Parameter","overrideOptions","hasQuestionToken","required","getFunctionOverrideOptions","save","contents","stringify"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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odDeclarationStructure, ParameterDeclarationStructure } from 'ts-morph';
|
1
|
+
import { ClassDeclarationStructure, FunctionDeclarationStructure, MethodDeclarationStructure, ParameterDeclarationStructure } from 'ts-morph';
|
2
2
|
import { Environment } from './environment/dto/Environment.js';
|
3
3
|
import { PlaydateSdkPath } from './environment/path/dto/PlaydateSdkPath.js';
|
4
4
|
export declare enum PlaydateSdkVersionIdentifier {
|
@@ -54,27 +54,14 @@ export interface FunctionDescription {
|
|
54
54
|
hasSelf: boolean;
|
55
55
|
docs: string;
|
56
56
|
}
|
57
|
-
export interface
|
58
|
-
name: string;
|
59
|
-
docs: string;
|
60
|
-
values: {
|
61
|
-
name: string;
|
62
|
-
value: number;
|
63
|
-
docs: string;
|
64
|
-
}[];
|
65
|
-
}
|
66
|
-
export interface PlaydateNamespace {
|
57
|
+
export interface ApiObject {
|
67
58
|
functions: FunctionDescription[];
|
68
59
|
methods: FunctionDescription[];
|
69
60
|
properties: PropertyDescription[];
|
70
|
-
|
71
|
-
export interface PlaydateType {
|
72
|
-
methods: FunctionDescription[];
|
61
|
+
namespaces: Record<string, ApiObject>;
|
73
62
|
}
|
74
63
|
export interface ApiDefinitions {
|
75
|
-
|
76
|
-
namespaces: Record<string, PlaydateNamespace>;
|
77
|
-
types: Record<string, PlaydateType>;
|
64
|
+
global: ApiObject;
|
78
65
|
}
|
79
66
|
export interface ParameterDetails {
|
80
67
|
name: string;
|
@@ -97,6 +84,7 @@ export interface FunctionDetails {
|
|
97
84
|
export type TypeProviderData = {
|
98
85
|
globalStatements: string[];
|
99
86
|
statements: string[];
|
87
|
+
classes: Record<string, Partial<ClassDeclarationStructure>>;
|
100
88
|
properties: Record<string, PropertyDetails>;
|
101
89
|
functions: Record<string, FunctionDetails>;
|
102
90
|
};
|
package/src/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../libs/cli/src/types.ts"],"sourcesContent":["import {\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ParameterDeclarationStructure,\n} from 'ts-morph';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { PlaydateSdkPath } from '@/cli/environment/path/dto/PlaydateSdkPath.js';\n\nexport enum PlaydateSdkVersionIdentifier {\n Latest = 'latest',\n}\n\nexport type PlaydateSdkVersion = PlaydateSdkVersionIdentifier.Latest | string;\n\nexport type EnvironmentHealthResult =\n | {\n isHealthy: true;\n environment: Environment;\n health: EnvironmentHealth;\n }\n | {\n isHealthy: false;\n health: EnvironmentHealth;\n };\n\nexport enum HealthCheckStatusType {\n Healthy = 'Healthy',\n Unhealthy = 'Unhealthy',\n Unknown = 'Unknown',\n}\n\nexport type HealthCheckStatus<TArgument> =\n | {\n healthStatus:\n | HealthCheckStatusType.Unknown\n | HealthCheckStatusType.Unhealthy;\n }\n | {\n healthStatus: HealthCheckStatusType.Healthy;\n argument: TArgument;\n };\n\nexport interface EnvironmentHealth {\n sdkPathKnown: HealthCheckStatus<PlaydateSdkPath>;\n}\n\nexport type CheckListItem<TResult> = {\n runningDescription: string;\n waitingDescription: string;\n errorDescription: string;\n finishedDescription: (result: TResult) => string;\n runner: () => Promise<TResult> | Promise<false>;\n onFinish?: (result: TResult) => void;\n ready?: boolean;\n};\n\nexport interface ParameterDescription {\n name: string;\n required: boolean;\n}\n\nexport interface PropertyDescription {\n signature: string;\n name: string;\n namespaces: string[];\n docs: string;\n}\n\nexport interface FunctionDescription {\n signature: string;\n name: string;\n namespaces: string[];\n parameters: ParameterDescription[];\n hasSelf: boolean;\n docs: string;\n}\
|
1
|
+
{"version":3,"sources":["../../../../libs/cli/src/types.ts"],"sourcesContent":["import {\n ClassDeclarationStructure,\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ParameterDeclarationStructure,\n} from 'ts-morph';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { PlaydateSdkPath } from '@/cli/environment/path/dto/PlaydateSdkPath.js';\n\nexport enum PlaydateSdkVersionIdentifier {\n Latest = 'latest',\n}\n\nexport type PlaydateSdkVersion = PlaydateSdkVersionIdentifier.Latest | string;\n\nexport type EnvironmentHealthResult =\n | {\n isHealthy: true;\n environment: Environment;\n health: EnvironmentHealth;\n }\n | {\n isHealthy: false;\n health: EnvironmentHealth;\n };\n\nexport enum HealthCheckStatusType {\n Healthy = 'Healthy',\n Unhealthy = 'Unhealthy',\n Unknown = 'Unknown',\n}\n\nexport type HealthCheckStatus<TArgument> =\n | {\n healthStatus:\n | HealthCheckStatusType.Unknown\n | HealthCheckStatusType.Unhealthy;\n }\n | {\n healthStatus: HealthCheckStatusType.Healthy;\n argument: TArgument;\n };\n\nexport interface EnvironmentHealth {\n sdkPathKnown: HealthCheckStatus<PlaydateSdkPath>;\n}\n\nexport type CheckListItem<TResult> = {\n runningDescription: string;\n waitingDescription: string;\n errorDescription: string;\n finishedDescription: (result: TResult) => string;\n runner: () => Promise<TResult> | Promise<false>;\n onFinish?: (result: TResult) => void;\n ready?: boolean;\n};\n\nexport interface ParameterDescription {\n name: string;\n required: boolean;\n}\n\nexport interface PropertyDescription {\n signature: string;\n name: string;\n namespaces: string[];\n docs: string;\n}\n\nexport interface FunctionDescription {\n signature: string;\n name: string;\n namespaces: string[];\n parameters: ParameterDescription[];\n hasSelf: boolean;\n docs: string;\n}\nexport interface ApiObject {\n functions: FunctionDescription[];\n methods: FunctionDescription[];\n properties: PropertyDescription[];\n namespaces: Record<string, ApiObject>;\n}\n\nexport interface ApiDefinitions {\n global: ApiObject;\n}\n\nexport interface ParameterDetails {\n name: string;\n type: string;\n overrideOptions?: Partial<\n Omit<ParameterDeclarationStructure, 'kind' | 'name' | 'type'>\n >;\n}\n\nexport interface PropertyDetails {\n signature: string;\n type: string;\n isStatic?: boolean;\n isReadOnly?: boolean;\n}\n\nexport interface FunctionDetails {\n signature: string;\n parameters: ParameterDetails[];\n returnType: string;\n overrideParameters?: boolean;\n overrideOptions?: Partial<\n FunctionDeclarationStructure | MethodDeclarationStructure\n >;\n}\n\nexport type TypeProviderData = {\n globalStatements: string[];\n statements: string[];\n classes: Record<string, Partial<ClassDeclarationStructure>>;\n properties: Record<string, PropertyDetails>;\n functions: Record<string, FunctionDetails>;\n};\n"],"names":["PlaydateSdkVersionIdentifier","HealthCheckStatusType"],"rangeMappings":";;;;;;;;;","mappings":";UASYA;;GAAAA,iCAAAA;;UAiBAC;;;;GAAAA,0BAAAA"}
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import { ModuleDeclaration, SourceFile } from 'ts-morph';
|
2
|
-
import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
|
3
|
-
import { FunctionDescription } from '../../../types.js';
|
4
|
-
export declare const generateFunction: (func: FunctionDescription, subject: SourceFile | ModuleDeclaration, typeProvider: ReturnType<typeof createTypeProvider>) => void;
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { _ as _extends } from "@swc/helpers/_/_extends";
|
2
|
-
import { TypescriptReservedNamed } from '../../../constants.js';
|
3
|
-
export const generateFunction = (func, subject, typeProvider)=>{
|
4
|
-
const isReserved = TypescriptReservedNamed.includes(func.name);
|
5
|
-
const name = isReserved ? `_${func.name}` : func.name;
|
6
|
-
var _typeProvider_getFunctionOverrideOptions;
|
7
|
-
subject.addFunction(_extends({
|
8
|
-
name,
|
9
|
-
docs: [
|
10
|
-
func.docs
|
11
|
-
],
|
12
|
-
returnType: typeProvider.getFunctionReturnType(func),
|
13
|
-
parameters: typeProvider.getParameters(func)
|
14
|
-
}, (_typeProvider_getFunctionOverrideOptions = typeProvider.getFunctionOverrideOptions(func)) != null ? _typeProvider_getFunctionOverrideOptions : {}));
|
15
|
-
if (isReserved) {
|
16
|
-
subject.addExportDeclaration({
|
17
|
-
namedExports: [
|
18
|
-
{
|
19
|
-
name,
|
20
|
-
alias: func.name
|
21
|
-
}
|
22
|
-
]
|
23
|
-
});
|
24
|
-
}
|
25
|
-
};
|
26
|
-
|
27
|
-
//# sourceMappingURL=generateFunction.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/generateFunction.ts"],"sourcesContent":["import {\n FunctionDeclarationStructure,\n ModuleDeclaration,\n SourceFile,\n} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport { FunctionDescription } from '@/cli/types.js';\n\nexport const generateFunction = (\n func: FunctionDescription,\n subject: SourceFile | ModuleDeclaration,\n typeProvider: ReturnType<typeof createTypeProvider>\n) => {\n const isReserved = TypescriptReservedNamed.includes(func.name);\n\n const name = isReserved ? `_${func.name}` : func.name;\n\n subject.addFunction({\n name,\n docs: [func.docs],\n returnType: typeProvider.getFunctionReturnType(func),\n parameters: typeProvider.getParameters(func),\n ...((typeProvider.getFunctionOverrideOptions(\n func\n ) as Partial<FunctionDeclarationStructure>) ?? {}),\n });\n\n if (isReserved) {\n subject.addExportDeclaration({\n namedExports: [\n {\n name,\n alias: func.name,\n },\n ],\n });\n }\n};\n"],"names":["TypescriptReservedNamed","generateFunction","func","subject","typeProvider","isReserved","includes","name","addFunction","docs","returnType","getFunctionReturnType","parameters","getParameters","getFunctionOverrideOptions","addExportDeclaration","namedExports","alias"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAMA,SAASA,uBAAuB,QAAQ,qBAAqB;AAG7D,OAAO,MAAMC,mBAAmB,CAC5BC,MACAC,SACAC;IAEA,MAAMC,aAAaL,wBAAwBM,QAAQ,CAACJ,KAAKK,IAAI;IAE7D,MAAMA,OAAOF,aAAa,CAAC,CAAC,EAAEH,KAAKK,IAAI,CAAC,CAAC,GAAGL,KAAKK,IAAI;QAO5CH;IALTD,QAAQK,WAAW,CAAC;QAChBD;QACAE,MAAM;YAACP,KAAKO,IAAI;SAAC;QACjBC,YAAYN,aAAaO,qBAAqB,CAACT;QAC/CU,YAAYR,aAAaS,aAAa,CAACX;OACnC,CAACE,2CAAAA,aAAaU,0BAA0B,CACxCZ,iBADCE,2CAE0C,CAAC;IAGpD,IAAIC,YAAY;QACZF,QAAQY,oBAAoB,CAAC;YACzBC,cAAc;gBACV;oBACIT;oBACAU,OAAOf,KAAKK,IAAI;gBACpB;aACH;QACL;IACJ;AACJ,EAAE"}
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import { ClassDeclaration, ModuleDeclaration, SourceFile } from 'ts-morph';
|
2
|
-
import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
|
3
|
-
import { PlaydateNamespace, PlaydateType } from '../../../types.js';
|
4
|
-
export declare const generateNamespace: (namespaceDescription: PlaydateNamespace, namespaces: string[], subjects: Map<string, SourceFile | ModuleDeclaration>, typeSubjects: Map<string, ClassDeclaration>, typeProvider: ReturnType<typeof createTypeProvider>, types: Record<string, PlaydateType>) => void;
|
@@ -1,81 +0,0 @@
|
|
1
|
-
import { _ as _extends } from "@swc/helpers/_/_extends";
|
2
|
-
import { VariableDeclarationKind } from 'ts-morph';
|
3
|
-
import { generateFunction } from '../../../commands/GenerateTypes/fn/generateFunction.js';
|
4
|
-
export const generateNamespace = (namespaceDescription, namespaces, subjects, typeSubjects, typeProvider, types)=>{
|
5
|
-
const subjectName = namespaces.slice(0, -1).join('.');
|
6
|
-
const namespaceName = namespaces[namespaces.length - 1];
|
7
|
-
const isRoot = namespaces.length === 1 && namespaces[0] === 'playdate';
|
8
|
-
const subject = namespaces.length <= 1 ? subjects.get('root') : subjects.get(subjectName);
|
9
|
-
if (!subject) {
|
10
|
-
return;
|
11
|
-
}
|
12
|
-
const module = namespaces.length > 0 ? subject.addModule({
|
13
|
-
name: namespaceName
|
14
|
-
}) : subject;
|
15
|
-
const addMethods = (typeName, subj, methods)=>{
|
16
|
-
const interfaceName = typeName.split('.').map((name)=>name[0].toUpperCase() + name.slice(1)).join('');
|
17
|
-
const typeClass = subj.addClass({
|
18
|
-
name: interfaceName
|
19
|
-
});
|
20
|
-
typeSubjects.set(typeName, typeClass);
|
21
|
-
for (const func of methods){
|
22
|
-
const parameters = typeProvider.getParameters(func);
|
23
|
-
typeClass.addMethod(_extends({
|
24
|
-
name: func.name,
|
25
|
-
docs: [
|
26
|
-
func.docs
|
27
|
-
],
|
28
|
-
returnType: typeProvider.getFunctionReturnType(func),
|
29
|
-
parameters
|
30
|
-
}, typeProvider.getFunctionOverrideOptions(func)));
|
31
|
-
}
|
32
|
-
};
|
33
|
-
if (isRoot && 'addJsDoc' in module) {
|
34
|
-
module.addJsDoc({
|
35
|
-
description: 'Playdate SDK'
|
36
|
-
});
|
37
|
-
module.addStatements(typeProvider.getStatements());
|
38
|
-
Object.keys(types).forEach((eachType)=>{
|
39
|
-
addMethods(eachType, module, types[eachType].methods);
|
40
|
-
});
|
41
|
-
}
|
42
|
-
if (namespaces.length > 0) {
|
43
|
-
subjects.set(namespaces.join('.'), module);
|
44
|
-
}
|
45
|
-
if (namespaceDescription.methods.length > 0) {
|
46
|
-
addMethods(namespaces.join('.'), subjects.get('playdate'), namespaceDescription.methods);
|
47
|
-
}
|
48
|
-
for (const property of namespaceDescription.properties){
|
49
|
-
const propertyDetails = typeProvider.getPropertyDetails(property);
|
50
|
-
if (!propertyDetails.isStatic) {
|
51
|
-
const typeName = namespaces.join('.');
|
52
|
-
if (typeSubjects.has(typeName)) {
|
53
|
-
const typeInterface = typeSubjects.get(typeName);
|
54
|
-
typeInterface.addProperty({
|
55
|
-
name: property.name,
|
56
|
-
type: propertyDetails.type,
|
57
|
-
docs: [
|
58
|
-
property.docs
|
59
|
-
],
|
60
|
-
isReadonly: propertyDetails.isReadOnly
|
61
|
-
});
|
62
|
-
}
|
63
|
-
continue;
|
64
|
-
}
|
65
|
-
const propertyType = propertyDetails.type;
|
66
|
-
module.addVariableStatement({
|
67
|
-
declarationKind: VariableDeclarationKind.Const,
|
68
|
-
declarations: [
|
69
|
-
{
|
70
|
-
name: property.name,
|
71
|
-
type: propertyType
|
72
|
-
}
|
73
|
-
]
|
74
|
-
});
|
75
|
-
}
|
76
|
-
for (const func of namespaceDescription.functions){
|
77
|
-
generateFunction(func, module, typeProvider);
|
78
|
-
}
|
79
|
-
};
|
80
|
-
|
81
|
-
//# sourceMappingURL=generateNamespace.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/generateNamespace.ts"],"sourcesContent":["import {\n ClassDeclaration,\n MethodDeclarationStructure,\n ModuleDeclaration,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph';\nimport { generateFunction } from '@/cli/commands/GenerateTypes/fn/generateFunction.js';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport {\n FunctionDescription,\n PlaydateNamespace,\n PlaydateType,\n} from '@/cli/types.js';\n\nexport const generateNamespace = (\n namespaceDescription: PlaydateNamespace,\n namespaces: string[],\n subjects: Map<string, SourceFile | ModuleDeclaration>,\n typeSubjects: Map<string, ClassDeclaration>,\n typeProvider: ReturnType<typeof createTypeProvider>,\n types: Record<string, PlaydateType>\n) => {\n const subjectName = namespaces.slice(0, -1).join('.');\n const namespaceName = namespaces[namespaces.length - 1];\n const isRoot = namespaces.length === 1 && namespaces[0] === 'playdate';\n const subject =\n namespaces.length <= 1\n ? subjects.get('root')\n : subjects.get(subjectName);\n\n if (!subject) {\n return;\n }\n\n const module =\n namespaces.length > 0\n ? subject.addModule({\n name: namespaceName,\n })\n : subject;\n\n const addMethods = (\n typeName: string,\n subj: ModuleDeclaration,\n methods: FunctionDescription[]\n ) => {\n const interfaceName = typeName\n .split('.')\n .map((name) => name[0].toUpperCase() + name.slice(1))\n .join('');\n const typeClass = subj.addClass({\n name: interfaceName,\n });\n typeSubjects.set(typeName, typeClass);\n\n for (const func of methods) {\n const parameters = typeProvider.getParameters(func);\n\n typeClass.addMethod({\n name: func.name,\n docs: [func.docs],\n returnType: typeProvider.getFunctionReturnType(func),\n parameters,\n ...(typeProvider.getFunctionOverrideOptions(\n func\n ) as Partial<MethodDeclarationStructure>),\n });\n }\n };\n\n if (isRoot && 'addJsDoc' in module) {\n module.addJsDoc({\n description: 'Playdate SDK',\n });\n module.addStatements(typeProvider.getStatements());\n\n Object.keys(types).forEach((eachType) => {\n addMethods(eachType, module, types[eachType].methods);\n });\n }\n\n if (namespaces.length > 0) {\n subjects.set(namespaces.join('.'), module);\n }\n\n if (namespaceDescription.methods.length > 0) {\n addMethods(\n namespaces.join('.'),\n subjects.get('playdate') as ModuleDeclaration,\n namespaceDescription.methods\n );\n }\n\n for (const property of namespaceDescription.properties) {\n const propertyDetails = typeProvider.getPropertyDetails(property);\n if (!propertyDetails.isStatic) {\n const typeName = namespaces.join('.');\n\n if (typeSubjects.has(typeName)) {\n const typeInterface = typeSubjects.get(\n typeName\n ) as ClassDeclaration;\n\n typeInterface.addProperty({\n name: property.name,\n type: propertyDetails.type,\n docs: [property.docs],\n isReadonly: propertyDetails.isReadOnly,\n });\n }\n\n continue;\n }\n\n const propertyType = propertyDetails.type;\n\n module.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: property.name,\n type: propertyType,\n },\n ],\n });\n }\n\n for (const func of namespaceDescription.functions) {\n generateFunction(func, module, typeProvider);\n }\n};\n"],"names":["VariableDeclarationKind","generateFunction","generateNamespace","namespaceDescription","namespaces","subjects","typeSubjects","typeProvider","types","subjectName","slice","join","namespaceName","length","isRoot","subject","get","module","addModule","name","addMethods","typeName","subj","methods","interfaceName","split","map","toUpperCase","typeClass","addClass","set","func","parameters","getParameters","addMethod","docs","returnType","getFunctionReturnType","getFunctionOverrideOptions","addJsDoc","description","addStatements","getStatements","Object","keys","forEach","eachType","property","properties","propertyDetails","getPropertyDetails","isStatic","has","typeInterface","addProperty","type","isReadonly","isReadOnly","propertyType","addVariableStatement","declarationKind","Const","declarations","functions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,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