-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3fbb2db
Showing
15 changed files
with
8,138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "TypeScriptToLua", | ||
"image": "mcr.microsoft.com/vscode/devcontainers/javascript-node:14", | ||
"settings": { | ||
"terminal.integrated.shell.linux": "/bin/bash" | ||
}, | ||
"extensions": [ | ||
"typescript-to-lua.vscode-typescript-to-lua", | ||
"dbaeumer.vscode-eslint", | ||
"editorconfig.editorconfig", | ||
"esbenp.prettier-vscode" | ||
], | ||
"postCreateCommand": "npm ci" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* text=auto eol=lf | ||
*.{cmd,[cC][mM][dD]} text eol=crlf | ||
*.{bat,[bB][aA][tT]} text eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules | ||
/dist | ||
|
||
yarn.lock | ||
.vscode | ||
.idea | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 120, | ||
"tabWidth": 4, | ||
"arrowParens": "avoid", | ||
"overrides": [{ "files": ["**/*.md", "**/*.yml"], "options": { "tabWidth": 2 } }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# railworks-tstl-template | ||
|
||
Write scripts for Train Simulator in TypeScript with the help of [TypeScriptToLua](https://typescripttolua.github.io/)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const fsPromises = require("fs/promises"), | ||
gulp = require("gulp"), | ||
filter = require("gulp-filter"), | ||
flatmap = require("gulp-flatmap"), | ||
intermediate = require("gulp-intermediate"), | ||
rename = require("gulp-rename"), | ||
path = require("path"), | ||
ts = require("typescript"), | ||
tstl = require("typescript-to-lua"); | ||
|
||
exports.default = exports.tstl = function (cb) { | ||
return gulp | ||
.src("src/mod/**/*.ts", { base: "src" }) | ||
.pipe( | ||
flatmap(function (stream, file) { | ||
return stream | ||
.pipe(gulp.src(["src/@types/**/*", "src/lib/**/*.ts"], { base: "src" })) | ||
.pipe( | ||
gulp.src(["node_modules/lua-types/**/*", "node_modules/typescript-to-lua/**/*"], { base: "." }) | ||
) | ||
.pipe( | ||
intermediate({}, async function (tempDir, cb) { | ||
await compileLua(tempDir, file.relative); | ||
cb(); | ||
}) | ||
) | ||
.pipe(filter(["mod/**/*.lua"])); | ||
}) | ||
) | ||
.pipe( | ||
rename(function (path) { | ||
path.dirname = path.dirname.replace(/^mod\//, ""); | ||
}) | ||
) | ||
.pipe(gulp.dest("dist")); | ||
}; | ||
|
||
async function compileLua(tempDir, luaPath) { | ||
// We need the root tsconfig.json node to set the value of "include". | ||
const tsconfig = path.join(tempDir, "tsconfig.json"); | ||
await fsPromises.writeFile( | ||
tsconfig, | ||
`{ "include": ["${path.join(tempDir, "@types")}", "${path.join(tempDir, "mod")}"] }` | ||
); | ||
|
||
const result = tstl.transpileProject(tsconfig, { | ||
types: ["lua-types/5.0"], | ||
typeRoots: [path.join(tempDir, "@types")], | ||
luaTarget: tstl.LuaTarget.Lua50, | ||
luaLibImport: tstl.LuaLibImportKind.Inline, | ||
sourceMapTraceback: false, | ||
luaBundle: path.join(path.dirname(luaPath), path.basename(luaPath, ".ts") + ".lua"), | ||
// The entry path needs to be absolute so that TSTL sets the correct module name. | ||
luaBundleEntry: path.join(tempDir, luaPath), | ||
}); | ||
printDiagnostics(result.diagnostics); | ||
} | ||
|
||
function printDiagnostics(diagnostics) { | ||
console.log( | ||
ts.formatDiagnosticsWithColorAndContext(diagnostics, { | ||
getCurrentDirectory: () => ts.sys.getCurrentDirectory(), | ||
getCanonicalFileName: f => f, | ||
getNewLine: () => "\n", | ||
}) | ||
); | ||
} |
Oops, something went wrong.