-
-
Notifications
You must be signed in to change notification settings - Fork 34
Convert Storybooks #870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Convert Storybooks #870
Changes from all commits
63771f3
3788a4d
a0cc732
53b9aa5
3dfd030
43d13b8
085cf59
357b474
fdd9891
144508f
dde4725
17bd59c
18255ea
f839626
3ae0802
4dc23d4
1d922fe
b4e1b0f
88c56ce
bd6a2b9
b84d2fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| test-results | ||
| *.swp | ||
| .DS_Store | ||
| node_modules | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -575,6 +575,7 @@ export function parseBookCollections(document: Document, dataDir: string, verbos | |
| } | ||
| const audio: BookCollectionAudioConfig[] = []; | ||
| let chaptersLabels: { [key: string]: string } | undefined; | ||
| const pageIllustrations: { num: number; filename: string }[] = []; | ||
| for (const page of book.getElementsByTagName('page')) { | ||
| if (verbose >= 2) { | ||
| console.log(`.. page: ${page.attributes[0].value}`); | ||
|
|
@@ -588,6 +589,20 @@ export function parseBookCollections(document: Document, dataDir: string, verbos | |
| const chapterNum = page.attributes.getNamedItem('num')!.value; | ||
| chaptersLabels[chapterNum] = char; | ||
| } | ||
| const imageFileTag = page.getElementsByTagName('image-filename')[0]; | ||
| if (imageFileTag) { | ||
| pageIllustrations.push({ | ||
| num: Number(page.attributes.getNamedItem('num')?.value), | ||
| filename: book.getElementsByTagName('images')[0] | ||
| ? tag.id + | ||
| '-' + | ||
| book.attributes.getNamedItem('id')!.value + | ||
| '-' + | ||
| imageFileTag.innerHTML | ||
| : imageFileTag.innerHTML | ||
| }); | ||
|
Comment on lines
+592
to
+603
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail fast when page At Line 595, Suggested fix const imageFileTag = page.getElementsByTagName('image-filename')[0];
if (imageFileTag) {
+ const pageNum = parseInt(page.attributes.getNamedItem('num')!.value, 10);
+ if (Number.isNaN(pageNum)) {
+ throw new Error(`Invalid page num for book ${book.id}`);
+ }
pageIllustrations.push({
- num: Number(page.attributes.getNamedItem('num')?.value),
+ num: pageNum,
filename: book.getElementsByTagName('images')[0]
? tag.id +
'-' +Based on learnings: For conversion modules under 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| const audioTag = page.getElementsByTagName('audio')[0]; | ||
| if (!audioTag) { | ||
| continue; | ||
|
|
@@ -783,7 +798,8 @@ export function parseBookCollections(document: Document, dataDir: string, verbos | |
| style, | ||
| styles, | ||
| footer, | ||
| bookTabs | ||
| bookTabs, | ||
| pageIllustrations | ||
| }); | ||
| if (verbose >= 3) { | ||
| console.log(`.... book: `, JSON.stringify(books[0])); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { spawn } from 'node:child_process'; | ||
|
|
||
| const args = process.argv.slice(2).join(' '); | ||
| console.log('playwright test ' + args); | ||
| spawn('playwright test ' + args, { | ||
| shell: true, | ||
| stdio: 'inherit' | ||
|
Comment on lines
+3
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's verify the file exists and check its content
cat -n convert/runTests.tsRepository: sillsdev/appbuilder-pwa Length of output: 519 🏁 Script executed: # Let's check the Node.js spawn documentation and common patterns
# First, let's see if there are any other spawn calls in the repository that use best practices
rg "spawn\(" --type ts -A 3 | head -50Repository: sillsdev/appbuilder-pwa Length of output: 414 🏁 Script executed: # Let's verify Node.js spawn API behavior with a quick test
# Check if there's any documentation or test files that show the correct pattern
fd -e md -e txt -e js -e ts | xargs grep -l "spawn.*args" | head -5Repository: sillsdev/appbuilder-pwa Length of output: 87 🏁 Script executed: # Let me verify the exit code propagation issue mentioned in the internal scratchpad
# Check if the code properly handles exit codes from both spawn calls
grep -A 10 "spawn('vitest" convert/runTests.tsRepository: sillsdev/appbuilder-pwa Length of output: 155 Forward argv as an argument array instead of a shell string.
🤖 Prompt for AI Agents |
||
| }).on('close', (code) => { | ||
| console.log('vitest ' + args); | ||
| spawn('vitest ' + args, { | ||
| shell: true, | ||
| stdio: 'inherit' | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| import { expect, test } from 'vitest'; | ||
| import { transformLists } from '../../convertBooks'; | ||
|
|
||
| function tokensOf(str: string) { | ||
| return str.split(/\s+/).filter((token) => token.length); | ||
| } | ||
|
|
||
| test('convert unordered list to milestones', () => { | ||
| const input = ` | ||
| \\m Some content | ||
| \\zuli1 One | ||
| \\zuli1 Two \\zuli1 Three in a row! | ||
| \\b | ||
| `; | ||
| const expected = ` | ||
| \\m Some content | ||
| \\nb \\zuli1\\* One | ||
| \\nb \\zuli1\\* Two | ||
| \\nb \\zuli1\\* Three in a row! | ||
| \\b | ||
| `; | ||
| const result = transformLists(input, '', ''); | ||
| expect(tokensOf(result)).toEqual(tokensOf(expected)); | ||
| }); | ||
|
|
||
| test('convert ordered list to milestones', () => { | ||
| const input = ` | ||
| \\m Some content | ||
| \\zon1 10 | ||
| \\zoli1 One | ||
| \\zoli1 Two \\zoli1 Three in a row! | ||
| \\b | ||
| `; | ||
| const expected = ` | ||
| \\m Some content | ||
| \\zon1 |start="10"\\* | ||
| \\nb \\zoli1\\* One | ||
| \\nb \\zoli1\\* Two | ||
| \\nb \\zoli1\\* Three in a row! | ||
| \\b | ||
| `; | ||
| const result = transformLists(input, '', ''); | ||
| expect(tokensOf(result)).toEqual(tokensOf(expected)); | ||
| }); | ||
|
|
||
| test('convert multilevel unordered list to milestones', () => { | ||
| const input = ` | ||
| \\c 2 | ||
| \\b | ||
| \\zuli1 Old Testament | ||
| \\zuli2 Pentateuch | ||
| \\zuli3 Genesis | ||
| \\zuli3 Exodus | ||
| \\zuli3 Leviticus | ||
| \\zuli2 Joshua | ||
| \\zuli2 Judges | ||
| \\zuli1 New Testament | ||
| \\zuli2 Matthew | ||
| \\zuli2 Mark | ||
| \\zuli2 Luke | ||
| \\zuli2 John | ||
| \\zuli1 Glossary | ||
| `; | ||
| const expected = ` | ||
| \\c 2 | ||
| \\b | ||
| \\nb \\zuli1\\* Old Testament | ||
| \\nb \\zuli2\\* Pentateuch | ||
| \\nb \\zuli3\\* Genesis | ||
| \\nb \\zuli3\\* Exodus | ||
| \\nb \\zuli3\\* Leviticus | ||
| \\nb \\zuli2\\* Joshua | ||
| \\nb \\zuli2\\* Judges | ||
| \\nb \\zuli1\\* New Testament | ||
| \\nb \\zuli2\\* Matthew | ||
| \\nb \\zuli2\\* Mark | ||
| \\nb \\zuli2\\* Luke | ||
| \\nb \\zuli2\\* John | ||
| \\nb \\zuli1\\* Glossary | ||
| `; | ||
| const result = transformLists(input, '', ''); | ||
| expect(tokensOf(result)).toEqual(tokensOf(expected)); | ||
| }); | ||
|
|
||
| test('convert multilevel ordered list to milestones', () => { | ||
| const input = ` | ||
| \\m My List: | ||
| \\b | ||
| \\zon1 1 | ||
| \\zoli1 Food | ||
| \\zon2 1 | ||
| \\zoli2 Fruit | ||
| \\zon3 1 | ||
| \\zoli3 Apples | ||
| \\zoli3 Bananas | ||
| \\zoli3 Pears | ||
| \\zoli2 Dessert | ||
| \\zoli3 Pie | ||
| \\zoli3 Cake | ||
| \\zoli3 Ice Cream | ||
| \\zoli1 Drinks | ||
| \\zoli2 Coffee | ||
| \\zoli2 Water | ||
| \\zoli2 Tea | ||
| `; | ||
| const expected = ` | ||
| \\m My List: | ||
| \\b | ||
| \\zon1 |start="1"\\* | ||
| \\nb \\zoli1\\* Food | ||
| \\zon2 |start="1"\\* | ||
| \\nb \\zoli2\\* Fruit | ||
| \\zon3 |start="1"\\* | ||
| \\nb \\zoli3\\* Apples | ||
| \\nb \\zoli3\\* Bananas | ||
| \\nb \\zoli3\\* Pears | ||
| \\nb \\zoli2\\* Dessert | ||
| \\nb \\zoli3\\* Pie | ||
| \\nb \\zoli3\\* Cake | ||
| \\nb \\zoli3\\* Ice Cream | ||
| \\nb \\zoli1\\* Drinks | ||
| \\nb \\zoli2\\* Coffee | ||
| \\nb \\zoli2\\* Water | ||
| \\nb \\zoli2\\* Tea | ||
| `; | ||
| const result = transformLists(input, '', ''); | ||
| expect(tokensOf(result)).toEqual(tokensOf(expected)); | ||
| }); | ||
|
|
||
| test('convert unordered list with formatting to milestones', () => { | ||
| const input = ` | ||
| \\m Some content | ||
| \\zuli1 One | ||
| \\zuli1 \\bd Two \\bd* | ||
| \\zuli1 Three in a row! | ||
| \\b | ||
| `; | ||
| const expected = ` | ||
| \\m Some content | ||
| \\nb \\zuli1\\* One | ||
| \\nb \\zuli1\\* \\bd Two \\bd* | ||
| \\nb \\zuli1\\* Three in a row! | ||
| \\b | ||
| `; | ||
| const result = transformLists(input, '', ''); | ||
| expect(tokensOf(result)).toEqual(tokensOf(expected)); | ||
| }); | ||
|
|
||
| test('convert ordered list with formatting to milestones', () => { | ||
| const input = ` | ||
| \\m Some content | ||
| \\zon1 10 | ||
| \\zoli1 One | ||
| \\zoli1 \\bdit Two \\bdit* | ||
| \\zoli1 Three in a row! | ||
| \\b | ||
| `; | ||
| const expected = ` | ||
| \\m Some content | ||
| \\zon1 |start="10"\\* | ||
| \\nb \\zoli1\\* One | ||
| \\nb \\zoli1\\* \\bdit Two \\bdit* | ||
| \\nb \\zoli1\\* Three in a row! | ||
| \\b | ||
| `; | ||
| const result = transformLists(input, '', ''); | ||
| expect(tokensOf(result)).toEqual(tokensOf(expected)); | ||
| }); | ||
|
|
||
| test('convert multilevel ordered list with formatting to milestones', () => { | ||
| const input = ` | ||
| \\m Some content | ||
| \\zon1 10 | ||
| \\zoli1 One | ||
| \\zon2 3 | ||
| \\zoli2 \\it sub-point 1 \\it* | ||
| \\zoli2 sub-point 2 | ||
| \\zoli1 \\bdit Two \\bdit* | ||
| \\zoli1 Three in a row! | ||
| \\b | ||
| `; | ||
| const expected = ` | ||
| \\m Some content | ||
| \\zon1 |start="10"\\* | ||
| \\nb \\zoli1\\* One | ||
| \\zon2 |start="3"\\* | ||
| \\nb \\zoli2\\* \\it sub-point 1 \\it* | ||
| \\nb \\zoli2\\* sub-point 2 | ||
| \\nb \\zoli1\\* \\bdit Two \\bdit* | ||
| \\nb \\zoli1\\* Three in a row! | ||
| \\b | ||
| `; | ||
| const result = transformLists(input, '', ''); | ||
| expect(tokensOf(result)).toEqual(tokensOf(expected)); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that it will fall to the default case, but I think it would be better to include
case 'story':abovedefault: