release: v0.1.0 package exports, CLI, integration guide, and AI rules template
This commit is contained in:
1 parent
c0ac6eaad6
commit
1f76bca55c
8 files changed
+500
-33
No files matched your search
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const path = require("node:path");
|
||||
const { spawnSync } = require("node:child_process");
|
||||
|
||||
const pkgRoot = path.resolve(__dirname, "..");
|
||||
const pkg = require(path.join(pkgRoot, "package.json"));
|
||||
|
||||
function printHelp() {
|
||||
console.log(`ts2lua-unreal v${pkg.version} - TypeScript to UnLua compiler toolchain
|
||||
|
||||
Usage:
|
||||
ts2lua-unreal build [tstl args...] Compile TS project to UnLua Lua (default: -p tsconfig.json)
|
||||
ts2lua-unreal watch [tstl args...] Watch and incrementally compile for UnLua HotReload
|
||||
ts2lua-unreal info Show installed version and local documentation paths
|
||||
ts2lua-unreal --help Show this help message
|
||||
`);
|
||||
}
|
||||
|
||||
function printInfo() {
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
name: pkg.name,
|
||||
version: pkg.version,
|
||||
packageRoot: pkgRoot,
|
||||
tsconfigBase: path.join(pkgRoot, "tsconfig.base.json"),
|
||||
unluaTypes: path.join(pkgRoot, "types", "unlua.d.ts"),
|
||||
docs: {
|
||||
integrationGuide: path.join(pkgRoot, "docs", "integration-guide.md"),
|
||||
spec: path.join(pkgRoot, "docs", "ts-unlua-spec.md"),
|
||||
aiRulesTemplate: path.join(pkgRoot, "docs", "ai-rules-template.md"),
|
||||
changelog: path.join(pkgRoot, "CHANGELOG.md"),
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function runTstl(extraArgs) {
|
||||
const tstlBin = require.resolve("typescript-to-lua/dist/tstl.js");
|
||||
const hasProjectFlag = extraArgs.some((arg) => arg === "-p" || arg === "--project");
|
||||
const args = hasProjectFlag ? extraArgs : ["-p", "tsconfig.json", ...extraArgs];
|
||||
const result = spawnSync(process.execPath, [tstlBin, ...args], {
|
||||
stdio: "inherit",
|
||||
});
|
||||
process.exit(result.status ?? 1);
|
||||
}
|
||||
|
||||
const [, , cmd, ...rest] = process.argv;
|
||||
|
||||
if (!cmd || cmd === "-h" || cmd === "--help" || cmd === "help") {
|
||||
printHelp();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (cmd === "-v" || cmd === "--version") {
|
||||
console.log(pkg.version);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (cmd === "info") {
|
||||
printInfo();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (cmd === "build") {
|
||||
runTstl(rest);
|
||||
} else if (cmd === "watch") {
|
||||
runTstl(["--watch", ...rest]);
|
||||
} else {
|
||||
// 直接透传给 tstl
|
||||
runTstl([cmd, ...rest]);
|
||||
}
|
||||
Reference in new issue
Block a user