crankscript 0.14.0 → 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.
Files changed (58) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/package.json +32 -31
  4. package/src/commands/CompileCommand/components/Compile.js +3 -1
  5. package/src/commands/CompileCommand/components/Compile.js.map +1 -1
  6. package/src/commands/CompileCommand/hooks/useCompileTasks.d.ts +6 -1
  7. package/src/commands/CompileCommand/hooks/useCompileTasks.js +2 -2
  8. package/src/commands/CompileCommand/hooks/useCompileTasks.js.map +1 -1
  9. package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.d.ts +1 -0
  10. package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js +25 -1
  11. package/src/commands/EnvironmentAwareCommand/EnvironmentAwareCommand.js.map +1 -1
  12. package/src/commands/EnvironmentAwareCommand/contexts/CrankScriptContext.d.ts +11 -0
  13. package/src/commands/EnvironmentAwareCommand/contexts/CrankScriptContext.js +20 -0
  14. package/src/commands/EnvironmentAwareCommand/contexts/CrankScriptContext.js.map +1 -0
  15. package/src/commands/GenerateTypes/hooks/useFormatTypeFile.js +4 -4
  16. package/src/commands/GenerateTypes/hooks/useFormatTypeFile.js.map +1 -1
  17. package/src/commands/SimulatorCommand/SimulatorCommand.d.ts +2 -0
  18. package/src/commands/SimulatorCommand/SimulatorCommand.js +27 -3
  19. package/src/commands/SimulatorCommand/SimulatorCommand.js.map +1 -1
  20. package/src/commands/SimulatorCommand/components/Simulator.d.ts +3 -1
  21. package/src/commands/SimulatorCommand/components/Simulator.js +20 -84
  22. package/src/commands/SimulatorCommand/components/Simulator.js.map +1 -1
  23. package/src/commands/SimulatorCommand/components/TemporaryFolderCreator.d.ts +7 -0
  24. package/src/commands/SimulatorCommand/components/TemporaryFolderCreator.js +43 -0
  25. package/src/commands/SimulatorCommand/components/TemporaryFolderCreator.js.map +1 -0
  26. package/src/commands/SimulatorCommand/fn/createTemporaryFolderPathFromEntryFile.d.ts +1 -0
  27. package/src/commands/SimulatorCommand/fn/createTemporaryFolderPathFromEntryFile.js +9 -0
  28. package/src/commands/SimulatorCommand/fn/createTemporaryFolderPathFromEntryFile.js.map +1 -0
  29. package/src/commands/SimulatorCommand/hooks/useFileWatcher.d.ts +6 -0
  30. package/src/commands/SimulatorCommand/hooks/useFileWatcher.js +37 -0
  31. package/src/commands/SimulatorCommand/hooks/useFileWatcher.js.map +1 -0
  32. package/src/commands/SimulatorCommand/hooks/useSimulatorTasks.d.ts +22 -0
  33. package/src/commands/SimulatorCommand/hooks/useSimulatorTasks.js +109 -0
  34. package/src/commands/SimulatorCommand/hooks/useSimulatorTasks.js.map +1 -0
  35. package/src/commands/TranspileCommand/TranspileCommand.d.ts +1 -0
  36. package/src/commands/TranspileCommand/TranspileCommand.js +3 -2
  37. package/src/commands/TranspileCommand/TranspileCommand.js.map +1 -1
  38. package/src/commands/TranspileCommand/fn/transpile.d.ts +3 -2
  39. package/src/commands/TranspileCommand/fn/transpile.js +18 -2
  40. package/src/commands/TranspileCommand/fn/transpile.js.map +1 -1
  41. package/src/commands/TranspileCommand/fn/validateEntryPoint.d.ts +2 -1
  42. package/src/commands/TranspileCommand/fn/validateEntryPoint.js +19 -9
  43. package/src/commands/TranspileCommand/fn/validateEntryPoint.js.map +1 -1
  44. package/src/commands/TranspileCommand/fn/validateExitPoint.d.ts +2 -1
  45. package/src/commands/TranspileCommand/fn/validateExitPoint.js +16 -10
  46. package/src/commands/TranspileCommand/fn/validateExitPoint.js.map +1 -1
  47. package/src/commands/TranspileCommand/hooks/useTranspileTasks.d.ts +3 -1
  48. package/src/commands/TranspileCommand/hooks/useTranspileTasks.js +4 -2
  49. package/src/commands/TranspileCommand/hooks/useTranspileTasks.js.map +1 -1
  50. package/src/commands/TranspileCommand/types.d.ts +4 -0
  51. package/src/commands/TranspileCommand/types.js +7 -0
  52. package/src/commands/TranspileCommand/types.js.map +1 -0
  53. package/src/components/CheckList/Item.js +8 -2
  54. package/src/components/CheckList/Item.js.map +1 -1
  55. package/src/components/ErrorBoundary.js +28 -0
  56. package/src/components/ErrorBoundary.js.map +1 -0
  57. package/src/index.js +5 -1
  58. 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,6 @@
