UNPKG

@nestia/sdk

Version:

Nestia SDK and Swagger generator

146 lines 7.81 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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 }); exports.SdkDistributionComposer = void 0; const __typia_transform__assertGuard = __importStar(require("typia/lib/internal/_assertGuard.js")); const child_process_1 = __importDefault(require("child_process")); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const typia_1 = __importDefault(require("typia")); var SdkDistributionComposer; (function (SdkDistributionComposer) { SdkDistributionComposer.compose = (props) => __awaiter(this, void 0, void 0, function* () { if (!fs_1.default.existsSync(props.config.distribute)) yield fs_1.default.promises.mkdir(props.config.distribute); const root = process.cwd(); const output = path_1.default.resolve(props.config.output); process.chdir(props.config.distribute); const exit = () => process.chdir(root); if (yield configured()) return exit(); // COPY FILES console.log("Composing SDK distribution environments..."); for (const file of yield fs_1.default.promises.readdir(BUNDLE)) yield fs_1.default.promises.copyFile(`${BUNDLE}/${file}`, file); // CONFIGURE PATHS for (const file of ["package.json", "tsconfig.json"]) yield replace({ root, output })(file); // INSTALL PACKAGES const v = yield dependencies(); execute("npm install --save-dev rimraf"); execute(`npm install --save @nestia/fetcher@${v.version}`); execute(`npm install --save typia@${v.typia}`); if (props.websocket) execute(`npm install --save tgrid@${v.tgrid}`); execute("npx typia setup --manager npm"); exit(); }); const configured = () => __awaiter(this, void 0, void 0, function* () { return ["package.json", "tsconfig.json"].every(fs_1.default.existsSync) && (yield (() => __awaiter(this, void 0, void 0, function* () { var _a; const content = JSON.parse(yield fs_1.default.promises.readFile("package.json", "utf8")); return !!((_a = content.dependencies) === null || _a === void 0 ? void 0 : _a["@nestia/fetcher"]); }))()); }); const execute = (command) => { console.log(` - ${command}`); child_process_1.default.execSync(command, { stdio: "ignore" }); }; const replace = (props) => (file) => __awaiter(this, void 0, void 0, function* () { const relative = (from) => (to) => path_1.default.relative(from, to).split("\\").join("/"); const root = relative(process.cwd())(props.root); const output = relative(process.cwd())(props.output); const current = relative(props.root)(process.cwd()); const content = yield fs_1.default.promises.readFile(file, "utf8"); yield fs_1.default.promises.writeFile(file, content .split("${root}") .join(root) .split("${output}") .join(output) .split("${current}") .join(current), "utf8"); }); const dependencies = () => __awaiter(this, void 0, void 0, function* () { const content = yield fs_1.default.promises.readFile(__dirname + "/../../../package.json", "utf8"); const json = JSON.parse(content); return (() => { const _io0 = input => "string" === typeof input.version && "string" === typeof input.typia && "string" === typeof input.tgrid; const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.version || __typia_transform__assertGuard._assertGuard(_exceptionable, { method: "typia.assert", path: _path + ".version", expected: "string", value: input.version }, _errorFactory)) && ("string" === typeof input.typia || __typia_transform__assertGuard._assertGuard(_exceptionable, { method: "typia.assert", path: _path + ".typia", expected: "string", value: input.typia }, _errorFactory)) && ("string" === typeof input.tgrid || __typia_transform__assertGuard._assertGuard(_exceptionable, { method: "typia.assert", path: _path + ".tgrid", expected: "string", value: input.tgrid }, _errorFactory)); const __is = input => "object" === typeof input && null !== input && _io0(input); let _errorFactory; return (input, errorFactory) => { if (false === __is(input)) { _errorFactory = errorFactory; ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, { method: "typia.assert", path: _path + "", expected: "IDependencies", value: input }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, { method: "typia.assert", path: _path + "", expected: "IDependencies", value: input }, _errorFactory))(input, "$input", true); } return input; }; })()(Object.assign(Object.assign(Object.assign({}, json.devDependencies), json.dependencies), { version: json.version })); }); })(SdkDistributionComposer || (exports.SdkDistributionComposer = SdkDistributionComposer = {})); const BUNDLE = __dirname + "/../../../assets/bundle/distribute"; //# sourceMappingURL=SdkDistributionComposer.js.map