@lark-project/cli
Version:
飞书项目插件开发工具
58 lines (57 loc) • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPluginProfileForV2 = void 0;
const get_cli_env_config_1 = require("./api/get-cli-env-config");
const get_plugin_info_1 = require("./api/get-plugin-info");
const local_plugin_config_1 = require("./local-plugin-config");
const types_1 = require("./types");
let __PLUGIN_PROFILE_INSTANCE__;
function findFirstFeaturePlatformByResourceId(resourceId) {
var _a, _b;
for (const feature of __PLUGIN_PROFILE_INSTANCE__.features) {
if (((_a = feature[types_1.EFeaturePlatform.web]) === null || _a === void 0 ? void 0 : _a.resourceId.resource) === resourceId) {
return types_1.EFeaturePlatform.web;
}
if (((_b = feature[types_1.EFeaturePlatform.mobile]) === null || _b === void 0 ? void 0 : _b.resourceId.resource) === resourceId) {
return types_1.EFeaturePlatform.mobile;
}
}
// 因为前置匹配过,理论上不会进这个兜底逻辑
return types_1.EFeaturePlatform.web;
}
function hasMobileFeature() {
var _a;
for (const feature of __PLUGIN_PROFILE_INSTANCE__.features) {
if ((_a = feature[types_1.EFeaturePlatform.mobile]) === null || _a === void 0 ? void 0 : _a.resourceId.resource) {
return true;
}
}
return false;
}
async function getPluginProfileForV2() {
if (__PLUGIN_PROFILE_INSTANCE__) {
return Object.assign(Object.assign({}, __PLUGIN_PROFILE_INSTANCE__), { findFirstFeaturePlatformByResourceId,
hasMobileFeature });
}
const localConfig = await (0, local_plugin_config_1.getLocalPluginConfig)();
const remoteConfig = await (0, get_plugin_info_1.getPluginInfo)(localConfig.pluginId, localConfig.pluginSecret, localConfig.siteDomain);
const envConfig = await (0, get_cli_env_config_1.getCliEnvConfig)({
domain: localConfig.siteDomain,
pluginId: localConfig.pluginId,
});
__PLUGIN_PROFILE_INSTANCE__ = {
frameworkVersion: remoteConfig.frameworkVersion,
siteDomain: localConfig.siteDomain,
pageServerDomain: envConfig.config.plugin_domain,
id: remoteConfig.id,
secret: localConfig.pluginSecret,
name: remoteConfig.name,
icon: remoteConfig.icon,
short: remoteConfig.short,
features: remoteConfig.features,
resources: localConfig.resources,
};
return Object.assign(Object.assign({}, __PLUGIN_PROFILE_INSTANCE__), { findFirstFeaturePlatformByResourceId,
hasMobileFeature });
}
exports.getPluginProfileForV2 = getPluginProfileForV2;