module-migration-tool
Version:
分析项目文件依赖并迁移到新项目的工具
45 lines (39 loc) • 1.09 kB
JavaScript
/**
* 依赖分析器入口
*/
const jsAnalyzer = require("./jsAnalyzer")
const cssAnalyzer = require("./cssAnalyzer")
const vueAnalyzer = require("./vueAnalyzer")
const path = require("path")
/**
* 根据文件类型选择合适的分析器
* @param {string} filePath - 文件路径
* @returns {Function} 分析器函数
*/
function getAnalyzer(filePath) {
const ext = path.extname(filePath).toLowerCase()
if ([".vue"].includes(ext)) {
return vueAnalyzer.analyzeFile
} else if ([".js", ".jsx", ".ts", ".tsx"].includes(ext)) {
return jsAnalyzer.analyzeFile
} else if ([".css", ".scss", ".less", ".sass"].includes(ext)) {
return cssAnalyzer.analyzeFile
}
// 默认返回一个空分析器
return () => []
}
/**
* 分析文件依赖
* @param {string} filePath - 文件路径
* @returns {string[]} 依赖路径数组
*/
function analyzeFile(filePath) {
const analyzer = getAnalyzer(filePath)
return analyzer(filePath)
}
module.exports = {
analyzeFile,
jsAnalyzer,
cssAnalyzer,
vueAnalyzer,
}