UNPKG

@erda-ui/cli

Version:

Command line interface for rapid Erda UI development

51 lines (50 loc) 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.walker = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const log_1 = require("./log"); const walker = ({ root, dealFile, recursive = true, excludePath = [], files = { level: 0 }, }) => { if (!dealFile) { (0, log_1.logError)('[walker] Not assign file handler'); process.exit(); } if (root.includes('node_modules')) { (0, log_1.logWarn)('[walker] Skip node_modules'); return; } if (excludePath.some((p) => root.startsWith(p))) { (0, log_1.logWarn)('[walker] Skip excluded path'); return; } fs_1.default.readdir(root, { encoding: 'utf8', withFileTypes: true }, (err, data) => { if (err) { (0, log_1.logError)(`[walker] Read directory ${root} error:`, err); return; } data.forEach((item) => { const { name: fileName } = item; if (fileName.startsWith('.')) { return; } const subPath = path_1.default.resolve(`${root}/${fileName}`); if (item.isDirectory() && recursive) { return (0, exports.walker)({ root: subPath, dealFile, recursive, files, excludePath }); } const filePath = subPath; files.level += 1; fs_1.default.readFile(filePath, 'utf8', (readErr, content) => { if (readErr) { (0, log_1.logError)(`[walker] Read file ${filePath} error:`, readErr); return; } dealFile(content, filePath, files.level === 1); files.level -= 1; }); }); }); }; exports.walker = walker;