Skip to content

Commit 5778430

Browse files
kckernclaude
andcommitted
feat: add migration script for regenerating YAML structures
Consolidates Bible and LDS YAML structure generation into a single script that can regenerate _structure.yml files from scriptdata.mjs for verification or future canon updates. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 962607d commit 5778430

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed

scripts/migrate-to-yaml.mjs

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// scripts/migrate-to-yaml.mjs
2+
/**
3+
* Migrate existing scriptdata.mjs to YAML structure
4+
* Run: node scripts/migrate-to-yaml.mjs
5+
*/
6+
7+
import { writeFileSync, mkdirSync } from 'fs';
8+
import { join } from 'path';
9+
import yaml from 'js-yaml';
10+
11+
// Import existing data
12+
import scriptdata from '../data/scriptdata.mjs';
13+
14+
const DATA_DIR = 'data';
15+
16+
// Bible books are the first 66 in scriptdata
17+
const BIBLE_BOOK_COUNT = 66;
18+
19+
// LDS-specific books: Book of Mormon (1 Nephi through Moroni), D&C, Pearl of Great Price
20+
const LDS_BOOKS = [
21+
'1 Nephi', '2 Nephi', 'Jacob', 'Enos', 'Jarom', 'Omni', 'Words of Mormon',
22+
'Mosiah', 'Alma', 'Helaman', '3 Nephi', '4 Nephi', 'Mormon', 'Ether', 'Moroni',
23+
'Doctrine and Covenants', 'Moses', 'Abraham',
24+
'Joseph Smith\u2014Matthew', 'Joseph Smith\u2014History', 'Articles of Faith'
25+
];
26+
27+
function ensureDir(path) {
28+
mkdirSync(path, { recursive: true });
29+
}
30+
31+
function writeYaml(path, data) {
32+
const content = yaml.dump(data, {
33+
lineWidth: 120,
34+
noRefs: true,
35+
sortKeys: false
36+
});
37+
writeFileSync(path, content);
38+
console.log(`Wrote: ${path}`);
39+
}
40+
41+
function nameToKey(name) {
42+
return name.toLowerCase()
43+
.replace(/[^a-z0-9]/g, '_')
44+
.replace(/_+/g, '_')
45+
.replace(/^_|_$/g, '');
46+
}
47+
48+
// Generate Bible structure
49+
function generateBibleStructure() {
50+
const bookNames = Object.keys(scriptdata);
51+
const books = [];
52+
let verseId = 1;
53+
54+
for (let i = 0; i < BIBLE_BOOK_COUNT; i++) {
55+
const bookName = bookNames[i];
56+
const chapters = scriptdata[bookName];
57+
const key = nameToKey(bookName);
58+
const firstVerseId = verseId;
59+
const totalVerses = chapters.reduce((sum, v) => sum + v, 0);
60+
61+
books.push({
62+
key: key,
63+
order: i + 1,
64+
chapters: chapters.length,
65+
verses: chapters,
66+
first_verse_id: firstVerseId
67+
});
68+
69+
verseId += totalVerses;
70+
}
71+
72+
return {
73+
canon: 'bible',
74+
name: 'Holy Bible (KJV)',
75+
description: 'King James Version - 66 books, Genesis through Revelation',
76+
id_format: 'integer',
77+
id_start: 1,
78+
id_end: verseId - 1,
79+
books
80+
};
81+
}
82+
83+
// Generate LDS structure
84+
function generateLDSStructure() {
85+
const bookNames = Object.keys(scriptdata);
86+
const books = [];
87+
88+
// First, calculate where Bible ends (verse ID after Bible)
89+
let verseId = 1;
90+
for (let i = 0; i < BIBLE_BOOK_COUNT; i++) {
91+
const chapters = scriptdata[bookNames[i]];
92+
const totalVerses = chapters.reduce((sum, v) => sum + v, 0);
93+
verseId += totalVerses;
94+
}
95+
96+
const ldsStartId = verseId;
97+
let order = BIBLE_BOOK_COUNT + 1;
98+
99+
for (const bookName of LDS_BOOKS) {
100+
const chapters = scriptdata[bookName];
101+
if (!chapters) {
102+
console.log(`Warning: Book "${bookName}" not found in scriptdata`);
103+
continue;
104+
}
105+
106+
const key = nameToKey(bookName);
107+
const firstVerseId = verseId;
108+
const totalVerses = chapters.reduce((sum, v) => sum + v, 0);
109+
110+
books.push({
111+
key: key,
112+
order: order,
113+
chapters: chapters.length,
114+
verses: chapters,
115+
first_verse_id: firstVerseId
116+
});
117+
118+
verseId += totalVerses;
119+
order++;
120+
}
121+
122+
return {
123+
canon: 'lds',
124+
name: 'LDS Restoration Scripture',
125+
description: 'Book of Mormon, Doctrine and Covenants, Pearl of Great Price',
126+
extends: 'bible',
127+
id_format: 'integer',
128+
id_start: ldsStartId,
129+
id_end: verseId - 1,
130+
books
131+
};
132+
}
133+
134+
// Main migration
135+
function migrate() {
136+
console.log('Migrating scripture data to YAML...\n');
137+
138+
// Create directories
139+
ensureDir(join(DATA_DIR, 'shared'));
140+
ensureDir(join(DATA_DIR, 'canons', 'bible'));
141+
ensureDir(join(DATA_DIR, 'canons', 'lds'));
142+
143+
// Generate and write structures
144+
const bibleStructure = generateBibleStructure();
145+
writeYaml(
146+
join(DATA_DIR, 'canons', 'bible', '_structure.yml'),
147+
bibleStructure
148+
);
149+
console.log(`Bible: ${bibleStructure.books.length} books, ${bibleStructure.id_end} verses`);
150+
151+
const ldsStructure = generateLDSStructure();
152+
writeYaml(
153+
join(DATA_DIR, 'canons', 'lds', '_structure.yml'),
154+
ldsStructure
155+
);
156+
console.log(`LDS: ${ldsStructure.books.length} books, verse IDs ${ldsStructure.id_start}-${ldsStructure.id_end}`);
157+
158+
console.log('\nMigration complete!');
159+
}
160+
161+
migrate();

0 commit comments

Comments
 (0)