crankscript 0.10.2 → 0.10.3
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 +2 -1
- package/src/commands/CompileCommand/hooks/useCompileTasks.d.ts +1 -1
- package/src/commands/CompileCommand/hooks/useCompileTasks.js +33 -7
- package/src/commands/CompileCommand/hooks/useCompileTasks.js.map +1 -1
- package/src/commands/SimulatorCommand/components/Simulator.js +19 -16
- package/src/commands/SimulatorCommand/components/Simulator.js.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "crankscript",
|
3
|
-
"version": "0.10.
|
3
|
+
"version": "0.10.3",
|
4
4
|
"scripts": {
|
5
5
|
"dev": "tsx src/index.ts",
|
6
6
|
"post-build": "tsc-alias --project tsconfig.json",
|
@@ -16,6 +16,7 @@
|
|
16
16
|
"cheerio": "^1.0.0",
|
17
17
|
"clipanion": "^4.0.0-rc.4",
|
18
18
|
"ink": "^5.0.1",
|
19
|
+
"open": "^10.1.0",
|
19
20
|
"react": "^18.3.1",
|
20
21
|
"tiged": "^3.0.0-rc.0",
|
21
22
|
"ts-morph": "^23.0.0",
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import { CheckListItem } from '../../../types.js';
|
2
|
-
export declare const useCompileTasks: (
|
2
|
+
export declare const useCompileTasks: (pdcPath: string) => CheckListItem<unknown>[];
|
@@ -1,9 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { spawn } from 'node:child_process';
|
2
2
|
import { existsSync } from 'node:fs';
|
3
|
-
import { promisify } from 'node:util';
|
4
3
|
import { useMemo } from 'react';
|
5
|
-
const
|
6
|
-
export const useCompileTasks = (sdkPath)=>{
|
4
|
+
export const useCompileTasks = (pdcPath)=>{
|
7
5
|
return useMemo(()=>[
|
8
6
|
{
|
9
7
|
waitingDescription: 'Waiting to check for pdc binary...',
|
@@ -11,10 +9,10 @@ export const useCompileTasks = (sdkPath)=>{
|
|
11
9
|
runningDescription: 'Checking for pdc binary...',
|
12
10
|
finishedDescription: (result)=>`Found pdc binary at "${result}"`,
|
13
11
|
runner: async ()=>{
|
14
|
-
if (!existsSync(
|
12
|
+
if (!existsSync(pdcPath)) {
|
15
13
|
throw new Error('Could not find pdc binary');
|
16
14
|
}
|
17
|
-
return
|
15
|
+
return pdcPath;
|
18
16
|
},
|
19
17
|
ready: true
|
20
18
|
},
|
@@ -24,7 +22,35 @@ export const useCompileTasks = (sdkPath)=>{
|
|
24
22
|
runningDescription: 'Compiling lua code...',
|
25
23
|
finishedDescription: ()=>'Lua code compiled',
|
26
24
|
runner: async ()=>{
|
27
|
-
return
|
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
|
+
});
|
53
|
+
});
|
28
54
|
},
|
29
55
|
ready: true
|
30
56
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/CompileCommand/hooks/useCompileTasks.ts"],"sourcesContent":["import {
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;wBAGzD;oBACJ;gBACJ;gBACAZ,OAAO;YACX;SACH,EACD,EAAE;AAEV,EAAE"}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { exec } from 'node:child_process';
|
2
1
|
import { watch as watchDir } from 'node:fs';
|
3
2
|
import { join } from 'node:path';
|
4
3
|
import { StatusMessage } from '@inkjs/ui';
|
4
|
+
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';
|
@@ -23,21 +23,24 @@ export const Simulator = ({ environment, path, watch = false, background = false
|
|
23
23
|
setHasChanged
|
24
24
|
]);
|
25
25
|
const handleFinish = useCallback(()=>{
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
open('Game.pdx', {
|
27
|
+
background
|
28
|
+
}).then(()=>{
|
29
|
+
if (!watch) {
|
30
|
+
process.exit();
|
31
|
+
}
|
32
|
+
setHasChangedMessage(false);
|
33
|
+
if (watcher.current) {
|
34
|
+
watcher.current.close();
|
35
|
+
}
|
36
|
+
setIsWatching(true);
|
37
|
+
watcher.current = watchDir(join(path, 'src'), {
|
38
|
+
recursive: true
|
39
|
+
}, ()=>{
|
40
|
+
setHasChanged(true);
|
41
|
+
setHasChangedMessage(true);
|
42
|
+
setIsWatching(false);
|
43
|
+
});
|
41
44
|
});
|
42
45
|
}, [
|
43
46
|
watch,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/components/Simulator.tsx"],"sourcesContent":["import {
|
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,YA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