@lark-project/cli
Version:
飞书项目插件开发工具
80 lines (79 loc) • 3.48 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const form_data_1 = __importDefault(require("form-data"));
const upload_zip_file_1 = require("../../../../api/upload-zip-file");
const utils_1 = require("../../../utils");
const constants_1 = require("../../../config/constants");
const paths_1 = __importDefault(require("../../../config/paths"));
const Factory_1 = __importDefault(require("../../config/Factory"));
const types_1 = require("../../../types");
const Compressor_1 = __importDefault(require("../../../utils/Compressor"));
class UploadRunner {
static async run() {
try {
this.collectConfigInfo();
await this.uploadPluginZip();
console.log('\nUpload successfully.\n');
}
catch (err) {
(0, utils_1.error)(`Bundles upload failed: ${err.message}`);
}
}
}
_a = UploadRunner;
UploadRunner._token = '';
UploadRunner._pluginID = '';
UploadRunner._version = '';
UploadRunner._domain = '';
/** 依赖参数收集 */
UploadRunner.collectConfigInfo = () => {
var _b, _c, _d;
const config = Factory_1.default.getConfig(types_1.EConfigType.Plugin);
const globalConfig = Factory_1.default.getConfig(types_1.EConfigType.Global);
_a._pluginID = (_b = config.get('pluginID', false)) !== null && _b !== void 0 ? _b : '';
_a._version = (_c = config.get('version', false)) !== null && _c !== void 0 ? _c : '';
_a._domain = (_d = config.get('domain', false)) !== null && _d !== void 0 ? _d : constants_1.DEFAULT_CONFIG.DOMAIN;
// /** 支持优先通过命令行参数方式传递 pluginSecret,不存在则取配置文件数据 */
const args = process.argv.slice(1);
const scriptIndex = args.findIndex(x => x.endsWith('upload') || x.endsWith('release'));
const commandArgs = scriptIndex === -1 ? [] : args.slice(scriptIndex + 1);
_a._token = commandArgs[0]
? commandArgs[0]
: config.get('pluginSecret', false) || globalConfig.get('secret', false) || '';
};
/** 依赖参数检查 */
UploadRunner.configCheck = async () => {
if (!_a._token) {
(0, utils_1.error)(`SecretKey is not exist, please set it using ${chalk_1.default.cyan('lpm config set pluginSecret <secret_value>')}`);
}
if (!(0, utils_1.validatePluginId)(_a._pluginID)) {
(0, utils_1.error)('Plugin ID is illegal.');
}
if (!(0, utils_1.validatePluginVersion)(_a._version)) {
(0, utils_1.error)('Version is illegal.');
}
};
UploadRunner.uploadZipFile = async () => {
const filename = constants_1.PATH.PRODUCT_ZIP_FILE;
const buffer = await Compressor_1.default.zipBuffer(paths_1.default.pluginBuild);
const form = new form_data_1.default();
form.append('file', buffer, filename);
const payload = {
pluginId: _a._pluginID,
domain: _a._domain,
token: _a._token,
formData: form,
};
return (0, upload_zip_file_1.uploadZipFile)(payload);
};
UploadRunner.uploadPluginZip = async () => {
await _a.configCheck();
console.log(`Plugin ID: ${chalk_1.default.cyan(_a._pluginID)}\nPlugin Version: ${chalk_1.default.cyan(_a._version)}`);
await (0, utils_1.wrapOraLoading)(_a.uploadZipFile, 'Uploading bundles...');
};
exports.default = UploadRunner;