crankscript 0.13.1 → 0.15.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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/package.json +32 -31
- package/src/commands/CompileCommand/components/Compile.js +3 -1
- package/src/commands/CompileCommand/components/Compile.js.map +1 -1
- package/src/commands/CompileCommand/hooks/useCompileTasks.d.ts +6 -1
- package/src/commands/CompileCommand/hooks/useCompileTasks.js +2 -2
- package/src/commands/CompileCommand/hooks/useCompileTasks.js.map +1 -1
- package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.d.ts +1 -0
- package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js +25 -1
- package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js.map +1 -1
- package/src/commands/EnvironmentAwareCommand/contexts/CrankScriptContext.d.ts +11 -0
- package/src/commands/EnvironmentAwareCommand/contexts/CrankScriptContext.js +20 -0
- package/src/commands/EnvironmentAwareCommand/contexts/CrankScriptContext.js.map +1 -0
- package/src/commands/GenerateTypes/hooks/useFormatTypeFile.js +4 -4
- package/src/commands/GenerateTypes/hooks/useFormatTypeFile.js.map +1 -1
- package/src/commands/SimulatorCommand/SimulatorCommand.d.ts +2 -0
- package/src/commands/SimulatorCommand/SimulatorCommand.js +27 -3
- package/src/commands/SimulatorCommand/SimulatorCommand.js.map +1 -1
- package/src/commands/SimulatorCommand/components/Simulator.d.ts +3 -1
- package/src/commands/SimulatorCommand/components/Simulator.js +20 -84
- package/src/commands/SimulatorCommand/components/Simulator.js.map +1 -1
- package/src/commands/SimulatorCommand/components/TemporaryFolderCreator.d.ts +7 -0
- package/src/commands/SimulatorCommand/components/TemporaryFolderCreator.js +43 -0
- package/src/commands/SimulatorCommand/components/TemporaryFolderCreator.js.map +1 -0
- package/src/commands/SimulatorCommand/fn/createTemporaryFolderPathFromEntryFile.d.ts +1 -0
- package/src/commands/SimulatorCommand/fn/createTemporaryFolderPathFromEntryFile.js +9 -0
- package/src/commands/SimulatorCommand/fn/createTemporaryFolderPathFromEntryFile.js.map +1 -0
- package/src/commands/SimulatorCommand/hooks/useFileWatcher.d.ts +6 -0
- package/src/commands/SimulatorCommand/hooks/useFileWatcher.js +37 -0
- package/src/commands/SimulatorCommand/hooks/useFileWatcher.js.map +1 -0
- package/src/commands/SimulatorCommand/hooks/useSimulatorTasks.d.ts +22 -0
- package/src/commands/SimulatorCommand/hooks/useSimulatorTasks.js +109 -0
- package/src/commands/SimulatorCommand/hooks/useSimulatorTasks.js.map +1 -0
- package/src/commands/TranspileCommand/TranspileCommand.d.ts +2 -0
- package/src/commands/TranspileCommand/TranspileCommand.js +10 -4
- package/src/commands/TranspileCommand/TranspileCommand.js.map +1 -1
- package/src/commands/TranspileCommand/components/Transpile.d.ts +2 -1
- package/src/commands/TranspileCommand/components/Transpile.js +3 -2
- package/src/commands/TranspileCommand/components/Transpile.js.map +1 -1
- package/src/commands/TranspileCommand/fn/transpile.d.ts +3 -2
- package/src/commands/TranspileCommand/fn/transpile.js +18 -2
- package/src/commands/TranspileCommand/fn/transpile.js.map +1 -1
- package/src/commands/TranspileCommand/fn/validateEntryPoint.d.ts +2 -1
- package/src/commands/TranspileCommand/fn/validateEntryPoint.js +19 -9
- package/src/commands/TranspileCommand/fn/validateEntryPoint.js.map +1 -1
- package/src/commands/TranspileCommand/fn/validateExitPoint.d.ts +2 -1
- package/src/commands/TranspileCommand/fn/validateExitPoint.js +16 -10
- package/src/commands/TranspileCommand/fn/validateExitPoint.js.map +1 -1
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.d.ts +4 -1
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.js +28 -4
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.js.map +1 -1
- package/src/commands/TranspileCommand/types.d.ts +4 -0
- package/src/commands/TranspileCommand/types.js +7 -0
- package/src/commands/TranspileCommand/types.js.map +1 -0
- package/src/components/CheckList/Item.js +8 -2
- package/src/components/CheckList/Item.js.map +1 -1
- package/src/components/ErrorBoundary.js +28 -0
- package/src/components/ErrorBoundary.js.map +1 -0
- package/src/index.js +5 -1
- package/src/index.js.map +1 -1
@@ -0,0 +1,43 @@
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
2
|
+
import React, { useMemo, useState } from 'react';
|
3
|
+
import { CheckList } from '../../../components/CheckList/index.js';
|
4
|
+
import { useCrankScriptContext } from '../../EnvironmentAwareCommand/contexts/CrankScriptContext.js';
|
5
|
+
import { createTemporaryFolderPathFromEntryFile } from '../fn/createTemporaryFolderPathFromEntryFile.js';
|
6
|
+
export const TemporaryFolderCreator = ({ entryFile, children })=>{
|
7
|
+
const [created, setCreated] = useState(false);
|
8
|
+
const { verbose } = useCrankScriptContext();
|
9
|
+
const temporaryFolder = useMemo(()=>{
|
10
|
+
return createTemporaryFolderPathFromEntryFile(entryFile);
|
11
|
+
}, [
|
12
|
+
entryFile
|
13
|
+
]);
|
14
|
+
const items = useMemo(()=>{
|
15
|
+
return [
|
16
|
+
{
|
17
|
+
waitingDescription: 'Waiting to create temporary directory...',
|
18
|
+
runningDescription: 'Creating temporary directory...',
|
19
|
+
errorDescription: 'Failed to create temporary directory',
|
20
|
+
runner: async ()=>{
|
21
|
+
if (!temporaryFolder) {
|
22
|
+
return false;
|
23
|
+
}
|
24
|
+
mkdirSync(temporaryFolder, {
|
25
|
+
recursive: true
|
26
|
+
});
|
27
|
+
return true;
|
28
|
+
},
|
29
|
+
finishedDescription: ()=>{
|
30
|
+
return `Temporary directory ${verbose ? `"${temporaryFolder}" ` : ''}created`;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
];
|
34
|
+
}, [
|
35
|
+
created
|
36
|
+
]);
|
37
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(CheckList, {
|
38
|
+
items: items,
|
39
|
+
onFinish: ()=>setCreated(true)
|
40
|
+
}), created && children);
|
41
|
+
};
|
42
|
+
|
43
|
+
//# sourceMappingURL=TemporaryFolderCreator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/components/TemporaryFolderCreator.tsx"],"sourcesContent":["import { mkdirSync } from 'node:fs';\nimport React, { useMemo, ReactNode, useState } from 'react';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { CheckListItem } from '@/cli/types.js';\nimport { useCrankScriptContext } from '../../EnvironmentAwareCommand/contexts/CrankScriptContext.js';\nimport { createTemporaryFolderPathFromEntryFile } from '../fn/createTemporaryFolderPathFromEntryFile.js';\n\ninterface Props {\n entryFile: string;\n children: ReactNode;\n}\n\nexport const TemporaryFolderCreator = ({ entryFile, children }: Props) => {\n const [created, setCreated] = useState(false);\n const { verbose } = useCrankScriptContext();\n const temporaryFolder = useMemo(() => {\n return createTemporaryFolderPathFromEntryFile(entryFile);\n }, [entryFile]);\n\n const items = useMemo(() => {\n return [\n {\n waitingDescription: 'Waiting to create temporary directory...',\n runningDescription: 'Creating temporary directory...',\n errorDescription: 'Failed to create temporary directory',\n runner: async () => {\n if (!temporaryFolder) {\n return false;\n }\n\n mkdirSync(temporaryFolder, { recursive: true });\n\n return true;\n },\n finishedDescription: () => {\n return `Temporary directory ${\n verbose ? `\"${temporaryFolder}\" ` : ''\n }created`;\n },\n },\n ] satisfies CheckListItem<unknown>[];\n }, [created]);\n\n return (\n <>\n <CheckList items={items} onFinish={() => setCreated(true)} />\n {created && children}\n </>\n );\n};\n"],"names":["mkdirSync","React","useMemo","useState","CheckList","useCrankScriptContext","createTemporaryFolderPathFromEntryFile","TemporaryFolderCreator","entryFile","children","created","setCreated","verbose","temporaryFolder","items","waitingDescription","runningDescription","errorDescription","runner","recursive","finishedDescription","onFinish"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,SAAS,QAAQ,UAAU;AACpC,OAAOC,SAASC,OAAO,EAAaC,QAAQ,QAAQ,QAAQ;AAC5D,SAASC,SAAS,QAAQ,sCAAsC;AAEhE,SAASC,qBAAqB,QAAQ,+DAA+D;AACrG,SAASC,sCAAsC,QAAQ,kDAAkD;AAOzG,OAAO,MAAMC,yBAAyB,CAAC,EAAEC,SAAS,EAAEC,QAAQ,EAAS;IACjE,MAAM,CAACC,SAASC,WAAW,GAAGR,SAAS;IACvC,MAAM,EAAES,OAAO,EAAE,GAAGP;IACpB,MAAMQ,kBAAkBX,QAAQ;QAC5B,OAAOI,uCAAuCE;IAClD,GAAG;QAACA;KAAU;IAEd,MAAMM,QAAQZ,QAAQ;QAClB,OAAO;YACH;gBACIa,oBAAoB;gBACpBC,oBAAoB;gBACpBC,kBAAkB;gBAClBC,QAAQ;oBACJ,IAAI,CAACL,iBAAiB;wBAClB,OAAO;oBACX;oBAEAb,UAAUa,iBAAiB;wBAAEM,WAAW;oBAAK;oBAE7C,OAAO;gBACX;gBACAC,qBAAqB;oBACjB,OAAO,CAAC,oBAAoB,EACxBR,UAAU,CAAC,CAAC,EAAEC,gBAAgB,EAAE,CAAC,GAAG,GACvC,OAAO,CAAC;gBACb;YACJ;SACH;IACL,GAAG;QAACH;KAAQ;IAEZ,qBACI,wDACI,oBAACN;QAAUU,OAAOA;QAAOO,UAAU,IAAMV,WAAW;QACnDD,WAAWD;AAGxB,EAAE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const createTemporaryFolderPathFromEntryFile: (entryFilePath: string) => string;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { createHash } from 'crypto';
|
2
|
+
import { tmpdir } from 'os';
|
3
|
+
import { join } from 'path';
|
4
|
+
export const createTemporaryFolderPathFromEntryFile = (entryFilePath)=>{
|
5
|
+
const hash = createHash('sha256').update(entryFilePath).digest('hex').slice(0, 8);
|
6
|
+
return join(tmpdir(), 'crankscript', `run-${hash}`);
|
7
|
+
};
|
8
|
+
|
9
|
+
//# sourceMappingURL=createTemporaryFolderPathFromEntryFile.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/fn/createTemporaryFolderPathFromEntryFile.ts"],"sourcesContent":["import { createHash } from 'crypto';\nimport { tmpdir } from 'os';\nimport { join } from 'path';\n\nexport const createTemporaryFolderPathFromEntryFile = (\n entryFilePath: string,\n) => {\n const hash = createHash('sha256')\n .update(entryFilePath)\n .digest('hex')\n .slice(0, 8);\n\n return join(tmpdir(), 'crankscript', `run-${hash}`);\n};\n"],"names":["createHash","tmpdir","join","createTemporaryFolderPathFromEntryFile","entryFilePath","hash","update","digest","slice"],"rangeMappings":";;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,SAAS;AACpC,SAASC,MAAM,QAAQ,KAAK;AAC5B,SAASC,IAAI,QAAQ,OAAO;AAE5B,OAAO,MAAMC,yCAAyC,CAClDC;IAEA,MAAMC,OAAOL,WAAW,UACnBM,MAAM,CAACF,eACPG,MAAM,CAAC,OACPC,KAAK,CAAC,GAAG;IAEd,OAAON,KAAKD,UAAU,eAAe,CAAC,IAAI,EAAEI,KAAK,CAAC;AACtD,EAAE"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { watch } from 'chokidar';
|
2
|
+
import { useEffect, useRef } from 'react';
|
3
|
+
export const useFileWatcher = (options)=>{
|
4
|
+
const watcher = useRef(null);
|
5
|
+
const started = useRef(false);
|
6
|
+
useEffect(()=>{
|
7
|
+
if (!options.enabled || started.current) {
|
8
|
+
return;
|
9
|
+
}
|
10
|
+
watcher.current = watch(options.watchPath, {
|
11
|
+
ignoreInitial: true,
|
12
|
+
awaitWriteFinish: {
|
13
|
+
stabilityThreshold: 200,
|
14
|
+
pollInterval: 100
|
15
|
+
}
|
16
|
+
});
|
17
|
+
if (options.additionalGlobs) {
|
18
|
+
watcher.current.add(options.additionalGlobs);
|
19
|
+
}
|
20
|
+
watcher.current.on('change', ()=>{
|
21
|
+
options.onChange();
|
22
|
+
});
|
23
|
+
started.current = true;
|
24
|
+
return ()=>{
|
25
|
+
var _watcher_current;
|
26
|
+
(_watcher_current = watcher.current) == null ? void 0 : _watcher_current.close();
|
27
|
+
watcher.current = null;
|
28
|
+
started.current = false;
|
29
|
+
};
|
30
|
+
}, [
|
31
|
+
options.enabled,
|
32
|
+
options.watchPath,
|
33
|
+
options.onChange
|
34
|
+
]);
|
35
|
+
};
|
36
|
+
|
37
|
+
//# sourceMappingURL=useFileWatcher.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/hooks/useFileWatcher.ts"],"sourcesContent":["import { FSWatcher, watch } from 'chokidar';\nimport { useEffect, useRef } from 'react';\n\nexport const useFileWatcher = (options: {\n watchPath: string;\n additionalGlobs?: string[];\n onChange: () => void;\n enabled: boolean;\n}) => {\n const watcher = useRef<FSWatcher | null>(null);\n const started = useRef(false);\n\n useEffect(() => {\n if (!options.enabled || started.current) {\n return;\n }\n\n watcher.current = watch(options.watchPath, {\n ignoreInitial: true,\n awaitWriteFinish: {\n stabilityThreshold: 200,\n pollInterval: 100,\n },\n });\n\n if (options.additionalGlobs) {\n watcher.current.add(options.additionalGlobs);\n }\n\n watcher.current.on('change', () => {\n options.onChange();\n });\n\n started.current = true;\n\n return () => {\n watcher.current?.close();\n watcher.current = null;\n started.current = false;\n };\n }, [options.enabled, options.watchPath, options.onChange]);\n};\n"],"names":["watch","useEffect","useRef","useFileWatcher","options","watcher","started","enabled","current","watchPath","ignoreInitial","awaitWriteFinish","stabilityThreshold","pollInterval","additionalGlobs","add","on","onChange","close"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAAoBA,KAAK,QAAQ,WAAW;AAC5C,SAASC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAE1C,OAAO,MAAMC,iBAAiB,CAACC;IAM3B,MAAMC,UAAUH,OAAyB;IACzC,MAAMI,UAAUJ,OAAO;IAEvBD,UAAU;QACN,IAAI,CAACG,QAAQG,OAAO,IAAID,QAAQE,OAAO,EAAE;YACrC;QACJ;QAEAH,QAAQG,OAAO,GAAGR,MAAMI,QAAQK,SAAS,EAAE;YACvCC,eAAe;YACfC,kBAAkB;gBACdC,oBAAoB;gBACpBC,cAAc;YAClB;QACJ;QAEA,IAAIT,QAAQU,eAAe,EAAE;YACzBT,QAAQG,OAAO,CAACO,GAAG,CAACX,QAAQU,eAAe;QAC/C;QAEAT,QAAQG,OAAO,CAACQ,EAAE,CAAC,UAAU;YACzBZ,QAAQa,QAAQ;QACpB;QAEAX,QAAQE,OAAO,GAAG;QAElB,OAAO;gBACHH;aAAAA,mBAAAA,QAAQG,OAAO,qBAAfH,iBAAiBa,KAAK;YACtBb,QAAQG,OAAO,GAAG;YAClBF,QAAQE,OAAO,GAAG;QACtB;IACJ,GAAG;QAACJ,QAAQG,OAAO;QAAEH,QAAQK,SAAS;QAAEL,QAAQa,QAAQ;KAAC;AAC7D,EAAE"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Environment } from '../../../environment/dto/Environment.js';
|
2
|
+
interface Props {
|
3
|
+
path: string;
|
4
|
+
environment: Environment;
|
5
|
+
watchForChanges: boolean;
|
6
|
+
recompileOnly: boolean;
|
7
|
+
background: boolean;
|
8
|
+
entryFile?: string;
|
9
|
+
luaOutputPath?: string;
|
10
|
+
gameOutputPath?: string;
|
11
|
+
requireWithinProjectPath?: boolean;
|
12
|
+
additionalGlobs?: string[];
|
13
|
+
}
|
14
|
+
export declare const useSimulatorTasks: ({ path, environment, watchForChanges, recompileOnly, background, entryFile, luaOutputPath, gameOutputPath, requireWithinProjectPath, additionalGlobs, }: Props) => {
|
15
|
+
tasks: import("../../../types.js").CheckListItem<unknown>[];
|
16
|
+
handleFinish: (hasFailure: boolean) => void;
|
17
|
+
hasChanged: boolean;
|
18
|
+
isWatching: boolean;
|
19
|
+
hasChangedMessage: boolean;
|
20
|
+
hasFailure: boolean;
|
21
|
+
};
|
22
|
+
export {};
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import { join } from 'node:path';
|
2
|
+
import open from 'open';
|
3
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
4
|
+
import { useState } from 'react';
|
5
|
+
import { useRef } from 'react';
|
6
|
+
import { isWindows } from '../../../utils/platform.js';
|
7
|
+
import { isMac } from '../../../utils/platform.js';
|
8
|
+
import { useFileWatcher } from './useFileWatcher.js';
|
9
|
+
import { getPdcPathFromEnvironment } from '../../CompileCommand/fn/getPdcPathFromEnvironment.js';
|
10
|
+
import { useCompileTasks } from '../../CompileCommand/hooks/useCompileTasks.js';
|
11
|
+
import { validateEntryPoint } from '../../TranspileCommand/fn/validateEntryPoint.js';
|
12
|
+
import { validateExitPoint } from '../../TranspileCommand/fn/validateExitPoint.js';
|
13
|
+
import { useTranspileTasks } from '../../TranspileCommand/hooks/useTranspileTasks.js';
|
14
|
+
import { TranspileMode } from '../../TranspileCommand/types.js';
|
15
|
+
import { getSimulatorPathFromEnvironment } from '../fn/getSimulatorPathFromEnvironment.js';
|
16
|
+
export const useSimulatorTasks = ({ path, environment, watchForChanges, recompileOnly, background, entryFile, luaOutputPath, gameOutputPath, requireWithinProjectPath = true, additionalGlobs = [] })=>{
|
17
|
+
const [isWatching, setIsWatching] = useState(false);
|
18
|
+
const [hasChanged, setHasChanged] = useState(false);
|
19
|
+
const [hasChangedMessage, setHasChangedMessage] = useState(false);
|
20
|
+
const [hasFailure, setHasFailure] = useState(false);
|
21
|
+
const didRun = useRef(false);
|
22
|
+
useEffect(()=>{
|
23
|
+
if (hasChanged) {
|
24
|
+
setHasChanged(false);
|
25
|
+
}
|
26
|
+
}, [
|
27
|
+
hasChanged,
|
28
|
+
setHasChanged
|
29
|
+
]);
|
30
|
+
const transpileTasks = useTranspileTasks({
|
31
|
+
entryPoint: validateEntryPoint({
|
32
|
+
projectPath: path,
|
33
|
+
entryFile: entryFile != null ? entryFile : join(path, 'src', 'index.ts'),
|
34
|
+
requireWithinProjectPath
|
35
|
+
}),
|
36
|
+
exitPoint: validateExitPoint({
|
37
|
+
projectPath: path,
|
38
|
+
exitFile: join(...luaOutputPath ? [
|
39
|
+
luaOutputPath
|
40
|
+
] : [
|
41
|
+
path,
|
42
|
+
'Source'
|
43
|
+
], 'main.lua'),
|
44
|
+
requireWithinProjectPath
|
45
|
+
}),
|
46
|
+
transpileMode: entryFile ? TranspileMode.File : TranspileMode.Project
|
47
|
+
});
|
48
|
+
const compileTasks = useCompileTasks({
|
49
|
+
pdcPath: getPdcPathFromEnvironment(environment),
|
50
|
+
outputPath: gameOutputPath
|
51
|
+
});
|
52
|
+
const handleFinish = useCallback((hasFailure)=>{
|
53
|
+
setHasFailure(hasFailure);
|
54
|
+
if (didRun.current && recompileOnly) {
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
didRun.current = true;
|
58
|
+
open(join(gameOutputPath != null ? gameOutputPath : process.cwd(), 'Game.pdx'), {
|
59
|
+
background,
|
60
|
+
app: isMac ? undefined : {
|
61
|
+
name: getSimulatorPathFromEnvironment(environment)
|
62
|
+
}
|
63
|
+
}).then(()=>{
|
64
|
+
if (!watchForChanges) {
|
65
|
+
if (!isWindows) {
|
66
|
+
process.exit();
|
67
|
+
}
|
68
|
+
setTimeout(process.exit, 1000);
|
69
|
+
} else {
|
70
|
+
setHasChangedMessage(false);
|
71
|
+
setIsWatching(true);
|
72
|
+
}
|
73
|
+
});
|
74
|
+
}, [
|
75
|
+
watchForChanges,
|
76
|
+
recompileOnly,
|
77
|
+
gameOutputPath,
|
78
|
+
environment,
|
79
|
+
background
|
80
|
+
]);
|
81
|
+
useFileWatcher({
|
82
|
+
watchPath: entryFile ? entryFile : join(path, 'src'),
|
83
|
+
enabled: isWatching,
|
84
|
+
onChange: ()=>{
|
85
|
+
setHasChanged(true);
|
86
|
+
setHasChangedMessage(true);
|
87
|
+
},
|
88
|
+
additionalGlobs
|
89
|
+
});
|
90
|
+
const tasks = useMemo(()=>{
|
91
|
+
return [
|
92
|
+
...transpileTasks,
|
93
|
+
...compileTasks
|
94
|
+
];
|
95
|
+
}, [
|
96
|
+
transpileTasks,
|
97
|
+
compileTasks
|
98
|
+
]);
|
99
|
+
return {
|
100
|
+
tasks,
|
101
|
+
handleFinish,
|
102
|
+
hasChanged,
|
103
|
+
isWatching,
|
104
|
+
hasChangedMessage,
|
105
|
+
hasFailure
|
106
|
+
};
|
107
|
+
};
|
108
|
+
|
109
|
+
//# sourceMappingURL=useSimulatorTasks.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/SimulatorCommand/hooks/useSimulatorTasks.ts"],"sourcesContent":["import { join } from 'node:path';\nimport open from 'open';\nimport { useCallback, useEffect, useMemo } from 'react';\nimport { useState } from 'react';\nimport { useRef } from 'react';\nimport { CheckListProps } from '@/cli/components/CheckList/CheckList.js';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { isWindows } from '@/cli/utils/platform.js';\nimport { isMac } from '@/cli/utils/platform.js';\nimport { useFileWatcher } from './useFileWatcher.js';\nimport { getPdcPathFromEnvironment } from '../../CompileCommand/fn/getPdcPathFromEnvironment.js';\nimport { useCompileTasks } from '../../CompileCommand/hooks/useCompileTasks.js';\nimport { validateEntryPoint } from '../../TranspileCommand/fn/validateEntryPoint.js';\nimport { validateExitPoint } from '../../TranspileCommand/fn/validateExitPoint.js';\nimport { useTranspileTasks } from '../../TranspileCommand/hooks/useTranspileTasks.js';\nimport { TranspileMode } from '../../TranspileCommand/types.js';\nimport { getSimulatorPathFromEnvironment } from '../fn/getSimulatorPathFromEnvironment.js';\n\ninterface Props {\n path: string;\n environment: Environment;\n watchForChanges: boolean;\n recompileOnly: boolean;\n background: boolean;\n entryFile?: string;\n luaOutputPath?: string;\n gameOutputPath?: string;\n requireWithinProjectPath?: boolean;\n additionalGlobs?: string[];\n}\n\nexport const useSimulatorTasks = ({\n path,\n environment,\n watchForChanges,\n recompileOnly,\n background,\n entryFile,\n luaOutputPath,\n gameOutputPath,\n requireWithinProjectPath = true,\n additionalGlobs = [],\n}: Props) => {\n const [isWatching, setIsWatching] = useState(false);\n const [hasChanged, setHasChanged] = useState(false);\n const [hasChangedMessage, setHasChangedMessage] = useState(false);\n const [hasFailure, setHasFailure] = useState(false);\n const didRun = useRef(false);\n\n useEffect(() => {\n if (hasChanged) {\n setHasChanged(false);\n }\n }, [hasChanged, setHasChanged]);\n\n const transpileTasks = useTranspileTasks({\n entryPoint: validateEntryPoint({\n projectPath: path,\n entryFile: entryFile ?? join(path, 'src', 'index.ts'),\n requireWithinProjectPath,\n }),\n exitPoint: validateExitPoint({\n projectPath: path,\n exitFile: join(\n ...(luaOutputPath ? [luaOutputPath] : [path, 'Source']),\n 'main.lua',\n ),\n requireWithinProjectPath,\n }),\n transpileMode: entryFile ? TranspileMode.File : TranspileMode.Project,\n });\n\n const compileTasks = useCompileTasks({\n pdcPath: getPdcPathFromEnvironment(environment),\n outputPath: gameOutputPath,\n });\n\n const handleFinish = useCallback(\n (hasFailure => {\n setHasFailure(hasFailure);\n\n if (didRun.current && recompileOnly) {\n return;\n }\n\n didRun.current = true;\n\n open(join(gameOutputPath ?? process.cwd(), 'Game.pdx'), {\n background,\n app: isMac\n ? undefined\n : {\n name: getSimulatorPathFromEnvironment(environment),\n },\n }).then(() => {\n if (!watchForChanges) {\n if (!isWindows) {\n process.exit();\n }\n setTimeout(process.exit, 1000);\n } else {\n setHasChangedMessage(false);\n setIsWatching(true);\n }\n });\n }) satisfies CheckListProps['onFinish'],\n [\n watchForChanges,\n recompileOnly,\n gameOutputPath,\n environment,\n background,\n ],\n );\n\n useFileWatcher({\n watchPath: entryFile ? entryFile : join(path, 'src'),\n enabled: isWatching,\n onChange: () => {\n setHasChanged(true);\n setHasChangedMessage(true);\n },\n additionalGlobs,\n });\n\n const tasks = useMemo(() => {\n return [...transpileTasks, ...compileTasks];\n }, [transpileTasks, compileTasks]);\n\n return {\n tasks,\n handleFinish,\n hasChanged,\n isWatching,\n hasChangedMessage,\n hasFailure,\n };\n};\n"],"names":["join","open","useCallback","useEffect","useMemo","useState","useRef","isWindows","isMac","useFileWatcher","getPdcPathFromEnvironment","useCompileTasks","validateEntryPoint","validateExitPoint","useTranspileTasks","TranspileMode","getSimulatorPathFromEnvironment","useSimulatorTasks","path","environment","watchForChanges","recompileOnly","background","entryFile","luaOutputPath","gameOutputPath","requireWithinProjectPath","additionalGlobs","isWatching","setIsWatching","hasChanged","setHasChanged","hasChangedMessage","setHasChangedMessage","hasFailure","setHasFailure","didRun","transpileTasks","entryPoint","projectPath","exitPoint","exitFile","transpileMode","File","Project","compileTasks","pdcPath","outputPath","handleFinish","current","process","cwd","app","undefined","name","then","exit","setTimeout","watchPath","enabled","onChange","tasks"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AACjC,OAAOC,UAAU,OAAO;AACxB,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,QAAQ,QAAQ;AACxD,SAASC,QAAQ,QAAQ,QAAQ;AACjC,SAASC,MAAM,QAAQ,QAAQ;AAG/B,SAASC,SAAS,QAAQ,0BAA0B;AACpD,SAASC,KAAK,QAAQ,0BAA0B;AAChD,SAASC,cAAc,QAAQ,sBAAsB;AACrD,SAASC,yBAAyB,QAAQ,uDAAuD;AACjG,SAASC,eAAe,QAAQ,gDAAgD;AAChF,SAASC,kBAAkB,QAAQ,kDAAkD;AACrF,SAASC,iBAAiB,QAAQ,iDAAiD;AACnF,SAASC,iBAAiB,QAAQ,oDAAoD;AACtF,SAASC,aAAa,QAAQ,kCAAkC;AAChE,SAASC,+BAA+B,QAAQ,2CAA2C;AAe3F,OAAO,MAAMC,oBAAoB,CAAC,EAC9BC,IAAI,EACJC,WAAW,EACXC,eAAe,EACfC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,aAAa,EACbC,cAAc,EACdC,2BAA2B,IAAI,EAC/BC,kBAAkB,EAAE,EAChB;IACJ,MAAM,CAACC,YAAYC,cAAc,GAAGxB,SAAS;IAC7C,MAAM,CAACyB,YAAYC,cAAc,GAAG1B,SAAS;IAC7C,MAAM,CAAC2B,mBAAmBC,qBAAqB,GAAG5B,SAAS;IAC3D,MAAM,CAAC6B,YAAYC,cAAc,GAAG9B,SAAS;IAC7C,MAAM+B,SAAS9B,OAAO;IAEtBH,UAAU;QACN,IAAI2B,YAAY;YACZC,cAAc;QAClB;IACJ,GAAG;QAACD;QAAYC;KAAc;IAE9B,MAAMM,iBAAiBvB,kBAAkB;QACrCwB,YAAY1B,mBAAmB;YAC3B2B,aAAarB;YACbK,WAAWA,oBAAAA,YAAavB,KAAKkB,MAAM,OAAO;YAC1CQ;QACJ;QACAc,WAAW3B,kBAAkB;YACzB0B,aAAarB;YACbuB,UAAUzC,QACFwB,gBAAgB;gBAACA;aAAc,GAAG;gBAACN;gBAAM;aAAS,EACtD;YAEJQ;QACJ;QACAgB,eAAenB,YAAYR,cAAc4B,IAAI,GAAG5B,cAAc6B,OAAO;IACzE;IAEA,MAAMC,eAAelC,gBAAgB;QACjCmC,SAASpC,0BAA0BS;QACnC4B,YAAYtB;IAChB;IAEA,MAAMuB,eAAe9C,YAChBgC,CAAAA;QACGC,cAAcD;QAEd,IAAIE,OAAOa,OAAO,IAAI5B,eAAe;YACjC;QACJ;QAEAe,OAAOa,OAAO,GAAG;QAEjBhD,KAAKD,KAAKyB,yBAAAA,iBAAkByB,QAAQC,GAAG,IAAI,aAAa;YACpD7B;YACA8B,KAAK5C,QACC6C,YACA;gBACIC,MAAMtC,gCAAgCG;YAC1C;QACV,GAAGoC,IAAI,CAAC;YACJ,IAAI,CAACnC,iBAAiB;gBAClB,IAAI,CAACb,WAAW;oBACZ2C,QAAQM,IAAI;gBAChB;gBACAC,WAAWP,QAAQM,IAAI,EAAE;YAC7B,OAAO;gBACHvB,qBAAqB;gBACrBJ,cAAc;YAClB;QACJ;IACJ,GACA;QACIT;QACAC;QACAI;QACAN;QACAG;KACH;IAGLb,eAAe;QACXiD,WAAWnC,YAAYA,YAAYvB,KAAKkB,MAAM;QAC9CyC,SAAS/B;QACTgC,UAAU;YACN7B,cAAc;YACdE,qBAAqB;QACzB;QACAN;IACJ;IAEA,MAAMkC,QAAQzD,QAAQ;QAClB,OAAO;eAAIiC;eAAmBQ;SAAa;IAC/C,GAAG;QAACR;QAAgBQ;KAAa;IAEjC,OAAO;QACHgB;QACAb;QACAlB;QACAF;QACAI;QACAE;IACJ;AACJ,EAAE"}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { RenderableCommand } from '../../commands/RenderableCommand.js';
|
3
|
+
export declare const defaultProjectPath: string;
|
3
4
|
export declare const projectPathOption: string;
|
4
5
|
export declare class TranspileCommand extends RenderableCommand {
|
5
6
|
static paths: string[][];
|
6
7
|
static usage: import("clipanion").Usage;
|
7
8
|
entryFile: string;
|
8
9
|
exitFile: string;
|
10
|
+
toybox: string | undefined;
|
9
11
|
projectPath: string;
|
10
12
|
render(): React.JSX.Element;
|
11
13
|
}
|
@@ -6,8 +6,9 @@ import { RenderableCommand } from '../../commands/RenderableCommand.js';
|
|
6
6
|
import { Transpile } from '../../commands/TranspileCommand/components/Transpile.js';
|
7
7
|
import { validateEntryPoint } from '../../commands/TranspileCommand/fn/validateEntryPoint.js';
|
8
8
|
import { validateExitPoint } from './fn/validateExitPoint.js';
|
9
|
-
export const
|
10
|
-
|
9
|
+
export const defaultProjectPath = process.cwd();
|
10
|
+
export const projectPathOption = Option.String('-p,--path', defaultProjectPath, {
|
11
|
+
description: `Where to find the project. Defaults to the current working directory ("${defaultProjectPath}")`,
|
11
12
|
validator: t.isString()
|
12
13
|
});
|
13
14
|
export class TranspileCommand extends RenderableCommand {
|
@@ -22,7 +23,8 @@ export class TranspileCommand extends RenderableCommand {
|
|
22
23
|
});
|
23
24
|
return /*#__PURE__*/ React.createElement(Transpile, {
|
24
25
|
entryPoint: validatedEntryPoint,
|
25
|
-
exitPoint: validatedExitPoint
|
26
|
+
exitPoint: validatedExitPoint,
|
27
|
+
toybox: this.toybox
|
26
28
|
});
|
27
29
|
}
|
28
30
|
constructor(...args){
|
@@ -31,10 +33,14 @@ export class TranspileCommand extends RenderableCommand {
|
|
31
33
|
description: 'The entry point to transpile',
|
32
34
|
validator: t.isString()
|
33
35
|
});
|
34
|
-
this.exitFile = Option.String('-o,--output', 'Source/
|
36
|
+
this.exitFile = Option.String('-o,--output', 'Source/index.lua', {
|
35
37
|
description: 'The output bundle',
|
36
38
|
validator: t.isString()
|
37
39
|
});
|
40
|
+
this.toybox = Option.String('--toybox', {
|
41
|
+
description: 'Output a toybox compatible bundle which exports to this namespace',
|
42
|
+
validator: t.isString()
|
43
|
+
});
|
38
44
|
this.projectPath = projectPathOption;
|
39
45
|
}
|
40
46
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/cli/src/commands/TranspileCommand/TranspileCommand.tsx"],"sourcesContent":["import process from 'node:process';\nimport { Command, Option } from 'clipanion';\nimport React from 'react';\nimport * as t from 'typanion';\nimport { RenderableCommand } from '@/cli/commands/RenderableCommand.js';\nimport { Transpile } from '@/cli/commands/TranspileCommand/components/Transpile.js';\nimport { validateEntryPoint } from '@/cli/commands/TranspileCommand/fn/validateEntryPoint.js';\nimport { validateExitPoint } from './fn/validateExitPoint.js';\n\nexport const projectPathOption = Option.String('-p,--path'
|
1
|
+
{"version":3,"sources":["../../../../../../libs/cli/src/commands/TranspileCommand/TranspileCommand.tsx"],"sourcesContent":["import process from 'node:process';\nimport { Command, Option } from 'clipanion';\nimport React from 'react';\nimport * as t from 'typanion';\nimport { RenderableCommand } from '@/cli/commands/RenderableCommand.js';\nimport { Transpile } from '@/cli/commands/TranspileCommand/components/Transpile.js';\nimport { validateEntryPoint } from '@/cli/commands/TranspileCommand/fn/validateEntryPoint.js';\nimport { validateExitPoint } from './fn/validateExitPoint.js';\n\nexport const defaultProjectPath = process.cwd();\nexport const projectPathOption = Option.String(\n '-p,--path',\n defaultProjectPath,\n {\n description: `Where to find the project. Defaults to the current working directory (\"${defaultProjectPath}\")`,\n validator: t.isString(),\n },\n);\n\nexport class TranspileCommand extends RenderableCommand {\n static override paths = [['transpile']];\n\n static override usage = Command.Usage({\n description: 'Transpile TypeScript files to Lua',\n });\n\n entryFile = Option.String('-i,--input', 'src/index.ts', {\n description: 'The entry point to transpile',\n validator: t.isString(),\n });\n\n exitFile = Option.String('-o,--output', 'Source/index.lua', {\n description: 'The output bundle',\n validator: t.isString(),\n });\n\n toybox = Option.String('--toybox', {\n description:\n 'Output a toybox compatible bundle which exports to this namespace',\n validator: t.isString(),\n });\n\n projectPath = projectPathOption;\n\n override render() {\n const validatedEntryPoint = validateEntryPoint({\n projectPath: this.projectPath,\n entryFile: this.entryFile,\n });\n\n const validatedExitPoint = validateExitPoint({\n projectPath: this.projectPath,\n exitFile: this.exitFile,\n });\n\n return (\n <Transpile\n entryPoint={validatedEntryPoint}\n exitPoint={validatedExitPoint}\n toybox={this.toybox}\n />\n );\n }\n}\n"],"names":["process","Command","Option","React","t","RenderableCommand","Transpile","validateEntryPoint","validateExitPoint","defaultProjectPath","cwd","projectPathOption","String","description","validator","isString","TranspileCommand","render","validatedEntryPoint","projectPath","entryFile","validatedExitPoint","exitFile","entryPoint","exitPoint","toybox","paths","usage","Usage"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,aAAa,eAAe;AACnC,SAASC,OAAO,EAAEC,MAAM,QAAQ,YAAY;AAC5C,OAAOC,WAAW,QAAQ;AAC1B,YAAYC,OAAO,WAAW;AAC9B,SAASC,iBAAiB,QAAQ,sCAAsC;AACxE,SAASC,SAAS,QAAQ,0DAA0D;AACpF,SAASC,kBAAkB,QAAQ,2DAA2D;AAC9F,SAASC,iBAAiB,QAAQ,4BAA4B;AAE9D,OAAO,MAAMC,qBAAqBT,QAAQU,GAAG,GAAG;AAChD,OAAO,MAAMC,oBAAoBT,OAAOU,MAAM,CAC1C,aACAH,oBACA;IACII,aAAa,CAAC,uEAAuE,EAAEJ,mBAAmB,EAAE,CAAC;IAC7GK,WAAWV,EAAEW,QAAQ;AACzB,GACF;AAEF,OAAO,MAAMC,yBAAyBX;IAyBzBY,SAAS;QACd,MAAMC,sBAAsBX,mBAAmB;YAC3CY,aAAa,IAAI,CAACA,WAAW;YAC7BC,WAAW,IAAI,CAACA,SAAS;QAC7B;QAEA,MAAMC,qBAAqBb,kBAAkB;YACzCW,aAAa,IAAI,CAACA,WAAW;YAC7BG,UAAU,IAAI,CAACA,QAAQ;QAC3B;QAEA,qBACI,oBAAChB;YACGiB,YAAYL;YACZM,WAAWH;YACXI,QAAQ,IAAI,CAACA,MAAM;;IAG/B;;;aApCAL,YAAYlB,OAAOU,MAAM,CAAC,cAAc,gBAAgB;YACpDC,aAAa;YACbC,WAAWV,EAAEW,QAAQ;QACzB;aAEAO,WAAWpB,OAAOU,MAAM,CAAC,eAAe,oBAAoB;YACxDC,aAAa;YACbC,WAAWV,EAAEW,QAAQ;QACzB;aAEAU,SAASvB,OAAOU,MAAM,CAAC,YAAY;YAC/BC,aACI;YACJC,WAAWV,EAAEW,QAAQ;QACzB;aAEAI,cAAcR;;AAqBlB;AA5CaK,iBACOU,QAAQ;IAAC;QAAC;KAAY;CAAC;AAD9BV,iBAGOW,QAAQ1B,QAAQ2B,KAAK,CAAC;IAClCf,aAAa;AACjB"}
|
@@ -4,6 +4,7 @@ import { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';
|
|
4
4
|
interface Props {
|
5
5
|
entryPoint: ValidatedEntryPoint;
|
6
6
|
exitPoint: ValidatedExitPoint;
|
7
|
+
toybox?: string;
|
7
8
|
}
|
8
|
-
export declare const Transpile: ({ entryPoint, exitPoint }: Props) => React.JSX.Element;
|
9
|
+
export declare const Transpile: ({ entryPoint, exitPoint, toybox }: Props) => React.JSX.Element;
|
9
10
|
export {};
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { useTranspileTasks } from '../../../commands/TranspileCommand/hooks/useTranspileTasks.js';
|
3
3
|
import { CheckList } from '../../../components/CheckList/index.js';
|
4
|
-
export const Transpile = ({ entryPoint, exitPoint })=>{
|
4
|
+
export const Transpile = ({ entryPoint, exitPoint, toybox })=>{
|
5
5
|
const items = useTranspileTasks({
|
6
6
|
entryPoint,
|
7
|
-
exitPoint
|
7
|
+
exitPoint,
|
8
|
+
toybox
|
8
9
|
});
|
9
10
|
return /*#__PURE__*/ React.createElement(CheckList, {
|
10
11
|
items: items,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/components/Transpile.tsx"],"sourcesContent":["import React from 'react';\nimport { useTranspileTasks } from '@/cli/commands/TranspileCommand/hooks/useTranspileTasks.js';\nimport { ValidatedEntryPoint } from '@/cli/commands/TranspileCommand/model/ValidatedEntryPoint.js';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';\n\ninterface Props {\n entryPoint: ValidatedEntryPoint;\n exitPoint: ValidatedExitPoint;\n}\n\nexport const Transpile = ({ entryPoint, exitPoint }: Props) => {\n const items = useTranspileTasks({\n entryPoint,\n exitPoint,\n });\n\n return <CheckList items={items} onFinish={() => process.exit} />;\n};\n"],"names":["React","useTranspileTasks","CheckList","Transpile","entryPoint","exitPoint","items","onFinish","process","exit"],"rangeMappings":"
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/components/Transpile.tsx"],"sourcesContent":["import React from 'react';\nimport { useTranspileTasks } from '@/cli/commands/TranspileCommand/hooks/useTranspileTasks.js';\nimport { ValidatedEntryPoint } from '@/cli/commands/TranspileCommand/model/ValidatedEntryPoint.js';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';\n\ninterface Props {\n entryPoint: ValidatedEntryPoint;\n exitPoint: ValidatedExitPoint;\n toybox?: string;\n}\n\nexport const Transpile = ({ entryPoint, exitPoint, toybox }: Props) => {\n const items = useTranspileTasks({\n entryPoint,\n exitPoint,\n toybox,\n });\n\n return <CheckList items={items} onFinish={() => process.exit} />;\n};\n"],"names":["React","useTranspileTasks","CheckList","Transpile","entryPoint","exitPoint","toybox","items","onFinish","process","exit"],"rangeMappings":";;;;;;;;;;;;;","mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,SAASC,iBAAiB,QAAQ,6DAA6D;AAE/F,SAASC,SAAS,QAAQ,sCAAsC;AAShE,OAAO,MAAMC,YAAY,CAAC,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAS;IAC9D,MAAMC,QAAQN,kBAAkB;QAC5BG;QACAC;QACAC;IACJ;IAEA,qBAAO,oBAACJ;QAAUK,OAAOA;QAAOC,UAAU,IAAMC,QAAQC,IAAI;;AAChE,EAAE"}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import * as tstl from 'typescript-to-lua';
|
2
2
|
import { ValidatedEntryPoint } from '../model/ValidatedEntryPoint.js';
|
3
3
|
import { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';
|
4
|
-
|
4
|
+
import { TranspileMode } from '../types.js';
|
5
|
+
export declare const transpile: ({ entryPoint, exitPoint, transpileMode, }: {
|
5
6
|
entryPoint: ValidatedEntryPoint;
|
6
7
|
exitPoint: ValidatedExitPoint;
|
7
|
-
|
8
|
+
transpileMode?: TranspileMode;
|
8
9
|
}) => tstl.EmitResult;
|
@@ -4,15 +4,31 @@ import { basename, dirname, join } from 'node:path';
|
|
4
4
|
import * as tstl from 'typescript-to-lua';
|
5
5
|
import { LuaTarget } from 'typescript-to-lua';
|
6
6
|
import { RootFolder } from '../../../constants.js';
|
7
|
-
|
7
|
+
import { TranspileMode } from '../types.js';
|
8
|
+
export const transpile = ({ entryPoint, exitPoint, transpileMode = TranspileMode.Project })=>{
|
8
9
|
const exitDir = dirname(exitPoint.exitPath);
|
9
10
|
if (!existsSync(exitDir)) {
|
10
11
|
mkdirSync(exitDir, {
|
11
12
|
recursive: true
|
12
13
|
});
|
13
14
|
}
|
15
|
+
if (transpileMode === TranspileMode.File) {
|
16
|
+
return tstl.transpileFiles([
|
17
|
+
entryPoint.entryFile
|
18
|
+
], {
|
19
|
+
luaTarget: LuaTarget.Lua54,
|
20
|
+
outDir: dirname(exitPoint.exitPath),
|
21
|
+
luaBundle: basename(exitPoint.exitPath),
|
22
|
+
luaBundleEntry: join(entryPoint.entryFile),
|
23
|
+
skipLibCheck: true,
|
24
|
+
luaPlugins: [
|
25
|
+
{
|
26
|
+
name: join(RootFolder, 'assets', 'index.js')
|
27
|
+
}
|
28
|
+
]
|
29
|
+
});
|
30
|
+
}
|
14
31
|
return tstl.transpileProject(join(entryPoint.projectPath, 'tsconfig.json'), {
|
15
|
-
buildMode,
|
16
32
|
luaTarget: LuaTarget.Lua54,
|
17
33
|
outDir: dirname(exitPoint.exitPath),
|
18
34
|
luaBundle: basename(exitPoint.exitPath),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/fn/transpile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdirSync } from 'node:fs';\nimport { basename, dirname, join } from 'node:path';\nimport * as tstl from 'typescript-to-lua';\nimport { LuaTarget } from 'typescript-to-lua';\nimport { RootFolder } from '@/cli/constants.js';\nimport { ValidatedEntryPoint } from '../model/ValidatedEntryPoint.js';\nimport { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';\n\nexport const transpile = ({\n entryPoint,\n exitPoint,\n
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/fn/transpile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdirSync } from 'node:fs';\nimport { basename, dirname, join } from 'node:path';\nimport * as tstl from 'typescript-to-lua';\nimport { LuaTarget } from 'typescript-to-lua';\nimport { RootFolder } from '@/cli/constants.js';\nimport { ValidatedEntryPoint } from '../model/ValidatedEntryPoint.js';\nimport { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';\nimport { TranspileMode } from '../types.js';\n\nexport const transpile = ({\n entryPoint,\n exitPoint,\n transpileMode = TranspileMode.Project,\n}: {\n entryPoint: ValidatedEntryPoint;\n exitPoint: ValidatedExitPoint;\n transpileMode?: TranspileMode;\n}) => {\n const exitDir = dirname(exitPoint.exitPath);\n\n if (!existsSync(exitDir)) {\n mkdirSync(exitDir, { recursive: true });\n }\n\n if (transpileMode === TranspileMode.File) {\n return tstl.transpileFiles([entryPoint.entryFile], {\n luaTarget: LuaTarget.Lua54,\n outDir: dirname(exitPoint.exitPath),\n luaBundle: basename(exitPoint.exitPath),\n luaBundleEntry: join(entryPoint.entryFile),\n skipLibCheck: true,\n luaPlugins: [\n {\n name: join(RootFolder, 'assets', 'index.js'),\n },\n ],\n });\n }\n\n return tstl.transpileProject(\n join(entryPoint.projectPath, 'tsconfig.json'),\n {\n luaTarget: LuaTarget.Lua54,\n outDir: dirname(exitPoint.exitPath),\n luaBundle: basename(exitPoint.exitPath),\n luaBundleEntry: join(entryPoint.entryFile),\n luaPlugins: [\n {\n name: join(RootFolder, 'assets', 'index.js'),\n },\n ],\n },\n );\n};\n"],"names":["existsSync","mkdirSync","basename","dirname","join","tstl","LuaTarget","RootFolder","TranspileMode","transpile","entryPoint","exitPoint","transpileMode","Project","exitDir","exitPath","recursive","File","transpileFiles","entryFile","luaTarget","Lua54","outDir","luaBundle","luaBundleEntry","skipLibCheck","luaPlugins","name","transpileProject","projectPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,UAAU;AACrC,SAASC,SAAS,QAAQ,UAAU;AACpC,SAASC,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,YAAY;AACpD,YAAYC,UAAU,oBAAoB;AAC1C,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,UAAU,QAAQ,qBAAqB;AAGhD,SAASC,aAAa,QAAQ,cAAc;AAE5C,OAAO,MAAMC,YAAY,CAAC,EACtBC,UAAU,EACVC,SAAS,EACTC,gBAAgBJ,cAAcK,OAAO,EAKxC;IACG,MAAMC,UAAUX,QAAQQ,UAAUI,QAAQ;IAE1C,IAAI,CAACf,WAAWc,UAAU;QACtBb,UAAUa,SAAS;YAAEE,WAAW;QAAK;IACzC;IAEA,IAAIJ,kBAAkBJ,cAAcS,IAAI,EAAE;QACtC,OAAOZ,KAAKa,cAAc,CAAC;YAACR,WAAWS,SAAS;SAAC,EAAE;YAC/CC,WAAWd,UAAUe,KAAK;YAC1BC,QAAQnB,QAAQQ,UAAUI,QAAQ;YAClCQ,WAAWrB,SAASS,UAAUI,QAAQ;YACtCS,gBAAgBpB,KAAKM,WAAWS,SAAS;YACzCM,cAAc;YACdC,YAAY;gBACR;oBACIC,MAAMvB,KAAKG,YAAY,UAAU;gBACrC;aACH;QACL;IACJ;IAEA,OAAOF,KAAKuB,gBAAgB,CACxBxB,KAAKM,WAAWmB,WAAW,EAAE,kBAC7B;QACIT,WAAWd,UAAUe,KAAK;QAC1BC,QAAQnB,QAAQQ,UAAUI,QAAQ;QAClCQ,WAAWrB,SAASS,UAAUI,QAAQ;QACtCS,gBAAgBpB,KAAKM,WAAWS,SAAS;QACzCO,YAAY;YACR;gBACIC,MAAMvB,KAAKG,YAAY,UAAU;YACrC;SACH;IACL;AAER,EAAE"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ValidatedEntryPoint } from '../model/ValidatedEntryPoint.js';
|
2
|
-
export declare const validateEntryPoint: (
|
2
|
+
export declare const validateEntryPoint: ({ projectPath, entryFile, requireWithinProjectPath, }: {
|
3
3
|
projectPath: string;
|
4
4
|
entryFile: string;
|
5
|
+
requireWithinProjectPath?: boolean;
|
5
6
|
}) => ValidatedEntryPoint;
|
@@ -1,16 +1,26 @@
|
|
1
1
|
import { existsSync, statSync } from 'node:fs';
|
2
2
|
import { resolve } from 'node:path';
|
3
|
-
export const validateEntryPoint = (
|
4
|
-
const resolvedPath = resolve(
|
5
|
-
const resolvedEntry = resolve(
|
6
|
-
|
7
|
-
|
3
|
+
export const validateEntryPoint = ({ projectPath, entryFile, requireWithinProjectPath = true })=>{
|
4
|
+
const resolvedPath = resolve(projectPath);
|
5
|
+
const resolvedEntry = resolve(entryFile);
|
6
|
+
const projectPathExists = existsSync(resolvedPath);
|
7
|
+
const projectPathIsDirectory = projectPathExists && statSync(resolvedPath).isDirectory();
|
8
|
+
const entryFileExists = existsSync(resolvedEntry);
|
9
|
+
const entryFileIsFile = entryFileExists && statSync(resolvedEntry).isFile();
|
10
|
+
if (!projectPathExists) {
|
11
|
+
throw new Error(`Path "${resolvedPath}" does not exist`);
|
8
12
|
}
|
9
|
-
if (!
|
10
|
-
throw new Error(`"${
|
13
|
+
if (!projectPathIsDirectory) {
|
14
|
+
throw new Error(`Path "${resolvedPath}" is not a directory`);
|
11
15
|
}
|
12
|
-
if (!
|
13
|
-
throw new Error(`
|
16
|
+
if (!entryFileExists) {
|
17
|
+
throw new Error(`Path "${resolvedEntry}" does not exist`);
|
18
|
+
}
|
19
|
+
if (!entryFileIsFile) {
|
20
|
+
throw new Error(`Path "${resolvedEntry}" is not a file`);
|
21
|
+
}
|
22
|
+
if (requireWithinProjectPath && !resolvedEntry.startsWith(resolvedPath)) {
|
23
|
+
throw new Error(`Entry "${resolvedEntry}" must be inside project path "${resolvedPath}"`);
|
14
24
|
}
|
15
25
|
return {
|
16
26
|
__validated: true,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/fn/validateEntryPoint.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { ValidatedEntryPoint } from '../model/ValidatedEntryPoint.js';\n\nexport const validateEntryPoint = (
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/fn/validateEntryPoint.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { ValidatedEntryPoint } from '../model/ValidatedEntryPoint.js';\n\nexport const validateEntryPoint = ({\n projectPath,\n entryFile,\n requireWithinProjectPath = true,\n}: {\n projectPath: string;\n entryFile: string;\n requireWithinProjectPath?: boolean;\n}): ValidatedEntryPoint => {\n const resolvedPath = resolve(projectPath);\n const resolvedEntry = resolve(entryFile);\n const projectPathExists = existsSync(resolvedPath);\n const projectPathIsDirectory =\n projectPathExists && statSync(resolvedPath).isDirectory();\n const entryFileExists = existsSync(resolvedEntry);\n const entryFileIsFile = entryFileExists && statSync(resolvedEntry).isFile();\n\n if (!projectPathExists) {\n throw new Error(`Path \"${resolvedPath}\" does not exist`);\n }\n\n if (!projectPathIsDirectory) {\n throw new Error(`Path \"${resolvedPath}\" is not a directory`);\n }\n\n if (!entryFileExists) {\n throw new Error(`Path \"${resolvedEntry}\" does not exist`);\n }\n\n if (!entryFileIsFile) {\n throw new Error(`Path \"${resolvedEntry}\" is not a file`);\n }\n\n if (requireWithinProjectPath && !resolvedEntry.startsWith(resolvedPath)) {\n throw new Error(\n `Entry \"${resolvedEntry}\" must be inside project path \"${resolvedPath}\"`,\n );\n }\n\n return {\n __validated: true,\n projectPath: resolvedPath,\n entryFile: resolvedEntry,\n } satisfies ValidatedEntryPoint;\n};\n"],"names":["existsSync","statSync","resolve","validateEntryPoint","projectPath","entryFile","requireWithinProjectPath","resolvedPath","resolvedEntry","projectPathExists","projectPathIsDirectory","isDirectory","entryFileExists","entryFileIsFile","isFile","Error","startsWith","__validated"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,EAAEC,QAAQ,QAAQ,UAAU;AAC/C,SAASC,OAAO,QAAQ,YAAY;AAGpC,OAAO,MAAMC,qBAAqB,CAAC,EAC/BC,WAAW,EACXC,SAAS,EACTC,2BAA2B,IAAI,EAKlC;IACG,MAAMC,eAAeL,QAAQE;IAC7B,MAAMI,gBAAgBN,QAAQG;IAC9B,MAAMI,oBAAoBT,WAAWO;IACrC,MAAMG,yBACFD,qBAAqBR,SAASM,cAAcI,WAAW;IAC3D,MAAMC,kBAAkBZ,WAAWQ;IACnC,MAAMK,kBAAkBD,mBAAmBX,SAASO,eAAeM,MAAM;IAEzE,IAAI,CAACL,mBAAmB;QACpB,MAAM,IAAIM,MAAM,CAAC,MAAM,EAAER,aAAa,gBAAgB,CAAC;IAC3D;IAEA,IAAI,CAACG,wBAAwB;QACzB,MAAM,IAAIK,MAAM,CAAC,MAAM,EAAER,aAAa,oBAAoB,CAAC;IAC/D;IAEA,IAAI,CAACK,iBAAiB;QAClB,MAAM,IAAIG,MAAM,CAAC,MAAM,EAAEP,cAAc,gBAAgB,CAAC;IAC5D;IAEA,IAAI,CAACK,iBAAiB;QAClB,MAAM,IAAIE,MAAM,CAAC,MAAM,EAAEP,cAAc,eAAe,CAAC;IAC3D;IAEA,IAAIF,4BAA4B,CAACE,cAAcQ,UAAU,CAACT,eAAe;QACrE,MAAM,IAAIQ,MACN,CAAC,OAAO,EAAEP,cAAc,+BAA+B,EAAED,aAAa,CAAC,CAAC;IAEhF;IAEA,OAAO;QACHU,aAAa;QACbb,aAAaG;QACbF,WAAWG;IACf;AACJ,EAAE"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';
|
2
|
-
export declare const validateExitPoint: (
|
2
|
+
export declare const validateExitPoint: ({ projectPath, exitFile, requireWithinProjectPath, }: {
|
3
3
|
projectPath: string;
|
4
4
|
exitFile: string;
|
5
|
+
requireWithinProjectPath?: boolean;
|
5
6
|
}) => ValidatedExitPoint;
|
@@ -1,19 +1,25 @@
|
|
1
1
|
import { existsSync, statSync } from 'node:fs';
|
2
2
|
import { resolve, dirname } from 'node:path';
|
3
|
-
export const validateExitPoint = (
|
4
|
-
const resolvedPath = resolve(
|
5
|
-
const resolvedExit = resolve(
|
3
|
+
export const validateExitPoint = ({ projectPath, exitFile, requireWithinProjectPath = true })=>{
|
4
|
+
const resolvedPath = resolve(projectPath);
|
5
|
+
const resolvedExit = resolve(exitFile);
|
6
6
|
const exitDir = dirname(resolvedExit);
|
7
|
-
|
8
|
-
|
7
|
+
const projectPathExists = existsSync(resolvedPath);
|
8
|
+
const projectPathIsDirectory = projectPathExists && statSync(resolvedPath).isDirectory();
|
9
|
+
const exitDirExists = existsSync(exitDir);
|
10
|
+
const exitDirIsDirectory = exitDirExists && statSync(exitDir).isDirectory();
|
11
|
+
if (!projectPathExists) {
|
12
|
+
throw new Error(`Path "${resolvedPath}" does not exist`);
|
9
13
|
}
|
10
|
-
if (!
|
14
|
+
if (!projectPathIsDirectory) {
|
15
|
+
throw new Error(`Path "${resolvedPath}" is not a directory`);
|
16
|
+
}
|
17
|
+
if (!exitDirExists) {
|
11
18
|
// Will be created
|
12
|
-
} else if (!
|
13
|
-
throw new Error(`"${exitDir}" exists but is not a directory`);
|
19
|
+
} else if (!exitDirIsDirectory) {
|
20
|
+
throw new Error(`Path "${exitDir}" exists but is not a directory`);
|
14
21
|
}
|
15
|
-
|
16
|
-
if (!exitDir.startsWith(resolvedPath)) {
|
22
|
+
if (requireWithinProjectPath && !exitDir.startsWith(resolvedPath)) {
|
17
23
|
throw new Error(`Exit path must be inside project path`);
|
18
24
|
}
|
19
25
|
return {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/fn/validateExitPoint.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\nimport { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';\n\nexport const validateExitPoint = (
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/fn/validateExitPoint.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\nimport { ValidatedExitPoint } from '../model/ValidatedExitPoint.js';\n\nexport const validateExitPoint = ({\n projectPath,\n exitFile,\n requireWithinProjectPath = true,\n}: {\n projectPath: string;\n exitFile: string;\n requireWithinProjectPath?: boolean;\n}): ValidatedExitPoint => {\n const resolvedPath = resolve(projectPath);\n const resolvedExit = resolve(exitFile);\n const exitDir = dirname(resolvedExit);\n const projectPathExists = existsSync(resolvedPath);\n const projectPathIsDirectory =\n projectPathExists && statSync(resolvedPath).isDirectory();\n const exitDirExists = existsSync(exitDir);\n const exitDirIsDirectory = exitDirExists && statSync(exitDir).isDirectory();\n\n if (!projectPathExists) {\n throw new Error(`Path \"${resolvedPath}\" does not exist`);\n }\n\n if (!projectPathIsDirectory) {\n throw new Error(`Path \"${resolvedPath}\" is not a directory`);\n }\n\n if (!exitDirExists) {\n // Will be created\n } else if (!exitDirIsDirectory) {\n throw new Error(`Path \"${exitDir}\" exists but is not a directory`);\n }\n\n if (requireWithinProjectPath && !exitDir.startsWith(resolvedPath)) {\n throw new Error(`Exit path must be inside project path`);\n }\n\n return {\n __validated: true,\n projectPath: resolvedPath,\n exitPath: resolvedExit,\n } satisfies ValidatedExitPoint;\n};\n"],"names":["existsSync","statSync","resolve","dirname","validateExitPoint","projectPath","exitFile","requireWithinProjectPath","resolvedPath","resolvedExit","exitDir","projectPathExists","projectPathIsDirectory","isDirectory","exitDirExists","exitDirIsDirectory","Error","startsWith","__validated","exitPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,EAAEC,QAAQ,QAAQ,UAAU;AAC/C,SAASC,OAAO,EAAEC,OAAO,QAAQ,YAAY;AAG7C,OAAO,MAAMC,oBAAoB,CAAC,EAC9BC,WAAW,EACXC,QAAQ,EACRC,2BAA2B,IAAI,EAKlC;IACG,MAAMC,eAAeN,QAAQG;IAC7B,MAAMI,eAAeP,QAAQI;IAC7B,MAAMI,UAAUP,QAAQM;IACxB,MAAME,oBAAoBX,WAAWQ;IACrC,MAAMI,yBACFD,qBAAqBV,SAASO,cAAcK,WAAW;IAC3D,MAAMC,gBAAgBd,WAAWU;IACjC,MAAMK,qBAAqBD,iBAAiBb,SAASS,SAASG,WAAW;IAEzE,IAAI,CAACF,mBAAmB;QACpB,MAAM,IAAIK,MAAM,CAAC,MAAM,EAAER,aAAa,gBAAgB,CAAC;IAC3D;IAEA,IAAI,CAACI,wBAAwB;QACzB,MAAM,IAAII,MAAM,CAAC,MAAM,EAAER,aAAa,oBAAoB,CAAC;IAC/D;IAEA,IAAI,CAACM,eAAe;IAChB,kBAAkB;IACtB,OAAO,IAAI,CAACC,oBAAoB;QAC5B,MAAM,IAAIC,MAAM,CAAC,MAAM,EAAEN,QAAQ,+BAA+B,CAAC;IACrE;IAEA,IAAIH,4BAA4B,CAACG,QAAQO,UAAU,CAACT,eAAe;QAC/D,MAAM,IAAIQ,MAAM,CAAC,qCAAqC,CAAC;IAC3D;IAEA,OAAO;QACHE,aAAa;QACbb,aAAaG;QACbW,UAAUV;IACd;AACJ,EAAE"}
|
@@ -1,7 +1,10 @@
|
|
1
1
|
import { ValidatedEntryPoint } from '../../../commands/TranspileCommand/model/ValidatedEntryPoint.js';
|
2
2
|
import { ValidatedExitPoint } from '../../../commands/TranspileCommand/model/ValidatedExitPoint.js';
|
3
3
|
import { CheckListItem } from '../../../types.js';
|
4
|
-
|
4
|
+
import { TranspileMode } from '../types.js';
|
5
|
+
export declare const useTranspileTasks: ({ entryPoint, exitPoint, toybox, transpileMode, }: {
|
5
6
|
entryPoint: ValidatedEntryPoint;
|
6
7
|
exitPoint: ValidatedExitPoint;
|
8
|
+
toybox?: string;
|
9
|
+
transpileMode?: TranspileMode;
|
7
10
|
}) => CheckListItem<unknown>[];
|