1
+ export declare const useFileWatcher: (options: {
2
+ watchPath: string;
3
+ additionalGlobs?: string[];
4
+ onChange: () => void;
5
+ enabled: boolean;
6
+ }) => void;
@@ -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,5 +1,6 @@
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,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 projectPathOption = Option.String('-p,--path', process.cwd(), {
10
- description: `Where to find the project. Defaults to the current working directory ("${process.cwd()}")`,
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 {
@@ -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', process.cwd(), {\n description: `Where to find the project. Defaults to the current working directory (\"${process.cwd()}\")`,\n validator: t.isString(),\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","projectPathOption","String","cwd","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,oBAAoBP,OAAOQ,MAAM,CAAC,aAAaV,QAAQW,GAAG,IAAI;IACvEC,aAAa,CAAC,uEAAuE,EAAEZ,QAAQW,GAAG,GAAG,EAAE,CAAC;IACxGE,WAAWT,EAAEU,QAAQ;AACzB,GAAG;AAEH,OAAO,MAAMC,yBAAyBV;IAyBzBW,SAAS;QACd,MAAMC,sBAAsBV,mBAAmB;YAC3CW,aAAa,IAAI,CAACA,WAAW;YAC7BC,WAAW,IAAI,CAACA,SAAS;QAC7B;QAEA,MAAMC,qBAAqBZ,kBAAkB;YACzCU,aAAa,IAAI,CAACA,WAAW;YAC7BG,UAAU,IAAI,CAACA,QAAQ;QAC3B;QAEA,qBACI,oBAACf;YACGgB,YAAYL;YACZM,WAAWH;YACXI,QAAQ,IAAI,CAACA,MAAM;;IAG/B;;;aApCAL,YAAYjB,OAAOQ,MAAM,CAAC,cAAc,gBAAgB;YACpDE,aAAa;YACbC,WAAWT,EAAEU,QAAQ;QACzB;aAEAO,WAAWnB,OAAOQ,MAAM,CAAC,eAAe,oBAAoB;YACxDE,aAAa;YACbC,WAAWT,EAAEU,QAAQ;QACzB;aAEAU,SAAStB,OAAOQ,MAAM,CAAC,YAAY;YAC/BE,aACI;YACJC,WAAWT,EAAEU,QAAQ;QACzB;aAEAI,cAAcT;;AAqBlB;AA5CaM,iBACOU,QAAQ;IAAC;QAAC;KAAY;CAAC;AAD9BV,iBAGOW,QAAQzB,QAAQ0B,KAAK,CAAC;IAClCf,aAAa;AACjB"}
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"}
@@ -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
- export declare const transpile: ({ entryPoint, exitPoint, buildMode, }: {
4
+ import { TranspileMode } from '../types.js';
5
+ export declare const transpile: ({ entryPoint, exitPoint, transpileMode, }: {
5
6
  entryPoint: ValidatedEntryPoint;
6
7
  exitPoint: ValidatedExitPoint;
7
- buildMode?: tstl.BuildMode;
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
- export const transpile = ({ entryPoint, exitPoint, buildMode = tstl.BuildMode.Default })=>{
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 buildMode = tstl.BuildMode.Default,\n}: {\n entryPoint: ValidatedEntryPoint;\n exitPoint: ValidatedExitPoint;\n buildMode?: tstl.BuildMode;\n}) => {\n const exitDir = dirname(exitPoint.exitPath);\n\n if (!existsSync(exitDir)) {\n mkdirSync(exitDir, { recursive: true });\n }\n\n return tstl.transpileProject(\n join(entryPoint.projectPath, 'tsconfig.json'),\n {\n buildMode,\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","transpile","entryPoint","exitPoint","buildMode","BuildMode","Default","exitDir","exitPath","recursive","transpileProject","projectPath","luaTarget","Lua54","outDir","luaBundle","luaBundleEntry","entryFile","luaPlugins","name"],"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;AAIhD,OAAO,MAAMC,YAAY,CAAC,EACtBC,UAAU,EACVC,SAAS,EACTC,YAAYN,KAAKO,SAAS,CAACC,OAAO,EAKrC;IACG,MAAMC,UAAUX,QAAQO,UAAUK,QAAQ;IAE1C,IAAI,CAACf,WAAWc,UAAU;QACtBb,UAAUa,SAAS;YAAEE,WAAW;QAAK;IACzC;IAEA,OAAOX,KAAKY,gBAAgB,CACxBb,KAAKK,WAAWS,WAAW,EAAE,kBAC7B;QACIP;QACAQ,WAAWb,UAAUc,KAAK;QAC1BC,QAAQlB,QAAQO,UAAUK,QAAQ;QAClCO,WAAWpB,SAASQ,UAAUK,QAAQ;QACtCQ,gBAAgBnB,KAAKK,WAAWe,SAAS;QACzCC,YAAY;YACR;gBACIC,MAAMtB,KAAKG,YAAY,UAAU;YACrC;SACH;IACL;AAER,EAAE"}
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: (input: {
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 = (input)=>{
4
- const resolvedPath = resolve(input.projectPath);
5
- const resolvedEntry = resolve(input.entryFile);
6
- if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) {
7
- throw new Error(`"${resolvedPath}" is not a valid project path`);
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 (!existsSync(resolvedEntry) || !statSync(resolvedEntry).isFile()) {
10
- throw new Error(`"${resolvedEntry}" is not a valid entry file`);
13
+ if (!projectPathIsDirectory) {
14
+ throw new Error(`Path "${resolvedPath}" is not a directory`);
11
15
  }
12
- if (!resolvedEntry.startsWith(resolvedPath)) {
13
- throw new Error(`Entry must be inside project path`);
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 = (input: {\n projectPath: string;\n entryFile: string;\n}): ValidatedEntryPoint => {\n const resolvedPath = resolve(input.projectPath);\n const resolvedEntry = resolve(input.entryFile);\n\n if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) {\n throw new Error(`\"${resolvedPath}\" is not a valid project path`);\n }\n\n if (!existsSync(resolvedEntry) || !statSync(resolvedEntry).isFile()) {\n throw new Error(`\"${resolvedEntry}\" is not a valid entry file`);\n }\n\n if (!resolvedEntry.startsWith(resolvedPath)) {\n throw new Error(`Entry must be inside project path`);\n }\n\n return {\n __validated: true,\n projectPath: resolvedPath,\n entryFile: resolvedEntry,\n } satisfies ValidatedEntryPoint;\n};\n"],"names":["existsSync","statSync","resolve","validateEntryPoint","input","resolvedPath","projectPath","resolvedEntry","entryFile","isDirectory","Error","isFile","startsWith","__validated"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,EAAEC,QAAQ,QAAQ,UAAU;AAC/C,SAASC,OAAO,QAAQ,YAAY;AAGpC,OAAO,MAAMC,qBAAqB,CAACC;IAI/B,MAAMC,eAAeH,QAAQE,MAAME,WAAW;IAC9C,MAAMC,gBAAgBL,QAAQE,MAAMI,SAAS;IAE7C,IAAI,CAACR,WAAWK,iBAAiB,CAACJ,SAASI,cAAcI,WAAW,IAAI;QACpE,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEL,aAAa,6BAA6B,CAAC;IACnE;IAEA,IAAI,CAACL,WAAWO,kBAAkB,CAACN,SAASM,eAAeI,MAAM,IAAI;QACjE,MAAM,IAAID,MAAM,CAAC,CAAC,EAAEH,cAAc,2BAA2B,CAAC;IAClE;IAEA,IAAI,CAACA,cAAcK,UAAU,CAACP,eAAe;QACzC,MAAM,IAAIK,MAAM,CAAC,iCAAiC,CAAC;IACvD;IAEA,OAAO;QACHG,aAAa;QACbP,aAAaD;QACbG,WAAWD;IACf;AACJ,EAAE"}
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: (input: {
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 = (input)=>{
4
- const resolvedPath = resolve(input.projectPath);
5
- const resolvedExit = resolve(input.exitFile);
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
- if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) {
8
- throw new Error(`"${resolvedPath}" is not a valid project path`);
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 (!existsSync(exitDir)) {
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 (!statSync(exitDir).isDirectory()) {
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
- // Check if the parent directory is inside the project path
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 = (input: {\n projectPath: string;\n exitFile: string;\n}): ValidatedExitPoint => {\n const resolvedPath = resolve(input.projectPath);\n const resolvedExit = resolve(input.exitFile);\n const exitDir = dirname(resolvedExit);\n\n if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) {\n throw new Error(`\"${resolvedPath}\" is not a valid project path`);\n }\n\n if (!existsSync(exitDir)) {\n // Will be created\n } else if (!statSync(exitDir).isDirectory()) {\n throw new Error(`\"${exitDir}\" exists but is not a directory`);\n }\n\n // Check if the parent directory is inside the project path\n if (!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","input","resolvedPath","projectPath","resolvedExit","exitFile","exitDir","isDirectory","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,CAACC;IAI9B,MAAMC,eAAeJ,QAAQG,MAAME,WAAW;IAC9C,MAAMC,eAAeN,QAAQG,MAAMI,QAAQ;IAC3C,MAAMC,UAAUP,QAAQK;IAExB,IAAI,CAACR,WAAWM,iBAAiB,CAACL,SAASK,cAAcK,WAAW,IAAI;QACpE,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEN,aAAa,6BAA6B,CAAC;IACnE;IAEA,IAAI,CAACN,WAAWU,UAAU;IACtB,kBAAkB;IACtB,OAAO,IAAI,CAACT,SAASS,SAASC,WAAW,IAAI;QACzC,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEF,QAAQ,+BAA+B,CAAC;IAChE;IAEA,2DAA2D;IAC3D,IAAI,CAACA,QAAQG,UAAU,CAACP,eAAe;QACnC,MAAM,IAAIM,MAAM,CAAC,qCAAqC,CAAC;IAC3D;IAEA,OAAO;QACHE,aAAa;QACbP,aAAaD;QACbS,UAAUP;IACd;AACJ,EAAE"}
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,8 +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
- export declare const useTranspileTasks: ({ entryPoint, exitPoint, toybox, }: {
4
+ import { TranspileMode } from '../types.js';
5
+ export declare const useTranspileTasks: ({ entryPoint, exitPoint, toybox, transpileMode, }: {
5
6
  entryPoint: ValidatedEntryPoint;
6
7
  exitPoint: ValidatedExitPoint;
7
8
  toybox?: string;
9
+ transpileMode?: TranspileMode;
8
10
  }) => CheckListItem<unknown>[];
@@ -3,13 +3,14 @@ import { basename, dirname, join } from 'node:path';
3
3
  import { useMemo } from 'react';
4
4
  import { getErrorMessage } from '../../../commands/TranspileCommand/fn/getErrorMessage.js';
5
5
  import { transpile } from '../../../commands/TranspileCommand/fn/transpile.js';
6
+ import { TranspileMode } from '../types.js';
6
7
  const getToyboxTemplate = (namespace, entryPoint)=>`${namespace} = ${namespace} or {}
7
8
  local ____exports = import("${entryPoint}")
8
9
  for k, v in pairs(____exports) do
9
10
  ${namespace}[k] = v
10
11
  end
11
12
  `;
12
- export const useTranspileTasks = ({ entryPoint, exitPoint, toybox })=>{
13
+ export const useTranspileTasks = ({ entryPoint, exitPoint, toybox, transpileMode = TranspileMode.Project })=>{
13
14
  return useMemo(()=>[
14
15
  {
15
16
  waitingDescription: 'Waiting to transpile code...',
@@ -19,7 +20,8 @@ export const useTranspileTasks = ({ entryPoint, exitPoint, toybox })=>{
19
20
  runner: async ()=>{
20
21
  const result = transpile({
21
22
  entryPoint,
22
- exitPoint
23
+ exitPoint,
24
+ transpileMode
23
25
  });
24
26
  if (result.diagnostics.length > 0) {
25
27
  const errors = getErrorMessage(result.diagnostics);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/hooks/useTranspileTasks.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { basename, dirname, join } from 'node:path';\nimport { useMemo } from 'react';\nimport { getErrorMessage } from '@/cli/commands/TranspileCommand/fn/getErrorMessage.js';\nimport { transpile } from '@/cli/commands/TranspileCommand/fn/transpile.js';\nimport { ValidatedEntryPoint } from '@/cli/commands/TranspileCommand/model/ValidatedEntryPoint.js';\nimport { ValidatedExitPoint } from '@/cli/commands/TranspileCommand/model/ValidatedExitPoint.js';\nimport { CheckListItem } from '@/cli/types.js';\n\nconst getToyboxTemplate = (\n namespace: string,\n entryPoint: string,\n) => `${namespace} = ${namespace} or {}\nlocal ____exports = import(\"${entryPoint}\")\nfor k, v in pairs(____exports) do\n ${namespace}[k] = v\nend\n`;\n\nexport const useTranspileTasks = ({\n entryPoint,\n exitPoint,\n toybox,\n}: {\n entryPoint: ValidatedEntryPoint;\n exitPoint: ValidatedExitPoint;\n toybox?: string;\n}) => {\n return useMemo(\n () => [\n {\n waitingDescription: 'Waiting to transpile code...',\n errorDescription: 'Could not transpile code',\n runningDescription: 'Transpiling code...',\n finishedDescription: () => 'Code transpiled',\n runner: async () => {\n const result = transpile({\n entryPoint,\n exitPoint,\n });\n\n if (result.diagnostics.length > 0) {\n const errors = getErrorMessage(result.diagnostics);\n\n throw new Error(\n `${\n result.diagnostics.length === 1\n ? 'An error'\n : 'Errors'\n } occurred while transpiling the code:\\n${errors}`,\n );\n }\n },\n ready: true,\n quitOnError: false,\n },\n ...(toybox\n ? [\n {\n waitingDescription:\n 'Waiting to create toybox import file...',\n errorDescription:\n 'Could not create toybox import file',\n runningDescription: 'Creating toybox import file...',\n finishedDescription: () =>\n 'Toybox import file created',\n runner: async () => {\n const template = getToyboxTemplate(\n toybox,\n basename(exitPoint.exitPath),\n );\n\n writeFileSync(\n join(\n dirname(exitPoint.exitPath),\n 'import.lua',\n ),\n template,\n );\n },\n },\n ]\n : []),\n ],\n [toybox],\n ) as CheckListItem<unknown>[];\n};\n"],"names":["writeFileSync","basename","dirname","join","useMemo","getErrorMessage","transpile","getToyboxTemplate","namespace","entryPoint","useTranspileTasks","exitPoint","toybox","waitingDescription","errorDescription","runningDescription","finishedDescription","runner","result","diagnostics","length","errors","Error","ready","quitOnError","template","exitPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,YAAY;AACpD,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,eAAe,QAAQ,wDAAwD;AACxF,SAASC,SAAS,QAAQ,kDAAkD;AAK5E,MAAMC,oBAAoB,CACtBC,WACAC,aACC,CAAC,EAAED,UAAU,GAAG,EAAEA,UAAU;4BACL,EAAEC,WAAW;;EAEvC,EAAED,UAAU;;AAEd,CAAC;AAED,OAAO,MAAME,oBAAoB,CAAC,EAC9BD,UAAU,EACVE,SAAS,EACTC,MAAM,EAKT;IACG,OAAOR,QACH,IAAM;YACF;gBACIS,oBAAoB;gBACpBC,kBAAkB;gBAClBC,oBAAoB;gBACpBC,qBAAqB,IAAM;gBAC3BC,QAAQ;oBACJ,MAAMC,SAASZ,UAAU;wBACrBG;wBACAE;oBACJ;oBAEA,IAAIO,OAAOC,WAAW,CAACC,MAAM,GAAG,GAAG;wBAC/B,MAAMC,SAAShB,gBAAgBa,OAAOC,WAAW;wBAEjD,MAAM,IAAIG,MACN,CAAC,EACGJ,OAAOC,WAAW,CAACC,MAAM,KAAK,IACxB,aACA,SACT,uCAAuC,EAAEC,OAAO,CAAC;oBAE1D;gBACJ;gBACAE,OAAO;gBACPC,aAAa;YACjB;eACIZ,SACE;gBACI;oBACIC,oBACI;oBACJC,kBACI;oBACJC,oBAAoB;oBACpBC,qBAAqB,IACjB;oBACJC,QAAQ;wBACJ,MAAMQ,WAAWlB,kBACbK,QACAX,SAASU,UAAUe,QAAQ;wBAG/B1B,cACIG,KACID,QAAQS,UAAUe,QAAQ,GAC1B,eAEJD;oBAER;gBACJ;aACH,GACD,EAAE;SACX,EACD;QAACb;KAAO;AAEhB,EAAE"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/hooks/useTranspileTasks.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { basename, dirname, join } from 'node:path';\nimport { useMemo } from 'react';\nimport { getErrorMessage } from '@/cli/commands/TranspileCommand/fn/getErrorMessage.js';\nimport { transpile } from '@/cli/commands/TranspileCommand/fn/transpile.js';\nimport { ValidatedEntryPoint } from '@/cli/commands/TranspileCommand/model/ValidatedEntryPoint.js';\nimport { ValidatedExitPoint } from '@/cli/commands/TranspileCommand/model/ValidatedExitPoint.js';\nimport { CheckListItem } from '@/cli/types.js';\nimport { TranspileMode } from '../types.js';\n\nconst getToyboxTemplate = (\n namespace: string,\n entryPoint: string,\n) => `${namespace} = ${namespace} or {}\nlocal ____exports = import(\"${entryPoint}\")\nfor k, v in pairs(____exports) do\n ${namespace}[k] = v\nend\n`;\n\nexport const useTranspileTasks = ({\n entryPoint,\n exitPoint,\n toybox,\n transpileMode = TranspileMode.Project,\n}: {\n entryPoint: ValidatedEntryPoint;\n exitPoint: ValidatedExitPoint;\n toybox?: string;\n transpileMode?: TranspileMode;\n}) => {\n return useMemo(\n () => [\n {\n waitingDescription: 'Waiting to transpile code...',\n errorDescription: 'Could not transpile code',\n runningDescription: 'Transpiling code...',\n finishedDescription: () => 'Code transpiled',\n runner: async () => {\n const result = transpile({\n entryPoint,\n exitPoint,\n transpileMode,\n });\n\n if (result.diagnostics.length > 0) {\n const errors = getErrorMessage(result.diagnostics);\n\n throw new Error(\n `${\n result.diagnostics.length === 1\n ? 'An error'\n : 'Errors'\n } occurred while transpiling the code:\\n${errors}`,\n );\n }\n },\n ready: true,\n quitOnError: false,\n },\n ...(toybox\n ? [\n {\n waitingDescription:\n 'Waiting to create toybox import file...',\n errorDescription:\n 'Could not create toybox import file',\n runningDescription: 'Creating toybox import file...',\n finishedDescription: () =>\n 'Toybox import file created',\n runner: async () => {\n const template = getToyboxTemplate(\n toybox,\n basename(exitPoint.exitPath),\n );\n\n writeFileSync(\n join(\n dirname(exitPoint.exitPath),\n 'import.lua',\n ),\n template,\n );\n },\n },\n ]\n : []),\n ],\n [toybox],\n ) as CheckListItem<unknown>[];\n};\n"],"names":["writeFileSync","basename","dirname","join","useMemo","getErrorMessage","transpile","TranspileMode","getToyboxTemplate","namespace","entryPoint","useTranspileTasks","exitPoint","toybox","transpileMode","Project","waitingDescription","errorDescription","runningDescription","finishedDescription","runner","result","diagnostics","length","errors","Error","ready","quitOnError","template","exitPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,YAAY;AACpD,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,eAAe,QAAQ,wDAAwD;AACxF,SAASC,SAAS,QAAQ,kDAAkD;AAI5E,SAASC,aAAa,QAAQ,cAAc;AAE5C,MAAMC,oBAAoB,CACtBC,WACAC,aACC,CAAC,EAAED,UAAU,GAAG,EAAEA,UAAU;4BACL,EAAEC,WAAW;;EAEvC,EAAED,UAAU;;AAEd,CAAC;AAED,OAAO,MAAME,oBAAoB,CAAC,EAC9BD,UAAU,EACVE,SAAS,EACTC,MAAM,EACNC,gBAAgBP,cAAcQ,OAAO,EAMxC;IACG,OAAOX,QACH,IAAM;YACF;gBACIY,oBAAoB;gBACpBC,kBAAkB;gBAClBC,oBAAoB;gBACpBC,qBAAqB,IAAM;gBAC3BC,QAAQ;oBACJ,MAAMC,SAASf,UAAU;wBACrBI;wBACAE;wBACAE;oBACJ;oBAEA,IAAIO,OAAOC,WAAW,CAACC,MAAM,GAAG,GAAG;wBAC/B,MAAMC,SAASnB,gBAAgBgB,OAAOC,WAAW;wBAEjD,MAAM,IAAIG,MACN,CAAC,EACGJ,OAAOC,WAAW,CAACC,MAAM,KAAK,IACxB,aACA,SACT,uCAAuC,EAAEC,OAAO,CAAC;oBAE1D;gBACJ;gBACAE,OAAO;gBACPC,aAAa;YACjB;eACId,SACE;gBACI;oBACIG,oBACI;oBACJC,kBACI;oBACJC,oBAAoB;oBACpBC,qBAAqB,IACjB;oBACJC,QAAQ;wBACJ,MAAMQ,WAAWpB,kBACbK,QACAZ,SAASW,UAAUiB,QAAQ;wBAG/B7B,cACIG,KACID,QAAQU,UAAUiB,QAAQ,GAC1B,eAEJD;oBAER;gBACJ;aACH,GACD,EAAE;SACX,EACD;QAACf;KAAO;AAEhB,EAAE"}
@@ -0,0 +1,4 @@
1
+ export declare enum TranspileMode {
2
+ Project = "Project",
3
+ File = "File"
4
+ }
@@ -0,0 +1,7 @@
1
+ export var TranspileMode;
2
+ (function(TranspileMode) {
3
+ TranspileMode["Project"] = "Project";
4
+ TranspileMode["File"] = "File";
5
+ })(TranspileMode || (TranspileMode = {}));
6
+
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/cli/src/commands/TranspileCommand/types.ts"],"sourcesContent":["export enum TranspileMode {\n Project = 'Project',\n File = 'File',\n}\n"],"names":["TranspileMode"],"rangeMappings":";;;;","mappings":";UAAYA;;;GAAAA,kBAAAA"}