typia
Version:
Superfast runtime validators with only one line
53 lines • 2.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });
const node_child_process_1 = require("node:child_process");
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const packageRoot = node_path_1.default.resolve(node_path_1.default.dirname(node_path_1.default.resolve((_a = process.argv[1]) !== null && _a !== void 0 ? _a : "")), "..", "..", "..");
const nativeProject = node_path_1.default.resolve(packageRoot, "native");
const nativeEntrypoint = node_path_1.default.resolve(nativeProject, "cmd", "ttsc-typia", "main.go");
const command = process.platform === "win32" ? "go.exe" : "go";
const invocationCwd = process.cwd();
const argv = [...process.argv.slice(2)];
if (process.env.TYPIA_TTSC_TRANSFORM_OUTPUT === "ts" &&
argv[0] === "transform" &&
!argv.some((value) => value === "--output" || value.startsWith("--output="))) {
argv.push("--output=ts");
}
if (argv.length > 0 &&
needsCwd(argv[0]) &&
!argv.some((value) => value === "--cwd" || value.startsWith("--cwd="))) {
argv.push(`--cwd=${invocationCwd}`);
}
const hasSourceEntrypoint = node_fs_1.default.existsSync(nativeEntrypoint);
if (!hasSourceEntrypoint) {
process.stderr.write("ttsc-typia: backend source is missing. Expected native/cmd/ttsc-typia/main.go inside the typia package.\n");
process.exitCode = 1;
}
else {
const result = (0, node_child_process_1.spawnSync)(command, ["run", "./cmd/ttsc-typia", ...argv], {
cwd: nativeProject,
env: process.env,
stdio: "inherit",
windowsHide: true,
});
if (result.error) {
process.stderr.write(`ttsc-typia: failed to launch source backend via ${command}: ${result.error.message}\n`);
process.exitCode = 1;
}
else {
process.exitCode = (_b = result.status) !== null && _b !== void 0 ? _b : 1;
}
}
function needsCwd(commandName) {
return (commandName === "build" ||
commandName === "check" ||
commandName === "transform" ||
commandName === "-p" ||
commandName === "--project");
}
//# sourceMappingURL=ttsc.js.map