UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

43 lines (42 loc) 1.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runPeek = void 0; const path_1 = __importDefault(require("path")); const fs_extra_1 = require("fs-extra"); const json_1 = require("./json"); const yaml_1 = require("./yaml"); const typescript_1 = require("./typescript"); const markdown_1 = require("./markdown"); const text_1 = require("./text"); /** * Route a peek request to the right parser based on file extension. * Unknown / no extension → fall back to the plain-text slicer. */ async function runPeek(req) { const { file, name, options } = req; if (!(0, fs_extra_1.existsSync)(file)) { process.stderr.write(`File not found: ${file}\n`); process.exit(1); } const ext = path_1.default.extname(file).toLowerCase(); const base = path_1.default.basename(file).toLowerCase(); // .d.ts 优先识别(双后缀),普通 .ts 也走 typescript 分支 if (base.endsWith('.d.ts') || ext === '.ts' || ext === '.tsx') { return (0, typescript_1.peekTypescript)(file, name, options); } if (ext === '.json') { return (0, json_1.peekJson)(file, name, options); } if (ext === '.yaml' || ext === '.yml') { return (0, yaml_1.peekYaml)(file, name, options); } if (ext === '.md' || ext === '.mdx' || ext === '.markdown') { return (0, markdown_1.peekMarkdown)(file, name, options); } // 兜底:纯文本切片 return (0, text_1.peekText)(file, options); } exports.runPeek = runPeek;