crankscript 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -11
- package/package.json +4 -2
- package/src/commands/CompileCommand/CompileCommand.d.ts +7 -0
- package/src/commands/CompileCommand/CompileCommand.js +49 -0
- package/src/commands/CompileCommand/CompileCommand.js.map +1 -0
- package/src/commands/CompileCommand/index.d.ts +1 -0
- package/src/commands/CompileCommand/index.js +3 -0
- package/src/commands/CompileCommand/index.js.map +1 -0
- package/src/commands/CompileCommand/plugin.js +168 -0
- package/src/commands/CompileCommand/plugin.js.map +1 -0
- package/src/commands/GenerateTypes/GenerateTypesCommand.d.ts +1 -0
- package/src/commands/GenerateTypes/GenerateTypesCommand.js +5 -1
- package/src/commands/GenerateTypes/GenerateTypesCommand.js.map +1 -1
- package/src/commands/GenerateTypes/components/GenerateTypes.d.ts +2 -1
- package/src/commands/GenerateTypes/components/GenerateTypes.js +11 -5
- package/src/commands/GenerateTypes/components/GenerateTypes.js.map +1 -1
- package/src/commands/GenerateTypes/fn/generateFunction.d.ts +4 -0
- package/src/commands/GenerateTypes/fn/generateFunction.js +28 -0
- package/src/commands/GenerateTypes/fn/generateFunction.js.map +1 -0
- package/src/commands/GenerateTypes/fn/generateNamespace.d.ts +4 -3
- package/src/commands/GenerateTypes/fn/generateNamespace.js +68 -21
- package/src/commands/GenerateTypes/fn/generateNamespace.js.map +1 -1
- package/src/commands/GenerateTypes/fn/getApiDefinitions.d.ts +2 -11
- package/src/commands/GenerateTypes/fn/getApiDefinitions.js +26 -9
- package/src/commands/GenerateTypes/fn/getApiDefinitions.js.map +1 -1
- package/src/commands/GenerateTypes/fn/getDescriptionsFromHtml.d.ts +5 -0
- package/src/commands/GenerateTypes/fn/getDescriptionsFromHtml.js +75 -0
- package/src/commands/GenerateTypes/fn/getDescriptionsFromHtml.js.map +1 -0
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.d.ts +1 -1
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.js +4 -6
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.d.ts +2 -1
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js +14 -23
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useGetVersion.d.ts +10 -0
- package/src/commands/GenerateTypes/hooks/useGetVersion.js +5 -1
- package/src/commands/GenerateTypes/hooks/useGetVersion.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useParseDocumentation.d.ts +0 -9
- package/src/commands/GenerateTypes/hooks/useParseDocumentation.js +3 -3
- package/src/commands/GenerateTypes/hooks/useParseDocumentation.js.map +1 -1
- package/src/commands/GenerateTypes/utils/createTypeProvider.d.ts +12 -0
- package/src/commands/GenerateTypes/utils/createTypeProvider.js +141 -0
- package/src/commands/GenerateTypes/utils/createTypeProvider.js.map +1 -0
- package/src/components/CheckList/CheckList.js +1 -2
- package/src/components/CheckList/CheckList.js.map +1 -1
- package/src/components/CheckList/Item.js +1 -0
- package/src/components/CheckList/Item.js.map +1 -1
- package/src/constants.d.ts +2 -0
- package/src/constants.js +4 -0
- package/src/constants.js.map +1 -1
- package/src/index.js +4 -2
- package/src/index.js.map +1 -1
- package/src/types.d.ts +34 -3
- package/src/types.js.map +1 -1
- package/src/utils/dirname.d.ts +1 -1
- package/src/utils/dirname.js +2 -3
- package/src/utils/dirname.js.map +1 -1
- package/src/commands/GenerateTypes/fn/getFunctionDescriptionsFromHtml.d.ts +0 -2
- package/src/commands/GenerateTypes/fn/getFunctionDescriptionsFromHtml.js +0 -37
- package/src/commands/GenerateTypes/fn/getFunctionDescriptionsFromHtml.js.map +0 -1
- package/src/commands/GenerateTypes/utils/playdateConstants.d.ts +0 -9
- package/src/commands/GenerateTypes/utils/playdateConstants.js +0 -134
- package/src/commands/GenerateTypes/utils/playdateConstants.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/generateNamespace.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/generateNamespace.ts"],"sourcesContent":["import {\n InterfaceDeclaration,\n MethodSignatureStructure,\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, InterfaceDeclaration>,\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 = subject.addModule({\n name: namespaceName,\n });\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 typeInterface = subj.addInterface({\n name: interfaceName,\n });\n typeSubjects.set(typeName, typeInterface);\n\n for (const func of methods) {\n const parameters = typeProvider.getParameters(func);\n\n typeInterface.addMethod({\n name: func.name,\n docs: [func.docs],\n returnType: typeProvider.getFunctionReturnType(func),\n parameters,\n ...(typeProvider.getFunctionOverrideOptions(\n func\n ) as Partial<MethodSignatureStructure>),\n });\n }\n };\n\n if (isRoot) {\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 subjects.set(namespaces.join('.'), module);\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 InterfaceDeclaration;\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 isExported: true,\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","typeInterface","addInterface","set","func","parameters","getParameters","addMethod","docs","returnType","getFunctionReturnType","getFunctionOverrideOptions","addJsDoc","description","addStatements","getStatements","Object","keys","forEach","eachType","property","properties","propertyDetails","getPropertyDetails","isStatic","has","addProperty","type","isReadonly","isReadOnly","propertyType","addVariableStatement","isExported","declarationKind","Const","declarations","functions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAKIA,uBAAuB,QACpB,WAAW;AAClB,SAASC,gBAAgB,QAAQ,sDAAsD;AAQvF,OAAO,MA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AEAlB,SAASyB,GAAG,CAAC1B,WAAWO,IAAI,CAAC,MAAMM;IAEnC,IAAId,qBAAqBoB,OAAO,CAACV,MAAM,GAAG,GAAG;QACzCO,WACIhB,WAAWO,IAAI,CAAC,MAChBN,SAASW,GAAG,CAAC,aACbb,qBAAqBoB,OAAO;IAEpC;IAEA,KAAK,MAAMwB,YAAY5C,qBAAqB6C,UAAU,CAAE;QACpD,MAAMC,kBAAkB1C,aAAa2C,kBAAkB,CAACH;QACxD,IAAI,CAACE,gBAAgBE,QAAQ,EAAE;YAC3B,MAAM9B,WAAWjB,WAAWO,IAAI,CAAC;YAEjC,IAAIL,aAAa8C,GAAG,CAAC/B,WAAW;gBAC5B,MAAMO,gBAAgBtB,aAAaU,GAAG,CAClCK;gBAGJO,cAAcyB,WAAW,CAAC;oBACtBlC,MAAM4B,SAAS5B,IAAI;oBACnBmC,MAAML,gBAAgBK,IAAI;oBAC1BnB,MAAM;wBAACY,SAASZ,IAAI;qBAAC;oBACrBoB,YAAYN,gBAAgBO,UAAU;gBAC1C;YACJ;YAEA;QACJ;QAEA,MAAMC,eAAeR,gBAAgBK,IAAI;QAEzCrC,OAAOyC,oBAAoB,CAAC;YACxBC,YAAY;YACZC,iBAAiB5D,wBAAwB6D,KAAK;YAC9CC,cAAc;gBACV;oBACI3C,MAAM4B,SAAS5B,IAAI;oBACnBmC,MAAMG;gBACV;aACH;QACL;IACJ;IAEA,KAAK,MAAM1B,QAAQ5B,qBAAqB4D,SAAS,CAAE;QAC/C9D,iBAAiB8B,MAAMd,QAAQV;IACnC;AACJ,EAAE"}
|
@@ -1,14 +1,5 @@
|
|
1
|
-
import { FunctionDescription, PlaydateNamespace, PlaydateType } from '../../../types.js';
|
2
|
-
export declare const getApiDefinitions: (functions: FunctionDescription[]) => {
|
1
|
+
import { FunctionDescription, PlaydateNamespace, PlaydateType, PropertyDescription } from '../../../types.js';
|
2
|
+
export declare const getApiDefinitions: (functions: FunctionDescription[], properties: PropertyDescription[]) => {
|
3
3
|
namespaces: Record<string, PlaydateNamespace>;
|
4
4
|
types: Record<string, PlaydateType>;
|
5
|
-
constants: {
|
6
|
-
name: string;
|
7
|
-
values: {
|
8
|
-
name: string;
|
9
|
-
value: number;
|
10
|
-
docs: string;
|
11
|
-
}[];
|
12
|
-
docs: string;
|
13
|
-
}[];
|
14
5
|
};
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
export const getApiDefinitions = (functions)=>{
|
1
|
+
export const getApiDefinitions = (functions, properties)=>{
|
3
2
|
const namespaces = {};
|
4
3
|
const types = {};
|
5
4
|
const realNamespaces = new Set();
|
@@ -9,17 +8,29 @@ export const getApiDefinitions = (functions)=>{
|
|
9
8
|
let currentNamespace = '';
|
10
9
|
func.namespaces.forEach((ns)=>{
|
11
10
|
currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
|
12
|
-
|
13
|
-
realNamespaces.
|
11
|
+
const realNamespaceName = currentNamespace.trim();
|
12
|
+
if (!realNamespaces.has(realNamespaceName)) {
|
13
|
+
realNamespaces.add(realNamespaceName);
|
14
|
+
}
|
14
15
|
});
|
15
16
|
}
|
16
17
|
});
|
18
|
+
properties.forEach((prop)=>{
|
19
|
+
let currentNamespace = '';
|
20
|
+
prop.namespaces.forEach((ns)=>{
|
21
|
+
currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
|
22
|
+
const realNamespaceName = currentNamespace.trim();
|
23
|
+
if (!realNamespaces.has(realNamespaceName)) {
|
24
|
+
realNamespaces.add(realNamespaceName);
|
25
|
+
}
|
26
|
+
});
|
27
|
+
});
|
17
28
|
functions.forEach((func)=>{
|
18
29
|
if (func.hasSelf) {
|
19
30
|
let currentNamespace = '';
|
20
31
|
func.namespaces.forEach((ns)=>{
|
21
32
|
currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
|
22
|
-
if (!
|
33
|
+
if (!potentialNamespaces.has(currentNamespace)) {
|
23
34
|
potentialNamespaces.add(currentNamespace);
|
24
35
|
}
|
25
36
|
});
|
@@ -28,14 +39,15 @@ export const getApiDefinitions = (functions)=>{
|
|
28
39
|
realNamespaces.forEach((ns)=>{
|
29
40
|
namespaces[ns] = {
|
30
41
|
functions: [],
|
31
|
-
|
42
|
+
methods: [],
|
43
|
+
properties: []
|
32
44
|
};
|
33
45
|
});
|
34
46
|
functions.forEach((func)=>{
|
35
47
|
const fullNamespacePath = func.namespaces.join('.');
|
36
48
|
if (realNamespaces.has(fullNamespacePath)) {
|
37
49
|
if (func.hasSelf) {
|
38
|
-
namespaces[fullNamespacePath].
|
50
|
+
namespaces[fullNamespacePath].methods.push(func);
|
39
51
|
} else {
|
40
52
|
namespaces[fullNamespacePath].functions.push(func);
|
41
53
|
}
|
@@ -48,10 +60,15 @@ export const getApiDefinitions = (functions)=>{
|
|
48
60
|
types[fullNamespacePath].methods.push(func);
|
49
61
|
}
|
50
62
|
});
|
63
|
+
properties.forEach((prop)=>{
|
64
|
+
const fullNamespacePath = prop.namespaces.join('.');
|
65
|
+
if (realNamespaces.has(fullNamespacePath)) {
|
66
|
+
namespaces[fullNamespacePath].properties.push(prop);
|
67
|
+
}
|
68
|
+
});
|
51
69
|
return {
|
52
70
|
namespaces,
|
53
|
-
types
|
54
|
-
constants: playdateConstants
|
71
|
+
types
|
55
72
|
};
|
56
73
|
};
|
57
74
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getApiDefinitions.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getApiDefinitions.ts"],"sourcesContent":["import {\n ApiDefinitions,\n FunctionDescription,\n PlaydateNamespace,\n PlaydateType,\n PropertyDescription,\n} from '@/cli/types.js';\n\nexport const getApiDefinitions = (\n functions: FunctionDescription[],\n properties: PropertyDescription[]\n) => {\n const namespaces: Record<string, PlaydateNamespace> = {};\n const types: Record<string, PlaydateType> = {};\n const realNamespaces = new Set<string>();\n const potentialNamespaces = new Set<string>();\n\n functions.forEach((func) => {\n if (!func.hasSelf) {\n let currentNamespace = '';\n func.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n const realNamespaceName = currentNamespace.trim();\n\n if (!realNamespaces.has(realNamespaceName)) {\n realNamespaces.add(realNamespaceName);\n }\n });\n }\n });\n\n properties.forEach((prop) => {\n let currentNamespace = '';\n prop.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n const realNamespaceName = currentNamespace.trim();\n\n if (!realNamespaces.has(realNamespaceName)) {\n realNamespaces.add(realNamespaceName);\n }\n });\n });\n\n functions.forEach((func) => {\n if (func.hasSelf) {\n let currentNamespace = '';\n func.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n if (!potentialNamespaces.has(currentNamespace)) {\n potentialNamespaces.add(currentNamespace);\n }\n });\n }\n });\n\n realNamespaces.forEach((ns) => {\n namespaces[ns] = {\n functions: [],\n methods: [],\n properties: [],\n };\n });\n\n functions.forEach((func) => {\n const fullNamespacePath = func.namespaces.join('.');\n\n if (realNamespaces.has(fullNamespacePath)) {\n if (func.hasSelf) {\n namespaces[fullNamespacePath].methods.push(func);\n } else {\n namespaces[fullNamespacePath].functions.push(func);\n }\n } else if (potentialNamespaces.has(fullNamespacePath)) {\n if (!types[fullNamespacePath]) {\n types[fullNamespacePath] = { methods: [] };\n }\n types[fullNamespacePath].methods.push(func);\n }\n });\n\n properties.forEach((prop) => {\n const fullNamespacePath = prop.namespaces.join('.');\n\n if (realNamespaces.has(fullNamespacePath)) {\n namespaces[fullNamespacePath].properties.push(prop);\n }\n });\n\n return {\n namespaces,\n types,\n } satisfies ApiDefinitions;\n};\n"],"names":["getApiDefinitions","functions","properties","namespaces","types","realNamespaces","Set","potentialNamespaces","forEach","func","hasSelf","currentNamespace","ns","realNamespaceName","trim","has","add","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CAACL;gBAC5B;YACJ;QACJ;IACJ;IAEAN,eAAeG,OAAO,CAAC,CAACI;QACpBT,UAAU,CAACS,GAAG,GAAG;YACbX,WAAW,EAAE;YACbiB,SAAS,EAAE;YACXhB,YAAY,EAAE;QAClB;IACJ;IAEAD,UAAUO,OAAO,CAAC,CAACC;QACf,MAAMU,oBAAoBV,KAAKN,UAAU,CAACiB,IAAI,CAAC;QAE/C,IAAIf,eAAeU,GAAG,CAACI,oBAAoB;YACvC,IAAIV,KAAKC,OAAO,EAAE;gBACdP,UAAU,CAACgB,kBAAkB,CAACD,OAAO,CAACG,IAAI,CAACZ;YAC/C,OAAO;gBACHN,UAAU,CAACgB,kBAAkB,CAAClB,SAAS,CAACoB,IAAI,CAACZ;YACjD;QACJ,OAAO,IAAIF,oBAAoBQ,GAAG,CAACI,oBAAoB;YACnD,IAAI,CAACf,KAAK,CAACe,kBAAkB,EAAE;gBAC3Bf,KAAK,CAACe,kBAAkB,GAAG;oBAAED,SAAS,EAAE;gBAAC;YAC7C;YACAd,KAAK,CAACe,kBAAkB,CAACD,OAAO,CAACG,IAAI,CAACZ;QAC1C;IACJ;IAEAP,WAAWM,OAAO,CAAC,CAACS;QAChB,MAAME,oBAAoBF,KAAKd,UAAU,CAACiB,IAAI,CAAC;QAE/C,IAAIf,eAAeU,GAAG,CAACI,oBAAoB;YACvChB,UAAU,CAACgB,kBAAkB,CAACjB,UAAU,CAACmB,IAAI,CAACJ;QAClD;IACJ;IAEA,OAAO;QACHd;QACAC;IACJ;AACJ,EAAE"}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
2
|
+
import { load } from 'cheerio';
|
3
|
+
import { PlaydateSdkUrl } from '../../../commands/GenerateTypes/constants.js';
|
4
|
+
import { parseFunctionSignature } from '../../../commands/GenerateTypes/fn/parseFunctionSignature.js';
|
5
|
+
const extractFunctionCalls = (input)=>{
|
6
|
+
const functionCallRegex = /([a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*(?::[a-zA-Z_]\w*)?)\s*(\([^)]*\))?/g;
|
7
|
+
const matches = [];
|
8
|
+
let match;
|
9
|
+
while((match = functionCallRegex.exec(input)) !== null){
|
10
|
+
matches.push(match[0].trim());
|
11
|
+
}
|
12
|
+
return matches;
|
13
|
+
};
|
14
|
+
const normalizeSignature = (signature)=>{
|
15
|
+
const closingParenIndex = signature.indexOf(')');
|
16
|
+
return closingParenIndex !== -1 ? signature.slice(0, closingParenIndex + 1) : signature;
|
17
|
+
};
|
18
|
+
export const getDescriptionsFromHtml = (html, version)=>{
|
19
|
+
const $ = load(html);
|
20
|
+
const functionSignatures = $('[id^="m-"], [id^="f-"], [id^="c-"], [id^="v-"]').toArray();
|
21
|
+
const functions = [];
|
22
|
+
const properties = [];
|
23
|
+
const visitedSignatures = [];
|
24
|
+
for (const element of functionSignatures){
|
25
|
+
var _$_attr;
|
26
|
+
const id = (_$_attr = $(element).attr('id')) != null ? _$_attr : '';
|
27
|
+
const isProperty = id.startsWith('v-');
|
28
|
+
const titleText = $(element).find('.title').text();
|
29
|
+
if (titleText.indexOf('#') !== -1 || /[a-zA-Z]\[/.test(titleText)) {
|
30
|
+
continue;
|
31
|
+
}
|
32
|
+
const titles = isProperty ? titleText.split(' ') : extractFunctionCalls(titleText);
|
33
|
+
var _$_find_html;
|
34
|
+
let docsString = ((_$_find_html = $(element).find('.content').html()) != null ? _$_find_html : '').trim();
|
35
|
+
if (docsString.startsWith('<div class="paragraph">')) {
|
36
|
+
docsString = docsString.slice('<div class="paragraph">'.length);
|
37
|
+
}
|
38
|
+
if (docsString.endsWith('</div>')) {
|
39
|
+
docsString = docsString.slice(0, docsString.length - '</div>'.length);
|
40
|
+
}
|
41
|
+
docsString = docsString.replace(/<a href="#/g, '<a href="' + PlaydateSdkUrl + version + '#');
|
42
|
+
const baseDocs = id ? `${docsString}\n[Read more](${PlaydateSdkUrl}${version}#${id})` : docsString;
|
43
|
+
for (const title of titles){
|
44
|
+
const signature = normalizeSignature(title);
|
45
|
+
if (visitedSignatures.includes(signature)) {
|
46
|
+
continue;
|
47
|
+
}
|
48
|
+
visitedSignatures.push(signature);
|
49
|
+
if (isProperty) {
|
50
|
+
properties.push({
|
51
|
+
name: title.split('.').slice(-1)[0],
|
52
|
+
namespaces: signature.split('.').slice(0, -1),
|
53
|
+
signature,
|
54
|
+
docs: baseDocs
|
55
|
+
});
|
56
|
+
} else {
|
57
|
+
try {
|
58
|
+
const description = parseFunctionSignature(signature);
|
59
|
+
const docs = description.hasSelf ? baseDocs : `${baseDocs}\n\n@noSelf`;
|
60
|
+
functions.push(_extends({}, description, {
|
61
|
+
docs
|
62
|
+
}));
|
63
|
+
} catch (e) {
|
64
|
+
// Ignore
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
return {
|
70
|
+
functions,
|
71
|
+
properties
|
72
|
+
};
|
73
|
+
};
|
74
|
+
|
75
|
+
//# sourceMappingURL=getDescriptionsFromHtml.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getDescriptionsFromHtml.ts"],"sourcesContent":["import { load } from 'cheerio';\nimport { PlaydateSdkUrl } from '@/cli/commands/GenerateTypes/constants.js';\nimport { parseFunctionSignature } from '@/cli/commands/GenerateTypes/fn/parseFunctionSignature.js';\nimport { FunctionDescription, PropertyDescription } from '@/cli/types.js';\n\nconst extractFunctionCalls = (input: string) => {\n const functionCallRegex =\n /([a-zA-Z_]\\w*(\\.[a-zA-Z_]\\w*)*(?::[a-zA-Z_]\\w*)?)\\s*(\\([^)]*\\))?/g;\n const matches: string[] = [];\n let match;\n\n while ((match = functionCallRegex.exec(input)) !== null) {\n matches.push(match[0].trim());\n }\n\n return matches;\n};\n\nconst normalizeSignature = (signature: string) => {\n const closingParenIndex = signature.indexOf(')');\n return closingParenIndex !== -1\n ? signature.slice(0, closingParenIndex + 1)\n : signature;\n};\n\nexport const getDescriptionsFromHtml = (html: string, version: string) => {\n const $ = load(html);\n\n const functionSignatures = $(\n '[id^=\"m-\"], [id^=\"f-\"], [id^=\"c-\"], [id^=\"v-\"]'\n ).toArray();\n const functions: FunctionDescription[] = [];\n const properties: PropertyDescription[] = [];\n const visitedSignatures: string[] = [];\n\n for (const element of functionSignatures) {\n const id = $(element).attr('id') ?? '';\n const isProperty = id.startsWith('v-');\n const titleText = $(element).find('.title').text();\n\n if (titleText.indexOf('#') !== -1 || /[a-zA-Z]\\[/.test(titleText)) {\n continue;\n }\n\n const titles = isProperty\n ? titleText.split(' ')\n : extractFunctionCalls(titleText);\n\n let docsString = ($(element).find('.content').html() ?? '').trim();\n\n if (docsString.startsWith('<div class=\"paragraph\">')) {\n docsString = docsString.slice('<div class=\"paragraph\">'.length);\n }\n\n if (docsString.endsWith('</div>')) {\n docsString = docsString.slice(\n 0,\n docsString.length - '</div>'.length\n );\n }\n\n docsString = docsString.replace(\n /<a href=\"#/g,\n '<a href=\"' + PlaydateSdkUrl + version + '#'\n );\n\n const baseDocs = id\n ? `${docsString}\\n[Read more](${PlaydateSdkUrl}${version}#${id})`\n : docsString;\n\n for (const title of titles) {\n const signature = normalizeSignature(title);\n\n if (visitedSignatures.includes(signature)) {\n continue;\n }\n\n visitedSignatures.push(signature);\n\n if (isProperty) {\n properties.push({\n name: title.split('.').slice(-1)[0],\n namespaces: signature.split('.').slice(0, -1),\n signature,\n docs: baseDocs,\n });\n } else {\n try {\n const description = parseFunctionSignature(signature);\n\n const docs = description.hasSelf\n ? baseDocs\n : `${baseDocs}\\n\\n@noSelf`;\n\n functions.push({\n ...description,\n docs,\n });\n } catch (e) {\n // Ignore\n }\n }\n }\n }\n\n return { functions, properties };\n};\n"],"names":["load","PlaydateSdkUrl","parseFunctionSignature","extractFunctionCalls","input","functionCallRegex","matches","match","exec","push","trim","normalizeSignature","signature","closingParenIndex","indexOf","slice","getDescriptionsFromHtml","html","version","$","functionSignatures","toArray","functions","properties","visitedSignatures","element","id","attr","isProperty","startsWith","titleText","find","text","test","titles","split","docsString","length","endsWith","replace","baseDocs","title","includes","name","namespaces","docs","description","hasSelf","e"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,IAAI,QAAQ,UAAU;AAC/B,SAASC,cAAc,QAAQ,4CAA4C;AAC3E,SAASC,sBAAsB,QAAQ,4DAA4D;AAGnG,MAAMC,uBAAuB,CAACC;IAC1B,MAAMC,oBACF;IACJ,MAAMC,UAAoB,EAAE;IAC5B,IAAIC;IAEJ,MAAO,AAACA,CAAAA,QAAQF,kBAAkBG,IAAI,CAACJ,MAAK,MAAO,KAAM;QACrDE,QAAQG,IAAI,CAACF,KAAK,CAAC,EAAE,CAACG,IAAI;IAC9B;IAEA,OAAOJ;AACX;AAEA,MAAMK,qBAAqB,CAACC;IACxB,MAAMC,oBAAoBD,UAAUE,OAAO,CAAC;IAC5C,OAAOD,sBAAsB,CAAC,IACxBD,UAAUG,KAAK,CAAC,GAAGF,oBAAoB,KACvCD;AACV;AAEA,OAAO,MAAMI,0BAA0B,CAACC,MAAcC;IAClD,MAAMC,IAAInB,KAAKiB;IAEf,MAAMG,qBAAqBD,EACvB,kDACFE,OAAO;IACT,MAAMC,YAAmC,EAAE;IAC3C,MAAMC,aAAoC,EAAE;IAC5C,MAAMC,oBAA8B,EAAE;IAEtC,KAAK,MAAMC,WAAWL,mBAAoB;YAC3BD;QAAX,MAAMO,KAAKP,CAAAA,UAAAA,EAAEM,SAASE,IAAI,CAAC,iBAAhBR,UAAyB;QACpC,MAAMS,aAAaF,GAAGG,UAAU,CAAC;QACjC,MAAMC,YAAYX,EAAEM,SAASM,IAAI,CAAC,UAAUC,IAAI;QAEhD,IAAIF,UAAUhB,OAAO,CAAC,SAAS,CAAC,KAAK,aAAamB,IAAI,CAACH,YAAY;YAC/D;QACJ;QAEA,MAAMI,SAASN,aACTE,UAAU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AACnC,EAAE"}
|
@@ -1,8 +1,6 @@
|
|
1
1
|
export const parseFunctionSignature = (signature)=>{
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
const [fullyQualifiedName, paramString] = signature.split('(');
|
2
|
+
const normalizedSignature = signature.includes('(') ? signature : signature + '()';
|
3
|
+
const [fullyQualifiedName, paramString] = normalizedSignature.split('(');
|
6
4
|
const hasSelf = fullyQualifiedName.includes(':');
|
7
5
|
const normalizedFullyQualifiedName = fullyQualifiedName.replace(':', '.');
|
8
6
|
const segments = normalizedFullyQualifiedName.split('.');
|
@@ -10,11 +8,11 @@ export const parseFunctionSignature = (signature)=>{
|
|
10
8
|
const namespaces = segments.slice(0, -1);
|
11
9
|
const params = paramString.split(')')[0].split(',').filter(Boolean);
|
12
10
|
return {
|
11
|
+
signature,
|
13
12
|
name: functionName,
|
14
13
|
namespaces,
|
15
14
|
parameters: params.map((eachParam)=>({
|
16
|
-
name: eachParam.replace(/\[/g, '').replace(
|
17
|
-
type: 'unknown',
|
15
|
+
name: eachParam.replace(/\[/g, '').replace(/]/g, '').trim(),
|
18
16
|
required: !eachParam.includes('[')
|
19
17
|
})),
|
20
18
|
hasSelf
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/parseFunctionSignature.ts"],"sourcesContent":["import { FunctionDescription } from '@/cli/types.js';\n\nexport const parseFunctionSignature = (signature: string) => {\n
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/parseFunctionSignature.ts"],"sourcesContent":["import { FunctionDescription } from '@/cli/types.js';\n\nexport const parseFunctionSignature = (signature: string) => {\n const normalizedSignature = signature.includes('(')\n ? signature\n : signature + '()';\n\n const [fullyQualifiedName, paramString] = normalizedSignature.split('(');\n const hasSelf = fullyQualifiedName.includes(':');\n const normalizedFullyQualifiedName = fullyQualifiedName.replace(':', '.');\n const segments = normalizedFullyQualifiedName.split('.');\n const functionName = segments[segments.length - 1];\n const namespaces = segments.slice(0, -1);\n const params = paramString.split(')')[0].split(',').filter(Boolean);\n\n return {\n signature,\n name: functionName,\n namespaces,\n parameters: params.map((eachParam) => ({\n name: eachParam.replace(/\\[/g, '').replace(/]/g, '').trim(),\n required: !eachParam.includes('['),\n })),\n hasSelf,\n } satisfies Omit<FunctionDescription, 'docs'>;\n};\n"],"names":["parseFunctionSignature","signature","normalizedSignature","includes","fullyQualifiedName","paramString","split","hasSelf","normalizedFullyQualifiedName","replace","segments","functionName","length","namespaces","slice","params","filter","Boolean","name","parameters","map","eachParam","trim","required"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,yBAAyB,CAACC;IACnC,MAAMC,sBAAsBD,UAAUE,QAAQ,CAAC,OACzCF,YACAA,YAAY;IAElB,MAAM,CAACG,oBAAoBC,YAAY,GAAGH,oBAAoBI,KAAK,CAAC;IACpE,MAAMC,UAAUH,mBAAmBD,QAAQ,CAAC;IAC5C,MAAMK,+BAA+BJ,mBAAmBK,OAAO,CAAC,KAAK;IACrE,MAAMC,WAAWF,6BAA6BF,KAAK,CAAC;IACpD,MAAMK,eAAeD,QAAQ,CAACA,SAASE,MAAM,GAAG,EAAE;IAClD,MAAMC,aAAaH,SAASI,KAAK,CAAC,GAAG,CAAC;IACtC,MAAMC,SAASV,YAAYC,KAAK,CAAC,IAAI,CAAC,EAAE,CAACA,KAAK,CAAC,KAAKU,MAAM,CAACC;IAE3D,OAAO;QACHhB;QACAiB,MAAMP;QACNE;QACAM,YAAYJ,OAAOK,GAAG,CAAC,CAACC,YAAe,CAAA;gBACnCH,MAAMG,UAAUZ,OAAO,CAAC,OAAO,IAAIA,OAAO,CAAC,MAAM,IAAIa,IAAI;gBACzDC,UAAU,CAACF,UAAUlB,QAAQ,CAAC;YAClC,CAAA;QACAI;IACJ;AACJ,EAAE"}
|
@@ -1,5 +1,6 @@
|
|
1
|
+
import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
|
1
2
|
import { ApiDefinitions } from '../../../types.js';
|
2
|
-
export declare const useGenerateTypeFile: (path: string, definitions: ApiDefinitions | null) => {
|
3
|
+
export declare const useGenerateTypeFile: (path: string, definitions: ApiDefinitions | null, typeProvider: ReturnType<typeof createTypeProvider> | null) => {
|
3
4
|
generateTypeFile: {
|
4
5
|
waitingDescription: string;
|
5
6
|
errorDescription: string;
|
@@ -1,7 +1,8 @@
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
1
2
|
import { useMemo } from 'react';
|
2
3
|
import { Project } from 'ts-morph';
|
3
4
|
import { generateNamespace } from '../../../commands/GenerateTypes/fn/generateNamespace.js';
|
4
|
-
export const useGenerateTypeFile = (path, definitions)=>{
|
5
|
+
export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
|
5
6
|
const generateTypeFile = useMemo(()=>{
|
6
7
|
return {
|
7
8
|
waitingDescription: 'Waiting to generate the type file...',
|
@@ -12,39 +13,29 @@ export const useGenerateTypeFile = (path, definitions)=>{
|
|
12
13
|
if (!definitions) {
|
13
14
|
throw new Error('Definitions are not set');
|
14
15
|
}
|
16
|
+
if (!typeProvider) {
|
17
|
+
throw new Error('Type provider is not set');
|
18
|
+
}
|
15
19
|
const project = new Project();
|
16
20
|
const typeFile = project.createSourceFile(path, '', {
|
17
21
|
overwrite: true
|
18
22
|
});
|
19
|
-
typeFile.addStatements(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
docs: [
|
24
|
-
constantDefinition.docs
|
25
|
-
],
|
26
|
-
isConst: true,
|
27
|
-
isExported: true,
|
28
|
-
members: constantDefinition.values.map((value)=>({
|
29
|
-
name: value.name,
|
30
|
-
docs: [
|
31
|
-
value.docs
|
32
|
-
],
|
33
|
-
value: value.value
|
34
|
-
}))
|
35
|
-
});
|
36
|
-
}
|
23
|
+
typeFile.addStatements(typeProvider.getGlobalStatements());
|
24
|
+
const subjects = new Map();
|
25
|
+
const typeSubjects = new Map();
|
26
|
+
subjects.set('root', typeFile);
|
37
27
|
Object.keys(definitions.namespaces).forEach((namespace)=>{
|
38
28
|
const namespaceDescription = definitions.namespaces[namespace];
|
39
29
|
const namespaces = namespace.split('.');
|
40
|
-
generateNamespace(
|
30
|
+
generateNamespace(namespaceDescription, namespaces, subjects, typeSubjects, typeProvider, definitions.types);
|
41
31
|
});
|
42
|
-
typeFile.
|
32
|
+
writeFileSync(path, typeFile.getFullText().replace('/** Playdate SDK */', '\n/** Playdate SDK */'));
|
43
33
|
},
|
44
|
-
ready: definitions !== null
|
34
|
+
ready: definitions !== null && typeProvider !== null
|
45
35
|
};
|
46
36
|
}, [
|
47
|
-
definitions
|
37
|
+
definitions,
|
38
|
+
typeProvider
|
48
39
|
]);
|
49
40
|
return {
|
50
41
|
generateTypeFile
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGenerateTypeFile.ts"],"sourcesContent":["import { useMemo } from 'react';\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 InterfaceDeclaration,\n ModuleDeclaration,\n Project,\n SourceFile,\n} from 'ts-morph';\nimport { generateNamespace } from '@/cli/commands/GenerateTypes/fn/generateNamespace.js';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { ApiDefinitions, 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 typeFile.addStatements(typeProvider.getGlobalStatements());\n\n const subjects = new Map<\n string,\n SourceFile | ModuleDeclaration\n >();\n const typeSubjects = new Map<string, InterfaceDeclaration>();\n subjects.set('root', typeFile);\n\n Object.keys(definitions.namespaces).forEach((namespace) => {\n const namespaceDescription =\n definitions.namespaces[namespace];\n const namespaces = namespace.split('.');\n generateNamespace(\n namespaceDescription,\n namespaces,\n subjects,\n typeSubjects,\n typeProvider,\n definitions.types\n );\n });\n\n writeFileSync(\n path,\n typeFile\n .getFullText()\n .replace('/** Playdate SDK */', '\\n/** Playdate SDK */')\n );\n },\n ready: definitions !== null && typeProvider !== null,\n } satisfies CheckListItem<void>;\n }, [definitions, typeProvider]);\n\n return {\n generateTypeFile,\n };\n};\n"],"names":["writeFileSync","useMemo","Project","generateNamespace","useGenerateTypeFile","path","definitions","typeProvider","generateTypeFile","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","project","typeFile","createSourceFile","overwrite","addStatements","getGlobalStatements","subjects","Map","typeSubjects","set","Object","keys","namespaces","forEach","namespace","namespaceDescription","split","types","getFullText","replace","ready"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAGIC,OAAO,QAEJ,WAAW;AAClB,SAASC,iBAAiB,QAAQ,uDAAuD;AAIzF,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;gBACAF,SAASG,aAAa,CAACZ,aAAaa,mBAAmB;gBAEvD,MAAMC,WAAW,IAAIC;gBAIrB,MAAMC,eAAe,IAAID;gBACzBD,SAASG,GAAG,CAAC,QAAQR;gBAErBS,OAAOC,IAAI,CAACpB,YAAYqB,UAAU,EAAEC,OAAO,CAAC,CAACC;oBACzC,MAAMC,uBACFxB,YAAYqB,UAAU,CAACE,UAAU;oBACrC,MAAMF,aAAaE,UAAUE,KAAK,CAAC;oBACnC5B,kBACI2B,sBACAH,YACAN,UACAE,cACAhB,cACAD,YAAY0B,KAAK;gBAEzB;gBAEAhC,cACIK,MACAW,SACKiB,WAAW,GACXC,OAAO,CAAC,uBAAuB;YAE5C;YACAC,OAAO7B,gBAAgB,QAAQC,iBAAiB;QACpD;IACJ,GAAG;QAACD;QAAaC;KAAa;IAE9B,OAAO;QACHC;IACJ;AACJ,EAAE"}
|
@@ -9,4 +9,14 @@ export declare const useGetVersion: (version: PlaydateSdkVersion) => {
|
|
9
9
|
runner: () => Promise<string>;
|
10
10
|
onFinish: (result: string) => void;
|
11
11
|
};
|
12
|
+
typeProvider: {
|
13
|
+
getGlobalStatements: () => string[];
|
14
|
+
getStatements: () => string[];
|
15
|
+
getPropertyDetails: (property: import("../../../types.js").PropertyDescription) => import("../../../types.js").PropertyDetails;
|
16
|
+
getFunctionReturnType: (func: import("../../../types.js").FunctionDescription) => string;
|
17
|
+
getParameterDetails: (func: import("../../../types.js").FunctionDescription, parameter: string) => import("../../../types.js").ParameterDetails;
|
18
|
+
getParameters: (func: import("../../../types.js").FunctionDescription) => import("ts-morph").FunctionDeclarationStructure["parameters"];
|
19
|
+
getFunctionOverrideOptions: (func: import("../../../types.js").FunctionDescription) => Partial<import("ts-morph").FunctionDeclarationStructure | import("ts-morph").MethodSignatureStructure>;
|
20
|
+
save: () => void;
|
21
|
+
} | null;
|
12
22
|
};
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { useCallback, useMemo, useState } from 'react';
|
2
2
|
import { PlaydateSdkUrl } from '../../../commands/GenerateTypes/constants.js';
|
3
|
+
import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
|
3
4
|
import { PlaydateSdkVersionIdentifier } from '../../../types.js';
|
4
5
|
export const useGetVersion = (version)=>{
|
6
|
+
const [typeProvider, setTypeProvider] = useState(null);
|
5
7
|
const [result, setResult] = useState(null);
|
6
8
|
const fetchLastVersion = useCallback(async ()=>{
|
7
9
|
const response = await fetch(PlaydateSdkUrl);
|
@@ -32,6 +34,7 @@ export const useGetVersion = (version)=>{
|
|
32
34
|
versionLiteral = await fetchLastVersion();
|
33
35
|
}
|
34
36
|
await validateVersion(versionLiteral);
|
37
|
+
setTypeProvider(createTypeProvider(versionLiteral));
|
35
38
|
return versionLiteral;
|
36
39
|
},
|
37
40
|
onFinish: (result)=>{
|
@@ -41,7 +44,8 @@ export const useGetVersion = (version)=>{
|
|
41
44
|
}, []);
|
42
45
|
return {
|
43
46
|
fetchedVersion: result,
|
44
|
-
getVersion
|
47
|
+
getVersion,
|
48
|
+
typeProvider
|
45
49
|
};
|
46
50
|
};
|
47
51
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGetVersion.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react';\nimport { PlaydateSdkUrl } from '@/cli/commands/GenerateTypes/constants.js';\nimport {\n CheckListItem,\n PlaydateSdkVersion,\n PlaydateSdkVersionIdentifier,\n} from '@/cli/types.js';\n\nexport const useGetVersion = (version: PlaydateSdkVersion) => {\n const [result, setResult] = useState<string | null>(null);\n const fetchLastVersion = useCallback(async () => {\n const response = await fetch(PlaydateSdkUrl);\n const url = response.url;\n\n const regex = /https:\\/\\/sdk.play.date\\/([0-9]+\\.[0-9]+\\.[0-9]+)\\//;\n const match = url.match(regex);\n\n if (!match || match.length < 2) {\n throw new Error('Could not find version in URL');\n }\n\n return match[1];\n }, []);\n const validateVersion = useCallback(async (version: string) => {\n const response = await fetch(`https://sdk.play.date/${version}/`);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch version ${version}`);\n }\n\n return true;\n }, []);\n\n const getVersion = useMemo(() => {\n return {\n waitingDescription: `Waiting to fetch version`,\n runningDescription: 'Fetching version...',\n errorDescription: 'Failed to fetch version',\n finishedDescription: (result) => `Fetched version ${result}`,\n runner: async () => {\n let versionLiteral = version;\n\n if (version === PlaydateSdkVersionIdentifier.Latest) {\n versionLiteral = await fetchLastVersion();\n }\n\n await validateVersion(versionLiteral);\n\n return versionLiteral;\n },\n onFinish: (result) => {\n setResult(result);\n },\n } satisfies CheckListItem<string>;\n }, []);\n\n return {\n fetchedVersion: result,\n getVersion,\n };\n};\n"],"names":["useCallback","useMemo","useState","PlaydateSdkUrl","PlaydateSdkVersionIdentifier","useGetVersion","version","result","setResult","fetchLastVersion","response","fetch","url","regex","match","length","Error","validateVersion","ok","getVersion","waitingDescription","runningDescription","errorDescription","finishedDescription","runner","versionLiteral","Latest","onFinish","fetchedVersion"],"rangeMappings":"
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGetVersion.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react';\nimport { PlaydateSdkUrl } from '@/cli/commands/GenerateTypes/constants.js';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport {\n CheckListItem,\n PlaydateSdkVersion,\n PlaydateSdkVersionIdentifier,\n} from '@/cli/types.js';\n\nexport const useGetVersion = (version: PlaydateSdkVersion) => {\n const [typeProvider, setTypeProvider] = useState<ReturnType<\n typeof createTypeProvider\n > | null>(null);\n const [result, setResult] = useState<string | null>(null);\n const fetchLastVersion = useCallback(async () => {\n const response = await fetch(PlaydateSdkUrl);\n const url = response.url;\n\n const regex = /https:\\/\\/sdk.play.date\\/([0-9]+\\.[0-9]+\\.[0-9]+)\\//;\n const match = url.match(regex);\n\n if (!match || match.length < 2) {\n throw new Error('Could not find version in URL');\n }\n\n return match[1];\n }, []);\n const validateVersion = useCallback(async (version: string) => {\n const response = await fetch(`https://sdk.play.date/${version}/`);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch version ${version}`);\n }\n\n return true;\n }, []);\n\n const getVersion = useMemo(() => {\n return {\n waitingDescription: `Waiting to fetch version`,\n runningDescription: 'Fetching version...',\n errorDescription: 'Failed to fetch version',\n finishedDescription: (result) => `Fetched version ${result}`,\n runner: async () => {\n let versionLiteral = version;\n\n if (version === PlaydateSdkVersionIdentifier.Latest) {\n versionLiteral = await fetchLastVersion();\n }\n\n await validateVersion(versionLiteral);\n\n setTypeProvider(createTypeProvider(versionLiteral));\n\n return versionLiteral;\n },\n onFinish: (result) => {\n setResult(result);\n },\n } satisfies CheckListItem<string>;\n }, []);\n\n return {\n fetchedVersion: result,\n getVersion,\n typeProvider,\n };\n};\n"],"names":["useCallback","useMemo","useState","PlaydateSdkUrl","createTypeProvider","PlaydateSdkVersionIdentifier","useGetVersion","version","typeProvider","setTypeProvider","result","setResult","fetchLastVersion","response","fetch","url","regex","match","length","Error","validateVersion","ok","getVersion","waitingDescription","runningDescription","errorDescription","finishedDescription","runner","versionLiteral","Latest","onFinish","fetchedVersion"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACvD,SAASC,cAAc,QAAQ,4CAA4C;AAC3E,SAASC,kBAAkB,QAAQ,2DAA2D;AAC9F,SAGIC,4BAA4B,QACzB,iBAAiB;AAExB,OAAO,MAAMC,gBAAgB,CAACC;IAC1B,MAAM,CAACC,cAAcC,gBAAgB,GAAGP,SAE9B;IACV,MAAM,CAACQ,QAAQC,UAAU,GAAGT,SAAwB;IACpD,MAAMU,mBAAmBZ,YAAY;QACjC,MAAMa,WAAW,MAAMC,MAAMX;QAC7B,MAAMY,MAAMF,SAASE,GAAG;QAExB,MAAMC,QAAQ;QACd,MAAMC,QAAQF,IAAIE,KAAK,CAACD;QAExB,IAAI,CAACC,SAASA,MAAMC,MAAM,GAAG,GAAG;YAC5B,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAOF,KAAK,CAAC,EAAE;IACnB,GAAG,EAAE;IACL,MAAMG,kBAAkBpB,YAAY,OAAOO;QACvC,MAAMM,WAAW,MAAMC,MAAM,CAAC,sBAAsB,EAAEP,QAAQ,CAAC,CAAC;QAEhE,IAAI,CAACM,SAASQ,EAAE,EAAE;YACd,MAAM,IAAIF,MAAM,CAAC,wBAAwB,EAAEZ,QAAQ,CAAC;QACxD;QAEA,OAAO;IACX,GAAG,EAAE;IAEL,MAAMe,aAAarB,QAAQ;QACvB,OAAO;YACHsB,oBAAoB,CAAC,wBAAwB,CAAC;YAC9CC,oBAAoB;YACpBC,kBAAkB;YAClBC,qBAAqB,CAAChB,SAAW,CAAC,gBAAgB,EAAEA,OAAO,CAAC;YAC5DiB,QAAQ;gBACJ,IAAIC,iBAAiBrB;gBAErB,IAAIA,YAAYF,6BAA6BwB,MAAM,EAAE;oBACjDD,iBAAiB,MAAMhB;gBAC3B;gBAEA,MAAMQ,gBAAgBQ;gBAEtBnB,gBAAgBL,mBAAmBwB;gBAEnC,OAAOA;YACX;YACAE,UAAU,CAACpB;gBACPC,UAAUD;YACd;QACJ;IACJ,GAAG,EAAE;IAEL,OAAO;QACHqB,gBAAgBrB;QAChBY;QACAd;IACJ;AACJ,EAAE"}
|
@@ -9,15 +9,6 @@ export declare const useParseDocumentation: (html: string | null, version: strin
|
|
9
9
|
runner: () => Promise<{
|
10
10
|
namespaces: Record<string, import("../../../types.js").PlaydateNamespace>;
|
11
11
|
types: Record<string, import("../../../types.js").PlaydateType>;
|
12
|
-
constants: {
|
13
|
-
name: string;
|
14
|
-
values: {
|
15
|
-
name: string;
|
16
|
-
value: number;
|
17
|
-
docs: string;
|
18
|
-
}[];
|
19
|
-
docs: string;
|
20
|
-
}[];
|
21
12
|
}>;
|
22
13
|
onFinish: (result: ApiDefinitions) => void;
|
23
14
|
ready: boolean;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { useMemo, useState } from 'react';
|
2
2
|
import { getApiDefinitions } from '../../../commands/GenerateTypes/fn/getApiDefinitions.js';
|
3
|
-
import {
|
3
|
+
import { getDescriptionsFromHtml } from '../../../commands/GenerateTypes/fn/getDescriptionsFromHtml.js';
|
4
4
|
export const useParseDocumentation = (html, version)=>{
|
5
5
|
const [result, setResult] = useState(null);
|
6
6
|
const parseDocumentation = useMemo(()=>{
|
@@ -13,8 +13,8 @@ export const useParseDocumentation = (html, version)=>{
|
|
13
13
|
if (!html) {
|
14
14
|
throw new Error('HTML is not set');
|
15
15
|
}
|
16
|
-
const functions =
|
17
|
-
return getApiDefinitions(functions);
|
16
|
+
const { functions, properties } = getDescriptionsFromHtml(html, version);
|
17
|
+
return getApiDefinitions(functions, properties);
|
18
18
|
},
|
19
19
|
onFinish: (result)=>{
|
20
20
|
setResult(result);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useParseDocumentation.ts"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { getApiDefinitions } from '@/cli/commands/GenerateTypes/fn/getApiDefinitions.js';\nimport {
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useParseDocumentation.ts"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { getApiDefinitions } from '@/cli/commands/GenerateTypes/fn/getApiDefinitions.js';\nimport { getDescriptionsFromHtml } from '@/cli/commands/GenerateTypes/fn/getDescriptionsFromHtml.js';\nimport { CheckListItem, ApiDefinitions } from '@/cli/types.js';\n\nexport const useParseDocumentation = (html: string | null, version: string) => {\n const [result, setResult] = useState<ApiDefinitions | null>(null);\n\n const parseDocumentation = useMemo(() => {\n return {\n waitingDescription: 'Waiting to parse the documentation...',\n errorDescription: 'Failed to parse the documentation',\n finishedDescription: () => 'Documentation parsed',\n runningDescription: 'Parsing the documentation...',\n runner: async () => {\n if (!html) {\n throw new Error('HTML is not set');\n }\n\n const { functions, properties } = getDescriptionsFromHtml(\n html,\n version\n );\n\n return getApiDefinitions(functions, properties);\n },\n onFinish: (result) => {\n setResult(result);\n },\n ready: html !== null,\n } satisfies CheckListItem<ApiDefinitions>;\n }, [html]);\n\n return {\n definitions: result,\n parseDocumentation,\n };\n};\n"],"names":["useMemo","useState","getApiDefinitions","getDescriptionsFromHtml","useParseDocumentation","html","version","result","setResult","parseDocumentation","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","functions","properties","onFinish","ready","definitions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC1C,SAASC,iBAAiB,QAAQ,uDAAuD;AACzF,SAASC,uBAAuB,QAAQ,6DAA6D;AAGrG,OAAO,MAAMC,wBAAwB,CAACC,MAAqBC;IACvD,MAAM,CAACC,QAAQC,UAAU,GAAGP,SAAgC;IAE5D,MAAMQ,qBAAqBT,QAAQ;QAC/B,OAAO;YACHU,oBAAoB;YACpBC,kBAAkB;YAClBC,qBAAqB,IAAM;YAC3BC,oBAAoB;YACpBC,QAAQ;gBACJ,IAAI,CAACT,MAAM;oBACP,MAAM,IAAIU,MAAM;gBACpB;gBAEA,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGd,wBAC9BE,MACAC;gBAGJ,OAAOJ,kBAAkBc,WAAWC;YACxC;YACAC,UAAU,CAACX;gBACPC,UAAUD;YACd;YACAY,OAAOd,SAAS;QACpB;IACJ,GAAG;QAACA;KAAK;IAET,OAAO;QACHe,aAAab;QACbE;IACJ;AACJ,EAAE"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { FunctionDeclarationStructure } from 'ts-morph';
|
2
|
+
import { FunctionDescription, ParameterDetails, PropertyDescription, PropertyDetails } from '../../../types.js';
|
3
|
+
export declare const createTypeProvider: (version: string) => {
|
4
|
+
getGlobalStatements: () => string[];
|
5
|
+
getStatements: () => string[];
|
6
|
+
getPropertyDetails: (property: PropertyDescription) => PropertyDetails;
|
7
|
+
getFunctionReturnType: (func: FunctionDescription) => string;
|
8
|
+
getParameterDetails: (func: FunctionDescription, parameter: string) => ParameterDetails;
|
9
|
+
getParameters: (func: FunctionDescription) => FunctionDeclarationStructure["parameters"];
|
10
|
+
getFunctionOverrideOptions: (func: FunctionDescription) => Partial<FunctionDeclarationStructure | import("ts-morph").MethodSignatureStructure>;
|
11
|
+
save: () => void;
|
12
|
+
};
|