crankscript 0.1.2 → 0.1.5-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +1 -11
  2. package/assets/package.json +4 -0
  3. package/assets/plugin.js +260 -0
  4. package/assets/plugin.ts +372 -0
  5. package/assets/tsconfig.json +10 -0
  6. package/package.json +30 -17
  7. package/src/commands/CompileCommand/CompileCommand.d.ts +8 -0
  8. package/src/commands/CompileCommand/CompileCommand.js +21 -0
  9. package/src/commands/CompileCommand/CompileCommand.js.map +1 -0
  10. package/src/commands/CompileCommand/components/Compile.d.ts +7 -0
  11. package/src/commands/CompileCommand/components/Compile.js +14 -0
  12. package/src/commands/CompileCommand/components/Compile.js.map +1 -0
  13. package/src/commands/CompileCommand/fn/getPdcPathFromEnvironment.d.ts +2 -0
  14. package/src/commands/CompileCommand/fn/getPdcPathFromEnvironment.js +6 -0
  15. package/src/commands/CompileCommand/fn/getPdcPathFromEnvironment.js.map +1 -0
  16. package/src/commands/CompileCommand/fn/getSimulatorPathFromEnvironment.d.ts +2 -0
  17. package/src/commands/CompileCommand/fn/getSimulatorPathFromEnvironment.js +6 -0
  18. package/src/commands/CompileCommand/fn/getSimulatorPathFromEnvironment.js.map +1 -0
  19. package/src/commands/CompileCommand/hooks/useCompileTasks.d.ts +2 -0
  20. package/src/commands/CompileCommand/hooks/useCompileTasks.js +60 -0
  21. package/src/commands/CompileCommand/hooks/useCompileTasks.js.map +1 -0
  22. package/src/commands/CompileCommand/index.d.ts +1 -0
  23. package/src/commands/CompileCommand/index.js +3 -0
  24. package/src/commands/CompileCommand/index.js.map +1 -0
  25. package/src/commands/DoctorCommand.d.ts +7 -0
  26. package/src/commands/DoctorCommand.js +26 -0
  27. package/src/commands/DoctorCommand.js.map +1 -0
  28. package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.d.ts +9 -0
  29. package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js +25 -0
  30. package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js.map +1 -0
  31. package/src/commands/EnvironmentAwareCommand/components/HealthReport.d.ts +7 -0
  32. package/src/commands/EnvironmentAwareCommand/components/HealthReport.js +41 -0
  33. package/src/commands/EnvironmentAwareCommand/components/HealthReport.js.map +1 -0
  34. package/src/commands/EnvironmentAwareCommand/index.d.ts +1 -0
  35. package/src/commands/EnvironmentAwareCommand/index.js +3 -0
  36. package/src/commands/EnvironmentAwareCommand/index.js.map +1 -0
  37. package/src/commands/GenerateTypes/GenerateTypesCommand.d.ts +10 -0
  38. package/src/commands/GenerateTypes/GenerateTypesCommand.js +45 -0
  39. package/src/commands/GenerateTypes/GenerateTypesCommand.js.map +1 -0
  40. package/src/commands/GenerateTypes/components/GenerateTypes.d.ts +9 -0
  41. package/src/commands/GenerateTypes/components/GenerateTypes.js +36 -0
  42. package/src/commands/GenerateTypes/components/GenerateTypes.js.map +1 -0
  43. package/src/commands/GenerateTypes/constants.d.ts +1 -0
  44. package/src/commands/GenerateTypes/constants.js +3 -0
  45. package/src/commands/GenerateTypes/constants.js.map +1 -0
  46. package/src/commands/GenerateTypes/fn/getApiDefinitions.d.ts +2 -0
  47. package/src/commands/GenerateTypes/fn/getApiDefinitions.js +39 -0
  48. package/src/commands/GenerateTypes/fn/getApiDefinitions.js.map +1 -0
  49. package/src/commands/GenerateTypes/fn/getDescriptionsFromHtml.d.ts +5 -0
  50. package/src/commands/GenerateTypes/fn/getDescriptionsFromHtml.js +78 -0
  51. package/src/commands/GenerateTypes/fn/getDescriptionsFromHtml.js.map +1 -0
  52. package/src/commands/GenerateTypes/fn/getFunctionTypeOverride.d.ts +1 -0
  53. package/src/commands/GenerateTypes/fn/getFunctionTypeOverride.js +7 -0
  54. package/src/commands/GenerateTypes/fn/getFunctionTypeOverride.js.map +1 -0
  55. package/src/commands/GenerateTypes/fn/getHtmlForVersion.d.ts +1 -0
  56. package/src/commands/GenerateTypes/fn/getHtmlForVersion.js +21 -0
  57. package/src/commands/GenerateTypes/fn/getHtmlForVersion.js.map +1 -0
  58. package/src/commands/GenerateTypes/fn/parseFunctionSignature.d.ts +10 -0
  59. package/src/commands/GenerateTypes/fn/parseFunctionSignature.js +22 -0
  60. package/src/commands/GenerateTypes/fn/parseFunctionSignature.js.map +1 -0
  61. package/src/commands/GenerateTypes/hooks/useFetchHtml.d.ts +12 -0
  62. package/src/commands/GenerateTypes/hooks/useFetchHtml.js +31 -0
  63. package/src/commands/GenerateTypes/hooks/useFetchHtml.js.map +1 -0
  64. package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.d.ts +12 -0
  65. package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js +126 -0
  66. package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js.map +1 -0
  67. package/src/commands/GenerateTypes/hooks/useGetVersion.d.ts +53 -0
  68. package/src/commands/GenerateTypes/hooks/useGetVersion.js +52 -0
  69. package/src/commands/GenerateTypes/hooks/useGetVersion.js.map +1 -0
  70. package/src/commands/GenerateTypes/hooks/useParseDocumentation.d.ts +13 -0
  71. package/src/commands/GenerateTypes/hooks/useParseDocumentation.js +34 -0
  72. package/src/commands/GenerateTypes/hooks/useParseDocumentation.js.map +1 -0
  73. package/src/commands/GenerateTypes/index.d.ts +1 -0
  74. package/src/commands/GenerateTypes/index.js +3 -0
  75. package/src/commands/GenerateTypes/index.js.map +1 -0
  76. package/src/commands/GenerateTypes/utils/createTypeProvider.d.ts +43 -0
  77. package/src/commands/GenerateTypes/utils/createTypeProvider.js +156 -0
  78. package/src/commands/GenerateTypes/utils/createTypeProvider.js.map +1 -0
  79. package/src/commands/GenerateTypes/utils/functionTypeOverrides.d.ts +2 -0
  80. package/src/commands/GenerateTypes/utils/functionTypeOverrides.js +18 -0
  81. package/src/commands/GenerateTypes/utils/functionTypeOverrides.js.map +1 -0
  82. package/src/commands/NewCommand/NewCommand.d.ts +10 -0
  83. package/src/commands/NewCommand/NewCommand.js +35 -0
  84. package/src/commands/NewCommand/NewCommand.js.map +1 -0
  85. package/src/commands/NewCommand/components/New.d.ts +8 -0
  86. package/src/commands/NewCommand/components/New.js +26 -0
  87. package/src/commands/NewCommand/components/New.js.map +1 -0
  88. package/src/commands/RenderableCommand.d.ts +7 -0
  89. package/src/commands/RenderableCommand.js +12 -0
  90. package/src/commands/RenderableCommand.js.map +1 -0
  91. package/src/commands/SimulatorCommand/SimulatorCommand.d.ts +12 -0
  92. package/src/commands/SimulatorCommand/SimulatorCommand.js +39 -0
  93. package/src/commands/SimulatorCommand/SimulatorCommand.js.map +1 -0
  94. package/src/commands/SimulatorCommand/components/Simulator.d.ts +11 -0
  95. package/src/commands/SimulatorCommand/components/Simulator.js +80 -0
  96. package/src/commands/SimulatorCommand/components/Simulator.js.map +1 -0
  97. package/src/commands/SimulatorCommand/index.d.ts +1 -0
  98. package/src/commands/SimulatorCommand/index.js +3 -0
  99. package/src/commands/SimulatorCommand/index.js.map +1 -0
  100. package/src/commands/TranspileCommand/TranspileCommand.d.ts +9 -0
  101. package/src/commands/TranspileCommand/TranspileCommand.js +31 -0
  102. package/src/commands/TranspileCommand/TranspileCommand.js.map +1 -0
  103. package/src/commands/TranspileCommand/components/Transpile.d.ts +6 -0
  104. package/src/commands/TranspileCommand/components/Transpile.js +12 -0
  105. package/src/commands/TranspileCommand/components/Transpile.js.map +1 -0
  106. package/src/commands/TranspileCommand/fn/transpile.d.ts +1 -0
  107. package/src/commands/TranspileCommand/fn/transpile.js +19 -0
  108. package/src/commands/TranspileCommand/fn/transpile.js.map +1 -0
  109. package/src/commands/TranspileCommand/hooks/useTranspileTasks.d.ts +2 -0
  110. package/src/commands/TranspileCommand/hooks/useTranspileTasks.js +18 -0
  111. package/src/commands/TranspileCommand/hooks/useTranspileTasks.js.map +1 -0
  112. package/src/commands/TranspileCommand/index.d.ts +1 -0
  113. package/src/commands/TranspileCommand/index.js +3 -0
  114. package/src/commands/TranspileCommand/index.js.map +1 -0
  115. package/src/components/CheckList/CheckList.d.ts +8 -0
  116. package/src/components/CheckList/CheckList.js +34 -0
  117. package/src/components/CheckList/CheckList.js.map +1 -0
  118. package/src/components/CheckList/Item.d.ts +7 -0
  119. package/src/components/CheckList/Item.js +87 -0
  120. package/src/components/CheckList/Item.js.map +1 -0
  121. package/src/components/CheckList/index.d.ts +1 -0
  122. package/src/components/CheckList/index.js +3 -0
  123. package/src/components/CheckList/index.js.map +1 -0
  124. package/src/components/Spinner.d.ts +3 -0
  125. package/src/components/Spinner.js +26 -0
  126. package/src/components/Spinner.js.map +1 -0
  127. package/src/constants.d.ts +3 -0
  128. package/src/constants.js +11 -0
  129. package/src/constants.js.map +1 -0
  130. package/src/environment/createEnvironment.d.ts +12 -0
  131. package/src/environment/createEnvironment.js +37 -0
  132. package/src/environment/createEnvironment.js.map +1 -0
  133. package/src/environment/dto/Environment.d.ts +7 -0
  134. package/src/environment/dto/Environment.js +7 -0
  135. package/src/environment/dto/Environment.js.map +1 -0
  136. package/src/environment/error/EnvironmentError.d.ts +2 -0
  137. package/src/environment/error/EnvironmentError.js +4 -0
  138. package/src/environment/error/EnvironmentError.js.map +1 -0
  139. package/src/environment/path/dto/PlaydateSdkPath.d.ts +5 -0
  140. package/src/environment/path/dto/PlaydateSdkPath.js +10 -0
  141. package/src/environment/path/dto/PlaydateSdkPath.js.map +1 -0
  142. package/src/environment/path/error/PlaydateSdkPathVariableNotSetError.d.ts +4 -0
  143. package/src/environment/path/error/PlaydateSdkPathVariableNotSetError.js +8 -0
  144. package/src/environment/path/error/PlaydateSdkPathVariableNotSetError.js.map +1 -0
  145. package/src/environment/path/getPlaydateSdkPath.d.ts +14 -0
  146. package/src/environment/path/getPlaydateSdkPath.js +16 -0
  147. package/src/environment/path/getPlaydateSdkPath.js.map +1 -0
  148. package/src/index.d.ts +1 -1
  149. package/src/index.js +30 -13
  150. package/src/index.js.map +1 -1
  151. package/src/types.d.ts +96 -0
  152. package/src/types.js +16 -0
  153. package/src/types.js.map +1 -0
  154. package/src/utils/dirname.d.ts +1 -0
  155. package/src/utils/dirname.js +5 -0
  156. package/src/utils/dirname.js.map +1 -0
