mp-lens
Version:
微信小程序分析工具 (Unused Code, Dependencies, Visualization)
79 lines • 3.24 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateHtmlGraph = generateHtmlGraph;
exports.generateJsonGraph = generateJsonGraph;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const debug_logger_1 = require("../../utils/debug-logger");
const html_renderer_1 = require("./html-renderer");
/**
* Generates HTML format graph
*/
async function generateHtmlGraph(projectStructure, reachableNodeIds, unusedFiles, projectRoot, outputPath) {
const htmlGenerator = new html_renderer_1.HtmlGeneratorPreact(projectStructure, reachableNodeIds, unusedFiles);
const htmlContent = await htmlGenerator.generate({
title: path.basename(projectRoot) + ' 依赖可视化',
});
const filePath = outputPath || path.resolve(process.cwd(), 'mp-lens-graph.html');
writeOutputToFile(htmlContent, filePath);
debug_logger_1.logger.info(`✅ 依赖图已保存至: ${filePath}`);
}
/**
* Generates JSON format graph
*/
function generateJsonGraph(projectStructure, outputPath) {
const jsonContent = JSON.stringify(projectStructure, null, 2);
const filePath = outputPath || path.resolve(process.cwd(), 'mp-lens-graph.json');
writeOutputToFile(jsonContent, filePath);
debug_logger_1.logger.info(`✅ 依赖图 JSON 已保存至: ${filePath}`);
}
/**
* Writes content to file, creating directories if needed
*/
function writeOutputToFile(content, filePath) {
try {
const outputDir = path.dirname(filePath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.writeFileSync(filePath, content);
}
catch (writeError) {
debug_logger_1.logger.error(`保存依赖图到 ${filePath} 失败: ${writeError.message}`);
throw writeError;
}
}
//# sourceMappingURL=graph-utils.js.map