|
1 | 1 | import { existsSync, readFileSync } from 'fs'; |
2 | 2 | import path from 'path'; |
3 | | -import { ScriptureConfig } from '$config'; |
| 3 | +import { ContentItem, ContentsData, LangContainer, LinkMeta, ScriptureConfig } from '$config'; |
4 | 4 | import jsdom from 'jsdom'; |
5 | 5 | import { ConfigTaskOutput, parseLangAttribute } from './convertConfig'; |
6 | 6 | import { createHashedFile, createOutputDir, deleteOutputDir, joinUrlPath } from './fileUtils'; |
7 | 7 | import { Task, TaskOutput } from './Task'; |
8 | 8 |
|
9 | | -export type LangContainer = { [lang: string]: string }; |
10 | | - |
11 | | -export type LinkMeta = { |
12 | | - // intended to pass between functions so that there is one object passed |
13 | | - linkType?: string; |
14 | | - linkTarget?: string; |
15 | | - linkLocation?: string; |
16 | | -}; |
17 | | - |
18 | | -type ContentItem = { |
19 | | - id: number; |
20 | | - heading?: boolean; |
21 | | - features?: any; |
22 | | - title: LangContainer; |
23 | | - subtitle?: LangContainer; |
24 | | - audioFilename?: LangContainer; |
25 | | - imageFilename?: string; |
26 | | - itemType?: string; |
27 | | - contentItemContainer: boolean; |
28 | | - linkType?: string; |
29 | | - linkTarget?: string; |
30 | | - linkLocation?: string; |
31 | | - layoutMode?: string; |
32 | | - layoutCollection?: string[]; |
33 | | - children?: ContentItem[]; |
34 | | -}; |
35 | | - |
36 | | -type ContentScreen = { |
37 | | - id: number; |
38 | | - title?: { |
39 | | - [lang: string]: string; |
40 | | - }; |
41 | | - items?: { |
42 | | - id: number; |
43 | | - }[]; |
44 | | -}; |
45 | | - |
46 | | -export type ContentsData = { |
47 | | - title?: { |
48 | | - [lang: string]: string; |
49 | | - }; |
50 | | - features?: any; |
51 | | - items?: ContentItem[]; |
52 | | - nestedItems?: boolean; |
53 | | - screens?: ContentScreen[]; |
54 | | -}; |
55 | | - |
56 | | -const data: ContentsData = {}; |
57 | | - |
58 | 9 | export interface ContentsTaskOutput extends TaskOutput { |
59 | 10 | taskName: 'ConvertContents'; |
60 | 11 | } |
@@ -367,6 +318,8 @@ export function convertContents( |
367 | 318 | deleteOutputDir(destDir); |
368 | 319 | } |
369 | 320 |
|
| 321 | + const data: ContentsData = {}; |
| 322 | + |
370 | 323 | const contentsFile = path.join(dataDir, 'contents.xml'); |
371 | 324 | if (!existsSync(contentsFile)) { |
372 | 325 | return data; |
@@ -602,8 +555,12 @@ export class ConvertContents extends Task { |
602 | 555 | data, |
603 | 556 | files: [ |
604 | 557 | { |
605 | | - path: 'src/lib/data/contents.js', |
606 | | - content: `export default ${JSON.stringify(data, null, 2)}` |
| 558 | + path: 'src/gen-assets/contents.ts', |
| 559 | + content: [ |
| 560 | + `import type { ContentsData } from '$config';`, |
| 561 | + `export const contents = ${JSON.stringify(data, null, 2)} as Readonly<ContentsData>;`, |
| 562 | + `export default contents;\n` |
| 563 | + ].join('\n') |
607 | 564 | } |
608 | 565 | ] |
609 | 566 | }; |
|
0 commit comments