crankscript 0.11.14 → 0.12.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/package.json +3 -3
- package/src/commands/GenerateTypes/components/GenerateTypes.js +6 -2
- package/src/commands/GenerateTypes/components/GenerateTypes.js.map +1 -1
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.js +5 -2
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useFormatTypeFile.d.ts +11 -0
- package/src/commands/GenerateTypes/hooks/useFormatTypeFile.js +70 -0
- package/src/commands/GenerateTypes/hooks/useFormatTypeFile.js.map +1 -0
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js +11 -4
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useGetVersion.d.ts +5 -35
- package/src/commands/GenerateTypes/types.d.ts +12 -0
- package/src/commands/GenerateTypes/types.js +3 -0
- package/src/commands/GenerateTypes/types.js.map +1 -0
- package/src/commands/GenerateTypes/utils/createTypeProvider.d.ts +7 -37
- package/src/commands/GenerateTypes/utils/createTypeProvider.js +51 -27
- package/src/commands/GenerateTypes/utils/createTypeProvider.js.map +1 -1
- package/src/commands/SimulatorCommand/components/Simulator.js +7 -1
- package/src/commands/SimulatorCommand/components/Simulator.js.map +1 -1
- package/src/commands/TranspileCommand/TranspileCommand.d.ts +1 -0
- package/src/commands/TranspileCommand/TranspileCommand.js +10 -1
- package/src/commands/TranspileCommand/TranspileCommand.js.map +1 -1
- package/src/commands/TranspileCommand/components/Transpile.d.ts +3 -2
- package/src/commands/TranspileCommand/components/Transpile.js +4 -2
- package/src/commands/TranspileCommand/components/Transpile.js.map +1 -1
- package/src/commands/TranspileCommand/fn/transpile.d.ts +5 -1
- package/src/commands/TranspileCommand/fn/transpile.js +5 -4
- package/src/commands/TranspileCommand/fn/transpile.js.map +1 -1
- package/src/commands/TranspileCommand/fn/validateEntryPoint.d.ts +5 -0
- package/src/commands/TranspileCommand/fn/validateEntryPoint.js +22 -0
- package/src/commands/TranspileCommand/fn/validateEntryPoint.js.map +1 -0
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.d.ts +4 -1
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.js +4 -2
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.js.map +1 -1
- package/src/commands/TranspileCommand/model/ValidatedEntryPoint.d.ts +11 -0
- package/src/commands/TranspileCommand/model/ValidatedEntryPoint.js +3 -0
- package/src/commands/TranspileCommand/model/ValidatedEntryPoint.js.map +1 -0
- package/src/components/CheckList/CheckList.d.ts +3 -3
- package/src/components/CheckList/CheckList.js.map +1 -1
- package/src/components/CheckList/Item.d.ts +1 -1
- package/src/components/CheckList/Item.js +19 -4
- package/src/components/CheckList/Item.js.map +1 -1
- package/src/types.d.ts +17 -16
- package/src/types.js.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "crankscript",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.12.0",
|
4
4
|
"scripts": {
|
5
5
|
"dev": "tsx src/index.ts",
|
6
6
|
"post-build": "tsc-alias --project tsconfig.json"
|
@@ -21,8 +21,8 @@
|
|
21
21
|
"ts-morph": "^23.0.0",
|
22
22
|
"turndown": "^7.2.0",
|
23
23
|
"typanion": "^3.14.0",
|
24
|
-
"typescript
|
25
|
-
"typescript": "
|
24
|
+
"typescript": "5.7.3",
|
25
|
+
"typescript-to-lua": "^1.27.0"
|
26
26
|
},
|
27
27
|
"type": "module",
|
28
28
|
"main": "./src/index.js",
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import React, { useMemo } from 'react';
|
2
2
|
import { useFetchHtml } from '../../../commands/GenerateTypes/hooks/useFetchHtml.js';
|
3
|
+
import { useFormatTypeFile } from '../../../commands/GenerateTypes/hooks/useFormatTypeFile.js';
|
3
4
|
import { useGenerateTypeFile } from '../../../commands/GenerateTypes/hooks/useGenerateTypeFile.js';
|
4
5
|
import { useGetVersion } from '../../../commands/GenerateTypes/hooks/useGetVersion.js';
|
5
6
|
import { useParseDocumentation } from '../../../commands/GenerateTypes/hooks/useParseDocumentation.js';
|
@@ -9,18 +10,21 @@ export const GenerateTypes = ({ output, version, overwriteJson })=>{
|
|
9
10
|
const { html, fetchHtml } = useFetchHtml(fetchedVersion);
|
10
11
|
const { definitions, parseDocumentation } = useParseDocumentation(html, version);
|
11
12
|
const { generateTypeFile } = useGenerateTypeFile(output, definitions, typeProvider);
|
13
|
+
const { formatTypeFile } = useFormatTypeFile(output);
|
12
14
|
const items = useMemo(()=>{
|
13
15
|
return [
|
14
16
|
getVersion,
|
15
17
|
fetchHtml,
|
16
18
|
parseDocumentation,
|
17
|
-
generateTypeFile
|
19
|
+
generateTypeFile,
|
20
|
+
formatTypeFile
|
18
21
|
];
|
19
22
|
}, [
|
20
23
|
fetchedVersion,
|
21
24
|
html,
|
22
25
|
definitions,
|
23
|
-
typeProvider
|
26
|
+
typeProvider,
|
27
|
+
formatTypeFile
|
24
28
|
]);
|
25
29
|
return /*#__PURE__*/ React.createElement(CheckList, {
|
26
30
|
items: items,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/components/GenerateTypes.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { useFetchHtml } from '@/cli/commands/GenerateTypes/hooks/useFetchHtml.js';\nimport { useGenerateTypeFile } from '@/cli/commands/GenerateTypes/hooks/useGenerateTypeFile.js';\nimport { useGetVersion } from '@/cli/commands/GenerateTypes/hooks/useGetVersion.js';\nimport { useParseDocumentation } from '@/cli/commands/GenerateTypes/hooks/useParseDocumentation.js';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { CheckListItem, PlaydateSdkVersion } from '@/cli/types.js';\n\ninterface Props {\n output: string;\n version: PlaydateSdkVersion;\n overwriteJson: boolean;\n}\n\nexport const GenerateTypes = ({ output, version, overwriteJson }: Props) => {\n const { typeProvider, fetchedVersion, getVersion } = useGetVersion(version);\n const { html, fetchHtml } = useFetchHtml(fetchedVersion);\n const { definitions, parseDocumentation } = useParseDocumentation(\n html,\n version,\n );\n const { generateTypeFile } = useGenerateTypeFile(\n output,\n definitions,\n typeProvider,\n );\n\n const items = useMemo(() => {\n return [\n getVersion,\n fetchHtml,\n parseDocumentation,\n generateTypeFile,\n ] as CheckListItem<unknown>[];\n }, [fetchedVersion, html, definitions, typeProvider]);\n\n return (\n <CheckList\n items={items}\n onFinish={() => {\n if (overwriteJson) {\n typeProvider?.save();\n }\n\n process.exit();\n }}\n />\n );\n};\n"],"names":["React","useMemo","useFetchHtml","useGenerateTypeFile","useGetVersion","useParseDocumentation","CheckList","GenerateTypes","output","version","overwriteJson","typeProvider","fetchedVersion","getVersion","html","fetchHtml","definitions","parseDocumentation","generateTypeFile","items","onFinish","save","process","exit"],"rangeMappings":"
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/components/GenerateTypes.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { useFetchHtml } from '@/cli/commands/GenerateTypes/hooks/useFetchHtml.js';\nimport { useFormatTypeFile } from '@/cli/commands/GenerateTypes/hooks/useFormatTypeFile.js';\nimport { useGenerateTypeFile } from '@/cli/commands/GenerateTypes/hooks/useGenerateTypeFile.js';\nimport { useGetVersion } from '@/cli/commands/GenerateTypes/hooks/useGetVersion.js';\nimport { useParseDocumentation } from '@/cli/commands/GenerateTypes/hooks/useParseDocumentation.js';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { CheckListItem, PlaydateSdkVersion } from '@/cli/types.js';\n\ninterface Props {\n output: string;\n version: PlaydateSdkVersion;\n overwriteJson: boolean;\n}\n\nexport const GenerateTypes = ({ output, version, overwriteJson }: Props) => {\n const { typeProvider, fetchedVersion, getVersion } = useGetVersion(version);\n const { html, fetchHtml } = useFetchHtml(fetchedVersion);\n const { definitions, parseDocumentation } = useParseDocumentation(\n html,\n version,\n );\n const { generateTypeFile } = useGenerateTypeFile(\n output,\n definitions,\n typeProvider,\n );\n const { formatTypeFile } = useFormatTypeFile(output);\n\n const items = useMemo(() => {\n return [\n getVersion,\n fetchHtml,\n parseDocumentation,\n generateTypeFile,\n formatTypeFile,\n ] as CheckListItem<unknown>[];\n }, [fetchedVersion, html, definitions, typeProvider, formatTypeFile]);\n\n return (\n <CheckList\n items={items}\n onFinish={() => {\n if (overwriteJson) {\n typeProvider?.save();\n }\n\n process.exit();\n }}\n />\n );\n};\n"],"names":["React","useMemo","useFetchHtml","useFormatTypeFile","useGenerateTypeFile","useGetVersion","useParseDocumentation","CheckList","GenerateTypes","output","version","overwriteJson","typeProvider","fetchedVersion","getVersion","html","fetchHtml","definitions","parseDocumentation","generateTypeFile","formatTypeFile","items","onFinish","save","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,SAASC,OAAO,QAAQ,QAAQ;AACvC,SAASC,YAAY,QAAQ,qDAAqD;AAClF,SAASC,iBAAiB,QAAQ,0DAA0D;AAC5F,SAASC,mBAAmB,QAAQ,4DAA4D;AAChG,SAASC,aAAa,QAAQ,sDAAsD;AACpF,SAASC,qBAAqB,QAAQ,8DAA8D;AACpG,SAASC,SAAS,QAAQ,sCAAsC;AAShE,OAAO,MAAMC,gBAAgB,CAAC,EAAEC,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAS;IACnE,MAAM,EAAEC,YAAY,EAAEC,cAAc,EAAEC,UAAU,EAAE,GAAGT,cAAcK;IACnE,MAAM,EAAEK,IAAI,EAAEC,SAAS,EAAE,GAAGd,aAAaW;IACzC,MAAM,EAAEI,WAAW,EAAEC,kBAAkB,EAAE,GAAGZ,sBACxCS,MACAL;IAEJ,MAAM,EAAES,gBAAgB,EAAE,GAAGf,oBACzBK,QACAQ,aACAL;IAEJ,MAAM,EAAEQ,cAAc,EAAE,GAAGjB,kBAAkBM;IAE7C,MAAMY,QAAQpB,QAAQ;QAClB,OAAO;YACHa;YACAE;YACAE;YACAC;YACAC;SACH;IACL,GAAG;QAACP;QAAgBE;QAAME;QAAaL;QAAcQ;KAAe;IAEpE,qBACI,oBAACb;QACGc,OAAOA;QACPC,UAAU;YACN,IAAIX,eAAe;gBACfC,gCAAAA,aAAcW,IAAI;YACtB;YAEAC,QAAQC,IAAI;QAChB;;AAGZ,EAAE"}
|
@@ -7,13 +7,16 @@ export const parseFunctionSignature = (signature)=>{
|
|
7
7
|
const functionName = segments[segments.length - 1];
|
8
8
|
const namespaces = segments.slice(0, -1);
|
9
9
|
const params = paramString.split(')')[0].split(',').filter(Boolean);
|
10
|
+
// Find if there's any optional parameter
|
11
|
+
const firstOptionalIndex = params.findIndex((param)=>param.includes('[') || param.includes(']'));
|
10
12
|
return {
|
11
13
|
signature,
|
12
14
|
name: functionName,
|
13
15
|
namespaces,
|
14
|
-
parameters: params.map((eachParam)=>({
|
16
|
+
parameters: params.map((eachParam, index)=>({
|
15
17
|
name: eachParam.replace(/\[/g, '').replace(/]/g, '').trim(),
|
16
|
-
required
|
18
|
+
// Parameter is not required if it has brackets or comes after an optional parameter
|
19
|
+
required: firstOptionalIndex === -1 ? !eachParam.includes('[') && !eachParam.includes(']') : index < firstOptionalIndex
|
17
20
|
})),
|
18
21
|
hasSelf
|
19
22
|
};
|
@@ -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 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
|
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 // Find if there's any optional parameter\n const firstOptionalIndex = params.findIndex(\n param => param.includes('[') || param.includes(']'),\n );\n\n return {\n signature,\n name: functionName,\n namespaces,\n parameters: params.map((eachParam, index) => ({\n name: eachParam.replace(/\\[/g, '').replace(/]/g, '').trim(),\n // Parameter is not required if it has brackets or comes after an optional parameter\n required:\n firstOptionalIndex === -1\n ? !eachParam.includes('[') && !eachParam.includes(']')\n : index < firstOptionalIndex,\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","firstOptionalIndex","findIndex","param","name","parameters","map","eachParam","index","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,yCAAyC;IACzC,MAAMC,qBAAqBH,OAAOI,SAAS,CACvCC,CAAAA,QAASA,MAAMjB,QAAQ,CAAC,QAAQiB,MAAMjB,QAAQ,CAAC;IAGnD,OAAO;QACHF;QACAoB,MAAMV;QACNE;QACAS,YAAYP,OAAOQ,GAAG,CAAC,CAACC,WAAWC,QAAW,CAAA;gBAC1CJ,MAAMG,UAAUf,OAAO,CAAC,OAAO,IAAIA,OAAO,CAAC,MAAM,IAAIiB,IAAI;gBACzD,oFAAoF;gBACpFC,UACIT,uBAAuB,CAAC,IAClB,CAACM,UAAUrB,QAAQ,CAAC,QAAQ,CAACqB,UAAUrB,QAAQ,CAAC,OAChDsB,QAAQP;YACtB,CAAA;QACAX;IACJ;AACJ,EAAE"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare const useFormatTypeFile: (path: string) => {
|
2
|
+
formatTypeFile: {
|
3
|
+
waitingDescription: string;
|
4
|
+
errorDescription: string;
|
5
|
+
finishedDescription: () => string;
|
6
|
+
runningDescription: string;
|
7
|
+
runner: () => Promise<boolean>;
|
8
|
+
ready: true;
|
9
|
+
skip: boolean;
|
10
|
+
};
|
11
|
+
};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { execSync } from 'node:child_process';
|
2
|
+
import { useMemo } from 'react';
|
3
|
+
export const useFormatTypeFile = (path)=>{
|
4
|
+
const formatTypeFile = useMemo(()=>{
|
5
|
+
// Check if prettier and eslint are available
|
6
|
+
const checkToolsAvailability = ()=>{
|
7
|
+
let hasPrettier = false;
|
8
|
+
let hasEslint = false;
|
9
|
+
try {
|
10
|
+
// Check if prettier is available
|
11
|
+
execSync('npx prettier --version', {
|
12
|
+
stdio: 'ignore'
|
13
|
+
});
|
14
|
+
hasPrettier = true;
|
15
|
+
} catch (error) {
|
16
|
+
// Prettier not available
|
17
|
+
}
|
18
|
+
try {
|
19
|
+
// Check if eslint is available
|
20
|
+
execSync('npx eslint --version', {
|
21
|
+
stdio: 'ignore'
|
22
|
+
});
|
23
|
+
hasEslint = true;
|
24
|
+
} catch (error) {
|
25
|
+
// ESLint not available
|
26
|
+
}
|
27
|
+
return {
|
28
|
+
hasPrettier,
|
29
|
+
hasEslint
|
30
|
+
};
|
31
|
+
};
|
32
|
+
const { hasPrettier, hasEslint } = checkToolsAvailability();
|
33
|
+
return {
|
34
|
+
waitingDescription: 'Waiting to format the type file...',
|
35
|
+
errorDescription: 'Failed to format the type file',
|
36
|
+
finishedDescription: ()=>'Type file formatted',
|
37
|
+
runningDescription: 'Formatting the type file...',
|
38
|
+
runner: async ()=>{
|
39
|
+
try {
|
40
|
+
// Run prettier on the generated file if available
|
41
|
+
if (hasPrettier) {
|
42
|
+
execSync(`npx prettier --write "${path}"`, {
|
43
|
+
stdio: 'ignore'
|
44
|
+
});
|
45
|
+
}
|
46
|
+
// Run eslint if available
|
47
|
+
if (hasEslint) {
|
48
|
+
execSync(`npx eslint --fix "${path}"`, {
|
49
|
+
stdio: 'ignore'
|
50
|
+
});
|
51
|
+
}
|
52
|
+
return true;
|
53
|
+
} catch (error) {
|
54
|
+
console.error('Error formatting file:', error);
|
55
|
+
return false;
|
56
|
+
}
|
57
|
+
},
|
58
|
+
ready: true,
|
59
|
+
// Skip only if both tools are unavailable
|
60
|
+
skip: !hasPrettier && !hasEslint
|
61
|
+
};
|
62
|
+
}, [
|
63
|
+
path
|
64
|
+
]);
|
65
|
+
return {
|
66
|
+
formatTypeFile
|
67
|
+
};
|
68
|
+
};
|
69
|
+
|
70
|
+
//# sourceMappingURL=useFormatTypeFile.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useFormatTypeFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { useMemo } from 'react';\nimport { CheckListItem } from '@/cli/types.js';\n\nexport const useFormatTypeFile = (path: string) => {\n const formatTypeFile = useMemo(() => {\n // Check if prettier and eslint are available\n const checkToolsAvailability = () => {\n let hasPrettier = false;\n let hasEslint = false;\n\n try {\n // Check if prettier is available\n execSync('npx prettier --version', { stdio: 'ignore' });\n hasPrettier = true;\n } catch (error) {\n // Prettier not available\n }\n\n try {\n // Check if eslint is available\n execSync('npx eslint --version', { stdio: 'ignore' });\n hasEslint = true;\n } catch (error) {\n // ESLint not available\n }\n\n return { hasPrettier, hasEslint };\n };\n\n const { hasPrettier, hasEslint } = checkToolsAvailability();\n\n return {\n waitingDescription: 'Waiting to format the type file...',\n errorDescription: 'Failed to format the type file',\n finishedDescription: () => 'Type file formatted',\n runningDescription: 'Formatting the type file...',\n runner: async () => {\n try {\n // Run prettier on the generated file if available\n if (hasPrettier) {\n execSync(`npx prettier --write \"${path}\"`, {\n stdio: 'ignore',\n });\n }\n\n // Run eslint if available\n if (hasEslint) {\n execSync(`npx eslint --fix \"${path}\"`, {\n stdio: 'ignore',\n });\n }\n\n return true;\n } catch (error) {\n console.error('Error formatting file:', error);\n return false;\n }\n },\n ready: true,\n // Skip only if both tools are unavailable\n skip: !hasPrettier && !hasEslint,\n } satisfies CheckListItem<boolean>;\n }, [path]);\n\n return {\n formatTypeFile,\n };\n};\n"],"names":["execSync","useMemo","useFormatTypeFile","path","formatTypeFile","checkToolsAvailability","hasPrettier","hasEslint","stdio","error","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","console","ready","skip"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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{ _ as _extends } from "@swc/helpers/_/_extends";
|
2
2
|
import { writeFileSync } from 'node:fs';
|
3
3
|
import { useMemo } from 'react';
|
4
|
-
import { Project, VariableDeclarationKind } from 'ts-morph';
|
4
|
+
import { ModuleDeclarationKind, Project, VariableDeclarationKind } from 'ts-morph';
|
5
5
|
import { TypescriptReservedNamed } from '../../../constants.js';
|
6
6
|
export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
|
7
7
|
const generateTypeFile = useMemo(()=>{
|
@@ -23,7 +23,12 @@ export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
|
|
23
23
|
});
|
24
24
|
const globalNamespace = definitions.global;
|
25
25
|
typeFile.addStatements(typeProvider.getGlobalStatements());
|
26
|
-
|
26
|
+
const globalModule = typeFile.addModule({
|
27
|
+
name: 'global',
|
28
|
+
hasDeclareKeyword: true,
|
29
|
+
declarationKind: ModuleDeclarationKind.Global
|
30
|
+
});
|
31
|
+
generateNamespace(globalNamespace, globalModule, typeProvider, '');
|
27
32
|
writeFileSync(path, typeFile.getFullText().replace('*/', '*/\n'));
|
28
33
|
},
|
29
34
|
ready: definitions !== null && typeProvider !== null
|
@@ -74,6 +79,7 @@ const generateNamespace = (apiObject, incomingSubject, typeProvider, namespace,
|
|
74
79
|
}, typeProvider.getFunctionOverrideOptions(func)));
|
75
80
|
if (isFunctionNameReserved) {
|
76
81
|
subject.addExportDeclaration({
|
82
|
+
leadingTrivia: '/** @ts-ignore */\n',
|
77
83
|
namedExports: [
|
78
84
|
{
|
79
85
|
name: resolvedName,
|
@@ -86,7 +92,8 @@ const generateNamespace = (apiObject, incomingSubject, typeProvider, namespace,
|
|
86
92
|
let propertiesSubject = null;
|
87
93
|
if (name && apiObject.methods.length > 0) {
|
88
94
|
const typeClass = incomingSubject.addClass(_extends({
|
89
|
-
name
|
95
|
+
name,
|
96
|
+
isExported: true
|
90
97
|
}, typeProvider.getClassOptions(fullNamespaceName)));
|
91
98
|
propertiesSubject = typeClass;
|
92
99
|
for (const method of apiObject.methods){
|
@@ -120,7 +127,7 @@ const generateNamespace = (apiObject, incomingSubject, typeProvider, namespace,
|
|
120
127
|
],
|
121
128
|
type: propertyDetails.type,
|
122
129
|
isStatic: propertyDetails.isStatic,
|
123
|
-
isReadonly: propertyDetails.
|
130
|
+
isReadonly: propertyDetails.isReadonly
|
124
131
|
});
|
125
132
|
} else {
|
126
133
|
subject.addVariableStatement({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGenerateTypeFile.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { useMemo } from 'react';\nimport {\n ClassDeclaration,\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ModuleDeclaration,\n Project,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport {\n ApiDefinitions,\n ApiObject,\n CheckListItem,\n PropertyDescription,\n} 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 constant of typeProvider.getConstants(fullNamespaceName)) {\n subject.addVariableStatement({\n declarations: [constant],\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n });\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 const dynamicProperties = typeProvider\n .getDynamicProperties(`${namespace}.${name}`)\n .map(\n dynamicProperty =>\n ({\n name: dynamicProperty.name,\n docs: dynamicProperty.docs,\n namespaces: namespace.split('.'),\n signature: `${namespace}.${name}.${dynamicProperty.name}`,\n } satisfies PropertyDescription),\n );\n\n for (const property of [...apiObject.properties, ...dynamicProperties]) {\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","VariableDeclarationKind","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","constant","getConstants","addVariableStatement","declarations","isExported","declarationKind","Const","func","functions","isFunctionNameReserved","includes","resolvedName","parameters","getParameters","addFunction","docs","returnType","getFunctionReturnType","getFunctionOverrideOptions","addExportDeclaration","namedExports","alias","propertiesSubject","methods","length","typeClass","addClass","getClassOptions","method","addMethod","dynamicProperties","getDynamicProperties","map","dynamicProperty","namespaces","split","signature","property","properties","propertyDetails","getPropertyDetails","addProperty","type","isStatic","isReadonly","isReadOnly","eachNamespace","Object","entries"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,aAAa,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GAAG,CACAC,CAAAA,kBACK,CAAA;YACGzC,MAAMyC,gBAAgBzC,IAAI;YAC1BuB,MAAMkB,gBAAgBlB,IAAI;YAC1BmB,YAAY3C,UAAU4C,KAAK,CAAC;YAC5BC,WAAW,CAAC,EAAE7C,UAAU,CAAC,EAAEC,KAAK,CAAC,EAAEyC,gBAAgBzC,IAAI,CAAC,CAAC;QAC7D,CAAA;IAGZ,KAAK,MAAM6C,YAAY;WAAIhD,UAAUiD,UAAU;WAAKR;KAAkB,CAAE;QACpE,MAAMS,kBAAkBtE,aAAauE,kBAAkB,CAACH;QAExD,IAAIf,mBAAmB;YACnBA,kBAAkBmB,WAAW,CAAC;gBAC1BjD,MAAM6C,SAAS7C,IAAI;gBACnBuB,MAAM;oBAACsB,SAAStB,IAAI;iBAAC;gBACrB2B,MAAMH,gBAAgBG,IAAI;gBAC1BC,UAAUJ,gBAAgBI,QAAQ;gBAClCC,YAAYL,gBAAgBM,UAAU;YAC1C;QACJ,OAAO;YACHpD,QAAQS,oBAAoB,CAAC;gBACzBa,MAAM;oBAACsB,SAAStB,IAAI;iBAAC;gBACrBZ,cAAc;oBACV;wBACIX,MAAM6C,SAAS7C,IAAI;wBACnBkD,MAAMH,gBAAgBG,IAAI;oBAC9B;iBACH;YACL;QACJ;IACJ;IAEA,KAAK,MAAMI,iBAAiBC,OAAOC,OAAO,CAAC3D,UAAU6C,UAAU,EAAG;QAC9DjD,kBACI6D,aAAa,CAAC,EAAE,EAChBrD,SACAxB,cACAyB,mBACAoD,aAAa,CAAC,EAAE;IAExB;AACJ"}
|
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 ModuleDeclarationKind,\n Project,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport {\n ApiDefinitions,\n ApiObject,\n CheckListItem,\n PropertyDescription,\n} 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 const globalModule = typeFile.addModule({\n name: 'global',\n hasDeclareKeyword: true,\n declarationKind: ModuleDeclarationKind.Global,\n });\n\n generateNamespace(\n globalNamespace,\n globalModule,\n typeProvider,\n '',\n );\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 constant of typeProvider.getConstants(fullNamespaceName)) {\n subject.addVariableStatement({\n declarations: [constant],\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n });\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 leadingTrivia: '/** @ts-ignore */\\n',\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 isExported: true,\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 const dynamicProperties = typeProvider\n .getDynamicProperties(`${namespace}.${name}`)\n .map(\n dynamicProperty =>\n ({\n name: dynamicProperty.name,\n docs: dynamicProperty.docs,\n namespaces: namespace.split('.'),\n signature: `${namespace}.${name}.${dynamicProperty.name}`,\n } satisfies PropertyDescription),\n );\n\n for (const property of [...apiObject.properties, ...dynamicProperties]) {\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","ModuleDeclarationKind","Project","VariableDeclarationKind","TypescriptReservedNamed","useGenerateTypeFile","path","definitions","typeProvider","generateTypeFile","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","project","typeFile","createSourceFile","overwrite","globalNamespace","global","addStatements","getGlobalStatements","globalModule","addModule","name","hasDeclareKeyword","declarationKind","Global","generateNamespace","getFullText","replace","ready","apiObject","incomingSubject","namespace","subject","fullNamespaceName","filter","Boolean","join","getStatements","constant","getConstants","addVariableStatement","declarations","isExported","Const","func","functions","isFunctionNameReserved","includes","resolvedName","parameters","getParameters","addFunction","docs","returnType","getFunctionReturnType","getFunctionOverrideOptions","addExportDeclaration","leadingTrivia","namedExports","alias","propertiesSubject","methods","length","typeClass","addClass","getClassOptions","method","addMethod","dynamicProperties","getDynamicProperties","map","dynamicProperty","namespaces","split","signature","property","properties","propertyDetails","getPropertyDetails","addProperty","type","isStatic","isReadonly","eachNamespace","Object","entries"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAKIC,qBAAqB,EACrBC,OAAO,EAEPC,uBAAuB,QACpB,WAAW;AAElB,SAASC,uBAAuB,QAAQ,qBAAqB;AAQ7D,OAAO,MAAMC,sBAAsB,CAC/BC,MACAC,aACAC;IAEA,MAAMC,mBAAmBT,QAAQ;QAC7B,OAAO;YACHU,oBAAoB;YACpBC,kBAAkB;YAClBC,qBAAqB,IAAM;YAC3BC,oBAAoB;YACpBC,QAAQ;gBACJ,IAAI,C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AAEV,KAAK,CAAC,EAAEkD,gBAAgBlD,IAAI,CAAC,CAAC;QAC7D,CAAA;IAGZ,KAAK,MAAMsD,YAAY;WAAI9C,UAAU+C,UAAU;WAAKR;KAAkB,CAAE;QACpE,MAAMS,kBAAkB1E,aAAa2E,kBAAkB,CAACH;QAExD,IAAIf,mBAAmB;YACnBA,kBAAkBmB,WAAW,CAAC;gBAC1B1D,MAAMsD,SAAStD,IAAI;gBACnB+B,MAAM;oBAACuB,SAASvB,IAAI;iBAAC;gBACrB4B,MAAMH,gBAAgBG,IAAI;gBAC1BC,UAAUJ,gBAAgBI,QAAQ;gBAClCC,YAAYL,gBAAgBK,UAAU;YAC1C;QACJ,OAAO;YACHlD,QAAQQ,oBAAoB,CAAC;gBACzBY,MAAM;oBAACuB,SAASvB,IAAI;iBAAC;gBACrBX,cAAc;oBACV;wBACIpB,MAAMsD,SAAStD,IAAI;wBACnB2D,MAAMH,gBAAgBG,IAAI;oBAC9B;iBACH;YACL;QACJ;IACJ;IAEA,KAAK,MAAMG,iBAAiBC,OAAOC,OAAO,CAACxD,UAAU2C,UAAU,EAAG;QAC9D/C,kBACI0D,aAAa,CAAC,EAAE,EAChBnD,SACA7B,cACA8B,mBACAkD,aAAa,CAAC,EAAE;IAExB;AACJ"}
|
@@ -15,44 +15,14 @@ export declare const useGetVersion: (version: PlaydateSdkVersion) => {
|
|
15
15
|
getClassOptions: (className: string) => Partial<import("ts-morph").ClassDeclarationStructure>;
|
16
16
|
getPropertyDetails: (property: import("../../../types.js").PropertyDescription) => import("../../../types.js").PropertyDetails;
|
17
17
|
getDynamicProperties: (namespace: string) => Pick<import("../../../types.js").PropertyDescription, "name" | "docs">[];
|
18
|
-
getFunctionReturnType: (func: import("../../../types.js").FunctionDescription) => string;
|
19
|
-
getParameterDetails: (func: import("../../../types.js").FunctionDescription, parameter: string) => import("
|
20
|
-
getParameters: (func: import("../../../types.js").FunctionDescription) => import("ts-morph").
|
21
|
-
getFunctionOverrideOptions: (func: import("../../../types.js").FunctionDescription) => Partial<import("ts-morph").FunctionDeclarationStructure
|
22
|
-
overloads: ({
|
23
|
-
docs: string[];
|
24
|
-
leadingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
25
|
-
trailingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
26
|
-
hasQuestionToken?: boolean | undefined;
|
27
|
-
scope?: import("ts-morph").Scope | undefined;
|
28
|
-
hasOverrideKeyword?: boolean | undefined;
|
29
|
-
parameters?: import("ts-morph").OptionalKind<import("ts-morph").ParameterDeclarationStructure>[] | undefined;
|
30
|
-
typeParameters?: (import("ts-morph").OptionalKind<import("ts-morph").TypeParameterDeclarationStructure> | string)[] | undefined;
|
31
|
-
isAbstract?: boolean | undefined;
|
32
|
-
returnType?: (string | import("ts-morph").WriterFunction) | undefined;
|
33
|
-
isAsync?: boolean | undefined;
|
34
|
-
isGenerator?: boolean | undefined;
|
35
|
-
isStatic?: boolean | undefined;
|
36
|
-
kind?: import("ts-morph").StructureKind.MethodOverload | undefined;
|
37
|
-
} | {
|
38
|
-
docs: string[];
|
39
|
-
leadingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
40
|
-
trailingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
41
|
-
parameters?: import("ts-morph").OptionalKind<import("ts-morph").ParameterDeclarationStructure>[] | undefined;
|
42
|
-
typeParameters?: (import("ts-morph").OptionalKind<import("ts-morph").TypeParameterDeclarationStructure> | string)[] | undefined;
|
43
|
-
hasDeclareKeyword?: boolean | undefined;
|
44
|
-
isExported?: boolean | undefined;
|
45
|
-
isDefaultExport?: boolean | undefined;
|
46
|
-
returnType?: (string | import("ts-morph").WriterFunction) | undefined;
|
47
|
-
isAsync?: boolean | undefined;
|
48
|
-
isGenerator?: boolean | undefined;
|
49
|
-
kind?: import("ts-morph").StructureKind.FunctionOverload | undefined;
|
50
|
-
})[];
|
51
|
-
};
|
18
|
+
getFunctionReturnType: (func: import("../../../types.js").FunctionDescription) => string | import("ts-morph").WriterFunction | undefined;
|
19
|
+
getParameterDetails: (func: import("../../../types.js").FunctionDescription, parameter: string) => import("ts-morph").ParameterDeclarationStructure;
|
20
|
+
getParameters: (func: import("../../../types.js").FunctionDescription) => import("ts-morph").ParameterDeclarationStructure[];
|
21
|
+
getFunctionOverrideOptions: (func: import("../../../types.js").FunctionDescription) => Partial<import("ts-morph").FunctionDeclarationStructure | import("ts-morph").MethodDeclarationStructure>;
|
52
22
|
getConstants: (fullNamespace: string) => {
|
53
23
|
kind: import("ts-morph").StructureKind.VariableDeclaration;
|
54
24
|
name: string;
|
55
|
-
type: string;
|
25
|
+
type: string | import("ts-morph").WriterFunction | undefined;
|
56
26
|
}[];
|
57
27
|
save: () => void;
|
58
28
|
} | null;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ClassDeclarationStructure, PropertyDeclarationStructure } from 'ts-morph';
|
2
|
+
export type ClassDefinition = Partial<ClassDeclarationStructure>;
|
3
|
+
export type PropertyDefinition = {
|
4
|
+
signature: string;
|
5
|
+
definition: Partial<PropertyDeclarationStructure>;
|
6
|
+
};
|
7
|
+
export type VersionDefinition = {
|
8
|
+
globalStatements: string[];
|
9
|
+
constants: Record<string, string[]>;
|
10
|
+
statements: string[];
|
11
|
+
classes: Record<string, ClassDefinition>;
|
12
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/cli/src/commands/GenerateTypes/types.ts"],"sourcesContent":["import {\n ClassDeclarationStructure,\n PropertyDeclarationStructure,\n} from 'ts-morph';\n\nexport type ClassDefinition = Partial<ClassDeclarationStructure>;\n\nexport type PropertyDefinition = {\n signature: string;\n definition: Partial<PropertyDeclarationStructure>;\n};\n\nexport type VersionDefinition = {\n globalStatements: string[];\n constants: Record<string, string[]>;\n statements: string[];\n classes: Record<string, ClassDefinition>;\n};\n"],"names":[],"rangeMappings":"","mappings":"AAYA,WAKE"}
|
@@ -1,49 +1,19 @@
|
|
1
|
-
import {
|
2
|
-
import { FunctionDescription,
|
1
|
+
import { ParameterDeclarationStructure, StructureKind, FunctionDeclarationStructure, MethodDeclarationStructure } from 'ts-morph';
|
2
|
+
import { FunctionDescription, PropertyDescription, PropertyDetails } from '../../../types.js';
|
3
3
|
export declare const createTypeProvider: (version: string) => {
|
4
4
|
getGlobalStatements: () => string[];
|
5
5
|
getStatements: () => string[];
|
6
6
|
getClassOptions: (className: string) => Partial<import("ts-morph").ClassDeclarationStructure>;
|
7
7
|
getPropertyDetails: (property: PropertyDescription) => PropertyDetails;
|
8
8
|
getDynamicProperties: (namespace: string) => Pick<PropertyDescription, "name" | "docs">[];
|
9
|
-
getFunctionReturnType: (func: FunctionDescription) => string;
|
10
|
-
getParameterDetails: (func: FunctionDescription, parameter: string) =>
|
11
|
-
getParameters: (func: FunctionDescription) =>
|
12
|
-
getFunctionOverrideOptions: (func: FunctionDescription) => Partial<FunctionDeclarationStructure
|
13
|
-
overloads: ({
|
14
|
-
docs: string[];
|
15
|
-
leadingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
16
|
-
trailingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
17
|
-
hasQuestionToken?: boolean | undefined;
|
18
|
-
scope?: import("ts-morph").Scope | undefined;
|
19
|
-
hasOverrideKeyword?: boolean | undefined;
|
20
|
-
parameters?: import("ts-morph").OptionalKind<ParameterDeclarationStructure>[] | undefined;
|
21
|
-
typeParameters?: (import("ts-morph").OptionalKind<import("ts-morph").TypeParameterDeclarationStructure> | string)[] | undefined;
|
22
|
-
isAbstract?: boolean | undefined;
|
23
|
-
returnType?: (string | import("ts-morph").WriterFunction) | undefined;
|
24
|
-
isAsync?: boolean | undefined;
|
25
|
-
isGenerator?: boolean | undefined;
|
26
|
-
isStatic?: boolean | undefined;
|
27
|
-
kind?: StructureKind.MethodOverload | undefined;
|
28
|
-
} | {
|
29
|
-
docs: string[];
|
30
|
-
leadingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
31
|
-
trailingTrivia?: (string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[]) | undefined;
|
32
|
-
parameters?: import("ts-morph").OptionalKind<ParameterDeclarationStructure>[] | undefined;
|
33
|
-
typeParameters?: (import("ts-morph").OptionalKind<import("ts-morph").TypeParameterDeclarationStructure> | string)[] | undefined;
|
34
|
-
hasDeclareKeyword?: boolean | undefined;
|
35
|
-
isExported?: boolean | undefined;
|
36
|
-
isDefaultExport?: boolean | undefined;
|
37
|
-
returnType?: (string | import("ts-morph").WriterFunction) | undefined;
|
38
|
-
isAsync?: boolean | undefined;
|
39
|
-
isGenerator?: boolean | undefined;
|
40
|
-
kind?: StructureKind.FunctionOverload | undefined;
|
41
|
-
})[];
|
42
|
-
};
|
9
|
+
getFunctionReturnType: (func: FunctionDescription) => string | import("ts-morph").WriterFunction | undefined;
|
10
|
+
getParameterDetails: (func: FunctionDescription, parameter: string) => ParameterDeclarationStructure;
|
11
|
+
getParameters: (func: FunctionDescription) => ParameterDeclarationStructure[];
|
12
|
+
getFunctionOverrideOptions: (func: FunctionDescription) => Partial<FunctionDeclarationStructure | MethodDeclarationStructure>;
|
43
13
|
getConstants: (fullNamespace: string) => {
|
44
14
|
kind: StructureKind.VariableDeclaration;
|
45
15
|
name: string;
|
46
|
-
type: string;
|
16
|
+
type: string | import("ts-morph").WriterFunction | undefined;
|
47
17
|
}[];
|
48
18
|
save: () => void;
|
49
19
|
};
|
@@ -74,7 +74,8 @@ export const createTypeProvider = (version)=>{
|
|
74
74
|
const details = {
|
75
75
|
signature: func.signature,
|
76
76
|
parameters: func.parameters.map((p)=>({
|
77
|
-
|
77
|
+
kind: StructureKind.Parameter,
|
78
|
+
name: kebabToCamelCase(p.name),
|
78
79
|
type: 'any'
|
79
80
|
})),
|
80
81
|
returnType: 'any'
|
@@ -99,49 +100,72 @@ export const createTypeProvider = (version)=>{
|
|
99
100
|
return returnType;
|
100
101
|
};
|
101
102
|
const getParameterDetails = (func, parameter)=>{
|
102
|
-
|
103
|
-
const
|
103
|
+
var _details_parameters;
|
104
|
+
const details = getFunctionDetails(func);
|
105
|
+
const param = (_details_parameters = details.parameters) == null ? void 0 : _details_parameters.find((p)=>p.name === parameter);
|
104
106
|
if (!param) {
|
105
107
|
return {
|
106
|
-
|
108
|
+
kind: StructureKind.Parameter,
|
109
|
+
name: kebabToCamelCase(parameter),
|
107
110
|
type: 'any'
|
108
111
|
};
|
109
112
|
}
|
110
|
-
return param
|
113
|
+
return _extends({}, param, {
|
114
|
+
name: kebabToCamelCase(param.name)
|
115
|
+
});
|
111
116
|
};
|
112
117
|
const getParameters = (func)=>{
|
113
|
-
const
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
name: kebabToCamelCase(parameter.name),
|
119
|
-
type: parameter.type
|
120
|
-
}, (_parameter_overrideOptions = parameter.overrideOptions) != null ? _parameter_overrideOptions : {});
|
121
|
-
};
|
122
|
-
if (overrideParameters) {
|
123
|
-
return parameters.map((details)=>{
|
124
|
-
return getParameterFromDetails(details);
|
125
|
-
});
|
118
|
+
const details = getFunctionDetails(func);
|
119
|
+
if (details.overrideParameters && details.parameters) {
|
120
|
+
return details.parameters.map((param)=>_extends({}, param, {
|
121
|
+
name: kebabToCamelCase(param.name)
|
122
|
+
}));
|
126
123
|
}
|
127
124
|
return func.parameters.map((parameter)=>{
|
128
125
|
const details = getParameterDetails(func, parameter.name);
|
129
|
-
return _extends({
|
126
|
+
return _extends({}, details, {
|
127
|
+
name: kebabToCamelCase(details.name),
|
130
128
|
hasQuestionToken: !parameter.required
|
131
|
-
}
|
129
|
+
});
|
132
130
|
});
|
133
131
|
};
|
134
132
|
const getFunctionOverrideOptions = (func)=>{
|
135
|
-
|
136
|
-
const options =
|
137
|
-
if (
|
138
|
-
|
139
|
-
|
133
|
+
const details = getFunctionDetails(func);
|
134
|
+
const options = {};
|
135
|
+
if (details.kind) {
|
136
|
+
options.kind = details.kind;
|
137
|
+
}
|
138
|
+
if (details.typeParameters) {
|
139
|
+
options.typeParameters = details.typeParameters;
|
140
|
+
}
|
141
|
+
if ('overloads' in details && Array.isArray(details.overloads)) {
|
142
|
+
if (details.kind === StructureKind.Method) {
|
143
|
+
options.overloads = details.overloads.map((overload)=>{
|
144
|
+
var _overload_parameters;
|
145
|
+
return _extends({}, overload, {
|
146
|
+
typeParameters: overload.typeParameters,
|
147
|
+
parameters: (_overload_parameters = overload.parameters) == null ? void 0 : _overload_parameters.map((param)=>_extends({}, param, {
|
148
|
+
name: kebabToCamelCase(param.name)
|
149
|
+
})),
|
140
150
|
docs: [
|
141
151
|
func.docs
|
142
152
|
]
|
143
|
-
})
|
144
|
-
|
153
|
+
});
|
154
|
+
});
|
155
|
+
} else {
|
156
|
+
options.overloads = details.overloads.map((overload)=>{
|
157
|
+
var _overload_parameters;
|
158
|
+
return _extends({}, overload, {
|
159
|
+
typeParameters: overload.typeParameters,
|
160
|
+
parameters: (_overload_parameters = overload.parameters) == null ? void 0 : _overload_parameters.map((param)=>_extends({}, param, {
|
161
|
+
name: kebabToCamelCase(param.name)
|
162
|
+
})),
|
163
|
+
docs: [
|
164
|
+
func.docs
|
165
|
+
]
|
166
|
+
});
|
167
|
+
});
|
168
|
+
}
|
145
169
|
}
|
146
170
|
return options;
|
147
171
|
};
|