crankscript 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/TranspileCommand/TranspileCommand.d.ts +1 -0
- package/src/commands/TranspileCommand/TranspileCommand.js +7 -2
- 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/hooks/useTranspileTasks.d.ts +2 -1
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.js +25 -3
- package/src/commands/TranspileCommand/hooks/useTranspileTasks.js.map +1 -1
package/package.json
CHANGED
@@ -22,7 +22,8 @@ export class TranspileCommand extends RenderableCommand {
|
|
22
22
|
});
|
23
23
|
return /*#__PURE__*/ React.createElement(Transpile, {
|
24
24
|
entryPoint: validatedEntryPoint,
|
25
|
-
exitPoint: validatedExitPoint
|
25
|
+
exitPoint: validatedExitPoint,
|
26
|
+
toybox: this.toybox
|
26
27
|
});
|
27
28
|
}
|
28
29
|
constructor(...args){
|
@@ -31,10 +32,14 @@ export class TranspileCommand extends RenderableCommand {
|
|
31
32
|
description: 'The entry point to transpile',
|
32
33
|
validator: t.isString()
|
33
34
|
});
|
34
|
-
this.exitFile = Option.String('-o,--output', 'Source/
|
35
|
+
this.exitFile = Option.String('-o,--output', 'Source/index.lua', {
|
35
36
|
description: 'The output bundle',
|
36
37
|
validator: t.isString()
|
37
38
|
});
|
39
|
+
this.toybox = Option.String('--toybox', {
|
40
|
+
description: 'Output a toybox compatible bundle which exports to this namespace',
|
41
|
+
validator: t.isString()
|
42
|
+
});
|
38
43
|
this.projectPath = projectPathOption;
|
39
44
|
}
|
40
45
|
}
|
@@ -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/
|
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"}
|
@@ -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,7 +1,8 @@
|
|
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, }: {
|
4
|
+
export declare const useTranspileTasks: ({ entryPoint, exitPoint, toybox, }: {
|
5
5
|
entryPoint: ValidatedEntryPoint;
|
6
6
|
exitPoint: ValidatedExitPoint;
|
7
|
+
toybox?: string;
|
7
8
|
}) => CheckListItem<unknown>[];
|
@@ -1,7 +1,15 @@
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
2
|
+
import { basename, dirname, join } from 'node:path';
|
1
3
|
import { useMemo } from 'react';
|
2
4
|
import { getErrorMessage } from '../../../commands/TranspileCommand/fn/getErrorMessage.js';
|
3
5
|
import { transpile } from '../../../commands/TranspileCommand/fn/transpile.js';
|
4
|
-
|
6
|
+
const getToyboxTemplate = (namespace, entryPoint)=>`${namespace} = ${namespace} or {}
|
7
|
+
local ____exports = import("${entryPoint}")
|
8
|
+
for k, v in pairs(____exports) do
|
9
|
+
${namespace}[k] = v
|
10
|
+
end
|
11
|
+
`;
|
12
|
+
export const useTranspileTasks = ({ entryPoint, exitPoint, toybox })=>{
|
5
13
|
return useMemo(()=>[
|
6
14
|
{
|
7
15
|
waitingDescription: 'Waiting to transpile code...',
|
@@ -20,8 +28,22 @@ export const useTranspileTasks = ({ entryPoint, exitPoint })=>{
|
|
20
28
|
},
|
21
29
|
ready: true,
|
22
30
|
quitOnError: false
|
23
|
-
}
|
24
|
-
|
31
|
+
},
|
32
|
+
...toybox ? [
|
33
|
+
{
|
34
|
+
waitingDescription: 'Waiting to create toybox import file...',
|
35
|
+
errorDescription: 'Could not create toybox import file',
|
36
|
+
runningDescription: 'Creating toybox import file...',
|
37
|
+
finishedDescription: ()=>'Toybox import file created',
|
38
|
+
runner: async ()=>{
|
39
|
+
const template = getToyboxTemplate(toybox, basename(exitPoint.exitPath));
|
40
|
+
writeFileSync(join(dirname(exitPoint.exitPath), 'import.lua'), template);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
] : []
|
44
|
+
], [
|
45
|
+
toybox
|
46
|
+
]);
|
25
47
|
};
|
26
48
|
|
27
49
|
//# sourceMappingURL=useTranspileTasks.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/hooks/useTranspileTasks.ts"],"sourcesContent":["import { 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\nexport const useTranspileTasks = ({\n entryPoint,\n exitPoint,\n}: {\n entryPoint: ValidatedEntryPoint;\n exitPoint: ValidatedExitPoint;\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 ],\n [],\n ) as CheckListItem<unknown>[];\n};\n"],"names":["useMemo","getErrorMessage","transpile","
|
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"}
|