crankscript 0.4.0 → 0.5.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 +25 -26
- package/src/commands/DoctorCommand.js +2 -2
- package/src/commands/DoctorCommand.js.map +1 -1
- package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.d.ts +2 -2
- package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js +4 -4
- package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js.map +1 -1
- package/src/commands/EnvironmentAwareCommand/components/HealthReport.d.ts +3 -3
- package/src/commands/EnvironmentAwareCommand/components/HealthReport.js +16 -22
- package/src/commands/EnvironmentAwareCommand/components/HealthReport.js.map +1 -1
- package/src/commands/GenerateTypes/GenerateTypesCommand.d.ts +4 -4
- package/src/commands/GenerateTypes/GenerateTypesCommand.js +15 -9
- package/src/commands/GenerateTypes/GenerateTypesCommand.js.map +1 -1
- package/src/commands/GenerateTypes/components/GenerateTypes.d.ts +4 -3
- package/src/commands/GenerateTypes/components/GenerateTypes.js +12 -8
- package/src/commands/GenerateTypes/components/GenerateTypes.js.map +1 -1
- package/src/commands/GenerateTypes/fn/generateNamespace.d.ts +3 -0
- package/src/commands/GenerateTypes/fn/generateNamespace.js +33 -0
- package/src/commands/GenerateTypes/fn/generateNamespace.js.map +1 -0
- package/src/commands/GenerateTypes/fn/getApiDefinitions.d.ts +14 -0
- package/src/commands/GenerateTypes/fn/getApiDefinitions.js +58 -0
- package/src/commands/GenerateTypes/fn/getApiDefinitions.js.map +1 -0
- package/src/commands/GenerateTypes/fn/getFunctionDescriptionsFromHtml.d.ts +2 -0
- package/src/commands/GenerateTypes/fn/getFunctionDescriptionsFromHtml.js +37 -0
- package/src/commands/GenerateTypes/fn/getFunctionDescriptionsFromHtml.js.map +1 -0
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.d.ts +10 -0
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.js +24 -0
- package/src/commands/GenerateTypes/fn/parseFunctionSignature.js.map +1 -0
- package/src/commands/GenerateTypes/hooks/useFetchHtml.js +1 -1
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.d.ts +2 -1
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js +29 -9
- package/src/commands/GenerateTypes/hooks/useGenerateTypeFile.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useGetVersion.d.ts +2 -2
- package/src/commands/GenerateTypes/hooks/useGetVersion.js +2 -2
- package/src/commands/GenerateTypes/hooks/useGetVersion.js.map +1 -1
- package/src/commands/GenerateTypes/hooks/useParseDocumentation.d.ts +25 -0
- package/src/commands/GenerateTypes/hooks/useParseDocumentation.js +33 -0
- package/src/commands/GenerateTypes/hooks/useParseDocumentation.js.map +1 -0
- package/src/commands/GenerateTypes/utils/playdateConstants.d.ts +9 -0
- package/src/commands/GenerateTypes/utils/playdateConstants.js +134 -0
- package/src/commands/GenerateTypes/utils/playdateConstants.js.map +1 -0
- package/src/components/CheckList/CheckList.d.ts +1 -1
- package/src/components/CheckList/Item.d.ts +1 -1
- package/src/constants.d.ts +1 -0
- package/src/constants.js +5 -0
- package/src/constants.js.map +1 -1
- package/src/environment/createEnvironment.js +8 -24
- package/src/environment/createEnvironment.js.map +1 -1
- package/src/environment/dto/Environment.d.ts +1 -4
- package/src/environment/dto/Environment.js +1 -2
- package/src/environment/dto/Environment.js.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +4 -4
- package/src/index.js.map +1 -1
- package/src/types.d.ts +44 -10
- package/src/types.js +6 -12
- package/src/types.js.map +1 -1
- package/src/environment/configuration/ConfigurationSchema.d.ts +0 -9
- package/src/environment/configuration/ConfigurationSchema.js +0 -9
- package/src/environment/configuration/ConfigurationSchema.js.map +0 -1
- package/src/environment/configuration/dto/Configuration.d.ts +0 -4
- package/src/environment/configuration/dto/Configuration.js +0 -7
- package/src/environment/configuration/dto/Configuration.js.map +0 -1
- package/src/environment/configuration/error/ConfigurationFileNotFoundError.d.ts +0 -4
- package/src/environment/configuration/error/ConfigurationFileNotFoundError.js +0 -8
- package/src/environment/configuration/error/ConfigurationFileNotFoundError.js.map +0 -1
- package/src/environment/configuration/error/ConfigurationFileValidationError.d.ts +0 -5
- package/src/environment/configuration/error/ConfigurationFileValidationError.js +0 -8
- package/src/environment/configuration/error/ConfigurationFileValidationError.js.map +0 -1
- package/src/environment/configuration/getConfiguration.d.ts +0 -4
- package/src/environment/configuration/getConfiguration.js +0 -31
- package/src/environment/configuration/getConfiguration.js.map +0 -1
package/package.json
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
"types": "./src/index.d.ts"
|
2
|
+
"name": "crankscript",
|
3
|
+
"version": "0.5.0",
|
4
|
+
"scripts": {
|
5
|
+
"dev": "tsx src/index.ts",
|
6
|
+
"post-build": "tsc-alias --project tsconfig.json"
|
7
|
+
},
|
8
|
+
"bin": {
|
9
|
+
"crankscript": "./src/index.js"
|
10
|
+
},
|
11
|
+
"license": "MIT",
|
12
|
+
"dependencies": {
|
13
|
+
"@inkjs/ui": "^2.0.0",
|
14
|
+
"@swc/helpers": "~0.5.11",
|
15
|
+
"cheerio": "^1.0.0",
|
16
|
+
"clipanion": "^4.0.0-rc.4",
|
17
|
+
"ink": "^5.0.1",
|
18
|
+
"react": "^18.3.1",
|
19
|
+
"ts-morph": "^23.0.0",
|
20
|
+
"typanion": "^3.14.0"
|
21
|
+
},
|
22
|
+
"type": "module",
|
23
|
+
"main": "./src/index.js",
|
24
|
+
"typings": "./src/index.d.ts",
|
25
|
+
"module": "./src/index.js",
|
26
|
+
"types": "./src/index.d.ts"
|
28
27
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Command } from 'clipanion';
|
2
2
|
import { Text } from 'ink';
|
3
3
|
import React from 'react';
|
4
|
-
import { createEnvironment } from '
|
4
|
+
import { createEnvironment } from '@/cli/environment/createEnvironment.js';
|
5
5
|
import { HealthReport } from './EnvironmentAwareCommand/components/HealthReport.js';
|
6
6
|
import { RenderableCommand } from './RenderableCommand.js';
|
7
7
|
export class DoctorCommand extends RenderableCommand {
|
@@ -10,7 +10,7 @@ export class DoctorCommand extends RenderableCommand {
|
|
10
10
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Text, {
|
11
11
|
color: "gray"
|
12
12
|
}, "Checking the environment..."), /*#__PURE__*/ React.createElement(HealthReport, {
|
13
|
-
|
13
|
+
environment: environment
|
14
14
|
}));
|
15
15
|
}
|
16
16
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../libs/cli/src/commands/DoctorCommand.tsx"],"sourcesContent":["import { Command } from 'clipanion';\nimport { Text } from 'ink';\nimport React from 'react';\nimport { createEnvironment } from '@/cli/environment/createEnvironment.js';\nimport { HealthReport } from './EnvironmentAwareCommand/components/HealthReport.js';\nimport { RenderableCommand } from './RenderableCommand.js';\n\nexport class DoctorCommand extends RenderableCommand {\n static override paths = [['doctor']];\n\n static override usage = Command.Usage({\n description: 'Check the health of the environment',\n });\n\n override render() {\n const environment = createEnvironment();\n\n return (\n <>\n <Text color=\"gray\">Checking the environment...</Text>\n <HealthReport
|
1
|
+
{"version":3,"sources":["../../../../../libs/cli/src/commands/DoctorCommand.tsx"],"sourcesContent":["import { Command } from 'clipanion';\nimport { Text } from 'ink';\nimport React from 'react';\nimport { createEnvironment } from '@/cli/environment/createEnvironment.js';\nimport { HealthReport } from './EnvironmentAwareCommand/components/HealthReport.js';\nimport { RenderableCommand } from './RenderableCommand.js';\n\nexport class DoctorCommand extends RenderableCommand {\n static override paths = [['doctor']];\n\n static override usage = Command.Usage({\n description: 'Check the health of the environment',\n });\n\n override render() {\n const environment = createEnvironment();\n\n return (\n <>\n <Text color=\"gray\">Checking the environment...</Text>\n <HealthReport environment={environment} />\n </>\n );\n }\n}\n"],"names":["Command","Text","React","createEnvironment","HealthReport","RenderableCommand","DoctorCommand","render","environment","color","paths","usage","Usage","description"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AACpC,SAASC,IAAI,QAAQ,MAAM;AAC3B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,iBAAiB,QAAQ,yCAAyC;AAC3E,SAASC,YAAY,QAAQ,uDAAuD;AACpF,SAASC,iBAAiB,QAAQ,yBAAyB;AAE3D,OAAO,MAAMC,sBAAsBD;IAOtBE,SAAS;QACd,MAAMC,cAAcL;QAEpB,qBACI,wDACI,oBAACF;YAAKQ,OAAM;WAAO,8CACnB,oBAACL;YAAaI,aAAaA;;IAGvC;AACJ;AAjBaF,cACOI,QAAQ;IAAC;QAAC;KAAS;CAAC;AAD3BJ,cAGOK,QAAQX,QAAQY,KAAK,CAAC;IAClCC,aAAa;AACjB"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { JSX } from 'react';
|
2
|
-
import { RenderableCommand } from '
|
3
|
-
import { Environment } from '
|
2
|
+
import { RenderableCommand } from '@/cli/commands/RenderableCommand.js';
|
3
|
+
import { Environment } from '@/cli/environment/dto/Environment.js';
|
4
4
|
export declare abstract class EnvironmentAwareCommand extends RenderableCommand {
|
5
5
|
private environment;
|
6
6
|
protected abstract renderWithEnvironment(environment: Environment): JSX.Element;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { HealthReport } from '
|
3
|
-
import { RenderableCommand } from '
|
4
|
-
import { createEnvironment } from '
|
2
|
+
import { HealthReport } from '@/cli/commands/EnvironmentAwareCommand/components/HealthReport.js';
|
3
|
+
import { RenderableCommand } from '@/cli/commands/RenderableCommand.js';
|
4
|
+
import { createEnvironment } from '@/cli/environment/createEnvironment.js';
|
5
5
|
export class EnvironmentAwareCommand extends RenderableCommand {
|
6
6
|
render() {
|
7
7
|
if (!this.environment) {
|
@@ -13,7 +13,7 @@ export class EnvironmentAwareCommand extends RenderableCommand {
|
|
13
13
|
const environmentHealth = createEnvironment();
|
14
14
|
if (!environmentHealth.isHealthy) {
|
15
15
|
this.renderElement(/*#__PURE__*/ React.createElement(HealthReport, {
|
16
|
-
|
16
|
+
environment: environmentHealth
|
17
17
|
}));
|
18
18
|
return;
|
19
19
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/cli/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.tsx"],"sourcesContent":["import React, { JSX } from 'react';\nimport { HealthReport } from '@/cli/commands/EnvironmentAwareCommand/components/HealthReport.js';\nimport { RenderableCommand } from '@/cli/commands/RenderableCommand.js';\nimport { createEnvironment } from '@/cli/environment/createEnvironment.js';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\n\nexport abstract class EnvironmentAwareCommand extends RenderableCommand {\n private environment: Environment | undefined;\n\n protected abstract renderWithEnvironment(\n environment: Environment\n ): JSX.Element;\n\n override render() {\n if (!this.environment) {\n throw new Error('Environment is not set');\n }\n\n return this.renderWithEnvironment(this.environment);\n }\n\n override async execute() {\n const environmentHealth = createEnvironment();\n\n if (!environmentHealth.isHealthy) {\n this.renderElement(\n <HealthReport
|
1
|
+
{"version":3,"sources":["../../../../../../libs/cli/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.tsx"],"sourcesContent":["import React, { JSX } from 'react';\nimport { HealthReport } from '@/cli/commands/EnvironmentAwareCommand/components/HealthReport.js';\nimport { RenderableCommand } from '@/cli/commands/RenderableCommand.js';\nimport { createEnvironment } from '@/cli/environment/createEnvironment.js';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\n\nexport abstract class EnvironmentAwareCommand extends RenderableCommand {\n private environment: Environment | undefined;\n\n protected abstract renderWithEnvironment(\n environment: Environment\n ): JSX.Element;\n\n override render() {\n if (!this.environment) {\n throw new Error('Environment is not set');\n }\n\n return this.renderWithEnvironment(this.environment);\n }\n\n override async execute() {\n const environmentHealth = createEnvironment();\n\n if (!environmentHealth.isHealthy) {\n this.renderElement(\n <HealthReport environment={environmentHealth} />\n );\n\n return;\n }\n\n this.environment = environmentHealth.environment;\n\n this.renderElement(this.render());\n }\n}\n"],"names":["React","HealthReport","RenderableCommand","createEnvironment","EnvironmentAwareCommand","render","environment","Error","renderWithEnvironment","execute","environmentHealth","isHealthy","renderElement"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,WAAoB,QAAQ;AACnC,SAASC,YAAY,QAAQ,oEAAoE;AACjG,SAASC,iBAAiB,QAAQ,sCAAsC;AACxE,SAASC,iBAAiB,QAAQ,yCAAyC;AAG3E,OAAO,MAAeC,gCAAgCF;IAOzCG,SAAS;QACd,IAAI,CAAC,IAAI,CAACC,WAAW,EAAE;YACnB,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAO,IAAI,CAACC,qBAAqB,CAAC,IAAI,CAACF,WAAW;IACtD;IAEA,MAAeG,UAAU;QACrB,MAAMC,oBAAoBP;QAE1B,IAAI,CAACO,kBAAkBC,SAAS,EAAE;YAC9B,IAAI,CAACC,aAAa,eACd,oBAACX;gBAAaK,aAAaI;;YAG/B;QACJ;QAEA,IAAI,CAACJ,WAAW,GAAGI,kBAAkBJ,WAAW;QAEhD,IAAI,CAACM,aAAa,CAAC,IAAI,CAACP,MAAM;IAClC;AACJ"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import {
|
2
|
+
import { EnvironmentHealthResult } from '@/cli/types.js';
|
3
3
|
interface Props {
|
4
|
-
|
4
|
+
environment: EnvironmentHealthResult;
|
5
5
|
}
|
6
|
-
export declare const HealthReport: ({
|
6
|
+
export declare const HealthReport: ({ environment }: Props) => React.JSX.Element[];
|
7
7
|
export {};
|
@@ -1,46 +1,40 @@
|
|
1
1
|
import { StatusMessage } from '@inkjs/ui';
|
2
2
|
import { Text } from 'ink';
|
3
3
|
import React from 'react';
|
4
|
-
import {
|
4
|
+
import { HealthCheckStatusType } from '@/cli/types.js';
|
5
5
|
const SuccessMessages = {
|
6
|
-
configurationFilePresent: {
|
7
|
-
[HealthCheckStatus.Unknown]: 'Configuration file status unknown',
|
8
|
-
[HealthCheckStatus.Healthy]: 'Configuration file found',
|
9
|
-
[HealthCheckStatus.Unhealthy]: 'Configuration file not found'
|
10
|
-
},
|
11
|
-
configurationFileValid: {
|
12
|
-
[HealthCheckStatus.Unknown]: 'Configuration file validity unknown',
|
13
|
-
[HealthCheckStatus.Healthy]: 'Configuration file is valid',
|
14
|
-
[HealthCheckStatus.Unhealthy]: 'Configuration file is invalid'
|
15
|
-
},
|
16
6
|
sdkPathKnown: {
|
17
|
-
[
|
18
|
-
[
|
19
|
-
[
|
7
|
+
[HealthCheckStatusType.Unknown]: 'SDK path status unknown',
|
8
|
+
[HealthCheckStatusType.Healthy]: (sdkPath)=>`SDK path found ("${sdkPath.path}")`,
|
9
|
+
[HealthCheckStatusType.Unhealthy]: 'SDK path not found'
|
20
10
|
}
|
21
11
|
};
|
22
12
|
const ColorMap = {
|
23
|
-
[
|
24
|
-
[
|
25
|
-
[
|
13
|
+
[HealthCheckStatusType.Healthy]: 'green',
|
14
|
+
[HealthCheckStatusType.Unhealthy]: 'red',
|
15
|
+
[HealthCheckStatusType.Unknown]: 'gray'
|
26
16
|
};
|
27
|
-
export const HealthReport = ({
|
17
|
+
export const HealthReport = ({ environment })=>{
|
18
|
+
const { health } = environment;
|
28
19
|
return Object.keys(health).map((eachKey)=>{
|
29
20
|
const healthKey = eachKey;
|
30
21
|
const keyHealth = health[healthKey];
|
31
22
|
let variant = 'info';
|
32
|
-
|
23
|
+
let message = SuccessMessages[healthKey][HealthCheckStatusType.Unknown];
|
24
|
+
if (health[healthKey].healthStatus === HealthCheckStatusType.Unhealthy) {
|
25
|
+
message = SuccessMessages[healthKey][HealthCheckStatusType.Unhealthy];
|
33
26
|
variant = 'error';
|
34
27
|
}
|
35
|
-
if (health[healthKey] ===
|
28
|
+
if (health[healthKey].healthStatus === HealthCheckStatusType.Healthy) {
|
29
|
+
message = SuccessMessages[healthKey][HealthCheckStatusType.Healthy](health[healthKey].argument);
|
36
30
|
variant = 'success';
|
37
31
|
}
|
38
32
|
return /*#__PURE__*/ React.createElement(StatusMessage, {
|
39
33
|
key: healthKey,
|
40
34
|
variant: variant
|
41
35
|
}, /*#__PURE__*/ React.createElement(Text, {
|
42
|
-
color: ColorMap[keyHealth]
|
43
|
-
}, keyHealth ===
|
36
|
+
color: ColorMap[keyHealth.healthStatus]
|
37
|
+
}, keyHealth.healthStatus === HealthCheckStatusType.Unhealthy && ' ', message));
|
44
38
|
});
|
45
39
|
};
|
46
40
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/EnvironmentAwareCommand/components/HealthReport.tsx"],"sourcesContent":["import { StatusMessage, StatusMessageProps } from '@inkjs/ui';\nimport { Text, TextProps } from 'ink';\nimport React from 'react';\nimport {
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/EnvironmentAwareCommand/components/HealthReport.tsx"],"sourcesContent":["import { StatusMessage, StatusMessageProps } from '@inkjs/ui';\nimport { Text, TextProps } from 'ink';\nimport React from 'react';\nimport { PlaydateSdkPath } from '@/cli/environment/path/dto/PlaydateSdkPath.js';\nimport {\n EnvironmentHealth,\n EnvironmentHealthResult,\n HealthCheckStatusType,\n} from '@/cli/types.js';\n\ninterface Props {\n environment: EnvironmentHealthResult;\n}\n\nconst SuccessMessages = {\n sdkPathKnown: {\n [HealthCheckStatusType.Unknown]: 'SDK path status unknown',\n [HealthCheckStatusType.Healthy]: (sdkPath: PlaydateSdkPath) =>\n `SDK path found (\"${sdkPath.path}\")`,\n [HealthCheckStatusType.Unhealthy]: 'SDK path not found',\n },\n} as const;\n\nconst ColorMap = {\n [HealthCheckStatusType.Healthy]: 'green',\n [HealthCheckStatusType.Unhealthy]: 'red',\n [HealthCheckStatusType.Unknown]: 'gray',\n} satisfies {\n [key in HealthCheckStatusType]: TextProps['color'];\n};\n\nexport const HealthReport = ({ environment }: Props) => {\n const { health } = environment;\n return Object.keys(health).map((eachKey) => {\n const healthKey = eachKey as keyof EnvironmentHealth;\n const keyHealth = health[healthKey];\n\n let variant: StatusMessageProps['variant'] = 'info';\n let message: string =\n SuccessMessages[healthKey][HealthCheckStatusType.Unknown];\n\n if (\n health[healthKey].healthStatus === HealthCheckStatusType.Unhealthy\n ) {\n message =\n SuccessMessages[healthKey][HealthCheckStatusType.Unhealthy];\n variant = 'error';\n }\n\n if (health[healthKey].healthStatus === HealthCheckStatusType.Healthy) {\n message = SuccessMessages[healthKey][HealthCheckStatusType.Healthy](\n health[healthKey].argument\n );\n variant = 'success';\n }\n\n return (\n <StatusMessage key={healthKey} variant={variant}>\n <Text color={ColorMap[keyHealth.healthStatus]}>\n {keyHealth.healthStatus ===\n HealthCheckStatusType.Unhealthy && ' '}\n {message}\n </Text>\n </StatusMessage>\n );\n });\n};\n"],"names":["StatusMessage","Text","React","HealthCheckStatusType","SuccessMessages","sdkPathKnown","Unknown","Healthy","sdkPath","path","Unhealthy","ColorMap","HealthReport","environment","health","Object","keys","map","eachKey","healthKey","keyHealth","variant","message","healthStatus","argument","key","color"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAA4B,YAAY;AAC9D,SAASC,IAAI,QAAmB,MAAM;AACtC,OAAOC,WAAW,QAAQ;AAE1B,SAGIC,qBAAqB,QAClB,iBAAiB;AAMxB,MAAMC,kBAAkB;IACpBC,cAAc;QACV,CAACF,sBAAsBG,OAAO,CAAC,EAAE;QACjC,CAACH,sBAAsBI,OAAO,CAAC,EAAE,CAACC,UAC9B,CAAC,iBAAiB,EAAEA,QAAQC,IAAI,CAAC,EAAE,CAAC;QACxC,CAACN,sBAAsBO,SAAS,CAAC,EAAE;IACvC;AACJ;AAEA,MAAMC,WAAW;IACb,CAACR,sBAAsBI,OAAO,CAAC,EAAE;IACjC,CAACJ,sBAAsBO,SAAS,CAAC,EAAE;IACnC,CAACP,sBAAsBG,OAAO,CAAC,EAAE;AACrC;AAIA,OAAO,MAAMM,eAAe,CAAC,EAAEC,WAAW,EAAS;IAC/C,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,OAAOE,OAAOC,IAAI,CAACF,QAAQG,GAAG,CAAC,CAACC;QAC5B,MAAMC,YAAYD;QAClB,MAAME,YAAYN,MAAM,CAACK,UAAU;QAEnC,IAAIE,UAAyC;QAC7C,IAAIC,UACAlB,eAAe,CAACe,UAAU,CAAChB,sBAAsBG,OAAO,CAAC;QAE7D,IACIQ,MAAM,CAACK,UAAU,CAACI,YAAY,KAAKpB,sBAAsBO,SAAS,EACpE;YACEY,UACIlB,eAAe,CAACe,UAAU,CAAChB,sBAAsBO,SAAS,CAAC;YAC/DW,UAAU;QACd;QAEA,IAAIP,MAAM,CAACK,UAAU,CAACI,YAAY,KAAKpB,sBAAsBI,OAAO,EAAE;YAClEe,UAAUlB,eAAe,CAACe,UAAU,CAAChB,sBAAsBI,OAAO,CAAC,CAC/DO,MAAM,CAACK,UAAU,CAACK,QAAQ;YAE9BH,UAAU;QACd;QAEA,qBACI,oBAACrB;YAAcyB,KAAKN;YAAWE,SAASA;yBACpC,oBAACpB;YAAKyB,OAAOf,QAAQ,CAACS,UAAUG,YAAY,CAAC;WACxCH,UAAUG,YAAY,KACnBpB,sBAAsBO,SAAS,IAAI,KACtCY;IAIjB;AACJ,EAAE"}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import {
|
3
|
-
|
4
|
-
export declare class GenerateTypesCommand extends EnvironmentAwareCommand {
|
2
|
+
import { RenderableCommand } from '@/cli/commands/RenderableCommand.js';
|
3
|
+
export declare class GenerateTypesCommand extends RenderableCommand {
|
5
4
|
static paths: string[][];
|
6
5
|
static usage: import("clipanion").Usage;
|
6
|
+
output: string;
|
7
7
|
version: any;
|
8
|
-
|
8
|
+
render(): React.JSX.Element;
|
9
9
|
}
|
@@ -1,22 +1,28 @@
|
|
1
|
+
import { join } from 'node:path';
|
2
|
+
import * as process from 'node:process';
|
1
3
|
import { Command, Option } from 'clipanion';
|
2
4
|
import React from 'react';
|
3
5
|
import * as t from 'typanion';
|
4
|
-
import {
|
5
|
-
import { PlaydateSdkVersionIdentifier } from '
|
6
|
+
import { RenderableCommand } from '@/cli/commands/RenderableCommand.js';
|
7
|
+
import { PlaydateSdkVersionIdentifier } from '@/cli/types.js';
|
6
8
|
import { GenerateTypes } from './components/GenerateTypes.js';
|
7
|
-
export class GenerateTypesCommand extends
|
8
|
-
|
9
|
+
export class GenerateTypesCommand extends RenderableCommand {
|
10
|
+
render() {
|
11
|
+
const output = this.output.endsWith('.d.ts') ? this.output : join(this.output, 'playdate.d.ts');
|
9
12
|
return /*#__PURE__*/ React.createElement(GenerateTypes, {
|
10
|
-
|
13
|
+
output: output,
|
14
|
+
version: this.version
|
11
15
|
});
|
12
16
|
}
|
13
17
|
constructor(...args){
|
14
18
|
super(...args);
|
15
|
-
this.
|
16
|
-
|
17
|
-
|
19
|
+
this.output = Option.String('-o,--output', process.cwd(), {
|
20
|
+
description: `Where to generate the playdate.d.ts file. Defaults to the current working directory ("${process.cwd()}")`,
|
21
|
+
validator: t.isString()
|
22
|
+
});
|
23
|
+
this.version = Option.String({
|
24
|
+
name: 'version',
|
18
25
|
validator: t.isOneOf([
|
19
|
-
t.isLiteral(PlaydateSdkVersionIdentifier.FromConfig),
|
20
26
|
t.isLiteral(PlaydateSdkVersionIdentifier.Latest),
|
21
27
|
t.matchesRegExp(/^[0-9]+\.[0-9]+\.[0-9]+$/)
|
22
28
|
])
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/cli/src/commands/GenerateTypes/GenerateTypesCommand.tsx"],"sourcesContent":["import { Command, Option } from 'clipanion';\nimport React from 'react';\nimport * as t from 'typanion';\nimport { AnyStrictValidator } from 'typanion';\nimport {
|
1
|
+
{"version":3,"sources":["../../../../../../libs/cli/src/commands/GenerateTypes/GenerateTypesCommand.tsx"],"sourcesContent":["import { join } from 'node:path';\nimport * as process from 'node:process';\nimport { Command, Option } from 'clipanion';\nimport React from 'react';\nimport * as t from 'typanion';\nimport { AnyStrictValidator } from 'typanion';\nimport { RenderableCommand } from '@/cli/commands/RenderableCommand.js';\nimport { PlaydateSdkVersionIdentifier } from '@/cli/types.js';\nimport { GenerateTypes } from './components/GenerateTypes.js';\n\nexport class GenerateTypesCommand extends RenderableCommand {\n static override paths = [['generate-types']];\n static override usage = Command.Usage({\n description: 'Generate types from the Playdate SDK documentation',\n });\n\n output = Option.String('-o,--output', process.cwd(), {\n description: `Where to generate the playdate.d.ts file. Defaults to the current working directory (\"${process.cwd()}\")`,\n validator: t.isString(),\n });\n\n version = Option.String({\n name: 'version',\n validator: t.isOneOf([\n t.isLiteral(PlaydateSdkVersionIdentifier.Latest),\n t.matchesRegExp(/^[0-9]+\\.[0-9]+\\.[0-9]+$/) as AnyStrictValidator,\n ]),\n });\n\n override render() {\n const output = this.output.endsWith('.d.ts')\n ? this.output\n : join(this.output, 'playdate.d.ts');\n\n return <GenerateTypes output={output} version={this.version} />;\n }\n}\n"],"names":["join","process","Command","Option","React","t","RenderableCommand","PlaydateSdkVersionIdentifier","GenerateTypes","GenerateTypesCommand","render","output","endsWith","version","String","cwd","description","validator","isString","name","isOneOf","isLiteral","Latest","matchesRegExp","paths","usage","Usage"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AACjC,YAAYC,aAAa,eAAe;AACxC,SAASC,OAAO,EAAEC,MAAM,QAAQ,YAAY;AAC5C,OAAOC,WAAW,QAAQ;AAC1B,YAAYC,OAAO,WAAW;AAE9B,SAASC,iBAAiB,QAAQ,sCAAsC;AACxE,SAASC,4BAA4B,QAAQ,iBAAiB;AAC9D,SAASC,aAAa,QAAQ,gCAAgC;AAE9D,OAAO,MAAMC,6BAA6BH;IAmB7BI,SAAS;QACd,MAAMC,SAAS,IAAI,CAACA,MAAM,CAACC,QAAQ,CAAC,WAC9B,IAAI,CAACD,MAAM,GACXX,KAAK,IAAI,CAACW,MAAM,EAAE;QAExB,qBAAO,oBAACH;YAAcG,QAAQA;YAAQE,SAAS,IAAI,CAACA,OAAO;;IAC/D;;;aAnBAF,SAASR,OAAOW,MAAM,CAAC,eAAeb,QAAQc,GAAG,IAAI;YACjDC,aAAa,CAAC,sFAAsF,EAAEf,QAAQc,GAAG,GAAG,EAAE,CAAC;YACvHE,WAAWZ,EAAEa,QAAQ;QACzB;aAEAL,UAAUV,OAAOW,MAAM,CAAC;YACpBK,MAAM;YACNF,WAAWZ,EAAEe,OAAO,CAAC;gBACjBf,EAAEgB,SAAS,CAACd,6BAA6Be,MAAM;gBAC/CjB,EAAEkB,aAAa,CAAC;aACnB;QACL;;AASJ;AA1Bad,qBACOe,QAAQ;IAAC;QAAC;KAAiB;CAAC;AADnCf,qBAEOgB,QAAQvB,QAAQwB,KAAK,CAAC;IAClCV,aAAa;AACjB"}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import {
|
2
|
+
import { PlaydateSdkVersion } from '@/cli/types.js';
|
3
3
|
interface Props {
|
4
|
-
|
4
|
+
output: string;
|
5
|
+
version: PlaydateSdkVersion;
|
5
6
|
}
|
6
|
-
export declare const GenerateTypes: ({ version }: Props) => React.JSX.Element;
|
7
|
+
export declare const GenerateTypes: ({ output, version }: Props) => React.JSX.Element;
|
7
8
|
export {};
|
@@ -1,23 +1,27 @@
|
|
1
1
|
import React, { useMemo } from 'react';
|
2
|
-
import { useFetchHtml } from '
|
3
|
-
import { useGenerateTypeFile } from '
|
4
|
-
import { useGetVersion } from '
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
|
2
|
+
import { useFetchHtml } from '@/cli/commands/GenerateTypes/hooks/useFetchHtml.js';
|
3
|
+
import { useGenerateTypeFile } from '@/cli/commands/GenerateTypes/hooks/useGenerateTypeFile.js';
|
4
|
+
import { useGetVersion } from '@/cli/commands/GenerateTypes/hooks/useGetVersion.js';
|
5
|
+
import { useParseDocumentation } from '@/cli/commands/GenerateTypes/hooks/useParseDocumentation.js';
|
6
|
+
import { CheckList } from '@/cli/components/CheckList/index.js';
|
7
|
+
import { useQuitOnCtrlC } from '@/cli/hooks/useQuitOnCtrlC.js';
|
8
|
+
export const GenerateTypes = ({ output, version })=>{
|
8
9
|
useQuitOnCtrlC();
|
9
10
|
const { fetchedVersion, getVersion } = useGetVersion(version);
|
10
11
|
const { html, fetchHtml } = useFetchHtml(fetchedVersion);
|
11
|
-
const {
|
12
|
+
const { definitions, parseDocumentation } = useParseDocumentation(html, version);
|
13
|
+
const { generateTypeFile } = useGenerateTypeFile(output, definitions);
|
12
14
|
const items = useMemo(()=>{
|
13
15
|
return [
|
14
16
|
getVersion,
|
15
17
|
fetchHtml,
|
18
|
+
parseDocumentation,
|
16
19
|
generateTypeFile
|
17
20
|
];
|
18
21
|
}, [
|
19
22
|
fetchedVersion,
|
20
|
-
html
|
23
|
+
html,
|
24
|
+
definitions
|
21
25
|
]);
|
22
26
|
return /*#__PURE__*/ React.createElement(CheckList, {
|
23
27
|
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 {
|
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 { useQuitOnCtrlC } from '@/cli/hooks/useQuitOnCtrlC.js';\nimport { CheckListItem, PlaydateSdkVersion } from '@/cli/types.js';\n\ninterface Props {\n output: string;\n version: PlaydateSdkVersion;\n}\n\nexport const GenerateTypes = ({ output, version }: Props) => {\n useQuitOnCtrlC();\n\n const { fetchedVersion, getVersion } = useGetVersion(version);\n const { html, fetchHtml } = useFetchHtml(fetchedVersion);\n const { definitions, parseDocumentation } = useParseDocumentation(\n html,\n version\n );\n const { generateTypeFile } = useGenerateTypeFile(output, definitions);\n\n const items = useMemo(() => {\n return [\n getVersion,\n fetchHtml,\n parseDocumentation,\n generateTypeFile,\n ] as CheckListItem<unknown>[];\n }, [fetchedVersion, html, definitions]);\n\n return <CheckList items={items} onFinish={process.exit} />;\n};\n"],"names":["React","useMemo","useFetchHtml","useGenerateTypeFile","useGetVersion","useParseDocumentation","CheckList","useQuitOnCtrlC","GenerateTypes","output","version","fetchedVersion","getVersion","html","fetchHtml","definitions","parseDocumentation","generateTypeFile","items","onFinish","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,SAASC,OAAO,QAAQ,QAAQ;AACvC,SAASC,YAAY,QAAQ,qDAAqD;AAClF,SAASC,mBAAmB,QAAQ,4DAA4D;AAChG,SAASC,aAAa,QAAQ,sDAAsD;AACpF,SAASC,qBAAqB,QAAQ,8DAA8D;AACpG,SAASC,SAAS,QAAQ,sCAAsC;AAChE,SAASC,cAAc,QAAQ,gCAAgC;AAQ/D,OAAO,MAAMC,gBAAgB,CAAC,EAAEC,MAAM,EAAEC,OAAO,EAAS;IACpDH;IAEA,MAAM,EAAEI,cAAc,EAAEC,UAAU,EAAE,GAAGR,cAAcM;IACrD,MAAM,EAAEG,IAAI,EAAEC,SAAS,EAAE,GAAGZ,aAAaS;IACzC,MAAM,EAAEI,WAAW,EAAEC,kBAAkB,EAAE,GAAGX,sBACxCQ,MACAH;IAEJ,MAAM,EAAEO,gBAAgB,EAAE,GAAGd,oBAAoBM,QAAQM;IAEzD,MAAMG,QAAQjB,QAAQ;QAClB,OAAO;YACHW;YACAE;YACAE;YACAC;SACH;IACL,GAAG;QAACN;QAAgBE;QAAME;KAAY;IAEtC,qBAAO,oBAACT;QAAUY,OAAOA;QAAOC,UAAUC,QAAQC,IAAI;;AAC1D,EAAE"}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { ModuleDeclaration, SourceFile } from 'ts-morph';
|
2
|
+
import { PlaydateNamespace } from '@/cli/types.js';
|
3
|
+
export declare const generateNamespace: (subject: SourceFile | ModuleDeclaration, namespace: string, namespaceDescription: PlaydateNamespace, nextNamespaces: string[]) => void;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { TypescriptReservedNamed } from '@/cli/constants.js';
|
2
|
+
export const generateNamespace = (subject, namespace, namespaceDescription, nextNamespaces)=>{
|
3
|
+
const module = subject.addModule({
|
4
|
+
name: namespace.trim()
|
5
|
+
});
|
6
|
+
if (nextNamespaces.length) {
|
7
|
+
generateNamespace(module, nextNamespaces[0], namespaceDescription, nextNamespaces.slice(1));
|
8
|
+
} else {
|
9
|
+
for (const func of namespaceDescription.functions){
|
10
|
+
const isReserved = TypescriptReservedNamed.includes(func.name);
|
11
|
+
const name = isReserved ? `_${func.name}` : func.name;
|
12
|
+
module.addFunction({
|
13
|
+
name,
|
14
|
+
docs: [
|
15
|
+
func.docs
|
16
|
+
],
|
17
|
+
isExported: !isReserved
|
18
|
+
});
|
19
|
+
if (isReserved) {
|
20
|
+
module.addExportDeclaration({
|
21
|
+
namedExports: [
|
22
|
+
{
|
23
|
+
name,
|
24
|
+
alias: func.name
|
25
|
+
}
|
26
|
+
]
|
27
|
+
});
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
};
|
32
|
+
|
33
|
+
//# sourceMappingURL=generateNamespace.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/generateNamespace.ts"],"sourcesContent":["import { ModuleDeclaration, SourceFile } from 'ts-morph';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport { PlaydateNamespace } from '@/cli/types.js';\n\nexport const generateNamespace = (\n subject: SourceFile | ModuleDeclaration,\n namespace: string,\n namespaceDescription: PlaydateNamespace,\n nextNamespaces: string[]\n) => {\n const module = subject.addModule({\n name: namespace.trim(),\n });\n\n if (nextNamespaces.length) {\n generateNamespace(\n module,\n nextNamespaces[0],\n namespaceDescription,\n nextNamespaces.slice(1)\n );\n } else {\n for (const func of namespaceDescription.functions) {\n const isReserved = TypescriptReservedNamed.includes(func.name);\n\n const name = isReserved ? `_${func.name}` : func.name;\n\n module.addFunction({\n name,\n docs: [func.docs],\n isExported: !isReserved,\n });\n\n if (isReserved) {\n module.addExportDeclaration({\n namedExports: [\n {\n name,\n alias: func.name,\n },\n ],\n });\n }\n }\n }\n};\n"],"names":["TypescriptReservedNamed","generateNamespace","subject","namespace","namespaceDescription","nextNamespaces","module","addModule","name","trim","length","slice","func","functions","isReserved","includes","addFunction","docs","isExported","addExportDeclaration","namedExports","alias"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,uBAAuB,QAAQ,qBAAqB;AAG7D,OAAO,MAAMC,oBAAoB,CAC7BC,SACAC,WACAC,sBACAC;IAEA,MAAMC,SAASJ,QAAQK,SAAS,CAAC;QAC7BC,MAAML,UAAUM,IAAI;IACxB;IAEA,IAAIJ,eAAeK,MAAM,EAAE;QACvBT,kBACIK,QACAD,cAAc,CAAC,EAAE,EACjBD,sBACAC,eAAeM,KAAK,CAAC;IAE7B,OAAO;QACH,KAAK,MAAMC,QAAQR,qBAAqBS,SAAS,CAAE;YAC/C,MAAMC,aAAad,wBAAwBe,QAAQ,CAACH,KAAKJ,IAAI;YAE7D,MAAMA,OAAOM,aAAa,CAAC,CAAC,EAAEF,KAAKJ,IAAI,CAAC,CAAC,GAAGI,KAAKJ,IAAI;YAErDF,OAAOU,WAAW,CAAC;gBACfR;gBACAS,MAAM;oBAACL,KAAKK,IAAI;iBAAC;gBACjBC,YAAY,CAACJ;YACjB;YAEA,IAAIA,YAAY;gBACZR,OAAOa,oBAAoB,CAAC;oBACxBC,cAAc;wBACV;4BACIZ;4BACAa,OAAOT,KAAKJ,IAAI;wBACpB;qBACH;gBACL;YACJ;QACJ;IACJ;AACJ,EAAE"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { FunctionDescription, PlaydateNamespace, PlaydateType } from '@/cli/types.js';
|
2
|
+
export declare const getApiDefinitions: (functions: FunctionDescription[]) => {
|
3
|
+
namespaces: Record<string, PlaydateNamespace>;
|
4
|
+
types: Record<string, PlaydateType>;
|
5
|
+
constants: {
|
6
|
+
name: string;
|
7
|
+
values: {
|
8
|
+
name: string;
|
9
|
+
value: number;
|
10
|
+
docs: string;
|
11
|
+
}[];
|
12
|
+
docs: string;
|
13
|
+
}[];
|
14
|
+
};
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { playdateConstants } from '@/cli/commands/GenerateTypes/utils/playdateConstants.js';
|
2
|
+
export const getApiDefinitions = (functions)=>{
|
3
|
+
const namespaces = {};
|
4
|
+
const types = {};
|
5
|
+
const realNamespaces = new Set();
|
6
|
+
const potentialNamespaces = new Set();
|
7
|
+
functions.forEach((func)=>{
|
8
|
+
if (!func.hasSelf) {
|
9
|
+
let currentNamespace = '';
|
10
|
+
func.namespaces.forEach((ns)=>{
|
11
|
+
currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
|
12
|
+
// Add to realNamespaces because there's a non-method function here
|
13
|
+
realNamespaces.add(currentNamespace);
|
14
|
+
});
|
15
|
+
}
|
16
|
+
});
|
17
|
+
functions.forEach((func)=>{
|
18
|
+
if (func.hasSelf) {
|
19
|
+
let currentNamespace = '';
|
20
|
+
func.namespaces.forEach((ns)=>{
|
21
|
+
currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
|
22
|
+
if (!realNamespaces.has(currentNamespace)) {
|
23
|
+
potentialNamespaces.add(currentNamespace);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
}
|
27
|
+
});
|
28
|
+
realNamespaces.forEach((ns)=>{
|
29
|
+
namespaces[ns] = {
|
30
|
+
functions: [],
|
31
|
+
callbacks: []
|
32
|
+
};
|
33
|
+
});
|
34
|
+
functions.forEach((func)=>{
|
35
|
+
const fullNamespacePath = func.namespaces.join('.');
|
36
|
+
if (realNamespaces.has(fullNamespacePath)) {
|
37
|
+
if (func.hasSelf) {
|
38
|
+
namespaces[fullNamespacePath].callbacks.push(func);
|
39
|
+
} else {
|
40
|
+
namespaces[fullNamespacePath].functions.push(func);
|
41
|
+
}
|
42
|
+
} else if (potentialNamespaces.has(fullNamespacePath)) {
|
43
|
+
if (!types[fullNamespacePath]) {
|
44
|
+
types[fullNamespacePath] = {
|
45
|
+
methods: []
|
46
|
+
};
|
47
|
+
}
|
48
|
+
types[fullNamespacePath].methods.push(func);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
return {
|
52
|
+
namespaces,
|
53
|
+
types,
|
54
|
+
constants: playdateConstants
|
55
|
+
};
|
56
|
+
};
|
57
|
+
|
58
|
+
//# sourceMappingURL=getApiDefinitions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getApiDefinitions.ts"],"sourcesContent":["import { playdateConstants } from '@/cli/commands/GenerateTypes/utils/playdateConstants.js';\nimport {\n ApiDefinitions,\n FunctionDescription,\n PlaydateNamespace,\n PlaydateType,\n} from '@/cli/types.js';\n\nexport const getApiDefinitions = (functions: FunctionDescription[]) => {\n const namespaces: Record<string, PlaydateNamespace> = {};\n const types: Record<string, PlaydateType> = {};\n const realNamespaces = new Set<string>();\n const potentialNamespaces: Set<string> = new Set();\n\n functions.forEach((func) => {\n if (!func.hasSelf) {\n let currentNamespace = '';\n func.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n // Add to realNamespaces because there's a non-method function here\n realNamespaces.add(currentNamespace);\n });\n }\n });\n\n functions.forEach((func) => {\n if (func.hasSelf) {\n let currentNamespace = '';\n func.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n if (!realNamespaces.has(currentNamespace)) {\n potentialNamespaces.add(currentNamespace);\n }\n });\n }\n });\n\n realNamespaces.forEach((ns) => {\n namespaces[ns] = {\n functions: [],\n callbacks: [],\n };\n });\n\n functions.forEach((func) => {\n const fullNamespacePath = func.namespaces.join('.');\n\n if (realNamespaces.has(fullNamespacePath)) {\n if (func.hasSelf) {\n namespaces[fullNamespacePath].callbacks.push(func);\n } else {\n namespaces[fullNamespacePath].functions.push(func);\n }\n } else if (potentialNamespaces.has(fullNamespacePath)) {\n if (!types[fullNamespacePath]) {\n types[fullNamespacePath] = { methods: [] };\n }\n types[fullNamespacePath].methods.push(func);\n }\n });\n\n return {\n namespaces,\n types,\n constants: playdateConstants,\n } satisfies ApiDefinitions;\n};\n"],"names":["playdateConstants","getApiDefinitions","functions","namespaces","types","realNamespaces","Set","potentialNamespaces","forEach","func","hasSelf","currentNamespace","ns","add","has","callbacks","fullNamespacePath","join","push","methods","constants"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,iBAAiB,QAAQ,0DAA0D;AAQ5F,OAAO,MAAMC,oBAAoB,CAACC;IAC9B,MAAMC,aAAgD,CAAC;IACvD,MAAMC,QAAsC,CAAC;IAC7C,MAAMC,iBAAiB,IAAIC;IAC3B,MAAMC,sBAAmC,IAAID;IAE7CJ,UAAUM,OAAO,CAAC,CAACC;QACf,IAAI,CAACA,KAAKC,OAAO,EAAE;YACf,IAAIC,mBAAmB;YACvBF,KAAKN,UAAU,CAACK,OAAO,CAAC,CAACI;gBACrBD,mBAAmBA,mBACb,CAAC,EAAEA,iBAAiB,CAAC,EAAEC,GAAG,CAAC,GAC3BA;gBAEN,mEAAmE;gBACnEP,eAAeQ,GAAG,CAACF;YACvB;QACJ;IACJ;IAEAT,UAAUM,OAAO,CAAC,CAACC;QACf,IAAIA,KAAKC,OAAO,EAAE;YACd,IAAIC,mBAAmB;YACvBF,KAAKN,UAAU,CAACK,OAAO,CAAC,CAACI;gBACrBD,mBAAmBA,mBACb,CAAC,EAAEA,iBAAiB,CAAC,EAAEC,GAAG,CAAC,GAC3BA;gBAEN,IAAI,CAACP,eAAeS,GAAG,CAACH,mBAAmB;oBACvCJ,oBAAoBM,GAAG,CAACF;gBAC5B;YACJ;QACJ;IACJ;IAEAN,eAAeG,OAAO,CAAC,CAACI;QACpBT,UAAU,CAACS,GAAG,GAAG;YACbV,WAAW,EAAE;YACba,WAAW,EAAE;QACjB;IACJ;IAEAb,UAAUM,OAAO,CAAC,CAACC;QACf,MAAMO,oBAAoBP,KAAKN,UAAU,CAACc,IAAI,CAAC;QAE/C,IAAIZ,eAAeS,GAAG,CAACE,oBAAoB;YACvC,IAAIP,KAAKC,OAAO,EAAE;gBACdP,UAAU,CAACa,kBAAkB,CAACD,SAAS,CAACG,IAAI,CAACT;YACjD,OAAO;gBACHN,UAAU,CAACa,kBAAkB,CAACd,SAAS,CAACgB,IAAI,CAACT;YACjD;QACJ,OAAO,IAAIF,oBAAoBO,GAAG,CAACE,oBAAoB;YACnD,IAAI,CAACZ,KAAK,CAACY,kBAAkB,EAAE;gBAC3BZ,KAAK,CAACY,kBAAkB,GAAG;oBAAEG,SAAS,EAAE;gBAAC;YAC7C;YACAf,KAAK,CAACY,kBAAkB,CAACG,OAAO,CAACD,IAAI,CAACT;QAC1C;IACJ;IAEA,OAAO;QACHN;QACAC;QACAgB,WAAWpB;IACf;AACJ,EAAE"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
2
|
+
import { load } from 'cheerio';
|
3
|
+
import { PlaydateSdkUrl } from '@/cli/commands/GenerateTypes/constants.js';
|
4
|
+
import { parseFunctionSignature } from '@/cli/commands/GenerateTypes/fn/parseFunctionSignature.js';
|
5
|
+
export const getFunctionDescriptionsFromHtml = (html, version)=>{
|
6
|
+
const $ = load(html);
|
7
|
+
const allSignatures = $('[id^="m-"], [id^="f-"], [id^="c-"]').toArray();
|
8
|
+
const result = [];
|
9
|
+
for (const element of allSignatures){
|
10
|
+
var _$_attr;
|
11
|
+
const id = (_$_attr = $(element).attr('id')) != null ? _$_attr : '';
|
12
|
+
var _$_find_text;
|
13
|
+
const titles = ((_$_find_text = $(element).find('.title').text()) != null ? _$_find_text : '').split(' ');
|
14
|
+
var _$_find_html;
|
15
|
+
let docsString = ((_$_find_html = $(element).find('.content').html()) != null ? _$_find_html : '').trim();
|
16
|
+
if (docsString.startsWith('<div class="paragraph">')) {
|
17
|
+
docsString = docsString.slice('<div class="paragraph">'.length);
|
18
|
+
}
|
19
|
+
if (docsString.endsWith('</div>')) {
|
20
|
+
docsString = docsString.slice(0, docsString.length - '</div>'.length);
|
21
|
+
}
|
22
|
+
docsString = docsString.replace(/<a href="#/g, '<a href="' + PlaydateSdkUrl + version + '#');
|
23
|
+
const docs = id ? `${docsString}\n[Read more](${PlaydateSdkUrl}${version}#${id})` : docsString;
|
24
|
+
for (const title of titles){
|
25
|
+
try {
|
26
|
+
result.push(_extends({}, parseFunctionSignature(title), {
|
27
|
+
docs
|
28
|
+
}));
|
29
|
+
} catch (e) {
|
30
|
+
// skip
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
return result;
|
35
|
+
};
|
36
|
+
|
37
|
+
//# sourceMappingURL=getFunctionDescriptionsFromHtml.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getFunctionDescriptionsFromHtml.ts"],"sourcesContent":["import { load } from 'cheerio';\nimport { PlaydateSdkUrl } from '@/cli/commands/GenerateTypes/constants.js';\nimport { parseFunctionSignature } from '@/cli/commands/GenerateTypes/fn/parseFunctionSignature.js';\nimport { FunctionDescription } from '@/cli/types.js';\n\nexport const getFunctionDescriptionsFromHtml = (\n html: string,\n version: string\n) => {\n const $ = load(html);\n\n const allSignatures = $('[id^=\"m-\"], [id^=\"f-\"], [id^=\"c-\"]').toArray();\n const result: FunctionDescription[] = [];\n\n for (const element of allSignatures) {\n const id = $(element).attr('id') ?? '';\n const titles = ($(element).find('.title').text() ?? '').split(' ');\n let docsString = ($(element).find('.content').html() ?? '').trim();\n\n if (docsString.startsWith('<div class=\"paragraph\">')) {\n docsString = docsString.slice('<div class=\"paragraph\">'.length);\n }\n\n if (docsString.endsWith('</div>')) {\n docsString = docsString.slice(\n 0,\n docsString.length - '</div>'.length\n );\n }\n\n docsString = docsString.replace(\n /<a href=\"#/g,\n '<a href=\"' + PlaydateSdkUrl + version + '#'\n );\n\n const docs = id\n ? `${docsString}\\n[Read more](${PlaydateSdkUrl}${version}#${id})`\n : docsString;\n\n for (const title of titles) {\n try {\n result.push({ ...parseFunctionSignature(title), docs });\n } catch (e) {\n // skip\n }\n }\n }\n\n return result;\n};\n"],"names":["load","PlaydateSdkUrl","parseFunctionSignature","getFunctionDescriptionsFromHtml","html","version","$","allSignatures","toArray","result","element","id","attr","titles","find","text","split","docsString","trim","startsWith","slice","length","endsWith","replace","docs","title","push","e"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,IAAI,QAAQ,UAAU;AAC/B,SAASC,cAAc,QAAQ,4CAA4C;AAC3E,SAASC,sBAAsB,QAAQ,4DAA4D;AAGnG,OAAO,MAAMC,kCAAkC,CAC3CC,MACAC;IAEA,MAAMC,IAAIN,KAAKI;IAEf,MAAMG,gBAAgBD,EAAE,sCAAsCE,OAAO;IACrE,MAAMC,SAAgC,EAAE;IAExC,KAAK,MAAMC,WAAWH,cAAe;YACtBD;QAAX,MAAMK,KAAKL,CAAAA,UAAAA,EAAEI,SAASE,IAAI,CAAC,iBAAhBN,UAAyB;YACpBA;QAAhB,MAAMO,SAAS,AAACP,CAAAA,CAAAA,eAAAA,EAAEI,SAASI,IAAI,CAAC,UAAUC,IAAI,cAA9BT,eAAoC,EAAC,EAAGU,KAAK,CAAC;YAC5CV;QAAlB,IAAIW,aAAa,AAACX,CAAAA,CAAAA,eAAAA,EAAEI,SAASI,IAAI,CAAC,YAAYV,IAAI,cAAhCE,eAAsC,EAAC,EAAGY,IAAI;QAEhE,IAAID,WAAWE,UAAU,CAAC,4BAA4B;YAClDF,aAAaA,WAAWG,KAAK,CAAC,0BAA0BC,MAAM;QAClE;QAEA,IAAIJ,WAAWK,QAAQ,CAAC,WAAW;YAC/BL,aAAaA,WAAWG,KAAK,CACzB,GACAH,WAAWI,MAAM,GAAG,SAASA,MAAM;QAE3C;QAEAJ,aAAaA,WAAWM,OAAO,CAC3B,eACA,cAActB,iBAAiBI,UAAU;QAG7C,MAAMmB,OAAOb,KACP,CAAC,EAAEM,WAAW,cAAc,EAAEhB,eAAe,EAAEI,QAAQ,CAAC,EAAEM,GAAG,CAAC,CAAC,GAC/DM;QAEN,KAAK,MAAMQ,SAASZ,OAAQ;YACxB,IAAI;gBACAJ,OAAOiB,IAAI,CAAC,aAAKxB,uBAAuBuB;oBAAQD;;YACpD,EAAE,OAAOG,GAAG;YACR,OAAO;YACX;QACJ;IACJ;IAEA,OAAOlB;AACX,EAAE"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export const parseFunctionSignature = (signature)=>{
|
2
|
+
if (!signature.includes('(')) {
|
3
|
+
throw new Error('Invalid signature');
|
4
|
+
}
|
5
|
+
const [fullyQualifiedName, paramString] = signature.split('(');
|
6
|
+
const hasSelf = fullyQualifiedName.includes(':');
|
7
|
+
const normalizedFullyQualifiedName = fullyQualifiedName.replace(':', '.');
|
8
|
+
const segments = normalizedFullyQualifiedName.split('.');
|
9
|
+
const functionName = segments[segments.length - 1];
|
10
|
+
const namespaces = segments.slice(0, -1);
|
11
|
+
const params = paramString.split(')')[0].split(',').filter(Boolean);
|
12
|
+
return {
|
13
|
+
name: functionName,
|
14
|
+
namespaces,
|
15
|
+
parameters: params.map((eachParam)=>({
|
16
|
+
name: eachParam.replace(/\[/g, '').replace(/\]/g, '').trim(),
|
17
|
+
type: 'unknown',
|
18
|
+
required: !eachParam.includes('[')
|
19
|
+
})),
|
20
|
+
hasSelf
|
21
|
+
};
|
22
|
+
};
|
23
|
+
|
24
|
+
//# 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 if (!signature.includes('(')) {\n throw new Error('Invalid signature');\n }\n\n const [fullyQualifiedName, paramString] = signature.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 name: functionName,\n namespaces,\n parameters: params.map((eachParam) => ({\n name: eachParam.replace(/\\[/g, '').replace(/\\]/g, '').trim(),\n type: 'unknown',\n required: !eachParam.includes('['),\n })),\n hasSelf,\n } satisfies Omit<FunctionDescription, 'docs'>;\n};\n"],"names":["parseFunctionSignature","signature","includes","Error","fullyQualifiedName","paramString","split","hasSelf","normalizedFullyQualifiedName","replace","segments","functionName","length","namespaces","slice","params","filter","Boolean","name","parameters","map","eachParam","trim","type","required"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,yBAAyB,CAACC;IACnC,IAAI,CAACA,UAAUC,QAAQ,CAAC,MAAM;QAC1B,MAAM,IAAIC,MAAM;IACpB;IAEA,MAAM,CAACC,oBAAoBC,YAAY,GAAGJ,UAAUK,KAAK,CAAC;IAC1D,MAAMC,UAAUH,mBAAmBF,QAAQ,CAAC;IAC5C,MAAMM,+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;QACHC,MAAMP;QACNE;QACAM,YAAYJ,OAAOK,GAAG,CAAC,CAACC,YAAe,CAAA;gBACnCH,MAAMG,UAAUZ,OAAO,CAAC,OAAO,IAAIA,OAAO,CAAC,OAAO,IAAIa,IAAI;gBAC1DC,MAAM;gBACNC,UAAU,CAACH,UAAUnB,QAAQ,CAAC;YAClC,CAAA;QACAK;IACJ;AACJ,EAAE"}
|