@lark-project/cli
Version:
飞书项目插件开发工具
44 lines (43 loc) • 1.86 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveWorkspaceContext = exports.BACKEND_HANDLE_DIRNAME = void 0;
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
/**
* config-only 后端工作区的默认目录名。
* 注意:检测按 plugin.config.json 的 `backendOnly` flag,**不再依赖此目录名**——
* 此常量仅作 `lpm init --config-only` 的缺省命名 + 存量 handle 的 legacy 回退识别。
*/
exports.BACKEND_HANDLE_DIRNAME = 'meegle-plugin-config';
const PLUGIN_CONFIG_FILE = 'plugin.config.json';
/**
* 是否后端向工程:优先看显式 `backendOnly` flag;
* 兼容存量——flag 引入前建的 config-only handle 没有该字段,靠"默认目录名 + 空 resources"回退识别。
*/
function isBackendHandle(cwd, pluginConfigPath) {
try {
const config = fs_extra_1.default.readJSONSync(pluginConfigPath);
if (config.backendOnly === true) {
return true;
}
// legacy 回退(flag 引入前建的 handle)
return (path_1.default.basename(cwd) === exports.BACKEND_HANDLE_DIRNAME &&
Array.isArray(config.resources) &&
config.resources.length === 0);
}
catch (_a) {
// 读不了 / 解析失败:当作普通工程
return false;
}
}
function resolveWorkspaceContext(cwd) {
const cwdConfig = path_1.default.join(cwd, PLUGIN_CONFIG_FILE);
if (fs_extra_1.default.existsSync(cwdConfig)) {
return isBackendHandle(cwd, cwdConfig) ? 'BACKEND_HANDLE_CWD' : 'PLUGIN_PROJECT';
}
return 'NONE';
}
exports.resolveWorkspaceContext = resolveWorkspaceContext;