UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

211 lines (204 loc) 8.42 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib_es6 = require('../tslib.es6-01322ba9.js'); var child_process = require('child_process'); var path = require('path'); var ip_ip = require('../ip/ip.js'); var publish_config = require('./config.js'); var publish_helper = require('./helper.js'); var publish_postFile = require('./post-file.js'); require('os'); require('fs'); require('../env-variable/env-variable.js'); require('http'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var path__namespace = /*#__PURE__*/_interopNamespace(path); var rootDir = publish_helper.getPublishRootDir(); var PUBLISH_BASH_FILE = publish_helper.getPublishBashPath(); function getDevPwd() { var devHostName = publish_helper.getPublishEnvValue(publish_config.ENV_MAP.DEV_HOST_NAME); var devHostPwd = publish_helper.getPublishEnvValue(publish_config.ENV_MAP.DEV_HOST_PWD); return { devHostName: devHostName, devHostPwd: devHostPwd }; } function validate(_a) { var dir = _a.dir, publishPathProd = _a.publishPathProd, publishPathTest = _a.publishPathTest, publishEnv = _a.publishEnv; if (!dir || typeof dir !== 'string') { console.log('[publish] 模块名称不正确,请检查.env.local'); return 0; } if (publishEnv === publish_config.PUBLISH_ENV_MAP.PROD && (!publishPathProd || typeof publishPathProd !== 'string')) { console.log('[publish] 正式环境发布路径不正确,请检查.env'); return 0; } if (publishEnv === publish_config.PUBLISH_ENV_MAP.TEST && (!publishPathTest || typeof publishPathTest !== 'string')) { console.log('[publish] 测试环境发布路径不正确,请检查.env'); return 0; } // 禁止本机发布 if ((ip_ip.getIPAddress().indexOf('10.45') === 0 || ip_ip.getIPAddress().indexOf('10.20') === 0) && publishEnv === publish_config.PUBLISH_ENV_MAP.PROD) { console.log('[publish] 禁止在本机发布!'); return 0; } return true; } function localPublish(options) { return tslib_es6.__awaiter(this, void 0, void 0, function () { var dir, author, publishPathProd, publishPathTest, _a, publishEnv, moduleName, staticDir, tarName, fileSrc, fileAll; return tslib_es6.__generator(this, function (_b) { switch (_b.label) { case 0: dir = publish_helper.getPublishEnvValue(publish_config.ENV_MAP.VUE_APP_DIR); author = publish_helper.getPublishEnvValue(publish_config.ENV_MAP.VUE_APP_AUTHOR); publishPathProd = publish_helper.getPublishEnvValue(publish_config.ENV_MAP.VUE_APP_PATH_PROD); publishPathTest = publish_helper.getPublishEnvValue(publish_config.ENV_MAP.VUE_APP_PATH_TEST); _a = options.publishEnv, publishEnv = _a === void 0 ? publish_config.PUBLISH_ENV_MAP.TEST : _a; if (!validate({ dir: dir, publishPathProd: publishPathProd, publishPathTest: publishPathTest, publishEnv: publishEnv })) { return [2 /*return*/]; } console.log('[publish] 准备发布模块:', dir); moduleName = publish_helper.getPublishModuleName(dir); staticDir = 'static'; tarName = "static_".concat(moduleName, "_").concat(ip_ip.getIPAddressStr()); fileSrc = options.fileTar || path__namespace.join(rootDir, 'dist', dir, staticDir, "".concat(tarName, ".tar")); fileAll = options.fileDir || path__namespace.join(rootDir, 'dist', dir, staticDir); console.log('[publish] moduleName: ', moduleName); return [4 /*yield*/, realPublish({ publishEnv: publishEnv, publishPathProd: publishPathProd, publishPathTest: publishPathTest, moduleName: moduleName, fileAll: fileAll, fileSrc: fileSrc, author: author, dir: dir, options: options })]; case 1: _b.sent(); return [2 /*return*/]; } }); }); } function realPublish(_a) { var publishEnv = _a.publishEnv, publishPathProd = _a.publishPathProd, publishPathTest = _a.publishPathTest, moduleName = _a.moduleName, fileAll = _a.fileAll, fileSrc = _a.fileSrc, author = _a.author, dir = _a.dir, options = _a.options; return tslib_es6.__awaiter(this, void 0, void 0, function () { var desc, env, shell, _b, devHostName, devHostPwd, fileDataInfo, files; return tslib_es6.__generator(this, function (_c) { switch (_c.label) { case 0: desc = ''; env = publish_config.PUBLISH_HOST_ENV.TEST; shell = {}; shell.runSync = function (cmd, args, options) { var shellResult = child_process.spawnSync(cmd, args, options); if (shellResult.status !== 0) { console.log('[publish] failed: ', shellResult.stderr); } return shellResult; }; if (publishEnv === publish_config.PUBLISH_ENV_MAP.PROD) { if (!publishPathProd || typeof publishPathProd !== 'string') { console.log('[publish] 正式环境发布路径不正确,请检查.env'); return [2 /*return*/]; } desc = "".concat(publishPathProd, "/").concat(moduleName); env = publish_config.PUBLISH_HOST_ENV.PROD; } else if (publishEnv === publish_config.PUBLISH_ENV_MAP.DEV_CLOUD) { _b = getDevPwd(), devHostName = _b.devHostName, devHostPwd = _b.devHostPwd; if (!devHostName || !devHostPwd) { console.log('[publish] failed: ', "\u6CA1\u6709\u627E\u5230\u6709\u6548\u7684 ".concat(publish_config.ENV_MAP.DEV_HOST_NAME, " \u6216 ").concat(publish_config.ENV_MAP.DEV_HOST_PWD)); return [2 /*return*/]; } if (options === null || options === void 0 ? void 0 : options.publishTargetDir) { shell.runSync('sh', [PUBLISH_BASH_FILE, fileAll, options.publishTargetDir, devHostName, devHostPwd], { stdio: 'inherit' }); } else if (moduleName === 'mobile-official-web') { shell.runSync('sh', [PUBLISH_BASH_FILE, fileAll, '/root/html/', devHostName, devHostPwd]); } else { shell.runSync('sh', [PUBLISH_BASH_FILE, fileAll, "/root/html/".concat(moduleName, "/"), devHostName, devHostPwd], { stdio: 'inherit' }); } return [2 /*return*/]; } else { if (!publishPathTest || typeof publishPathTest !== 'string') { console.log('[publish] 测试环境发布路径不正确,请检查.env'); return [2 /*return*/]; } desc = "".concat(publishPathTest, "/").concat(moduleName); env = publish_config.PUBLISH_HOST_ENV.TEST; } fileDataInfo = [{ urlKey: 'src', urlValue: fileSrc }, { urlKey: 'des', urlValue: desc }, { urlKey: 'env', urlValue: env }, { urlKey: 'author', urlValue: author || '' }]; console.log('[publish] ', { fileDataInfo: fileDataInfo }); files = [{ urlKey: 'src', urlValue: fileSrc }]; return [4 /*yield*/, publish_postFile.postFile(fileDataInfo, files, options).then(function (data) { if (data.r == 0) { console.log("[\u53D1\u5E03\u6210\u529F]........publish ".concat(dir, " to ").concat(env, " success........\n")); } else { console.log('[发布失败]', data); } })["catch"](function (err) { console.log('[发布失败]', err); })]; case 1: _c.sent(); return [2 /*return*/]; } }); }); } exports.localPublish = localPublish;