57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const vm = require('vm');
|
|
|
|
function extractLessonArray(content, varNameCandidates) {
|
|
for (const varName of varNameCandidates) {
|
|
const re = new RegExp(varName.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + "\\s*=\\s*\\[([\\s\\S]*?)\\];", 'm');
|
|
const m = re.exec(content);
|
|
if (m) return m[1];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function evalArrayText(arrayText) {
|
|
const wrapped = '[' + arrayText + ']';
|
|
const script = new vm.Script(wrapped, { filename: 'array.js' });
|
|
const context = vm.createContext({});
|
|
return script.runInContext(context);
|
|
}
|
|
|
|
function loadLessons(filePath, varCandidates) {
|
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
const arrText = extractLessonArray(content, varCandidates);
|
|
if (!arrText) return [];
|
|
const arr = evalArrayText(arrText);
|
|
return arr;
|
|
}
|
|
|
|
function main() {
|
|
const repo = path.join(__dirname);
|
|
const file1 = path.join(repo, 'bisaya-course-plan-24-43.js');
|
|
const file2 = path.join(repo, 'bisaya-course-phase3-extension.js');
|
|
|
|
const lessons1 = loadLessons(file1, ['const BISAYA_LESSONS_24_43_BASE', 'BISAYA_LESSONS_24_43_BASE', 'BISAYA_LESSONS_24_43']);
|
|
const lessons2 = loadLessons(file2, ['export const BISAYA_PHASE3_LESSONS', 'BISAYA_PHASE3_LESSONS']);
|
|
|
|
const mapping = {};
|
|
for (const l of lessons1) {
|
|
if (l && typeof l.num === 'number') mapping[l.num] = true;
|
|
}
|
|
for (const l of lessons2) {
|
|
if (l && typeof l.num === 'number') mapping[l.num] = true;
|
|
}
|
|
|
|
// Also include any missing range 24..63
|
|
for (let n = 24; n <= 63; n++) mapping[n] = true;
|
|
|
|
const outDir = path.join(__dirname, '..', 'data');
|
|
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
const outFile = path.join(outDir, 'lesson-checkpoints.json');
|
|
fs.writeFileSync(outFile, JSON.stringify(mapping, null, 2));
|
|
console.log('Wrote', outFile);
|
|
console.log('Marked lessons:', Object.keys(mapping).length);
|
|
}
|
|
|
|
main();
|