@nestia/sdk
Version:
Nestia SDK and Swagger generator
59 lines • 2.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TtscExecutor = void 0;
const child_process_1 = __importDefault(require("child_process"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
var TtscExecutor;
(function (TtscExecutor) {
TtscExecutor.run = (props) => {
var _a;
const args = [bin(props.cwd), "-p", props.project];
if (process.env.TTSC_CACHE_DIR !== undefined)
args.push("--cache-dir", process.env.TTSC_CACHE_DIR);
return child_process_1.default.execFileSync(process.execPath, args, {
cwd: props.cwd,
env: Object.assign(Object.assign({}, process.env), props.env),
stdio: (_a = props.stdio) !== null && _a !== void 0 ? _a : "pipe",
maxBuffer: 64 * 1024 * 1024,
});
};
const bin_ = new Map();
const bin = (cwd) => {
var _a;
const cached = bin_.get(cwd);
if (cached !== undefined)
return cached;
// Prefer the user's project-local ttsc; fall back to the module's own
// lookup path so a programmatic caller without an installed ttsc in
// `cwd` still resolves the bundled dep.
let manifest;
try {
manifest = require.resolve("ttsc/package.json", { paths: [cwd] });
}
catch (_b) {
manifest = require.resolve("ttsc/package.json");
}
const directory = path_1.default.dirname(manifest);
const pack = JSON.parse(fs_1.default.readFileSync(manifest, "utf8"));
const location = typeof pack.bin === "string" ? pack.bin : (_a = pack.bin) === null || _a === void 0 ? void 0 : _a.ttsc;
if (location === undefined) {
const keys = typeof pack.bin === "object" && pack.bin !== null
? Object.keys(pack.bin).join(", ")
: "<none>";
throw new Error(`Unable to find "ttsc" binary from package metadata. ` +
`Available bin entries: ${keys}. ` +
`Reinstall with: npm install --save-dev ttsc`);
}
const resolved = path_1.default.join(directory, location);
if (!fs_1.default.existsSync(resolved))
throw new Error(`"ttsc" binary not found at "${resolved}". ` +
`Reinstall with: npm install --save-dev ttsc`);
bin_.set(cwd, resolved);
return resolved;
};
})(TtscExecutor || (exports.TtscExecutor = TtscExecutor = {}));
//# sourceMappingURL=TtscExecutor.js.map