UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

49 lines (48 loc) 3.18 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateProject = void 0; const path_1 = __importDefault(require("path")); const fs_extra_1 = require("fs-extra"); const get_plugin_info_1 = require("../../../api/get-plugin-info"); const local_plugin_config_1 = require("../../../local-plugin-config"); const with_loading_spinner_1 = require("../../../utils/with-loading-spinner"); const download_codebase_1 = require("../init/download-codebase"); const logger_1 = require("../../../utils/logger"); const utils_1 = require("../../../v1/utils"); const file_1 = require("../utils/file"); const downloadTemplate = async (templateTargetDir) => { await (0, with_loading_spinner_1.withLoadingSpinner)(download_codebase_1.downloadCodeBase, 'Code template downloading...', templateTargetDir, 'react-initialized'); }; const updateProject = async () => { const templateTargetDir = path_1.default.join(process.cwd(), '.template'); await downloadTemplate(templateTargetDir); logger_1.logger.info('Start fetching project latest data...'); const localConfig = await (0, local_plugin_config_1.getLocalPluginConfig)(); if (!localConfig) { logger_1.logger.error('Please init project first'); return; } const remoteConfig = await (0, get_plugin_info_1.getPluginInfo)(localConfig.pluginId, localConfig.pluginSecret, localConfig.siteDomain); const { list, newResourceRelation, syncResourceIds, unSyncResourceIds, needRemoveResourceIds } = await (0, file_1.generateResourceCode)({ remoteConfig, localConfig, targetDir: process.cwd(), siteDomain: localConfig.siteDomain, }); if (!list.length) { logger_1.logger.info('No new features'); return; } await (0, with_loading_spinner_1.withLoadingSpinner)(async () => { await Promise.all(list); (0, local_plugin_config_1.setLocalPluginConfig)(Object.assign(Object.assign({}, localConfig), { pluginSecret: (0, utils_1.encrypt)(localConfig.pluginSecret), resources: localConfig.resources.concat(newResourceRelation) })); }, 'Pulling code templates for the new features is in progress...'); await (0, fs_extra_1.remove)(templateTargetDir); (syncResourceIds === null || syncResourceIds === void 0 ? void 0 : syncResourceIds.length) && logger_1.logger.info(`Some new features were synchronized successfully and sample templates were generated:\n${syncResourceIds.join('\n')}`); (unSyncResourceIds === null || unSyncResourceIds === void 0 ? void 0 : unSyncResourceIds.length) && logger_1.logger.error(`Some features need to manually specify the entry file, which needs to be handled in plugin.config.json:\n${unSyncResourceIds.join('\n')}`); (needRemoveResourceIds === null || needRemoveResourceIds === void 0 ? void 0 : needRemoveResourceIds.length) && logger_1.logger.warn(`Some features were removed and need to be manually removed from plugin.config.json:\n${needRemoveResourceIds.join('\n')}`); }; exports.updateProject = updateProject;