UNPKG

typia

Version:

Superfast runtime validators with only one line

84 lines (81 loc) 3.25 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_module_1 = require("node:module"); const node_path_1 = __importDefault(require("node:path")); const USAGE = `Wrong command has been detected. Use like below: npx typia generate [options] [files...] npx typia generate --input src/templates \\ --output src/generated npx typia generate --output src/generated \\ "src/**/*.typia.ts" `; const halt = (desc) => { console.error(desc); process.exit(-1); }; const loadTypeScript = () => { loadPackage("typescript/package.json", `typescript has not been installed. Run "npm i -D ttsc typescript" before.`); }; const loadTtsc = () => { loadPackage("ttsc/package.json", `ttsc has not been installed. Run "npm i -D ttsc typescript" before.`); }; const loadPackage = (request, desc) => { // The ambient CJS `require` does not exist in the transcoded `.mjs`; // anchor explicit resolvers on the consuming project (cwd) first, then on // this executable's own location, mirroring the original lookup order. const resolvers = [ () => (0, node_module_1.createRequire)(node_path_1.default.join(process.cwd(), "package.json")).resolve(request), () => { var _a; return (0, node_module_1.createRequire)(node_path_1.default.resolve((_a = process.argv[1]) !== null && _a !== void 0 ? _a : "")).resolve(request); }, ]; for (const resolve of resolvers) { try { resolve(); return; } catch (_a) { } } halt(desc); }; const isHelp = (args) => { return args.some((arg) => arg === "--help" || arg === "-h"); }; const main = () => __awaiter(void 0, void 0, void 0, function* () { try { yield import("inquirer"); yield import("commander"); } catch (_a) { halt(`typia has not been installed. Run "npm i typia" before.`); } const type = process.argv[2]; if (type === "generate") { if (isHelp(process.argv.slice(3)) === false) { loadTtsc(); loadTypeScript(); } const { TypiaGenerateWizard } = yield import("./TypiaGenerateWizard.js"); yield TypiaGenerateWizard.generate(); } else halt(USAGE); }); main().catch((exp) => { console.error(exp instanceof URIError ? exp.message : exp); process.exit(-1); }); //# sourceMappingURL=typia.js.map