UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

59 lines (58 loc) 2.96 kB
"use strict"; // only for v2 plugin var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeLocalPointConfig = exports.getLocalPointConfig = exports.LOCAL_CONFIG_FILE = exports.getLocalConfigPath = void 0; const fs_extra_1 = require("fs-extra"); const path_1 = __importDefault(require("path")); const local_plugin_config_1 = require("../local-plugin-config"); const get_project_directory_1 = require("./get-project-directory"); const logger_1 = require("./logger"); const REMOTE_CONFIG_DIR = '.'; const LOCAL_CONFIG_FILE = 'point.config.local.json'; exports.LOCAL_CONFIG_FILE = LOCAL_CONFIG_FILE; function getLocalConfigPath() { const projectDir = (0, get_project_directory_1.getProjectDirectory)(); return path_1.default.join(projectDir, REMOTE_CONFIG_DIR, LOCAL_CONFIG_FILE); } exports.getLocalConfigPath = getLocalConfigPath; async function getLocalPointConfig() { const localConfigPath = getLocalConfigPath(); if (!(0, fs_extra_1.existsSync)(localConfigPath)) { throw new Error(`Local config file not found at ${REMOTE_CONFIG_DIR}/${LOCAL_CONFIG_FILE}`); } const localFeatures = (0, fs_extra_1.readJSONSync)(localConfigPath); return localFeatures; } exports.getLocalPointConfig = getLocalPointConfig; async function writeLocalPointConfig(remoteFeatures, overwrite = false) { const projectDir = (0, get_project_directory_1.getProjectDirectory)(); const localPluginConfig = (0, local_plugin_config_1.getLocalPluginConfig)(); if (!localPluginConfig) { logger_1.logger.error('Cannot find plugin.config.json in current directory.'); process.exit(1); } const { pluginId, siteDomain } = localPluginConfig; logger_1.logger.info('Pulling remote plugin config...'); logger_1.logger.info(`Plugin ID: ${pluginId}`); logger_1.logger.info(`Site Domain: ${siteDomain}`); const remoteConfigDir = path_1.default.join(projectDir, REMOTE_CONFIG_DIR); (0, fs_extra_1.ensureDirSync)(remoteConfigDir); try { const remoteConfigPath = path_1.default.join(remoteConfigDir, LOCAL_CONFIG_FILE); if ((0, fs_extra_1.existsSync)(remoteConfigPath) && !overwrite) { logger_1.logger.info(`Config file already exists at ${REMOTE_CONFIG_DIR}/${LOCAL_CONFIG_FILE}`); logger_1.logger.info('Use the existing config file. If you want to update it, please delete the file first.'); return; } (0, fs_extra_1.writeJSONSync)(remoteConfigPath, remoteFeatures || [], { spaces: 2 }); logger_1.logger.success(`Remote plugin config saved to ${REMOTE_CONFIG_DIR}/${LOCAL_CONFIG_FILE}`); } catch (error) { logger_1.logger.error('Failed to write local plugin config:', error); process.exit(1); } } exports.writeLocalPointConfig = writeLocalPointConfig;