crankscript 0.10.3 → 0.10.5-beta.1

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 CHANGED
@@ -1,32 +1,32 @@
1
1
  {
2
- "name": "crankscript",
3
- "version": "0.10.3",
4
- "scripts": {
5
- "dev": "tsx src/index.ts",
6
- "post-build": "tsc-alias --project tsconfig.json",
7
- "prepare-assets": "npx tsc -p assets/tsconfig.json"
8
- },
9
- "bin": {
10
- "crankscript": "./src/index.js"
11
- },
12
- "license": "MIT",
13
- "dependencies": {
14
- "@inkjs/ui": "^2.0.0",
15
- "@swc/helpers": "~0.5.11",
16
- "cheerio": "^1.0.0",
17
- "clipanion": "^4.0.0-rc.4",
18
- "ink": "^5.0.1",
19
- "open": "^10.1.0",
20
- "react": "^18.3.1",
21
- "tiged": "^3.0.0-rc.0",
22
- "ts-morph": "^23.0.0",
23
- "turndown": "^7.2.0",
24
- "typanion": "^3.14.0",
25
- "typescript-to-lua": "^1.27.0"
26
- },
27
- "type": "module",
28
- "main": "./src/index.js",
29
- "typings": "./src/index.d.ts",
30
- "module": "./src/index.js",
31
- "types": "./src/index.d.ts"
2
+ "name": "crankscript",
3
+ "version": "0.10.5-beta.1",
4
+ "scripts": {
5
+ "dev": "tsx src/index.ts",
6
+ "post-build": "tsc-alias --project tsconfig.json",
7
+ "prepare-assets": "npx tsc -p assets/tsconfig.json"
8
+ },
9
+ "bin": {
10
+ "crankscript": "./src/index.js"
11
+ },
12
+ "license": "MIT",
13
+ "dependencies": {
14
+ "@inkjs/ui": "^2.0.0",
15
+ "@swc/helpers": "~0.5.11",
16
+ "cheerio": "^1.0.0",
17
+ "clipanion": "^4.0.0-rc.4",
18
+ "ink": "^5.0.1",
19
+ "open": "^10.1.0",
20
+ "react": "^18.3.1",
21
+ "tiged": "^3.0.0-rc.0",
22
+ "ts-morph": "^23.0.0",
23
+ "turndown": "^7.2.0",
24
+ "typanion": "^3.14.0",
25
+ "typescript-to-lua": "^1.27.0"
26
+ },
27
+ "type": "module",
28
+ "main": "./src/index.js",
29
+ "typings": "./src/index.d.ts",
30
+ "module": "./src/index.js",
31
+ "types": "./src/index.d.ts"
32
32
  }
@@ -1,6 +1,7 @@
1
1
  import { join } from 'node:path';
2
+ import { appendExeOnWindows } from '../../../utils/appendExeOnWindows.js';
2
3
  export const getPdcPathFromEnvironment = (environment)=>{
3
- return join(environment.sdkPath.path, 'bin', 'pdc');
4
+ return join(environment.sdkPath.path, 'bin', appendExeOnWindows('pdc'));
4
5
  };
5
6
 
6
7
  //# sourceMappingURL=getPdcPathFromEnvironment.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/CompileCommand/fn/getPdcPathFromEnvironment.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\n\nexport const getPdcPathFromEnvironment = (environment: Environment) => {\n return join(environment.sdkPath.path, 'bin', 'pdc');\n};\n"],"names":["join","getPdcPathFromEnvironment","environment","sdkPath","path"],"rangeMappings":";;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AAGjC,OAAO,MAAMC,4BAA4B,CAACC;IACtC,OAAOF,KAAKE,YAAYC,OAAO,CAACC,IAAI,EAAE,OAAO;AACjD,EAAE"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/CompileCommand/fn/getPdcPathFromEnvironment.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { appendExeOnWindows } from '@/cli/utils/appendExeOnWindows.js';\n\nexport const getPdcPathFromEnvironment = (environment: Environment) => {\n return join(environment.sdkPath.path, 'bin', appendExeOnWindows('pdc'));\n};\n"],"names":["join","appendExeOnWindows","getPdcPathFromEnvironment","environment","sdkPath","path"],"rangeMappings":";;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AAEjC,SAASC,kBAAkB,QAAQ,oCAAoC;AAEvE,OAAO,MAAMC,4BAA4B,CAACC;IACtC,OAAOH,KAAKG,YAAYC,OAAO,CAACC,IAAI,EAAE,OAAOJ,mBAAmB;AACpE,EAAE"}
@@ -1,6 +1,7 @@
1
- import { spawn } from 'node:child_process';
2
1
  import { existsSync } from 'node:fs';
2
+ import open from 'open';
3
3
  import { useMemo } from 'react';
