Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ static/illustrations
static/icons
static/manifest*.json
static/assets
static/collections
static/contents
src/lib/data/catalog.js
src/lib/data/firebase-config.js
src/lib/data/config.js
src/lib/data/contents.js
src/gen-assets
vite.config.js.timestamp*
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ node_modules
.env.*
!.env.example
/data
src/lib/data/config.js
src/gen-assets
src/lib/data/catalog.js
src/lib/data/firebase-config.js
static
Expand Down
61 changes: 56 additions & 5 deletions config/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export type BookConfig = {
file: string;
hashedFileName?: string; // currently just for HTML books
audio: BookCollectionAudioConfig[];
features: any;
quizFeatures?: Record<string, string | boolean | number>;
features: FeatureConfig;
quizFeatures?: FeatureConfig;
footer?: HTML;
style?: StyleConfig;
styles?: {
Expand Down Expand Up @@ -157,13 +157,17 @@ export type MenuItemConfig = {
file: string;
}[];
};

export type FeatureValue = string | boolean | number;
export type FeatureConfig = Record<string, FeatureValue>;

export type AppConfig = {
name?: string;
package?: string;
version?: string;
programVersion?: string;
programType?: string;
mainFeatures?: any;
programVersion: string;
programType: string;
mainFeatures: FeatureConfig;
audio?: AudioConfig;
fonts?: {
name?: string;
Expand Down Expand Up @@ -379,3 +383,50 @@ export type Quiz = {
}[];
passScore?: number; //\pm
};

export type LangContainer = { [lang: string]: string };

export type LinkMeta = {
// intended to pass between functions so that there is one object passed
linkType?: string;
linkTarget?: string;
linkLocation?: string;
};

export type ContentItem = {
id: number;
heading?: boolean;
features?: any;
title: LangContainer;
subtitle?: LangContainer;
audioFilename?: LangContainer;
imageFilename?: string;
itemType?: string;
contentItemContainer: boolean;
linkType?: string;
linkTarget?: string;
linkLocation?: string;
layoutMode?: string;
layoutCollection?: string[];
children?: ContentItem[];
};

export type ContentScreen = {
id: number;
title?: {
[lang: string]: string;
};
items?: {
id: number;
}[];
};

export type ContentsData = {
title?: {
[lang: string]: string;
};
features?: any;
items?: ContentItem[];
nestedItems?: boolean;
screens?: ContentScreen[];
};
18 changes: 14 additions & 4 deletions convert/convertConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readdirSync, readFileSync, type PathLike } from 'fs';
import { existsSync, mkdirSync, readdirSync, readFileSync, type PathLike } from 'fs';
import path, { basename, extname, join } from 'path';
import type {
AppConfig,
Expand Down Expand Up @@ -219,6 +219,10 @@ function isDictionaryConfig(data: ScriptureConfig | DictionaryConfig): data is D
}

function convertConfig(dataDir: string, verbose: number) {
const genAssets = path.join('src/gen-assets');
if (!existsSync(genAssets)) {
mkdirSync(genAssets, { recursive: true });
}
const dom = new jsdom.JSDOM(readFileSync(path.join(dataDir, 'appdef.xml')).toString(), {
contentType: 'text/xml'
});
Expand Down Expand Up @@ -1613,7 +1617,7 @@ export interface ConfigTaskOutput extends TaskOutput {

/**
* Converts appdef.xml into a config object which is passed to other conversion functions
* and is also written to src/config.js.
* and is also written to src/gen-assets/config.ts.
*/
export class ConvertConfig extends Task {
public triggerFiles: string[] = ['appdef.xml'];
Expand All @@ -1624,8 +1628,14 @@ export class ConvertConfig extends Task {
data,
files: [
{
path: 'src/lib/data/config.js',
content: `export default ${JSON.stringify(data, null, 2)};`
path: 'src/gen-assets/config.ts',
content: [
`import type { AppConfig, DictionaryConfig, ScriptureConfig } from '$config';`,
`export const config = ${JSON.stringify(data, null, 2)} as Readonly<AppConfig>;`,
`export const dictionaryConfig = config as Readonly<DictionaryConfig>;`,
`export const scriptureConfig = config as Readonly<ScriptureConfig>;`,
`export default config;\n`
Comment thread
FyreByrd marked this conversation as resolved.
].join('\n')
}
]
};
Expand Down
61 changes: 9 additions & 52 deletions convert/convertContents.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,11 @@
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { ScriptureConfig } from '$config';
import { ContentItem, ContentsData, LangContainer, LinkMeta, ScriptureConfig } from '$config';
import jsdom from 'jsdom';
import { ConfigTaskOutput, parseLangAttribute } from './convertConfig';
import { createHashedFile, createOutputDir, deleteOutputDir, joinUrlPath } from './fileUtils';
import { Task, TaskOutput } from './Task';

export type LangContainer = { [lang: string]: string };

export type LinkMeta = {
// intended to pass between functions so that there is one object passed
linkType?: string;
linkTarget?: string;
linkLocation?: string;
};

type ContentItem = {
id: number;
heading?: boolean;
features?: any;
title: LangContainer;
subtitle?: LangContainer;
audioFilename?: LangContainer;
imageFilename?: string;
itemType?: string;
contentItemContainer: boolean;
linkType?: string;
linkTarget?: string;
linkLocation?: string;
layoutMode?: string;
layoutCollection?: string[];
children?: ContentItem[];
};

type ContentScreen = {
id: number;
title?: {
[lang: string]: string;
};
items?: {
id: number;
}[];
};

export type ContentsData = {
title?: {
[lang: string]: string;
};
features?: any;
items?: ContentItem[];
nestedItems?: boolean;
screens?: ContentScreen[];
};

const data: ContentsData = {};

export interface ContentsTaskOutput extends TaskOutput {
taskName: 'ConvertContents';
}
Expand Down Expand Up @@ -367,6 +318,8 @@ export function convertContents(
deleteOutputDir(destDir);
}

const data: ContentsData = {};

const contentsFile = path.join(dataDir, 'contents.xml');
if (!existsSync(contentsFile)) {
return data;
Expand Down Expand Up @@ -602,8 +555,12 @@ export class ConvertContents extends Task {
data,
files: [
{
path: 'src/lib/data/contents.js',
content: `export default ${JSON.stringify(data, null, 2)}`
path: 'src/gen-assets/contents.ts',
content: [
`import type { ContentsData } from '$config';`,
`export const contents = ${JSON.stringify(data, null, 2)} as Readonly<ContentsData>;`,
`export default contents;\n`
].join('\n')
}
]
};
Expand Down
7 changes: 4 additions & 3 deletions convert/convertFirebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ export interface FirebaseTaskOutput extends TaskOutput {
export function convertFirebase(dataDir: string, verbose: number) {
const srcFile = path.join(dataDir, 'firebase-config.js');
const srcExists = existsSync(srcFile);
const dstFile = path.join('src', 'lib', 'data', 'firebase-config.js');
const dstFile = path.join('src', 'gen-assets', 'firebase-config.ts');
if (verbose) {
console.log(`FirebaseConfig: path=${srcFile}, exists=${srcExists}`);
}
const prefix = `import type { FirebaseOptions } from 'firebase/app';\nexport const firebaseConfig: Readonly<FirebaseOptions> | null`;
if (srcExists) {
let content = readFileSync(srcFile, 'utf-8');
content = content.replace('const firebaseConfig', 'export const firebaseConfig');
content = content.replace('const firebaseConfig', prefix);
writeFileSync(dstFile, content, 'utf-8');
} else {
const firebaseConfig = 'export const firebaseConfig = null;';
const firebaseConfig = `${prefix} = null`;
writeFileSync(dstFile, firebaseConfig);
}
}
Expand Down
17 changes: 3 additions & 14 deletions convert/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFile } from 'fs';
import { writeFile } from 'fs/promises';
import path from 'path';
import { watch } from 'chokidar';
import { ConvertAbout } from './convertAbout';
Expand Down Expand Up @@ -87,14 +87,7 @@ async function fullConvert(printDetails: boolean): Promise<boolean> {
// step may be async, in which case it should be awaited
const out = await step.run(verbose, outputs, step.triggerFiles);
outputs.set(step.constructor.name, out);
await Promise.all(
out.files.map(
(f) =>
new Promise((r) => {
writeFile(f.path, f.content, r);
})
)
);
await Promise.all(out.files.map((f) => writeFile(f.path, f.content)));
} catch (e) {
oldConsoleLog(lastStepOutput);
oldConsoleLog(e);
Expand Down Expand Up @@ -157,11 +150,7 @@ if (process.argv.includes('--watch')) {
outputs.set(step.constructor.name, out);
// Write all files to disk
/*await*/ // We don't need to await the file writes; next steps can continue running while writes occur
Promise.all(
out.files.map((f) => {
new Promise((r) => writeFile(f.path, f.content, r));
})
);
Promise.all(out.files.map((f) => writeFile(f.path, f.content)));
} catch (e) {
oldConsoleLog(lastStepOutput);
oldConsoleLog(e);
Expand Down
2 changes: 1 addition & 1 deletion convert/tests/dab/convertConfigDAB.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from 'fs';
import path from 'path';
import type { DictionaryConfig, DictionaryWritingSystemConfig } from '$config';
import type { DictionaryWritingSystemConfig } from '$config';
import jsdom from 'jsdom';
import { expect, test } from 'vitest';
import { parseDictionaryWritingSystem, parseFeatures } from '../../convertConfig';
Expand Down
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default ts.config(
'.env.*',
'!env.example',
'data',
'src/config.js',
'static',
'example_data',
'test_data',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"convert": "ts-node convert/index.ts",
"convert:watch": "ts-node convert/index.ts --watch",
"sandbox": "ts-node data-sandbox/index.ts",
"clean": "rimraf .svelte-kit build src/gen-assets src/lib/data/config.js src/lib/data/catalog.js src/lib/data/firebase-config.js src/lib/data/contents.js static/illustrations static/icons static/contents static/manifest*.json && echo 🔔 Reminder: The project cannot be built until the conversion scripts are run again.",
"clean": "rimraf .svelte-kit build src/gen-assets src/lib/data/catalog.js static/illustrations static/icons static/collections static/contents static/manifest*.json && echo 🔔 Reminder: The project cannot be built until the conversion scripts are run again.",
"clean:data": "rimraf --glob data/*",
"clean:all": "npm run clean && npm run clean:data",
"test": "vitest",
Expand Down
9 changes: 5 additions & 4 deletions src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="@sveltejs/kit" />
/// <reference types="svelte-gestures" />
/// <reference types="$config" />

// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
Expand Down Expand Up @@ -64,11 +65,11 @@ declare namespace App {

interface CollectionEntry {
id: string;
name: string;
name?: string;
// boolean value for if a collection is allowed
// to be shown in single pane view
singlePane: boolean;
description: string;
description?: string;
image?: string;
}

Expand All @@ -86,8 +87,8 @@ declare namespace App {
key: string;
entries?: string[];
values?: string[];
value?: string | boolean;
defaultValue?: string | boolean;
value?: FeatureValue;
defaultValue?: FeatureValue;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/AudioBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TODO:
- display audio not found message in UI when audio is not found
-->
<script lang="ts">
import config from '$assets/config';
import {
changeVerse,
format,
Expand All @@ -15,7 +16,6 @@ TODO:
skip,
updatePlaybackSpeed
} from '$lib/data/audio';
import config from '$lib/data/config';
import {
audioPlayer,
convertStyle,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/BookSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The navbar component.
-->
<script>
import config from '$lib/data/config';
import config from '$assets/config';
import { convertStyle, nextRef, refs, s, t, userSettingsOrDefault } from '$lib/data/stores';
import { DropdownIcon } from '$lib/icons';
import { getRoute, navigateToText, navigateToUrl } from '$lib/navigate';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/BookTabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A component that displays the book tabs and allows the user to switch between th
-->
<script>
import { base } from '$app/paths';
import config from '$lib/data/config';
import config from '$assets/config';
import {
convertStyle,
language,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/BottomNavigationBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
-->
<script>
import { base } from '$app/paths';
import config from '$lib/data/config';
import contents from '$lib/data/contents';
import config from '$assets/config';
import contents from '$assets/contents';
import { language, languageDefault, refs, s, theme } from '$lib/data/stores';
import { gotoRoute } from '$lib/navigate';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/ChapterSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The navbar component.
-->
<script>
import config from '$lib/data/config';
import config from '$assets/config';
import { convertStyle, nextRef, refs, s, t, userSettingsOrDefault } from '$lib/data/stores';
import { DropdownIcon } from '$lib/icons';
import { navigateToText } from '$lib/navigate';
Expand Down
Loading
Loading