@@ -0,0 +1,78 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { load } from 'cheerio';
3
+ import Turndown from 'turndown';
4
+ import { PlaydateSdkUrl } from '../../../commands/GenerateTypes/constants.js';
5
+ import { parseFunctionSignature } from '../../../commands/GenerateTypes/fn/parseFunctionSignature.js';
6
+ const extractFunctionCalls = (input)=>{
7
+ const functionCallRegex = /([a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*(?::[a-zA-Z_]\w*)?)\s*(\([^)]*\))?/g;
8
+ const matches = [];
9
+ let match;
10
+ while((match = functionCallRegex.exec(input)) !== null){
11
+ matches.push(match[0].trim());
12
+ }
13
+ return matches;
14
+ };
15
+ const normalizeSignature = (signature)=>{
16
+ const closingParenIndex = signature.indexOf(')');
17
+ return closingParenIndex !== -1 ? signature.slice(0, closingParenIndex + 1) : signature;
18
+ };
19
+ export const getDescriptionsFromHtml = (html, version)=>{
20
+ const $ = load(html);
21
+ const functionSignatures = $('[id^="m-"], [id^="f-"], [id^="c-"], [id^="v-"]').toArray();
22
+ const functions = [];
23
+ const properties = [];
24
+ const visitedSignatures = [];
25
+ const turndown = new Turndown();
26
+ for (const element of functionSignatures){
27
+ var _$_attr;
28
+ const id = (_$_attr = $(element).attr('id')) != null ? _$_attr : '';
29
+ const isProperty = id.startsWith('v-');
30
+ const titleText = $(element).find('> .title').text();
31
+ if (titleText.indexOf('#') !== -1 || /[a-zA-Z]\[/.test(titleText) || /^-[a-zA-Z]/.test(titleText) || /[+*/]/.test(titleText) || titleText.indexOf(' - ') !== -1 || titleText.indexOf(' .. ') !== -1) {
32
+ continue;
33
+ }
34
+ const titles = isProperty ? titleText.split(' ') : extractFunctionCalls(titleText);
35
+ var _$_find_html;
36
+ let docsString = ((_$_find_html = $(element).find('.content').html()) != null ? _$_find_html : '').trim();
37
+ if (docsString.startsWith('<div class="paragraph">')) {
38
+ docsString = docsString.slice('<div class="paragraph">'.length);
39
+ }
40
+ if (docsString.endsWith('</div>')) {
41
+ docsString = docsString.slice(0, docsString.length - '</div>'.length);
42
+ }
43
+ docsString = docsString.replace(/<a href="#/g, '<a href="' + PlaydateSdkUrl + version + '#');
44
+ docsString = turndown.turndown(docsString);
45
+ const baseDocs = id ? `${docsString}\n\n[Read more](${PlaydateSdkUrl}${version}#${id})` : docsString;
46
+ for (const title of titles){
47
+ const signature = normalizeSignature(title);
48
+ if (visitedSignatures.includes(signature)) {
49
+ continue;
50
+ }
51
+ visitedSignatures.push(signature);
52
+ if (isProperty) {
53
+ properties.push({
54
+ name: title.split('.').slice(-1)[0],
55
+ namespaces: signature.split('.').slice(0, -1),
56
+ signature,
57
+ docs: baseDocs
58
+ });
59
+ } else {
60
+ try {
61
+ const description = parseFunctionSignature(signature);
62
+ const docs = description.hasSelf ? baseDocs : `${baseDocs}\n\n@noSelf`;
63
+ functions.push(_extends({}, description, {
64
+ docs
65
+ }));
66
+ } catch (e) {
67
+ // Ignore
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return {
73
+ functions,
74
+ properties
75
+ };
76
+ };
77
+
78
+ //# 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 Turndown from 'turndown';\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 const turndown = new Turndown();\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 (\n titleText.indexOf('#') !== -1 ||\n /[a-zA-Z]\\[/.test(titleText) ||\n /^-[a-zA-Z]/.test(titleText) ||\n /[+*/]/.test(titleText) ||\n titleText.indexOf(' - ') !== -1 ||\n titleText.indexOf(' .. ') !== -1\n ) {\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 docsString = turndown.turndown(docsString);\n\n const baseDocs = id\n ? `${docsString}\\n\\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","Turndown","PlaydateSdkUrl","parseFunctionSignature","extractFunctionCalls","input","functionCallRegex","matches","match","exec","push","trim","normalizeSignature","signature","closingParenIndex","indexOf","slice","getDescriptionsFromHtml","html","version","$","functionSignatures","toArray","functions","properties","visitedSignatures","turndown","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":"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"}
@@ -0,0 +1 @@
1
+ export declare const getFunctionTypeOverride: (version: string) => import("../../../types.js").FunctionTypeOverrideMap;
@@ -0,0 +1,7 @@
1
+ import { functionTypeOverrides } from '../../../commands/GenerateTypes/utils/functionTypeOverrides.js';
2
+ export const getFunctionTypeOverride = (version)=>{
3
+ var _functionTypeOverrides_version;
4
+ return (_functionTypeOverrides_version = functionTypeOverrides[version]) != null ? _functionTypeOverrides_version : functionTypeOverrides['defaultVersion'];
5
+ };
6
+
7
+ //# sourceMappingURL=getFunctionTypeOverride.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getFunctionTypeOverride.ts"],"sourcesContent":["import { functionTypeOverrides } from '@/cli/commands/GenerateTypes/utils/functionTypeOverrides.js';\n\nexport const getFunctionTypeOverride = (version: string) => {\n return (\n functionTypeOverrides[version] ??\n functionTypeOverrides['defaultVersion']\n );\n};\n"],"names":["functionTypeOverrides","getFunctionTypeOverride","version"],"rangeMappings":";;;;","mappings":"AAAA,SAASA,qBAAqB,QAAQ,8DAA8D;AAEpG,OAAO,MAAMC,0BAA0B,CAACC;QAEhCF;IADJ,OACIA,CAAAA,iCAAAA,qBAAqB,CAACE,QAAQ,YAA9BF,iCACAA,qBAAqB,CAAC,iBAAiB;AAE/C,EAAE"}
@@ -0,0 +1 @@
1
+ export declare const getHtmlForVersion: (version: string) => Promise<string>;
@@ -0,0 +1,21 @@
1
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { mkdirSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ export const getHtmlForVersion = async (version)=>{
6
+ const cacheDir = join(tmpdir(), 'crankscript', 'cache');
7
+ const path = join(cacheDir, `${version}.html`);
8
+ if (!existsSync(cacheDir)) {
9
+ mkdirSync(cacheDir, {
10
+ recursive: true
11
+ });
12
+ }
13
+ if (existsSync(path)) {
14
+ return readFileSync(path, 'utf8');
15
+ }
16
+ const html = await fetch(`https://sdk.play.date/${version}/`).then((res)=>res.text());
17
+ writeFileSync(path, html, 'utf8');
18
+ return html;
19
+ };
20
+
21
+ //# sourceMappingURL=getHtmlForVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getHtmlForVersion.ts"],"sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { mkdirSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\n\nexport const getHtmlForVersion = async (version: string) => {\n const cacheDir = join(tmpdir(), 'crankscript', 'cache');\n const path = join(cacheDir, `${version}.html`);\n\n if (!existsSync(cacheDir)) {\n mkdirSync(cacheDir, { recursive: true });\n }\n\n if (existsSync(path)) {\n return readFileSync(path, 'utf8');\n }\n\n const html = await fetch(`https://sdk.play.date/${version}/`).then((res) =>\n res.text()\n );\n\n writeFileSync(path, html, 'utf8');\n\n return html;\n};\n"],"names":["existsSync","readFileSync","writeFileSync","mkdirSync","tmpdir","join","getHtmlForVersion","version","cacheDir","path","recursive","html","fetch","then","res","text"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,EAAEC,aAAa,QAAQ,UAAU;AAClE,SAASC,SAAS,QAAQ,UAAU;AACpC,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,IAAI,QAAQ,YAAY;AAEjC,OAAO,MAAMC,oBAAoB,OAAOC;IACpC,MAAMC,WAAWH,KAAKD,UAAU,eAAe;IAC/C,MAAMK,OAAOJ,KAAKG,UAAU,CAAC,EAAED,QAAQ,KAAK,CAAC;IAE7C,IAAI,CAACP,WAAWQ,WAAW;QACvBL,UAAUK,UAAU;YAAEE,WAAW;QAAK;IAC1C;IAEA,IAAIV,WAAWS,OAAO;QAClB,OAAOR,aAAaQ,MAAM;IAC9B;IAEA,MAAME,OAAO,MAAMC,MAAM,CAAC,sBAAsB,EAAEL,QAAQ,CAAC,CAAC,EAAEM,IAAI,CAAC,CAACC,MAChEA,IAAIC,IAAI;IAGZb,cAAcO,MAAME,MAAM;IAE1B,OAAOA;AACX,EAAE"}
@@ -0,0 +1,10 @@
1
+ export declare const parseFunctionSignature: (signature: string) => {
2
+ signature: string;
3
+ name: string;
4
+ namespaces: string[];
5
+ parameters: {
6
+ name: string;
7
+ required: boolean;
8
+ }[];
9
+ hasSelf: boolean;
10
+ };
@@ -0,0 +1,22 @@
1
+ export const parseFunctionSignature = (signature)=>{
2
+ const normalizedSignature = signature.includes('(') ? signature : signature + '()';
3
+ const [fullyQualifiedName, paramString] = normalizedSignature.split('(');
4
+ const hasSelf = fullyQualifiedName.includes(':');
5
+ const normalizedFullyQualifiedName = fullyQualifiedName.replace(':', '.');
6
+ const segments = normalizedFullyQualifiedName.split('.');
7
+ const functionName = segments[segments.length - 1];
8
+ const namespaces = segments.slice(0, -1);
9
+ const params = paramString.split(')')[0].split(',').filter(Boolean);
10
+ return {
11
+ signature,
12
+ name: functionName,
13
+ namespaces,
14
+ parameters: params.map((eachParam)=>({
15
+ name: eachParam.replace(/\[/g, '').replace(/]/g, '').trim(),
16
+ required: !eachParam.includes('[') && !eachParam.includes(']')
17
+ })),
18
+ hasSelf
19
+ };
20
+ };
21
+
22
+ //# sourceMappingURL=parseFunctionSignature.js.map
@@ -0,0 +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 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('[') && !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,QAAQ,CAACkB,UAAUlB,QAAQ,CAAC;YAC9D,CAAA;QACAI;IACJ;AACJ,EAAE"}
@@ -0,0 +1,12 @@
1
+ export declare const useFetchHtml: (version: string | null) => {
2
+ html: string | null;
3
+ fetchHtml: {
4
+ waitingDescription: string;
5
+ errorDescription: string;
6
+ finishedDescription: () => string;
7
+ runningDescription: string;
8
+ runner: () => Promise<string>;
9
+ onFinish: (result: string) => void;
10
+ ready: boolean;
11
+ };
12
+ };
@@ -0,0 +1,31 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { getHtmlForVersion } from '../../../commands/GenerateTypes/fn/getHtmlForVersion.js';
3
+ export const useFetchHtml = (version)=>{
4
+ const [html, setHtml] = useState(null);
5
+ const fetchHtml = useMemo(()=>{
6
+ return {
7
+ waitingDescription: 'Waiting to fetch HTML contents',
8
+ errorDescription: 'Failed to fetch HTML contents',
9
+ finishedDescription: ()=>'HTML contents fetched',
10
+ runningDescription: 'Fetching HTML contents...',
11
+ runner: async ()=>{
12
+ if (!version) {
13
+ throw new Error('Version is not set');
14
+ }
15
+ return getHtmlForVersion(version);
16
+ },
17
+ onFinish: (result)=>{
18
+ setHtml(result);
19
+ },
20
+ ready: version !== null
21
+ };
22
+ }, [
23
+ version
24
+ ]);
25
+ return {
26
+ html,
27
+ fetchHtml
28
+ };
29
+ };
30
+
31
+ //# sourceMappingURL=useFetchHtml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useFetchHtml.ts"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { getHtmlForVersion } from '@/cli/commands/GenerateTypes/fn/getHtmlForVersion.js';\nimport { CheckListItem } from '@/cli/types.js';\n\nexport const useFetchHtml = (version: string | null) => {\n const [html, setHtml] = useState<string | null>(null);\n\n const fetchHtml = useMemo(() => {\n return {\n waitingDescription: 'Waiting to fetch HTML contents',\n errorDescription: 'Failed to fetch HTML contents',\n finishedDescription: () => 'HTML contents fetched',\n runningDescription: 'Fetching HTML contents...',\n runner: async () => {\n if (!version) {\n throw new Error('Version is not set');\n }\n\n return getHtmlForVersion(version);\n },\n onFinish: (result) => {\n setHtml(result);\n },\n ready: version !== null,\n } satisfies CheckListItem<string>;\n }, [version]);\n\n return {\n html,\n fetchHtml,\n };\n};\n"],"names":["useMemo","useState","getHtmlForVersion","useFetchHtml","version","html","setHtml","fetchHtml","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","onFinish","result","ready"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC1C,SAASC,iBAAiB,QAAQ,uDAAuD;AAGzF,OAAO,MAAMC,eAAe,CAACC;IACzB,MAAM,CAACC,MAAMC,QAAQ,GAAGL,SAAwB;IAEhD,MAAMM,YAAYP,QAAQ;QACtB,OAAO;YACHQ,oBAAoB;YACpBC,kBAAkB;YAClBC,qBAAqB,IAAM;YAC3BC,oBAAoB;YACpBC,QAAQ;gBACJ,IAAI,CAACR,SAAS;oBACV,MAAM,IAAIS,MAAM;gBACpB;gBAEA,OAAOX,kBAAkBE;YAC7B;YACAU,UAAU,CAACC;gBACPT,QAAQS;YACZ;YACAC,OAAOZ,YAAY;QACvB;IACJ,GAAG;QAACA;KAAQ;IAEZ,OAAO;QACHC;QACAE;IACJ;AACJ,EAAE"}
@@ -0,0 +1,12 @@
1
+ import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
2
+ import { ApiDefinitions } from '../../../types.js';
3
+ export declare const useGenerateTypeFile: (path: string, definitions: ApiDefinitions | null, typeProvider: ReturnType<typeof createTypeProvider> | null) => {
4
+ generateTypeFile: {
5
+ waitingDescription: string;
6
+ errorDescription: string;
7
+ finishedDescription: () => string;
8
+ runningDescription: string;
9
+ runner: () => Promise<void>;
10
+ ready: boolean;
11
+ };
12
+ };
@@ -0,0 +1,126 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { writeFileSync } from 'node:fs';
3
+ import { useMemo } from 'react';
4
+ import { Project } from 'ts-morph';
5
+ import { TypescriptReservedNamed } from '../../../constants.js';
6
+ export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
7
+ const generateTypeFile = useMemo(()=>{
8
+ return {
9
+ waitingDescription: 'Waiting to generate the type file...',
10
+ errorDescription: 'Failed to generate the type file',
11
+ finishedDescription: ()=>'Type file generated',
12
+ runningDescription: 'Generating the type file...',
13
+ runner: async ()=>{
14
+ if (!definitions) {
15
+ throw new Error('Definitions are not set');
16
+ }
17
+ if (!typeProvider) {
18
+ throw new Error('Type provider is not set');
19
+ }
20
+ const project = new Project();
21
+ const typeFile = project.createSourceFile(path, '', {
22
+ overwrite: true
23
+ });
24
+ const globalNamespace = definitions.global;
25
+ typeFile.addStatements(typeProvider.getGlobalStatements());
26
+ generateNamespace(globalNamespace, typeFile, typeProvider, '');
27
+ writeFileSync(path, typeFile.getFullText().replace('*/', '*/\n'));
28
+ },
29
+ ready: definitions !== null && typeProvider !== null
30
+ };
31
+ }, [
32
+ definitions,
33
+ typeProvider
34
+ ]);
35
+ return {
36
+ generateTypeFile
37
+ };
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
+ };
125
+
126
+ //# sourceMappingURL=useGenerateTypeFile.js.map
@@ -0,0 +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 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":"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"}
@@ -0,0 +1,53 @@
1
+ import { PlaydateSdkVersion } from '../../../types.js';
2
+ export declare const useGetVersion: (version: PlaydateSdkVersion) => {
3
+ fetchedVersion: string | null;
4
+ getVersion: {
5
+ waitingDescription: string;
6
+ runningDescription: string;
7
+ errorDescription: string;
8
+ finishedDescription: (result: string) => string;
9
+ runner: () => Promise<string>;
10
+ onFinish: (result: string) => void;
11
+ };
12
+ typeProvider: {
13
+ getGlobalStatements: () => string[];
14
+ getStatements: () => string[];
15
+ getClassOptions: (className: string) => Partial<import("ts-morph").ClassDeclarationStructure>;
16
+ getPropertyDetails: (property: import("../../../types.js").PropertyDescription) => import("../../../types.js").PropertyDetails;
17
+ getFunctionReturnType: (func: import("../../../types.js").FunctionDescription) => string;
18
+ getParameterDetails: (func: import("../../../types.js").FunctionDescription, parameter: string) => import("../../../types.js").ParameterDetails;
19
+ getParameters: (func: import("../../../types.js").FunctionDescription) => import("ts-morph").FunctionDeclarationStructure["parameters"];
20
+ getFunctionOverrideOptions: (func: import("../../../types.js").FunctionDescription) => Partial<import("ts-morph").FunctionDeclarationStructure> | Partial<import("ts-morph").MethodDeclarationStructure> | {
21
+ overloads: ({
22
+ docs: string[];
23
+ leadingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
24
+ trailingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
25
+ hasQuestionToken?: boolean | undefined;
26
+ scope?: import("ts-morph").Scope | undefined;
27
+ hasOverrideKeyword?: boolean | undefined;
28
+ parameters?: import("ts-morph").OptionalKind<import("ts-morph").ParameterDeclarationStructure>[] | undefined;
29
+ typeParameters?: (import("ts-morph").OptionalKind<import("ts-morph").TypeParameterDeclarationStructure> | string)[] | undefined;
30
+ isAbstract?: boolean | undefined;
31
+ returnType?: (string | import("ts-morph").WriterFunction) | undefined;
32
+ isAsync?: boolean | undefined;
33
+ isGenerator?: boolean | undefined;
34
+ isStatic?: boolean | undefined;
35
+ kind?: import("ts-morph").StructureKind.MethodOverload | undefined;
36
+ } | {
37
+ docs: string[];
38
+ leadingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
39
+ trailingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
40
+ parameters?: import("ts-morph").OptionalKind<import("ts-morph").ParameterDeclarationStructure>[] | undefined;
41
+ typeParameters?: (import("ts-morph").OptionalKind<import("ts-morph").TypeParameterDeclarationStructure> | string)[] | undefined;
42
+ hasDeclareKeyword?: boolean | undefined;
43
+ isExported?: boolean | undefined;
44
+ isDefaultExport?: boolean | undefined;
45
+ returnType?: (string | import("ts-morph").WriterFunction) | undefined;
46
+ isAsync?: boolean | undefined;
47
+ isGenerator?: boolean | undefined;
48
+ kind?: import("ts-morph").StructureKind.FunctionOverload | undefined;
49
+ })[];
50
+ };
51
+ save: () => void;
52
+ } | null;
53
+ };
@@ -0,0 +1,52 @@
1
+ import { useCallback, useMemo, useState } from 'react';
2
+ import { PlaydateSdkUrl } from '../../../commands/GenerateTypes/constants.js';
3
+ import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
4
+ import { PlaydateSdkVersionIdentifier } from '../../../types.js';
5
+ export const useGetVersion = (version)=>{
6
+ const [typeProvider, setTypeProvider] = useState(null);
7
+ const [result, setResult] = useState(null);
8
+ const fetchLastVersion = useCallback(async ()=>{
9
+ const response = await fetch(PlaydateSdkUrl);
10
+ const url = response.url;
11
+ const regex = /https:\/\/sdk.play.date\/([0-9]+\.[0-9]+\.[0-9]+)\//;
12
+ const match = url.match(regex);
13
+ if (!match || match.length < 2) {
14
+ throw new Error('Could not find version in URL');
15
+ }
16
+ return match[1];
17
+ }, []);
18
+ const validateVersion = useCallback(async (version)=>{
19
+ const response = await fetch(`https://sdk.play.date/${version}/`);
20
+ if (!response.ok) {
21
+ throw new Error(`Failed to fetch version ${version}`);
22
+ }
23
+ return true;
24
+ }, []);
25
+ const getVersion = useMemo(()=>{
26
+ return {
27
+ waitingDescription: `Waiting to fetch version`,
28
+ runningDescription: 'Fetching version...',
29
+ errorDescription: 'Failed to fetch version',
30
+ finishedDescription: (result)=>`Fetched version ${result}`,
31
+ runner: async ()=>{
32
+ let versionLiteral = version;
33
+ if (version === PlaydateSdkVersionIdentifier.Latest) {
34
+ versionLiteral = await fetchLastVersion();
35
+ }
36
+ await validateVersion(versionLiteral);
37
+ setTypeProvider(createTypeProvider(versionLiteral));
38
+ return versionLiteral;
39
+ },
40
+ onFinish: (result)=>{
41
+ setResult(result);
42
+ }
43
+ };
44
+ }, []);
45
+ return {
46
+ fetchedVersion: result,
47
+ getVersion,
48
+ typeProvider
49
+ };
50
+ };
51
+
52
+ //# sourceMappingURL=useGetVersion.js.map
@@ -0,0 +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 { 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"}
@@ -0,0 +1,13 @@
1
+ import { ApiDefinitions } from '../../../types.js';
2
+ export declare const useParseDocumentation: (html: string | null, version: string) => {
3
+ definitions: ApiDefinitions | null;
4
+ parseDocumentation: {
5
+ waitingDescription: string;
6
+ errorDescription: string;
7
+ finishedDescription: () => string;
8
+ runningDescription: string;
9
+ runner: () => Promise<ApiDefinitions>;
10
+ onFinish: (result: ApiDefinitions) => void;
11
+ ready: boolean;
12
+ };
13
+ };
@@ -0,0 +1,34 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { getApiDefinitions } from '../../../commands/GenerateTypes/fn/getApiDefinitions.js';
3
+ import { getDescriptionsFromHtml } from '../../../commands/GenerateTypes/fn/getDescriptionsFromHtml.js';
4
+ import { getFunctionTypeOverride } from '../../../commands/GenerateTypes/fn/getFunctionTypeOverride.js';
5
+ export const useParseDocumentation = (html, version)=>{
6
+ const [result, setResult] = useState(null);
7
+ const parseDocumentation = useMemo(()=>{
8
+ return {
9
+ waitingDescription: 'Waiting to parse the documentation...',
10
+ errorDescription: 'Failed to parse the documentation',
11
+ finishedDescription: ()=>'Documentation parsed',
12
+ runningDescription: 'Parsing the documentation...',
13
+ runner: async ()=>{
14
+ if (!html) {
15
+ throw new Error('HTML is not set');
16
+ }
17
+ const { functions, properties } = getDescriptionsFromHtml(html, version);
18
+ return getApiDefinitions(functions, properties, getFunctionTypeOverride(version));
19
+ },
20
+ onFinish: (result)=>{
21
+ setResult(result);
22
+ },
23
+ ready: html !== null
24
+ };
25
+ }, [
26
+ html
27
+ ]);
28
+ return {
29
+ definitions: result,
30
+ parseDocumentation
31
+ };
32
+ };
33
+
34
+ //# sourceMappingURL=useParseDocumentation.js.map
@@ -0,0 +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 { getDescriptionsFromHtml } from '@/cli/commands/GenerateTypes/fn/getDescriptionsFromHtml.js';\nimport { getFunctionTypeOverride } from '@/cli/commands/GenerateTypes/fn/getFunctionTypeOverride.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(\n functions,\n properties,\n getFunctionTypeOverride(version)\n );\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","getFunctionTypeOverride","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;AACrG,SAASC,uBAAuB,QAAQ,6DAA6D;AAGrG,OAAO,MAAMC,wBAAwB,CAACC,MAAqBC;IACvD,MAAM,CAACC,QAAQC,UAAU,GAAGR,SAAgC;IAE5D,MAAMS,qBAAqBV,QAAQ;QAC/B,OAAO;YACHW,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,GAAGf,wBAC9BG,MACAC;gBAGJ,OAAOL,kBACHe,WACAC,YACAd,wBAAwBG;YAEhC;YACAY,UAAU,CAACX;gBACPC,UAAUD;YACd;YACAY,OAAOd,SAAS;QACpB;IACJ,GAAG;QAACA;KAAK;IAET,OAAO;QACHe,aAAab;QACbE;IACJ;AACJ,EAAE"}
@@ -0,0 +1 @@
1
+ export * from './GenerateTypesCommand.js';
@@ -0,0 +1,3 @@
1
+ export * from './GenerateTypesCommand.js';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/cli/src/commands/GenerateTypes/index.ts"],"sourcesContent":["export * from './GenerateTypesCommand.js';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,4BAA4B"}