4
+ import { isWindows } from '../../../utils/platform.js';
4
5
  export const useCompileTasks = (pdcPath)=>{
5
6
  return useMemo(()=>[
6
7
  {
@@ -22,35 +23,20 @@ export const useCompileTasks = (pdcPath)=>{
22
23
  runningDescription: 'Compiling lua code...',
23
24
  finishedDescription: ()=>'Lua code compiled',
24
25
  runner: async ()=>{
25
- return new Promise((resolve, reject)=>{
26
- const pdc = spawn(pdcPath, [
27
- 'Source',
28
- 'Game.pdx'
29
- ]);
30
- // Collect any standard output or errors
31
- let stdout = '';
32
- let stderr = '';
33
- // Handle stdout (standard output)
34
- pdc.stdout.on('data', (data)=>{
35
- stdout += data.toString();
36
- });
37
- // Handle stderr (standard error)
38
- pdc.stderr.on('data', (data)=>{
39
- stderr += data.toString();
40
- });
41
- // Handle the process closing
42
- pdc.on('close', (code)=>{
43
- if (code === 0) {
44
- resolve(stdout); // Resolve the promise with the output
45
- } else {
46
- reject(new Error(`pdc exited with code ${code}: ${stderr}`));
47
- }
48
- });
49
- // Handle any errors that occur while starting the process
50
- pdc.on('error', (err)=>{
51
- reject(new Error(`Failed to start pdc process: ${err.message}`));
52
- });
26
+ await open('', {
27
+ app: {
28
+ name: pdcPath,
29
+ arguments: [
30
+ 'Source',
31
+ 'Game.pdx'
32
+ ]
33
+ }
53
34
  });
35
+ if (isWindows) {
36
+ // Wait for pdc.exe to compile
37
+ // See https://github.com/sindresorhus/open/issues/298
38
+ await new Promise((resolve)=>setTimeout(resolve, 1000));
39
+ }
54
40
  },
55
41
  ready: true
56
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/CompileCommand/hooks/useCompileTasks.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { useMemo } from 'react';\nimport { CheckListItem } from '@/cli/types.js';\n\nexport const useCompileTasks = (pdcPath: string) => {\n return useMemo(\n () => [\n {\n waitingDescription: 'Waiting to check for pdc binary...',\n errorDescription: 'Could not find pdc binary',\n runningDescription: 'Checking for pdc binary...',\n finishedDescription: (result) =>\n `Found pdc binary at \"${result}\"`,\n runner: async () => {\n if (!existsSync(pdcPath)) {\n throw new Error('Could not find pdc binary');\n }\n\n return pdcPath;\n },\n ready: true,\n } satisfies CheckListItem<string>,\n {\n waitingDescription: 'Waiting for pdc binary path...',\n errorDescription: 'Could not compile lua code',\n runningDescription: 'Compiling lua code...',\n finishedDescription: () => 'Lua code compiled',\n runner: async () => {\n return new Promise((resolve, reject) => {\n const pdc = spawn(pdcPath, ['Source', 'Game.pdx']);\n\n // Collect any standard output or errors\n let stdout = '';\n let stderr = '';\n\n // Handle stdout (standard output)\n pdc.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n\n // Handle stderr (standard error)\n pdc.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n // Handle the process closing\n pdc.on('close', (code) => {\n if (code === 0) {\n resolve(stdout); // Resolve the promise with the output\n } else {\n reject(\n new Error(\n `pdc exited with code ${code}: ${stderr}`\n )\n );\n }\n });\n\n // Handle any errors that occur while starting the process\n pdc.on('error', (err) => {\n reject(\n new Error(\n `Failed to start pdc process: ${err.message}`\n )\n );\n });\n });\n },\n ready: true,\n },\n ],\n []\n ) as CheckListItem<unknown>[];\n};\n"],"names":["spawn","existsSync","useMemo","useCompileTasks","pdcPath","waitingDescription","errorDescription","runningDescription","finishedDescription","result","runner","Error","ready","Promise","resolve","reject","pdc","stdout","stderr","on","data","toString","code","err","message"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,KAAK,QAAQ,qBAAqB;AAC3C,SAASC,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AAE"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/CompileCommand/hooks/useCompileTasks.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport open from 'open';\nimport { useMemo } from 'react';\nimport { CheckListItem } from '@/cli/types.js';\nimport { isWindows } from '@/cli/utils/platform.js';\n\nexport const useCompileTasks = (pdcPath: string) => {\n return useMemo(\n () => [\n {\n waitingDescription: 'Waiting to check for pdc binary...',\n errorDescription: 'Could not find pdc binary',\n runningDescription: 'Checking for pdc binary...',\n finishedDescription: (result) =>\n `Found pdc binary at \"${result}\"`,\n runner: async () => {\n if (!existsSync(pdcPath)) {\n throw new Error('Could not find pdc binary');\n }\n\n return pdcPath;\n },\n ready: true,\n } satisfies CheckListItem<string>,\n {\n waitingDescription: 'Waiting for pdc binary path...',\n errorDescription: 'Could not compile lua code',\n runningDescription: 'Compiling lua code...',\n finishedDescription: () => 'Lua code compiled',\n runner: async () => {\n await open('', {\n app: {\n name: pdcPath,\n arguments: ['Source', 'Game.pdx'],\n },\n });\n\n if (isWindows) {\n // Wait for pdc.exe to compile\n // See https://github.com/sindresorhus/open/issues/298\n await new Promise((resolve) =>\n setTimeout(resolve, 1000)\n );\n }\n },\n ready: true,\n },\n ],\n []\n ) as CheckListItem<unknown>[];\n};\n"],"names":["existsSync","open","useMemo","isWindows","useCompileTasks","pdcPath","waitingDescription","errorDescription","runningDescription","finishedDescription","result","runner","Error","ready","app","name","arguments","Promise","resolve","setTimeout"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,UAAU;AACrC,OAAOC,UAAU,OAAO;AACxB,SAASC,OAAO,QAAQ,QAAQ;AAEhC,SAASC,SAAS,QAAQ,0BAA0B;AAEpD,OAAO,MAAMC,kBAAkB,CAACC;IAC5B,OAAOH,QACH,IAAM;YACF;gBACII,oBAAoB;gBACpBC,kBAAkB;gBAClBC,oBAAoB;gBACpBC,qBAAqB,CAACC,SAClB,CAAC,qBAAqB,EAAEA,OAAO,CAAC,CAAC;gBACrCC,QAAQ;oBACJ,IAAI,CAACX,WAAWK,UAAU;wBACtB,MAAM,IAAIO,MAAM;oBACpB;oBAEA,OAAOP;gBACX;gBACAQ,OAAO;YACX;YACA;gBACIP,oBAAoB;gBACpBC,kBAAkB;gBAClBC,oBAAoB;gBACpBC,qBAAqB,IAAM;gBAC3BE,QAAQ;oBACJ,MAAMV,KAAK,IAAI;wBACXa,KAAK;4BACDC,MAAMV;4BACNW,WAAW;gCAAC;gCAAU;6BAAW;wBACrC;oBACJ;oBAEA,IAAIb,WAAW;wBACX,8BAA8B;wBAC9B,sDAAsD;wBACtD,MAAM,IAAIc,QAAQ,CAACC,UACfC,WAAWD,SAAS;oBAE5B;gBACJ;gBACAL,OAAO;YACX;SACH,EACD,EAAE;AAEV,EAAE"}
@@ -24,7 +24,7 @@ export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
24
24
  const globalNamespace = definitions.global;
25
25
  typeFile.addStatements(typeProvider.getGlobalStatements());
26
26
  generateNamespace(globalNamespace, typeFile, typeProvider, '');
27
- writeFileSync(path, typeFile.getFullText().replace('/**', '\n/**'));
27
+ writeFileSync(path, typeFile.getFullText().replace('*/', '*/\n'));
28
28
  },
29
29
  ready: definitions !== null && typeProvider !== null
30
30
  };
@@ -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} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport { ApiDefinitions, ApiObject, CheckListItem } from '@/cli/types.js';\n\nexport const useGenerateTypeFile = (\n path: string,\n definitions: ApiDefinitions | null,\n typeProvider: ReturnType<typeof createTypeProvider> | null\n) => {\n const generateTypeFile = useMemo(() => {\n return {\n waitingDescription: 'Waiting to generate the type file...',\n errorDescription: 'Failed to generate the type file',\n finishedDescription: () => 'Type file generated',\n runningDescription: 'Generating the type file...',\n runner: async () => {\n if (!definitions) {\n throw new Error('Definitions are not set');\n }\n\n if (!typeProvider) {\n throw new Error('Type provider is not set');\n }\n\n const project = new Project();\n const typeFile = project.createSourceFile(path, '', {\n overwrite: true,\n });\n\n const globalNamespace = definitions.global;\n\n typeFile.addStatements(typeProvider.getGlobalStatements());\n\n generateNamespace(globalNamespace, typeFile, typeProvider, '');\n\n writeFileSync(\n path,\n typeFile.getFullText().replace('/**', '\\n/**')\n );\n },\n ready: definitions !== null && typeProvider !== null,\n } satisfies CheckListItem<void>;\n }, [definitions, typeProvider]);\n\n return {\n generateTypeFile,\n };\n};\n\nconst generateNamespace = (\n apiObject: ApiObject,\n incomingSubject: SourceFile | ModuleDeclaration,\n typeProvider: ReturnType<typeof createTypeProvider>,\n namespace: string,\n name?: string\n) => {\n let subject = incomingSubject;\n const fullNamespaceName = [namespace, name].filter(Boolean).join('.');\n\n if (name) {\n subject = incomingSubject.addModule({\n name,\n });\n }\n\n if (name === 'playdate') {\n subject.addStatements(typeProvider.getStatements());\n }\n\n for (const func of apiObject.functions) {\n const isFunctionNameReserved = TypescriptReservedNamed.includes(\n func.name\n );\n const resolvedName = `_${func.name}`;\n const parameters = typeProvider.getParameters(func);\n\n subject.addFunction({\n name: isFunctionNameReserved ? resolvedName : func.name,\n docs: [func.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(func),\n isExported: !!name,\n ...(typeProvider.getFunctionOverrideOptions(\n func\n ) as FunctionDeclarationStructure),\n });\n\n if (isFunctionNameReserved) {\n subject.addExportDeclaration({\n namedExports: [\n {\n name: resolvedName,\n alias: func.name,\n },\n ],\n });\n }\n }\n\n let propertiesSubject: ClassDeclaration | null = null;\n\n if (name && apiObject.methods.length > 0) {\n const typeClass = incomingSubject.addClass({\n name,\n ...typeProvider.getClassOptions(fullNamespaceName),\n });\n propertiesSubject = typeClass;\n\n for (const method of apiObject.methods) {\n const parameters = typeProvider.getParameters(method);\n\n typeClass.addMethod({\n name: method.name,\n docs: [method.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(method),\n ...(typeProvider.getFunctionOverrideOptions(\n method\n ) as Partial<MethodDeclarationStructure>),\n });\n }\n }\n\n for (const property of apiObject.properties) {\n const propertyDetails = typeProvider.getPropertyDetails(property);\n\n if (propertiesSubject) {\n propertiesSubject.addProperty({\n name: property.name,\n docs: [property.docs],\n type: propertyDetails.type,\n isStatic: propertyDetails.isStatic,\n isReadonly: propertyDetails.isReadOnly,\n });\n } else {\n subject.addVariableStatement({\n docs: [property.docs],\n declarations: [\n {\n name: property.name,\n type: propertyDetails.type,\n },\n ],\n });\n }\n }\n\n for (const eachNamespace of Object.entries(apiObject.namespaces)) {\n generateNamespace(\n eachNamespace[1],\n subject,\n typeProvider,\n fullNamespaceName,\n eachNamespace[0]\n );\n }\n};\n"],"names":["writeFileSync","useMemo","Project","TypescriptReservedNamed","useGenerateTypeFile","path","definitions","typeProvider","generateTypeFile","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","project","typeFile","createSourceFile","overwrite","globalNamespace","global","addStatements","getGlobalStatements","generateNamespace","getFullText","replace","ready","apiObject","incomingSubject","namespace","name","subject","fullNamespaceName","filter","Boolean","join","addModule","getStatements","func","functions","isFunctionNameReserved","includes","resolvedName","parameters","getParameters","addFunction","docs","returnType","getFunctionReturnType","isExported","getFunctionOverrideOptions","addExportDeclaration","namedExports","alias","propertiesSubject","methods","length","typeClass","addClass","getClassOptions","method","addMethod","property","properties","propertyDetails","getPropertyDetails","addProperty","type","isStatic","isReadonly","isReadOnly","addVariableStatement","declarations","eachNamespace","Object","entries","namespaces"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AI;gBACnBgB,MAAM;oBAACgB,SAAShB,IAAI;iBAAC;gBACrBqB,MAAMH,gBAAgBG,IAAI;gBAC1BC,UAAUJ,gBAAgBI,QAAQ;gBAClCC,YAAYL,gBAAgBM,UAAU;YAC1C;QACJ,OAAO;YACHvC,QAAQwC,oBAAoB,CAAC;gBACzBzB,MAAM;oBAACgB,SAAShB,IAAI;iBAAC;gBACrB0B,cAAc;oBACV;wBACI1C,MAAMgC,SAAShC,IAAI;wBACnBqC,MAAMH,gBAAgBG,IAAI;oBAC9B;iBACH;YACL;QACJ;IACJ;IAEA,KAAK,MAAMM,iBAAiBC,OAAOC,OAAO,CAAChD,UAAUiD,UAAU,EAAG;QAC9DrD,kBACIkD,aAAa,CAAC,EAAE,EAChB1C,SACAxB,cACAyB,mBACAyC,aAAa,CAAC,EAAE;IAExB;AACJ"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGenerateTypeFile.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { useMemo } from 'react';\nimport {\n ClassDeclaration,\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ModuleDeclaration,\n Project,\n SourceFile,\n} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport { ApiDefinitions, ApiObject, CheckListItem } from '@/cli/types.js';\n\nexport const useGenerateTypeFile = (\n path: string,\n definitions: ApiDefinitions | null,\n typeProvider: ReturnType<typeof createTypeProvider> | null\n) => {\n const generateTypeFile = useMemo(() => {\n return {\n waitingDescription: 'Waiting to generate the type file...',\n errorDescription: 'Failed to generate the type file',\n finishedDescription: () => 'Type file generated',\n runningDescription: 'Generating the type file...',\n runner: async () => {\n if (!definitions) {\n throw new Error('Definitions are not set');\n }\n\n if (!typeProvider) {\n throw new Error('Type provider is not set');\n }\n\n const project = new Project();\n const typeFile = project.createSourceFile(path, '', {\n overwrite: true,\n });\n\n const globalNamespace = definitions.global;\n\n typeFile.addStatements(typeProvider.getGlobalStatements());\n\n generateNamespace(globalNamespace, typeFile, typeProvider, '');\n\n writeFileSync(\n path,\n typeFile.getFullText().replace('*/', '*/\\n')\n );\n },\n ready: definitions !== null && typeProvider !== null,\n } satisfies CheckListItem<void>;\n }, [definitions, typeProvider]);\n\n return {\n generateTypeFile,\n };\n};\n\nconst generateNamespace = (\n apiObject: ApiObject,\n incomingSubject: SourceFile | ModuleDeclaration,\n typeProvider: ReturnType<typeof createTypeProvider>,\n namespace: string,\n name?: string\n) => {\n let subject = incomingSubject;\n const fullNamespaceName = [namespace, name].filter(Boolean).join('.');\n\n if (name) {\n subject = incomingSubject.addModule({\n name,\n });\n }\n\n if (name === 'playdate') {\n subject.addStatements(typeProvider.getStatements());\n }\n\n for (const func of apiObject.functions) {\n const isFunctionNameReserved = TypescriptReservedNamed.includes(\n func.name\n );\n const resolvedName = `_${func.name}`;\n const parameters = typeProvider.getParameters(func);\n\n subject.addFunction({\n name: isFunctionNameReserved ? resolvedName : func.name,\n docs: [func.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(func),\n isExported: !!name,\n ...(typeProvider.getFunctionOverrideOptions(\n func\n ) as FunctionDeclarationStructure),\n });\n\n if (isFunctionNameReserved) {\n subject.addExportDeclaration({\n namedExports: [\n {\n name: resolvedName,\n alias: func.name,\n },\n ],\n });\n }\n }\n\n let propertiesSubject: ClassDeclaration | null = null;\n\n if (name && apiObject.methods.length > 0) {\n const typeClass = incomingSubject.addClass({\n name,\n ...typeProvider.getClassOptions(fullNamespaceName),\n });\n propertiesSubject = typeClass;\n\n for (const method of apiObject.methods) {\n const parameters = typeProvider.getParameters(method);\n\n typeClass.addMethod({\n name: method.name,\n docs: [method.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(method),\n ...(typeProvider.getFunctionOverrideOptions(\n method\n ) as Partial<MethodDeclarationStructure>),\n });\n }\n }\n\n for (const property of apiObject.properties) {\n const propertyDetails = typeProvider.getPropertyDetails(property);\n\n if (propertiesSubject) {\n propertiesSubject.addProperty({\n name: property.name,\n docs: [property.docs],\n type: propertyDetails.type,\n isStatic: propertyDetails.isStatic,\n isReadonly: propertyDetails.isReadOnly,\n });\n } else {\n subject.addVariableStatement({\n docs: [property.docs],\n declarations: [\n {\n name: property.name,\n type: propertyDetails.type,\n },\n ],\n });\n }\n }\n\n for (const eachNamespace of Object.entries(apiObject.namespaces)) {\n generateNamespace(\n eachNamespace[1],\n subject,\n typeProvider,\n fullNamespaceName,\n eachNamespace[0]\n );\n }\n};\n"],"names":["writeFileSync","useMemo","Project","TypescriptReservedNamed","useGenerateTypeFile","path","definitions","typeProvider","generateTypeFile","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","project","typeFile","createSourceFile","overwrite","globalNamespace","global","addStatements","getGlobalStatements","generateNamespace","getFullText","replace","ready","apiObject","incomingSubject","namespace","name","subject","fullNamespaceName","filter","Boolean","join","addModule","getStatements","func","functions","isFunctionNameReserved","includes","resolvedName","parameters","getParameters","addFunction","docs","returnType","getFunctionReturnType","isExported","getFunctionOverrideOptions","addExportDeclaration","namedExports","alias","propertiesSubject","methods","length","typeClass","addClass","getClassOptions","method","addMethod","property","properties","propertyDetails","getPropertyDetails","addProperty","type","isStatic","isReadonly","isReadOnly","addVariableStatement","declarations","eachNamespace","Object","entries","namespaces"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAKIC,OAAO,QAEJ,WAAW;AAElB,SAASC,uBAAuB,QAAQ,qBAAqB;AAG7D,OAAO,MAAMC,sBAAsB,CAC/BC,MACAC,aACAC;IAEA,MAAMC,mBAAmBP,QAAQ;QAC7B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IAAI;oBAC9B;iBACH;YACL;QACJ;IACJ;IAEA,KAAK,MAAMM,iBAAiBC,OAAOC,OAAO,CAAChD,UAAUiD,UAAU,EAAG;QAC9DrD,kBACIkD,aAAa,CAAC,EAAE,EAChB1C,SACAxB,cACAyB,mBACAyC,aAAa,CAAC,EAAE;IAExB;AACJ"}
@@ -5,6 +5,7 @@ export declare class SimulatorCommand extends EnvironmentAwareCommand {
5
5
  static paths: string[][];
6
6
  static usage: import("clipanion").Usage;
7
7
  watch: boolean;
8
+ compileOnly: boolean;
8
9
  background: boolean;
9
10
  projectPath: string;
10
11
  renderWithEnvironment(environment: Environment): React.JSX.Element;
@@ -9,6 +9,7 @@ export class SimulatorCommand extends EnvironmentAwareCommand {
9
9
  environment: environment,
10
10
  path: this.projectPath,
11
11
  watch: this.watch,
12
+ recompileOnly: this.compileOnly,
12
13
  background: this.background
13
14
  });
14
15
  }
@@ -17,6 +18,9 @@ export class SimulatorCommand extends EnvironmentAwareCommand {
17
18
  this.watch = Option.Boolean('-w,--watch', false, {
18
19
  description: 'Watch for changes'
19
20
  });
21
+ this.compileOnly = Option.Boolean('-c,--compile-only', false, {
22
+ description: 'Use with --watch to only recompile without launching the simulator'
23
+ });
20
24
  this.background = Option.Boolean('-b,--background', false, {
21
25
  description: 'Do not bring simulator to foreground'
22
26
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/cli/src/commands/SimulatorCommand/SimulatorCommand.tsx"],"sourcesContent":["import { Command, Option } from 'clipanion';\nimport React from 'react';\nimport { EnvironmentAwareCommand } from '@/cli/commands/EnvironmentAwareCommand/index.js';\nimport { Simulator } from '@/cli/commands/SimulatorCommand/components/Simulator.js';\nimport { projectPathOption } from '@/cli/commands/TranspileCommand/index.js';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\n\nexport class SimulatorCommand extends EnvironmentAwareCommand {\n static override paths = [['simulator']];\n\n static override usage = Command.Usage({\n description: 'Transpile, compile, and run the simulator',\n });\n\n watch = Option.Boolean('-w,--watch', false, {\n description: 'Watch for changes',\n });\n\n background = Option.Boolean('-b,--background', false, {\n description: 'Do not bring simulator to foreground',\n });\n\n projectPath = projectPathOption;\n\n override renderWithEnvironment(environment: Environment) {\n return (\n <Simulator\n environment={environment}\n path={this.projectPath}\n watch={this.watch}\n background={this.background}\n />\n );\n }\n}\n"],"names":["Command","Option","React","EnvironmentAwareCommand","Simulator","projectPathOption","SimulatorCommand","renderWithEnvironment","environment","path","projectPath","watch","background","Boolean","description","paths","usage","Usage"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,EAAEC,MAAM,QAAQ,YAAY;AAC5C,OAAOC,WAAW,QAAQ;AAC1B,SAASC,uBAAuB,QAAQ,kDAAkD;AAC1F,SAASC,SAAS,QAAQ,0DAA0D;AACpF,SAASC,iBAAiB,QAAQ,2CAA2C;AAG7E,OAAO,MAAMC,yBAAyBH;IAiBzBI,sBAAsBC,WAAwB,EAAE;QACrD,qBACI,oBAACJ;YACGI,aAAaA;YACbC,MAAM,IAAI,CAACC,WAAW;YACtBC,OAAO,IAAI,CAACA,KAAK;YACjBC,YAAY,IAAI,CAACA,UAAU;;IAGvC;;;aAnBAD,QAAQV,OAAOY,OAAO,CAAC,cAAc,OAAO;YACxCC,aAAa;QACjB;aAEAF,aAAaX,OAAOY,OAAO,CAAC,mBAAmB,OAAO;YAClDC,aAAa;QACjB;aAEAJ,cAAcL;;AAYlB;AA3BaC,iBACOS,QAAQ;IAAC;QAAC;KAAY;CAAC;AAD9BT,iBAGOU,QAAQhB,QAAQiB,KAAK,CAAC;IAClCH,aAAa;AACjB"}
1
+ {"version":3,"sources":["../../../../../../libs/cli/src/commands/SimulatorCommand/SimulatorCommand.tsx"],"sourcesContent":["import { Command, Option } from 'clipanion';\nimport React from 'react';\nimport { EnvironmentAwareCommand } from '@/cli/commands/EnvironmentAwareCommand/index.js';\nimport { Simulator } from '@/cli/commands/SimulatorCommand/components/Simulator.js';\nimport { projectPathOption } from '@/cli/commands/TranspileCommand/index.js';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\n\nexport class SimulatorCommand extends EnvironmentAwareCommand {\n static override paths = [['simulator']];\n\n static override usage = Command.Usage({\n description: 'Transpile, compile, and run the simulator',\n });\n\n watch = Option.Boolean('-w,--watch', false, {\n description: 'Watch for changes',\n });\n\n compileOnly = Option.Boolean('-c,--compile-only', false, {\n description:\n 'Use with --watch to only recompile without launching the simulator',\n });\n\n background = Option.Boolean('-b,--background', false, {\n description: 'Do not bring simulator to foreground',\n });\n\n projectPath = projectPathOption;\n\n override renderWithEnvironment(environment: Environment) {\n return (\n <Simulator\n environment={environment}\n path={this.projectPath}\n watch={this.watch}\n recompileOnly={this.compileOnly}\n background={this.background}\n />\n );\n }\n}\n"],"names":["Command","Option","React","EnvironmentAwareCommand","Simulator","projectPathOption","SimulatorCommand","renderWithEnvironment","environment","path","projectPath","watch","recompileOnly","compileOnly","background","Boolean","description","paths","usage","Usage"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,EAAEC,MAAM,QAAQ,YAAY;AAC5C,OAAOC,WAAW,QAAQ;AAC1B,SAASC,uBAAuB,QAAQ,kDAAkD;AAC1F,SAASC,SAAS,QAAQ,0DAA0D;AACpF,SAASC,iBAAiB,QAAQ,2CAA2C;AAG7E,OAAO,MAAMC,yBAAyBH;IAsBzBI,sBAAsBC,WAAwB,EAAE;QACrD,qBACI,oBAACJ;YACGI,aAAaA;YACbC,MAAM,IAAI,CAACC,WAAW;YACtBC,OAAO,IAAI,CAACA,KAAK;YACjBC,eAAe,IAAI,CAACC,WAAW;YAC/BC,YAAY,IAAI,CAACA,UAAU;;IAGvC;;;aAzBAH,QAAQV,OAAOc,OAAO,CAAC,cAAc,OAAO;YACxCC,aAAa;QACjB;aAEAH,cAAcZ,OAAOc,OAAO,CAAC,qBAAqB,OAAO;YACrDC,aACI;QACR;aAEAF,aAAab,OAAOc,OAAO,CAAC,mBAAmB,OAAO;YAClDC,aAAa;QACjB;aAEAN,cAAcL;;AAalB;AAjCaC,iBACOW,QAAQ;IAAC;QAAC;KAAY;CAAC;AAD9BX,iBAGOY,QAAQlB,QAAQmB,KAAK,CAAC;IAClCH,aAAa;AACjB"}
@@ -4,7 +4,8 @@ interface Props {
4
4
  environment: Environment;
5
5
  path: string;
6
6
  watch?: boolean;
7
+ recompileOnly?: boolean;
7
8
  background?: boolean;
8
9
  }
9
- export declare const Simulator: ({ environment, path, watch, background, }: Props) => React.JSX.Element;
10
+ export declare const Simulator: ({ environment, path, watch, recompileOnly, background, }: Props) => React.JSX.Element;
10
11
  export {};
@@ -1,19 +1,24 @@
1
1
  import { watch as watchDir } from 'node:fs';
2
+ import { platform } from 'node:os';
2
3
  import { join } from 'node:path';
3
4
  import { StatusMessage } from '@inkjs/ui';
4
5
  import open from 'open';
5
6
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
7
  import { getPdcPathFromEnvironment } from '../../../commands/CompileCommand/fn/getPdcPathFromEnvironment.js';
7
8
  import { useCompileTasks } from '../../../commands/CompileCommand/hooks/useCompileTasks.js';
9
+ import { getSimulatorPathFromEnvironment } from '../../../commands/SimulatorCommand/fn/getSimulatorPathFromEnvironment.js';
8
10
  import { useTranspileTasks } from '../../../commands/TranspileCommand/hooks/useTranspileTasks.js';
9
11
  import { CheckList } from '../../../components/CheckList/index.js';
10
- export const Simulator = ({ environment, path, watch = false, background = false })=>{
12
+ import { isWindows } from '../../../utils/platform.js';
13
+ const platformName = platform();
14
+ export const Simulator = ({ environment, path, watch = false, recompileOnly = false, background = false })=>{
11
15
  const watcher = useRef(null);
12
16
  const [isWatching, setIsWatching] = useState(false);
13
17
  const [hasChanged, setHasChanged] = useState(false);
14
18
  const [hasChangedMessage, setHasChangedMessage] = useState(false);
15
19
  const transpileTasks = useTranspileTasks(path);
16
20
  const compileTasks = useCompileTasks(getPdcPathFromEnvironment(environment));
21
+ const hasRun = useRef(false);
17
22
  useEffect(()=>{
18
23
  if (hasChanged) {
19
24
  setHasChanged(false);
@@ -23,24 +28,37 @@ export const Simulator = ({ environment, path, watch = false, background = false
23
28
  setHasChanged
24
29
  ]);
25
30
  const handleFinish = useCallback(()=>{
31
+ if (hasRun.current && recompileOnly) {
32
+ return;
33
+ }
34
+ hasRun.current = true;
26
35
  open('Game.pdx', {
27
- background
36
+ background,
37
+ app: platformName === 'darwin' ? undefined : {
38
+ name: getSimulatorPathFromEnvironment(environment)
39
+ }
28
40
  }).then(()=>{
29
41
  if (!watch) {
30
- process.exit();
31
- }
32
- setHasChangedMessage(false);
33
- if (watcher.current) {
34
- watcher.current.close();
42
+ if (!isWindows) {
43
+ process.exit();
44
+ }
45
+ // Wait for the simulator to start
46
+ // See https://github.com/sindresorhus/open/issues/298
47
+ setTimeout(process.exit, 1000);
48
+ } else {
49
+ setHasChangedMessage(false);
50
+ if (watcher.current) {
51
+ watcher.current.close();
52
+ }
53
+ setIsWatching(true);
54
+ watcher.current = watchDir(join(path, 'src'), {
55
+ recursive: true
56
+ }, ()=>{
57
+ setHasChanged(true);
58
+ setHasChangedMessage(true);
59
+ setIsWatching(false);
60
+ });
35
61
  }
36
- setIsWatching(true);
37
- watcher.current = watchDir(join(path, 'src'), {
38
- recursive: true
39
- }, ()=>{
40
- setHasChanged(true);
41
- setHasChangedMessage(true);
42
- setIsWatching(false);
43
- });
44
62
  });
45
63
  }, [
46
64
  watch,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/components/Simulator.tsx"],"sourcesContent":["import { FSWatcher, watch as watchDir } from 'node:fs';\nimport { join } from 'node:path';\nimport { StatusMessage } from '@inkjs/ui';\nimport open from 'open';\nimport React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { getPdcPathFromEnvironment } from '@/cli/commands/CompileCommand/fn/getPdcPathFromEnvironment.js';\nimport { useCompileTasks } from '@/cli/commands/CompileCommand/hooks/useCompileTasks.js';\nimport { useTranspileTasks } from '@/cli/commands/TranspileCommand/hooks/useTranspileTasks.js';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\n\ninterface Props {\n environment: Environment;\n path: string;\n watch?: boolean;\n background?: boolean;\n}\n\nexport const Simulator = ({\n environment,\n path,\n watch = false,\n background = false,\n}: Props) => {\n const watcher = useRef<FSWatcher | null>(null);\n const [isWatching, setIsWatching] = useState(false);\n const [hasChanged, setHasChanged] = useState(false);\n const [hasChangedMessage, setHasChangedMessage] = useState(false);\n const transpileTasks = useTranspileTasks(path);\n const compileTasks = useCompileTasks(\n getPdcPathFromEnvironment(environment)\n );\n\n useEffect(() => {\n if (hasChanged) {\n setHasChanged(false);\n }\n }, [hasChanged, setHasChanged]);\n\n const handleFinish = useCallback(() => {\n open('Game.pdx', {\n background,\n }).then(() => {\n if (!watch) {\n process.exit();\n }\n\n setHasChangedMessage(false);\n\n if (watcher.current) {\n watcher.current.close();\n }\n\n setIsWatching(true);\n\n watcher.current = watchDir(\n join(path, 'src'),\n { recursive: true },\n () => {\n setHasChanged(true);\n setHasChangedMessage(true);\n setIsWatching(false);\n }\n );\n });\n }, [watch, setHasChanged, setIsWatching]);\n\n const tasks = useMemo(() => {\n return [...transpileTasks, ...compileTasks];\n }, [transpileTasks, compileTasks]);\n\n return (\n <>\n {!hasChanged && <CheckList items={tasks} onFinish={handleFinish} />}\n {isWatching && !hasChangedMessage && (\n <StatusMessage variant=\"info\">\n Watching for changes...\n </StatusMessage>\n )}\n {hasChangedMessage && (\n <StatusMessage variant=\"info\">Change detected</StatusMessage>\n )}\n </>\n );\n};\n"],"names":["watch","watchDir","join","StatusMessage","open","React","useCallback","useEffect","useMemo","useRef","useState","getPdcPathFromEnvironment","useCompileTasks","useTranspileTasks","CheckList","Simulator","environment","path","background","watcher","isWatching","setIsWatching","hasChanged","setHasChanged","hasChangedMessage","setHasChangedMessage","transpileTasks","compileTasks","handleFinish","then","process","exit","current","close","recursive","tasks","items","onFinish","variant"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAAoBA,SAASC,QAAQ,QAAQ,UAAU;AACvD,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,aAAa,QAAQ,YAAY;AAC1C,OAAOC,UAAU,OAAO;AACxB,OAAOC,SACHC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,QAAQ;AACf,SAASC,yBAAyB,QAAQ,gEAAgE;AAC1G,SAASC,eAAe,QAAQ,yDAAyD;AACzF,SAASC,iBAAiB,QAAQ,6DAA6D;AAC/F,SAASC,SAAS,QAAQ,sCAAsC;AAUhE,OAAO,MAAMC,YAAY,CAAC,EACtBC,WAAW,EACXC,IAAI,EACJjB,QAAQ,KAAK,EACbkB,aAAa,KAAK,EACd;IACJ,MAAMC,UAAUV,OAAyB;IACzC,MAAM,CAACW,YAAYC,cAAc,GAAGX,SAAS;IAC7C,MAAM,CAACY,YAAYC,cAAc,GAAGb,SAAS;IAC7C,MAAM,CAACc,mBAAmBC,qBAAqB,GAAGf,SAAS;IAC3D,MAAMgB,iBAAiBb,kBAAkBI;IACzC,MAAMU,eAAef,gBACjBD,0BAA0BK;IAG9BT,UAAU;QACN,IAAIe,YAAY;YACZC,cAAc;QAClB;IACJ,GAAG;QAACD;QAAYC;KAAc;IAE9B,MAAMK,eAAetB,YAAY;QAC7BF,KAAK,YAAY;YACbc;QACJ,GAAGW,IAAI,CAAC;YACJ,IAAI,CAAC7B,OAAO;gBACR8B,QAAQC,IAAI;YAChB;YAEAN,qBAAqB;YAErB,IAAIN,QAAQa,OAAO,EAAE;gBACjBb,QAAQa,OAAO,CAACC,KAAK;YACzB;YAEAZ,cAAc;YAEdF,QAAQa,OAAO,GAAG/B,SACdC,KAAKe,MAAM,QACX;gBAAEiB,WAAW;YAAK,GAClB;gBACIX,cAAc;gBACdE,qBAAqB;gBACrBJ,cAAc;YAClB;QAER;IACJ,GAAG;QAACrB;QAAOuB;QAAeF;KAAc;IAExC,MAAMc,QAAQ3B,QAAQ;QAClB,OAAO;eAAIkB;eAAmBC;SAAa;IAC/C,GAAG;QAACD;QAAgBC;KAAa;IAEjC,qBACI,0CACK,CAACL,4BAAc,oBAACR;QAAUsB,OAAOD;QAAOE,UAAUT;QAClDR,cAAc,CAACI,mCACZ,oBAACrB;QAAcmC,SAAQ;OAAO,4BAIjCd,mCACG,oBAACrB;QAAcmC,SAAQ;OAAO;AAI9C,EAAE"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/components/Simulator.tsx"],"sourcesContent":["import { FSWatcher, watch as watchDir } from 'node:fs';\nimport { platform } from 'node:os';\nimport { join } from 'node:path';\nimport { StatusMessage } from '@inkjs/ui';\nimport open from 'open';\nimport React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { getPdcPathFromEnvironment } from '@/cli/commands/CompileCommand/fn/getPdcPathFromEnvironment.js';\nimport { useCompileTasks } from '@/cli/commands/CompileCommand/hooks/useCompileTasks.js';\nimport { getSimulatorPathFromEnvironment } from '@/cli/commands/SimulatorCommand/fn/getSimulatorPathFromEnvironment.js';\nimport { useTranspileTasks } from '@/cli/commands/TranspileCommand/hooks/useTranspileTasks.js';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { isWindows } from '@/cli/utils/platform.js';\n\ninterface Props {\n environment: Environment;\n path: string;\n watch?: boolean;\n recompileOnly?: boolean;\n background?: boolean;\n}\n\nconst platformName = platform();\n\nexport const Simulator = ({\n environment,\n path,\n watch = false,\n recompileOnly = false,\n background = false,\n}: Props) => {\n const watcher = useRef<FSWatcher | null>(null);\n const [isWatching, setIsWatching] = useState(false);\n const [hasChanged, setHasChanged] = useState(false);\n const [hasChangedMessage, setHasChangedMessage] = useState(false);\n const transpileTasks = useTranspileTasks(path);\n const compileTasks = useCompileTasks(\n getPdcPathFromEnvironment(environment)\n );\n const hasRun = useRef(false);\n\n useEffect(() => {\n if (hasChanged) {\n setHasChanged(false);\n }\n }, [hasChanged, setHasChanged]);\n\n const handleFinish = useCallback(() => {\n if (hasRun.current && recompileOnly) {\n return;\n }\n\n hasRun.current = true;\n\n open('Game.pdx', {\n background,\n app:\n platformName === 'darwin'\n ? undefined\n : {\n name: getSimulatorPathFromEnvironment(environment),\n },\n }).then(() => {\n if (!watch) {\n if (!isWindows) {\n process.exit();\n }\n\n // Wait for the simulator to start\n // See https://github.com/sindresorhus/open/issues/298\n setTimeout(process.exit, 1000);\n } else {\n setHasChangedMessage(false);\n\n if (watcher.current) {\n watcher.current.close();\n }\n\n setIsWatching(true);\n\n watcher.current = watchDir(\n join(path, 'src'),\n { recursive: true },\n () => {\n setHasChanged(true);\n setHasChangedMessage(true);\n setIsWatching(false);\n }\n );\n }\n });\n }, [watch, setHasChanged, setIsWatching]);\n\n const tasks = useMemo(() => {\n return [...transpileTasks, ...compileTasks];\n }, [transpileTasks, compileTasks]);\n\n return (\n <>\n {!hasChanged && <CheckList items={tasks} onFinish={handleFinish} />}\n {isWatching && !hasChangedMessage && (\n <StatusMessage variant=\"info\">\n Watching for changes...\n </StatusMessage>\n )}\n {hasChangedMessage && (\n <StatusMessage variant=\"info\">Change detected</StatusMessage>\n )}\n </>\n );\n};\n"],"names":["watch","watchDir","platform","join","StatusMessage","open","React","useCallback","useEffect","useMemo","useRef","useState","getPdcPathFromEnvironment","useCompileTasks","getSimulatorPathFromEnvironment","useTranspileTasks","CheckList","isWindows","platformName","Simulator","environment","path","recompileOnly","background","watcher","isWatching","setIsWatching","hasChanged","setHasChanged","hasChangedMessage","setHasChangedMessage","transpileTasks","compileTasks","hasRun","handleFinish","current","app","undefined","name","then","process","exit","setTimeout","close","recursive","tasks","items","onFinish","variant"],"rangeMappings":";;;;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mB,YACA;gBACIC,MAAMxB,gCAAgCM;YAC1C;QACd,GAAGmB,IAAI,CAAC;YACJ,IAAI,CAACvC,OAAO;gBACR,IAAI,CAACiB,WAAW;oBACZuB,QAAQC,IAAI;gBAChB;gBAEA,kCAAkC;gBAClC,sDAAsD;gBACtDC,WAAWF,QAAQC,IAAI,EAAE;YAC7B,OAAO;gBACHX,qBAAqB;gBAErB,IAAIN,QAAQW,OAAO,EAAE;oBACjBX,QAAQW,OAAO,CAACQ,KAAK;gBACzB;gBAEAjB,cAAc;gBAEdF,QAAQW,OAAO,GAAGlC,SACdE,KAAKkB,MAAM,QACX;oBAAEuB,WAAW;gBAAK,GAClB;oBACIhB,cAAc;oBACdE,qBAAqB;oBACrBJ,cAAc;gBAClB;YAER;QACJ;IACJ,GAAG;QAAC1B;QAAO4B;QAAeF;KAAc;IAExC,MAAMmB,QAAQpC,QAAQ;QAClB,OAAO;eAAIsB;eAAmBC;SAAa;IAC/C,GAAG;QAACD;QAAgBC;KAAa;IAEjC,qBACI,0CACK,CAACL,4BAAc,oBAACX;QAAU8B,OAAOD;QAAOE,UAAUb;QAClDT,cAAc,CAACI,mCACZ,oBAACzB;QAAc4C,SAAQ;OAAO,4BAIjCnB,mCACG,oBAACzB;QAAc4C,SAAQ;OAAO;AAI9C,EAAE"}
@@ -0,0 +1,2 @@
1
+ import { Environment } from '../../../environment/dto/Environment.js';
2
+ export declare const getSimulatorPathFromEnvironment: (environment: Environment) => string;
@@ -0,0 +1,7 @@
1
+ import { join } from 'node:path';
2
+ import { appendExeOnWindows } from '../../../utils/appendExeOnWindows.js';
3
+ export const getSimulatorPathFromEnvironment = (environment)=>{
4
+ return join(environment.sdkPath.path, 'bin', appendExeOnWindows('PlaydateSimulator'));
5
+ };
6
+
7
+ //# sourceMappingURL=getSimulatorPathFromEnvironment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/fn/getSimulatorPathFromEnvironment.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { appendExeOnWindows } from '@/cli/utils/appendExeOnWindows.js';\n\nexport const getSimulatorPathFromEnvironment = (environment: Environment) => {\n return join(\n environment.sdkPath.path,\n 'bin',\n appendExeOnWindows('PlaydateSimulator')\n );\n};\n"],"names":["join","appendExeOnWindows","getSimulatorPathFromEnvironment","environment","sdkPath","path"],"rangeMappings":";;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AAEjC,SAASC,kBAAkB,QAAQ,oCAAoC;AAEvE,OAAO,MAAMC,kCAAkC,CAACC;IAC5C,OAAOH,KACHG,YAAYC,OAAO,CAACC,IAAI,EACxB,OACAJ,mBAAmB;AAE3B,EAAE"}
@@ -0,0 +1 @@
1
+ export declare const appendExeOnWindows: (binary: string) => string;
@@ -0,0 +1,6 @@
1
+ import { isWindows } from '../utils/platform.js';
2
+ export const appendExeOnWindows = (binary)=>{
3
+ return isWindows ? `${binary}.exe` : binary;
4
+ };
5
+
6
+ //# sourceMappingURL=appendExeOnWindows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/cli/src/utils/appendExeOnWindows.ts"],"sourcesContent":["import { isWindows } from '@/cli/utils/platform.js';\n\nexport const appendExeOnWindows = (binary: string) => {\n return isWindows ? `${binary}.exe` : binary;\n};\n"],"names":["isWindows","appendExeOnWindows","binary"],"rangeMappings":";;;","mappings":"AAAA,SAASA,SAAS,QAAQ,0BAA0B;AAEpD,OAAO,MAAMC,qBAAqB,CAACC;IAC/B,OAAOF,YAAY,CAAC,EAAEE,OAAO,IAAI,CAAC,GAAGA;AACzC,EAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const platformName: NodeJS.Platform;
2
+ export declare const isWindows: boolean;
@@ -0,0 +1,5 @@
1
+ import { platform } from 'node:os';
2
+ export const platformName = platform();
3
+ export const isWindows = platformName === 'win32';
4
+
5
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/cli/src/utils/platform.ts"],"sourcesContent":["import { platform } from 'node:os';\n\nexport const platformName = platform();\nexport const isWindows = platformName === 'win32';\n"],"names":["platform","platformName","isWindows"],"rangeMappings":";;","mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAU;AAEnC,OAAO,MAAMC,eAAeD,WAAW;AACvC,OAAO,MAAME,YAAYD,iBAAiB,QAAQ"}