@ywfe/cli
Version:
遥望前端开发命令行工具
135 lines (134 loc) • 6.17 kB
JavaScript
;
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.getAllPageNextVersion = exports.getRouteAndFilePathByAppId = exports.getAllAppInfo = exports.publishFn = exports.getBuildPageInfo = exports.handleApiUrl = void 0;
const axios_1 = __importDefault(require("axios"));
const chalk_1 = __importDefault(require("chalk"));
const messages_1 = require("../util/messages");
const handleApiUrl = (config) => {
let url = 'https://dps.ywwl.com';
if ((config === null || config === void 0 ? void 0 : config.dpsEnv) === 'test') {
url = 'https://dps-test.ywwl.com';
}
else if ((config === null || config === void 0 ? void 0 : config.dpsEnv) === 'mock') {
url = 'http://192.168.36.70:7001';
}
return url;
};
exports.handleApiUrl = handleApiUrl;
const getBuildPageInfo = (changId, config) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const url = (0, exports.handleApiUrl)(config);
try {
const res = yield axios_1.default.get(`${url}/api/change-page/info?id=${changId}`);
if ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.success) {
const { data } = res.data;
const { pages, detail } = data;
const { iteration_id: iterationId } = detail;
if (!pages.length) {
const devopsUrl = `${url}/iterateDetail/${iterationId}`;
console.log(chalk_1.default.red(messages_1.MESSAGES.NOT_RELATIVE_PAGES(devopsUrl)));
process.exit(1);
}
return res === null || res === void 0 ? void 0 : res.data;
}
else {
throw res === null || res === void 0 ? void 0 : res.data;
}
}
catch (e) {
console.log(chalk_1.default.red(messages_1.MESSAGES.NOT_GET_PAGE_INFO), e);
return { success: false };
}
});
exports.getBuildPageInfo = getBuildPageInfo;
const publishFn = (params, config) => __awaiter(void 0, void 0, void 0, function* () {
var _b;
const url = (0, exports.handleApiUrl)(config);
try {
const res = yield axios_1.default.post(`${url}/api/asset/publish`, params);
if ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.success) {
return { success: true, data: res.data };
}
else {
throw res === null || res === void 0 ? void 0 : res.data;
}
}
catch (e) {
console.log(chalk_1.default.red(messages_1.MESSAGES.PUBLISH_FAIL_TIPS), e);
process.exit(1);
}
});
exports.publishFn = publishFn;
const getAllAppInfo = (config) => __awaiter(void 0, void 0, void 0, function* () {
var _c, _d;
const url = (0, exports.handleApiUrl)(config);
try {
const res = yield axios_1.default.get(`${url}/api/app/list?pageIndex=1&pageSize=9999`);
if ((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.success) {
const data = res.data || {};
const list = ((_d = data === null || data === void 0 ? void 0 : data.data) === null || _d === void 0 ? void 0 : _d.list) || [];
if (!(list === null || list === void 0 ? void 0 : list.length)) {
throw 'list长度为0 ';
}
return list;
}
else {
throw res === null || res === void 0 ? void 0 : res.data;
}
}
catch (e) {
console.log(chalk_1.default.red(messages_1.MESSAGES.NOT_FOUND_ALL_APP_INFO), e);
process.exit(1);
}
});
exports.getAllAppInfo = getAllAppInfo;
const getRouteAndFilePathByAppId = (appId, gitlabId, config) => __awaiter(void 0, void 0, void 0, function* () {
var _e;
const url = (0, exports.handleApiUrl)(config);
try {
const res = yield axios_1.default.get(`${url}/api/page/get-pages-list?app_id=${appId}&pageSize=9999`);
if ((_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.success) {
const { data } = res.data;
return (data === null || data === void 0 ? void 0 : data.list) || [];
}
else {
throw res === null || res === void 0 ? void 0 : res.data;
}
}
catch (e) {
console.log(chalk_1.default.red(messages_1.MESSAGES.NOT_GET_RELATIVE_INFO(gitlabId)), e);
process.exit(1);
}
});
exports.getRouteAndFilePathByAppId = getRouteAndFilePathByAppId;
const getAllPageNextVersion = (changId, assetEnvNumber, config) => __awaiter(void 0, void 0, void 0, function* () {
var _f;
try {
const url = (0, exports.handleApiUrl)(config);
const res = yield axios_1.default.get(`${url}/api/asset/get-version-by-change-id?change_id=${changId}&asset_env=${assetEnvNumber}`);
if ((_f = res === null || res === void 0 ? void 0 : res.data) === null || _f === void 0 ? void 0 : _f.success) {
const { data } = res.data;
return data;
}
else {
throw res === null || res === void 0 ? void 0 : res.data;
}
}
catch (e) {
console.log(chalk_1.default.red(messages_1.MESSAGES.GET_NEXT_VERSION_FAIL), e);
return { success: false };
}
});
exports.getAllPageNextVersion = getAllPageNextVersion;