crankscript 0.10.4 → 0.10.5

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,6 +1,6 @@
1
1
  {
2
2
  "name": "crankscript",
3
- "version": "0.10.4",
3
+ "version": "0.10.5",
4
4
  "scripts": {
5
5
  "dev": "tsx src/index.ts",
6
6
  "post-build": "tsc-alias --project tsconfig.json",
@@ -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,UAAU,QAAQ,UAAU;AACrC,SAASC,OAAO,QAAQ,QAAQ;AAGhC,OAAO,MAAMC,kBAAkB,CAACC;IAC5B,OAAOF,QACH,IAAM;YACF;gBACIG,oBAAoB;gBACpBC,kBAAkB;gBAClBC,oBAAoB;gBACpBC,qBAAqB,CAACC,SAClB,CAAC,qBAAqB,EAAEA,OAAO,CAAC,CAAC;gBACrCC,QAAQ;oBACJ,IAAI,CAACT,WAAWG,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,OAAO,IAAIG,QAAQ,CAACC,SAASC;wBACzB,MAAMC,MAAMhB,MAAMI,SAAS;4BAAC;4BAAU;yBAAW;wBAEjD,wCAAwC;wBACxC,IAAIa,SAAS;wBACb,IAAIC,SAAS;wBAEb,kCAAkC;wBAClCF,IAAIC,MAAM,CAACE,EAAE,CAAC,QAAQ,CAACC;4BACnBH,UAAUG,KAAKC,QAAQ;wBAC3B;wBAEA,iCAAiC;wBACjCL,IAAIE,MAAM,CAACC,EAAE,CAAC,QAAQ,CAACC;4BACnBF,UAAUE,KAAKC,QAAQ;wBAC3B;wBAEA,6BAA6B;wBAC7BL,IAAIG,EAAE,CAAC,SAAS,CAACG;4BACb,IAAIA,SAAS,GAAG;gCACZR,QAAQG,SAAS,sCAAsC;4BAC3D,OAAO;gCACHF,OACI,IAAIJ,MACA,CAAC,qBAAqB,EAAEW,KAAK,EAAE,EAAEJ,OAAO,CAAC;4BAGrD;wBACJ;wBAEA,0DAA0D;wBAC1DF,IAAIG,EAAE,CAAC,SAAS,CAACI;4BACbR,OACI,IAAIJ,MACA,CAAC,6BAA6B,EAAEY,IAAIC,OAAO,CAAC,CAAC;wBAGzD;oBACJ;gBACJ;gBACAZ,OAAO;YACX;SACH,EACD,EAAE;AAEV,EAAE"}
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"}
@@ -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
+ recompileOnly: 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.recompileOnly,
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.recompileOnly = Option.Boolean('-r,--recompile-only', false, {
22
+ description: 'Use with --watch to only recompile without launching the simulator when files change'
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 recompileOnly = Option.Boolean('-r,--recompile-only', false, {\n description:\n 'Use with --watch to only recompile without launching the simulator when files change',\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.recompileOnly}\n background={this.background}\n />\n );\n }\n}\n"],"names":["Command","Option","React","EnvironmentAwareCommand","Simulator","projectPathOption","SimulatorCommand","renderWithEnvironment","environment","path","projectPath","watch","recompileOnly","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,CAACA,aAAa;YACjCC,YAAY,IAAI,CAACA,UAAU;;IAGvC;;;aAzBAF,QAAQV,OAAOa,OAAO,CAAC,cAAc,OAAO;YACxCC,aAAa;QACjB;aAEAH,gBAAgBX,OAAOa,OAAO,CAAC,uBAAuB,OAAO;YACzDC,aACI;QACR;aAEAF,aAAaZ,OAAOa,OAAO,CAAC,mBAAmB,OAAO;YAClDC,aAAa;QACjB;aAEAL,cAAcL;;AAalB;AAjCaC,iBACOU,QAAQ;IAAC;QAAC;KAAY;CAAC;AAD9BV,iBAGOW,QAAQjB,QAAQkB,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 {};
@@ -5,15 +5,18 @@ import open from 'open';
5
5
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
6
  import { getPdcPathFromEnvironment } from '../../../commands/CompileCommand/fn/getPdcPathFromEnvironment.js';
7
7
  import { useCompileTasks } from '../../../commands/CompileCommand/hooks/useCompileTasks.js';
8
+ import { getSimulatorPathFromEnvironment } from '../../../commands/SimulatorCommand/fn/getSimulatorPathFromEnvironment.js';
8
9
  import { useTranspileTasks } from '../../../commands/TranspileCommand/hooks/useTranspileTasks.js';
9
10
  import { CheckList } from '../../../components/CheckList/index.js';
10
- export const Simulator = ({ environment, path, watch = false, background = false })=>{
11
+ import { isMac, isWindows } from '../../../utils/platform.js';
12
+ export const Simulator = ({ environment, path, watch = false, recompileOnly = false, background = false })=>{
11
13
  const watcher = useRef(null);
12
14
  const [isWatching, setIsWatching] = useState(false);
13
15
  const [hasChanged, setHasChanged] = useState(false);
14
16
  const [hasChangedMessage, setHasChangedMessage] = useState(false);
15
17
  const transpileTasks = useTranspileTasks(path);
16
18
  const compileTasks = useCompileTasks(getPdcPathFromEnvironment(environment));
19
+ const didRun = useRef(false);
17
20
  useEffect(()=>{
18
21
  if (hasChanged) {
19
22
  setHasChanged(false);
@@ -23,24 +26,37 @@ export const Simulator = ({ environment, path, watch = false, background = false
23
26
  setHasChanged
24
27
  ]);
25
28
  const handleFinish = useCallback(()=>{
29
+ if (didRun.current && recompileOnly) {
30
+ return;
31
+ }
32
+ didRun.current = true;
26
33
  open('Game.pdx', {
27
- background
34
+ background,
35
+ app: isMac ? undefined : {
36
+ name: getSimulatorPathFromEnvironment(environment)
37
+ }
28
38
  }).then(()=>{
29
39
  if (!watch) {
30
- process.exit();
31
- }
32
- setHasChangedMessage(false);
33
- if (watcher.current) {
34
- watcher.current.close();
40
+ if (!isWindows) {
41
+ process.exit();
42
+ }
43
+ // Wait for the simulator to start
44
+ // See https://github.com/sindresorhus/open/issues/298
45
+ setTimeout(process.exit, 1000);
46
+ } else {
47
+ setHasChangedMessage(false);
48
+ if (watcher.current) {
49
+ watcher.current.close();
50
+ }
51
+ setIsWatching(true);
52
+ watcher.current = watchDir(join(path, 'src'), {
53
+ recursive: true
54
+ }, ()=>{
55
+ setHasChanged(true);
56
+ setHasChangedMessage(true);
57
+ setIsWatching(false);
58
+ });
35
59
  }
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
60
  });
45
61
  }, [
46
62
  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 { 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 { isMac, 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\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 didRun = useRef(false);\n\n useEffect(() => {\n if (hasChanged) {\n setHasChanged(false);\n }\n }, [hasChanged, setHasChanged]);\n\n const handleFinish = useCallback(() => {\n if (didRun.current && recompileOnly) {\n return;\n }\n\n didRun.current = true;\n\n open('Game.pdx', {\n background,\n app: isMac\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","join","StatusMessage","open","React","useCallback","useEffect","useMemo","useRef","useState","getPdcPathFromEnvironment","useCompileTasks","getSimulatorPathFromEnvironment","useTranspileTasks","CheckList","isMac","isWindows","Simulator","environment","path","recompileOnly","background","watcher","isWatching","setIsWatching","hasChanged","setHasChanged","hasChangedMessage","setHasChangedMessage","transpileTasks","compileTasks","didRun","handleFinish","current","app","undefined","name","then","process","exit","setTimeout","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,+BAA+B,QAAQ,wEAAwE;AACxH,SAASC,iBAAiB,QAAQ,6DAA6D;AAC/F,SAASC,SAAS,QAAQ,sCAAsC;AAEhE,SAASC,KAAK,EAAEC,SAAS,QAAQ,0BAA0B;AAU3D,OAAO,MAAMC,YAAY,CAAC,EACtBC,WAAW,EACXC,IAAI,EACJpB,QAAQ,KAAK,EACbqB,gBAAgB,KAAK,EACrBC,aAAa,KAAK,EACd;IACJ,MAAMC,UAAUd,OAAyB;IACzC,MAAM,CAACe,YAAYC,cAAc,GAAGf,SAAS;IAC7C,MAAM,CAACgB,YAAYC,cAAc,GAAGjB,SAAS;IAC7C,MAAM,CAACkB,mBAAmBC,qBAAqB,GAAGnB,SAAS;IAC3D,MAAMoB,iBAAiBhB,kBAAkBM;IACzC,MAAMW,eAAenB,gBACjBD,0BAA0BQ;IAE9B,MAAMa,SAASvB,OAAO;IAEtBF,UAAU;QACN,IAAImB,YAAY;YACZC,cAAc;QAClB;IACJ,GAAG;QAACD;QAAYC;KAAc;IAE9B,MAAMM,eAAe3B,YAAY;QAC7B,IAAI0B,OAAOE,OAAO,IAAIb,eAAe;YACjC;QACJ;QAEAW,OAAOE,OAAO,GAAG;QAEjB9B,KAAK,YAAY;YACbkB;YACAa,KAAKnB,QACCoB,YACA;gBACIC,MAAMxB,gCAAgCM;YAC1C;QACV,GAAGmB,IAAI,CAAC;YACJ,IAAI,CAACtC,OAAO;gBACR,IAAI,CAACiB,WAAW;oBACZsB,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,GAAGjC,SACdC,KAAKkB,MAAM,QACX;oBAAEuB,WAAW;gBAAK,GAClB;oBACIhB,cAAc;oBACdE,qBAAqB;oBACrBJ,cAAc;gBAClB;YAER;QACJ;IACJ,GAAG;QAACzB;QAAO2B;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,3 @@
1
+ export declare const platformName: NodeJS.Platform;
2
+ export declare const isWindows: boolean;
3
+ export declare const isMac: boolean;
@@ -0,0 +1,6 @@
1
+ import { platform } from 'node:os';
2
+ export const platformName = platform();
3
+ export const isWindows = platformName === 'win32';
4
+ export const isMac = platformName === 'darwin';
5
+
6
+ //# 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';\nexport const isMac = platformName === 'darwin';\n"],"names":["platform","platformName","isWindows","isMac"],"rangeMappings":";;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAU;AAEnC,OAAO,MAAMC,eAAeD,WAAW;AACvC,OAAO,MAAME,YAAYD,iBAAiB,QAAQ;AAClD,OAAO,MAAME,QAAQF,iBAAiB,SAAS"}