35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
|
|
const fs = require('fs');
|
||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
// 读取mockData.js文件
|
||
|
|
const mockDataPath = path.join(__dirname, 'src/data/mockData.js');
|
||
|
|
const mockDataContent = fs.readFileSync(mockDataPath, 'utf-8');
|
||
|
|
|
||
|
|
// 提取homework数组中的课程对象
|
||
|
|
// 匹配 { id: X, name: "xxx", level: "xxx", ... } 格式
|
||
|
|
const coursePattern = /\{\s*id:\s*\d+,\s*name:\s*"([^"]+)",\s*level:\s*"[^"]+"/g;
|
||
|
|
|
||
|
|
let matches = mockDataContent.match(coursePattern);
|
||
|
|
console.log('mockData.js中找到的课程对象总数:', matches ? matches.length : 0);
|
||
|
|
|
||
|
|
// 统计units结构中的courses
|
||
|
|
const unitsPattern = /units:\s*\[([\s\S]*?)\]\s*,\s*\/\/ 保留原始list用于兼容/g;
|
||
|
|
const unitsMatches = [...mockDataContent.matchAll(unitsPattern)];
|
||
|
|
|
||
|
|
console.log('\n找到的units结构数量:', unitsMatches.length);
|
||
|
|
|
||
|
|
let totalCoursesInUnits = 0;
|
||
|
|
unitsMatches.forEach((match, index) => {
|
||
|
|
const unitsContent = match[1];
|
||
|
|
const coursesInThisSection = (unitsContent.match(/\{\s*id:\s*\d+,\s*name:\s*"[^"]+",\s*level:/g) || []).length;
|
||
|
|
console.log(` - 第${index + 1}个section的units中有 ${coursesInThisSection} 个课程`);
|
||
|
|
totalCoursesInUnits += coursesInThisSection;
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('\nunits结构中的课程总数:', totalCoursesInUnits);
|
||
|
|
|
||
|
|
// 检查有多少课程已经有imageUrl
|
||
|
|
const imageUrlPattern = /imageUrl:\s*"https:\/\/[^"]+"/g;
|
||
|
|
const imageUrlMatches = mockDataContent.match(imageUrlPattern);
|
||
|
|
console.log('\n已添加imageUrl的课程数:', imageUrlMatches ? imageUrlMatches.length : 0);
|