@helloao/cli 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -126
- package/actions.d.ts +64 -0
- package/actions.js +159 -43
- package/cli.js +88 -31
- package/db.d.ts +22 -9
- package/db.js +155 -154
- package/files.d.ts +7 -2
- package/files.js +29 -8
- package/migrations/20240623183848_add_book_order/migration.sql +26 -26
- package/migrations/20240629194121_add_chapter_links/migration.sql +45 -45
- package/migrations/20240629194513_add_chapter_content/migration.sql +30 -30
- package/migrations/20240705221833_remove_unused_columns/migration.sql +27 -27
- package/package.json +5 -2
- package/prisma-gen/edge.js +5 -5
- package/prisma-gen/index.js +7 -7
- package/s3.d.ts +32 -2
- package/s3.js +105 -12
- package/schema.prisma +154 -154
- package/uploads.d.ts +15 -5
- package/uploads.js +9 -89
package/README.md
CHANGED
|
@@ -1,126 +1,125 @@
|
|
|
1
|
-
## Hello AO CLI
|
|
2
|
-
|
|
3
|
-
A Command Line Interface (CLI) that makes it easy to generate and manage your own [Free Use Bible API](https://bible.helloao.org/).
|
|
4
|
-
|
|
5
|
-
Additionally, it includes many functions and utilities that can make working with commonly formatted Bible data much easier.
|
|
6
|
-
|
|
7
|
-
### Features
|
|
8
|
-
|
|
9
|
-
- Supports [USFM](https://ubsicap.github.io/usfm/), [USX](https://ubsicap.github.io/usx/), and Codex (A JSON format).
|
|
10
|
-
- Download over 1000 Bible translations from [fetch.bible](https://fetch.bible/).
|
|
11
|
-
- Import Bible translations into a SQLite database.
|
|
12
|
-
- Upload to S3, a zip file, or a local directory.
|
|
13
|
-
|
|
14
|
-
### Usage
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
Usage: helloao [options] [command]
|
|
18
|
-
|
|
19
|
-
A CLI for managing a Free Use Bible API.
|
|
20
|
-
|
|
21
|
-
Options:
|
|
22
|
-
-V, --version output the version number
|
|
23
|
-
-h, --help display help for command
|
|
24
|
-
|
|
25
|
-
Commands:
|
|
26
|
-
init [options] [path] Initialize a new Bible API DB.
|
|
27
|
-
import-translation [options] <dir> [dirs...] Imports a translation from the given directory into the database.
|
|
28
|
-
import-translations [options] <dir> Imports all translations from the given directory into the database.
|
|
29
|
-
generate-translation-files [options] <input> <dir> Generates API files from the given input translation.
|
|
30
|
-
generate-translations-files [options] <input> <dir> Generates API files from the given input translations.
|
|
31
|
-
upload-api-files [options] <dest> Uploads API files to the specified destination. For S3, use the format s3://bucket-name/path/to/folder.
|
|
32
|
-
fetch-translations [options] <dir> [translations...] Fetches the specified translations from fetch.bible and places them in the given directory.
|
|
33
|
-
fetch-audio [options] <dir> [translations...] Fetches the specified audio translations and places them in the given directory.
|
|
34
|
-
Translations should be in the format "translationId/audioId". e.g. "BSB/gilbert"
|
|
35
|
-
fetch-bible-metadata <dir> Fetches the Theographic bible metadata and places it in the given directory.
|
|
36
|
-
help [command] display help for command
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
The `@helloao/cli` package can also be used as a library.
|
|
40
|
-
|
|
41
|
-
The library exports a variety of actions, utilities, and supporting classes designed to assist with generating and managing a Free Use Bible API.
|
|
42
|
-
|
|
43
|
-
There are 6 main exports:
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
import {
|
|
94
|
-
import {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
```
|
|
1
|
+
## Hello AO CLI
|
|
2
|
+
|
|
3
|
+
A Command Line Interface (CLI) that makes it easy to generate and manage your own [Free Use Bible API](https://bible.helloao.org/).
|
|
4
|
+
|
|
5
|
+
Additionally, it includes many functions and utilities that can make working with commonly formatted Bible data much easier.
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- Supports [USFM](https://ubsicap.github.io/usfm/), [USX](https://ubsicap.github.io/usx/), and Codex (A JSON format).
|
|
10
|
+
- Download over 1000 Bible translations from [fetch.bible](https://fetch.bible/).
|
|
11
|
+
- Import Bible translations into a SQLite database.
|
|
12
|
+
- Upload to S3, a zip file, or a local directory.
|
|
13
|
+
|
|
14
|
+
### Usage
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Usage: helloao [options] [command]
|
|
18
|
+
|
|
19
|
+
A CLI for managing a Free Use Bible API.
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
-V, --version output the version number
|
|
23
|
+
-h, --help display help for command
|
|
24
|
+
|
|
25
|
+
Commands:
|
|
26
|
+
init [options] [path] Initialize a new Bible API DB.
|
|
27
|
+
import-translation [options] <dir> [dirs...] Imports a translation from the given directory into the database.
|
|
28
|
+
import-translations [options] <dir> Imports all translations from the given directory into the database.
|
|
29
|
+
generate-translation-files [options] <input> <dir> Generates API files from the given input translation.
|
|
30
|
+
generate-translations-files [options] <input> <dir> Generates API files from the given input translations.
|
|
31
|
+
upload-api-files [options] <dest> Uploads API files to the specified destination. For S3, use the format s3://bucket-name/path/to/folder.
|
|
32
|
+
fetch-translations [options] <dir> [translations...] Fetches the specified translations from fetch.bible and places them in the given directory.
|
|
33
|
+
fetch-audio [options] <dir> [translations...] Fetches the specified audio translations and places them in the given directory.
|
|
34
|
+
Translations should be in the format "translationId/audioId". e.g. "BSB/gilbert"
|
|
35
|
+
fetch-bible-metadata <dir> Fetches the Theographic bible metadata and places it in the given directory.
|
|
36
|
+
help [command] display help for command
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The `@helloao/cli` package can also be used as a library.
|
|
40
|
+
|
|
41
|
+
The library exports a variety of actions, utilities, and supporting classes designed to assist with generating and managing a Free Use Bible API.
|
|
42
|
+
|
|
43
|
+
There are 6 main exports:
|
|
44
|
+
|
|
45
|
+
- `actions` - This export contains function versions of the CLI commands. They make it easy to call a CLI command from a script.
|
|
46
|
+
- `db` - This export contains functions that make working with a database easier. It supports operations like importing translations into a database, inserting chapters, verses, etc. and getting an updated database instance from a path.
|
|
47
|
+
- `downloads` - This export contains functions that make downloading files easier.
|
|
48
|
+
- `files` - This export contains functions that make working with files easier. It has functions to load files from a translation, discover translation metadata from the filesystem, and classes that support uploading API files to the local file system or to a zip archive.
|
|
49
|
+
- `uploads` - This export contains functions that make it easy to upload an API to a destination like S3, the local filesystem, or a zip archive.
|
|
50
|
+
- `s3` - This export contains a class that can upload files to S3.
|
|
51
|
+
|
|
52
|
+
Here are some common operations that you might want to perform:
|
|
53
|
+
|
|
54
|
+
#### Get a SQL Database
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { db } from '@helloao/cli';
|
|
58
|
+
|
|
59
|
+
const pathToDb = './bible-database.db';
|
|
60
|
+
const database = await db.getDb(pathToDb);
|
|
61
|
+
|
|
62
|
+
// do work on the database
|
|
63
|
+
|
|
64
|
+
// Close it when you are done.
|
|
65
|
+
database.close();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Import a translation into a database from a directory
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { db } from '@helloao/cli';
|
|
72
|
+
|
|
73
|
+
const pathToDb = './bible-database.db';
|
|
74
|
+
const database = await db.getDb(pathToDb);
|
|
75
|
+
|
|
76
|
+
// Get a DOMParser for parsing USX.
|
|
77
|
+
// On Node.js, you may have to import jsdom or linkedom.
|
|
78
|
+
const parser = new DOMParser();
|
|
79
|
+
|
|
80
|
+
const pathToTranslation = './path/to/translation';
|
|
81
|
+
|
|
82
|
+
// Whether to overwrite files that already exist in the database.
|
|
83
|
+
// The system will automatically determine the hashes of the input files and overwrite changed files if needed, so this is only needed
|
|
84
|
+
// when you know that they need to be overwritten.
|
|
85
|
+
const overwrite = false;
|
|
86
|
+
await db.importTranslations(database, pathToTranslation, parser, overwrite);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Generate an API from a translation
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { files, uploads } from '@helloao/cli';
|
|
93
|
+
import { generation } from '@helloao/tools';
|
|
94
|
+
import { toAsyncIterable } from '@helloao/tools/parser/iterators';
|
|
95
|
+
|
|
96
|
+
const translationPath = './path/to/translation';
|
|
97
|
+
const translationFiles = await files.loadTranslationFiles(translationPath);
|
|
98
|
+
|
|
99
|
+
// Used to parse XML
|
|
100
|
+
const domParser = new DOMParser();
|
|
101
|
+
|
|
102
|
+
// Generate a dataset from the files
|
|
103
|
+
// Datasets organize all the files and their content
|
|
104
|
+
// by translation, book, chapter, and verse
|
|
105
|
+
const dataset = generation.dataset.generateDataset(files, parser);
|
|
106
|
+
|
|
107
|
+
// You can optionally specifiy a prefix that should be added to all API
|
|
108
|
+
// links
|
|
109
|
+
const pathPrefix = '';
|
|
110
|
+
|
|
111
|
+
// Generate an API representation from the files
|
|
112
|
+
// This adds links between chapters and additional metadata.
|
|
113
|
+
const api = generation.api.generateApiForDataset(dataset, {
|
|
114
|
+
pathPrefix,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Generate output files from the API representation.
|
|
118
|
+
// This will give us a list of files and file paths that represent
|
|
119
|
+
// the entire API.
|
|
120
|
+
const outputFiles = generation.api.generateFilesForApi(api);
|
|
121
|
+
|
|
122
|
+
// Optionally upload files by using:
|
|
123
|
+
// const dest = 's3://my-bucket';
|
|
124
|
+
// await uploads.serializeAndUploadDatasets(dest, toAsyncIterable(outputFiles));
|
|
125
|
+
```
|
package/actions.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UploadApiFromDatabaseOptions, UploadApiOptions } from './uploads';
|
|
1
2
|
export interface InitDbOptions {
|
|
2
3
|
/**
|
|
3
4
|
* The path to the source database to copy the schema from.
|
|
@@ -54,4 +55,67 @@ export declare function fetchTranslations(dir: string, translations?: string[],
|
|
|
54
55
|
* @param options The options.
|
|
55
56
|
*/
|
|
56
57
|
export declare function fetchAudio(dir: string, translations: string[], options?: FetchTranslationsOptions): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Generates the translation files directly from the translations stored in the given input directory.
|
|
60
|
+
* @param input The input directory that the translations are stored in.
|
|
61
|
+
* @param dest The destination to upload the API files to.
|
|
62
|
+
* @param options The options for the generation.
|
|
63
|
+
*/
|
|
64
|
+
export declare function generateTranslationsFiles(input: string, dest: string, options: UploadApiFromDatabaseOptions): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Generates the translation files directly from the translation stored in the given input directory.
|
|
67
|
+
* @param input The input directory that the translation is stored in.
|
|
68
|
+
* @param dest The destination to upload the API files to.
|
|
69
|
+
* @param options The options for the generation.
|
|
70
|
+
*/
|
|
71
|
+
export declare function generateTranslationFiles(input: string, dest: string, options: UploadApiOptions): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* The options for uploading the test translations.
|
|
74
|
+
*/
|
|
75
|
+
export interface UploadTestTranslationOptions extends UploadApiOptions {
|
|
76
|
+
/**
|
|
77
|
+
* The s3 URL to upload the translations to.
|
|
78
|
+
* Defaults to "s3://ao-bible-api-public-uploads"
|
|
79
|
+
*/
|
|
80
|
+
s3Url?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface UploadTestTranslationResult {
|
|
83
|
+
/**
|
|
84
|
+
* The S3 URL where the translations were uploaded to.
|
|
85
|
+
*/
|
|
86
|
+
uploadS3Url: string;
|
|
87
|
+
/**
|
|
88
|
+
* The HTTP URL that the version can be accessed at.
|
|
89
|
+
*/
|
|
90
|
+
url: string;
|
|
91
|
+
/**
|
|
92
|
+
* The URL that the available translations can be accessed at.
|
|
93
|
+
*/
|
|
94
|
+
availableTranslationsUrl: string;
|
|
95
|
+
/**
|
|
96
|
+
* The version that was uploaded.
|
|
97
|
+
* This is a SHA-256 hash of the input files.
|
|
98
|
+
*/
|
|
99
|
+
version: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Generates the API files directly from the translations stored in the given input directory and
|
|
103
|
+
* uploads them to the HelloAO test s3 bucket.
|
|
104
|
+
*
|
|
105
|
+
* Requires access to the HelloAO test s3 bucket. Email hello@helloao.org for access.
|
|
106
|
+
*
|
|
107
|
+
* @param input The input directory that the translations are stored in.
|
|
108
|
+
* @param options The options to use for the upload.
|
|
109
|
+
*/
|
|
110
|
+
export declare function uploadTestTranslations(input: string, options: UploadTestTranslationOptions): Promise<UploadTestTranslationResult>;
|
|
111
|
+
/**
|
|
112
|
+
* Generates the API files directly from the given translation and
|
|
113
|
+
* uploads them to the HelloAO test s3 bucket.
|
|
114
|
+
*
|
|
115
|
+
* Requires access to the HelloAO test s3 bucket. Email hello@helloao.org for access.
|
|
116
|
+
*
|
|
117
|
+
* @param input The input directory that the translations are stored in.
|
|
118
|
+
* @param options The options to use for the upload.
|
|
119
|
+
*/
|
|
120
|
+
export declare function uploadTestTranslation(input: string, options: UploadTestTranslationOptions): Promise<UploadTestTranslationResult>;
|
|
57
121
|
//# sourceMappingURL=actions.d.ts.map
|
package/actions.js
CHANGED
|
@@ -31,6 +31,10 @@ exports.importTranslation = importTranslation;
|
|
|
31
31
|
exports.importTranslations = importTranslations;
|
|
32
32
|
exports.fetchTranslations = fetchTranslations;
|
|
33
33
|
exports.fetchAudio = fetchAudio;
|
|
34
|
+
exports.generateTranslationsFiles = generateTranslationsFiles;
|
|
35
|
+
exports.generateTranslationFiles = generateTranslationFiles;
|
|
36
|
+
exports.uploadTestTranslations = uploadTestTranslations;
|
|
37
|
+
exports.uploadTestTranslation = uploadTestTranslation;
|
|
34
38
|
const node_path_1 = __importStar(require("node:path"));
|
|
35
39
|
const database = __importStar(require("./db"));
|
|
36
40
|
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
@@ -42,6 +46,11 @@ const fs_extra_1 = require("fs-extra");
|
|
|
42
46
|
const audio_1 = require("@helloao/tools/generation/audio");
|
|
43
47
|
const book_order_1 = require("@helloao/tools/generation/book-order");
|
|
44
48
|
const downloads_1 = require("./downloads");
|
|
49
|
+
const iterators_1 = require("@helloao/tools/parser/iterators");
|
|
50
|
+
const files_1 = require("./files");
|
|
51
|
+
const dataset_1 = require("@helloao/tools/generation/dataset");
|
|
52
|
+
const uploads_1 = require("./uploads");
|
|
53
|
+
const s3_1 = require("./s3");
|
|
45
54
|
/**
|
|
46
55
|
* Initializes a new Bible API DB.
|
|
47
56
|
* @param dbPath The path to the database. If null or empty, then the "bible-api.db" will be used from the current working directory.
|
|
@@ -56,47 +65,49 @@ async function initDb(dbPath, options) {
|
|
|
56
65
|
console.log('Copying schema from source DB...');
|
|
57
66
|
if (options.language) {
|
|
58
67
|
console.log('Copying only the following languages:', options.language);
|
|
59
|
-
const languages = `(${options.language
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
CREATE TABLE "
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
68
|
+
const languages = `(${options.language
|
|
69
|
+
.map((l) => `'${l}'`)
|
|
70
|
+
.join(', ')})`;
|
|
71
|
+
db.exec(`
|
|
72
|
+
ATTACH DATABASE "${sourcePath}" AS source;
|
|
73
|
+
|
|
74
|
+
CREATE TABLE "_prisma_migrations" AS SELECT * FROM source._prisma_migrations;
|
|
75
|
+
|
|
76
|
+
CREATE TABLE "Translation" AS SELECT * FROM source.Translation
|
|
77
|
+
WHERE language IN ${languages};
|
|
78
|
+
|
|
79
|
+
CREATE TABLE "Book" AS SELECT * FROM source.Book
|
|
80
|
+
INNER JOIN source.Translation ON source.Translation.id = source.Book.translationId
|
|
81
|
+
WHERE source.Translation.language IN ${languages};
|
|
82
|
+
|
|
83
|
+
CREATE TABLE "Chapter" AS SELECT * FROM source.Chapter
|
|
84
|
+
INNER JOIN source.Translation ON source.Translation.id = source.Chapter.translationId
|
|
85
|
+
WHERE source.Translation.language IN ${languages};
|
|
86
|
+
|
|
87
|
+
CREATE TABLE "ChapterVerse" AS SELECT * FROM source.ChapterVerse
|
|
88
|
+
INNER JOIN source.Translation ON source.Translation.id = source.ChapterVerse.translationId
|
|
89
|
+
WHERE source.Translation.language IN ${languages};
|
|
90
|
+
|
|
91
|
+
CREATE TABLE "ChapterFootnote" AS SELECT * FROM source.ChapterFootnote
|
|
92
|
+
INNER JOIN source.Translation ON source.Translation.id = source.ChapterFootnote.translationId
|
|
93
|
+
WHERE source.Translation.language IN ${languages};
|
|
94
|
+
|
|
95
|
+
CREATE TABLE "ChapterAudioUrl" AS SELECT * FROM source.ChapterAudioUrl
|
|
96
|
+
INNER JOIN source.Translation ON source.Translation.id = source.ChapterAudioUrl.translationId
|
|
97
|
+
WHERE source.Translation.language IN ${languages};
|
|
87
98
|
`);
|
|
88
99
|
}
|
|
89
100
|
else {
|
|
90
|
-
db.exec(`
|
|
91
|
-
ATTACH DATABASE "${sourcePath}" AS source;
|
|
92
|
-
|
|
93
|
-
CREATE TABLE "_prisma_migrations" AS SELECT * FROM source._prisma_migrations;
|
|
94
|
-
CREATE TABLE "Translation" AS SELECT * FROM source.Translation;
|
|
95
|
-
CREATE TABLE "Book" AS SELECT * FROM source.Book;
|
|
96
|
-
CREATE TABLE "Chapter" AS SELECT * FROM source.Chapter;
|
|
97
|
-
CREATE TABLE "ChapterVerse" AS SELECT * FROM source.ChapterVerse;
|
|
98
|
-
CREATE TABLE "ChapterFootnote" AS SELECT * FROM source.ChapterFootnote;
|
|
99
|
-
CREATE TABLE "ChapterAudioUrl" AS SELECT * FROM source.ChapterAudioUrl;
|
|
101
|
+
db.exec(`
|
|
102
|
+
ATTACH DATABASE "${sourcePath}" AS source;
|
|
103
|
+
|
|
104
|
+
CREATE TABLE "_prisma_migrations" AS SELECT * FROM source._prisma_migrations;
|
|
105
|
+
CREATE TABLE "Translation" AS SELECT * FROM source.Translation;
|
|
106
|
+
CREATE TABLE "Book" AS SELECT * FROM source.Book;
|
|
107
|
+
CREATE TABLE "Chapter" AS SELECT * FROM source.Chapter;
|
|
108
|
+
CREATE TABLE "ChapterVerse" AS SELECT * FROM source.ChapterVerse;
|
|
109
|
+
CREATE TABLE "ChapterFootnote" AS SELECT * FROM source.ChapterFootnote;
|
|
110
|
+
CREATE TABLE "ChapterAudioUrl" AS SELECT * FROM source.ChapterAudioUrl;
|
|
100
111
|
`);
|
|
101
112
|
}
|
|
102
113
|
console.log('Done.');
|
|
@@ -142,7 +153,7 @@ async function importTranslations(dir, options) {
|
|
|
142
153
|
const db = await database.getDbFromDir(process.cwd());
|
|
143
154
|
try {
|
|
144
155
|
const files = await (0, promises_1.readdir)(dir);
|
|
145
|
-
const translationDirs = files.map(f => node_path_1.default.resolve(dir, f));
|
|
156
|
+
const translationDirs = files.map((f) => node_path_1.default.resolve(dir, f));
|
|
146
157
|
console.log(`Importing ${translationDirs.length} translations`);
|
|
147
158
|
await database.importTranslations(db, translationDirs, parser, !!options.overwrite);
|
|
148
159
|
}
|
|
@@ -164,7 +175,9 @@ async function fetchTranslations(dir, translations, options = {}) {
|
|
|
164
175
|
const collection = await client.fetch_collection();
|
|
165
176
|
const collectionTranslations = collection.get_translations();
|
|
166
177
|
console.log(`Discovered ${collectionTranslations.length} translations`);
|
|
167
|
-
const filtered = translations && translations.length <= 0
|
|
178
|
+
const filtered = translations && translations.length <= 0
|
|
179
|
+
? collectionTranslations
|
|
180
|
+
: collectionTranslations.filter((t) => translationsSet.has(t.id));
|
|
168
181
|
let batches = [];
|
|
169
182
|
while (filtered.length > 0) {
|
|
170
183
|
batches.push(filtered.splice(0, 10));
|
|
@@ -187,7 +200,8 @@ async function fetchTranslations(dir, translations, options = {}) {
|
|
|
187
200
|
};
|
|
188
201
|
const books = await Promise.all(collection.get_books(t.id).map(async (b) => {
|
|
189
202
|
const name = `${b.id}.usx`;
|
|
190
|
-
if (!options.all &&
|
|
203
|
+
if (!options.all &&
|
|
204
|
+
(await (0, fs_extra_1.exists)(node_path_1.default.resolve(dir, translation.id, name)))) {
|
|
191
205
|
return null;
|
|
192
206
|
}
|
|
193
207
|
const content = await collection.fetch_book(t.id, b.id, 'usx');
|
|
@@ -196,7 +210,7 @@ async function fetchTranslations(dir, translations, options = {}) {
|
|
|
196
210
|
fileType: 'usx',
|
|
197
211
|
content: contentString,
|
|
198
212
|
metadata: {
|
|
199
|
-
translation
|
|
213
|
+
translation,
|
|
200
214
|
},
|
|
201
215
|
name,
|
|
202
216
|
};
|
|
@@ -252,7 +266,7 @@ async function fetchAudio(dir, translations, options = {}) {
|
|
|
252
266
|
const [translationId, reader] = translation.split('/');
|
|
253
267
|
const name = `${chapter}.${reader}${ext}`;
|
|
254
268
|
const fullPath = node_path_1.default.resolve(dir, 'audio', translationId, bookId, name);
|
|
255
|
-
if (!options.all && await (0, fs_extra_1.exists)(fullPath)) {
|
|
269
|
+
if (!options.all && (await (0, fs_extra_1.exists)(fullPath))) {
|
|
256
270
|
continue;
|
|
257
271
|
}
|
|
258
272
|
await (0, downloads_1.downloadFile)(url, fullPath);
|
|
@@ -260,3 +274,105 @@ async function fetchAudio(dir, translations, options = {}) {
|
|
|
260
274
|
}
|
|
261
275
|
}
|
|
262
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Generates the translation files directly from the translations stored in the given input directory.
|
|
279
|
+
* @param input The input directory that the translations are stored in.
|
|
280
|
+
* @param dest The destination to upload the API files to.
|
|
281
|
+
* @param options The options for the generation.
|
|
282
|
+
*/
|
|
283
|
+
async function generateTranslationsFiles(input, dest, options) {
|
|
284
|
+
const parser = new linkedom_1.DOMParser();
|
|
285
|
+
globalThis.DOMParser = linkedom_1.DOMParser;
|
|
286
|
+
globalThis.Element = linkedom_1.Element;
|
|
287
|
+
globalThis.Node = linkedom_1.Node;
|
|
288
|
+
const dirs = await (0, promises_1.readdir)(node_path_1.default.resolve(input));
|
|
289
|
+
const batchSize = typeof options.batchSize === 'number'
|
|
290
|
+
? options.batchSize
|
|
291
|
+
: parseInt(options.batchSize);
|
|
292
|
+
for (let b of (0, iterators_1.batch)(dirs, batchSize)) {
|
|
293
|
+
const files = await (0, files_1.loadTranslationsFiles)(b);
|
|
294
|
+
const dataset = (0, dataset_1.generateDataset)(files, parser);
|
|
295
|
+
await (0, uploads_1.serializeAndUploadDatasets)(dest, (0, iterators_1.toAsyncIterable)([dataset]), options);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Generates the translation files directly from the translation stored in the given input directory.
|
|
300
|
+
* @param input The input directory that the translation is stored in.
|
|
301
|
+
* @param dest The destination to upload the API files to.
|
|
302
|
+
* @param options The options for the generation.
|
|
303
|
+
*/
|
|
304
|
+
async function generateTranslationFiles(input, dest, options) {
|
|
305
|
+
const parser = new linkedom_1.DOMParser();
|
|
306
|
+
globalThis.DOMParser = linkedom_1.DOMParser;
|
|
307
|
+
globalThis.Element = linkedom_1.Element;
|
|
308
|
+
globalThis.Node = linkedom_1.Node;
|
|
309
|
+
const files = await (0, files_1.loadTranslationFiles)(node_path_1.default.resolve(input));
|
|
310
|
+
const dataset = (0, dataset_1.generateDataset)(files, parser);
|
|
311
|
+
await (0, uploads_1.serializeAndUploadDatasets)(dest, (0, iterators_1.toAsyncIterable)([dataset]), options);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Generates the API files directly from the translations stored in the given input directory and
|
|
315
|
+
* uploads them to the HelloAO test s3 bucket.
|
|
316
|
+
*
|
|
317
|
+
* Requires access to the HelloAO test s3 bucket. Email hello@helloao.org for access.
|
|
318
|
+
*
|
|
319
|
+
* @param input The input directory that the translations are stored in.
|
|
320
|
+
* @param options The options to use for the upload.
|
|
321
|
+
*/
|
|
322
|
+
async function uploadTestTranslations(input, options) {
|
|
323
|
+
const parser = new linkedom_1.DOMParser();
|
|
324
|
+
globalThis.DOMParser = linkedom_1.DOMParser;
|
|
325
|
+
globalThis.Element = linkedom_1.Element;
|
|
326
|
+
globalThis.Node = linkedom_1.Node;
|
|
327
|
+
const dirs = await (0, promises_1.readdir)(node_path_1.default.resolve(input));
|
|
328
|
+
const files = await (0, files_1.loadTranslationsFiles)(dirs);
|
|
329
|
+
const hash = (0, files_1.hashInputFiles)(files);
|
|
330
|
+
const dataset = (0, dataset_1.generateDataset)(files, parser);
|
|
331
|
+
const url = options.s3Url || 's3://ao-bible-api-public-uploads';
|
|
332
|
+
await (0, uploads_1.serializeAndUploadDatasets)(url, (0, iterators_1.toAsyncIterable)([dataset]), {
|
|
333
|
+
...options,
|
|
334
|
+
pathPrefix: `/${hash}`,
|
|
335
|
+
});
|
|
336
|
+
const urls = getUrls(url);
|
|
337
|
+
return {
|
|
338
|
+
...urls,
|
|
339
|
+
version: hash,
|
|
340
|
+
availableTranslationsUrl: `${urls.url}/${hash}/api/available_translations.json`,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Generates the API files directly from the given translation and
|
|
345
|
+
* uploads them to the HelloAO test s3 bucket.
|
|
346
|
+
*
|
|
347
|
+
* Requires access to the HelloAO test s3 bucket. Email hello@helloao.org for access.
|
|
348
|
+
*
|
|
349
|
+
* @param input The input directory that the translations are stored in.
|
|
350
|
+
* @param options The options to use for the upload.
|
|
351
|
+
*/
|
|
352
|
+
async function uploadTestTranslation(input, options) {
|
|
353
|
+
const parser = new linkedom_1.DOMParser();
|
|
354
|
+
globalThis.DOMParser = linkedom_1.DOMParser;
|
|
355
|
+
globalThis.Element = linkedom_1.Element;
|
|
356
|
+
globalThis.Node = linkedom_1.Node;
|
|
357
|
+
const files = await (0, files_1.loadTranslationFiles)(node_path_1.default.resolve(input));
|
|
358
|
+
const hash = (0, files_1.hashInputFiles)(files);
|
|
359
|
+
const dataset = (0, dataset_1.generateDataset)(files, parser);
|
|
360
|
+
const url = options.s3Url || 's3://ao-bible-api-public-uploads';
|
|
361
|
+
await (0, uploads_1.serializeAndUploadDatasets)(url, (0, iterators_1.toAsyncIterable)([dataset]), {
|
|
362
|
+
...options,
|
|
363
|
+
pathPrefix: `/${hash}`,
|
|
364
|
+
});
|
|
365
|
+
const urls = getUrls(url);
|
|
366
|
+
return {
|
|
367
|
+
...urls,
|
|
368
|
+
version: hash,
|
|
369
|
+
availableTranslationsUrl: `${urls.url}/${hash}/api/available_translations.json`,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function getUrls(dest) {
|
|
373
|
+
const url = (0, s3_1.getHttpUrl)(dest);
|
|
374
|
+
return {
|
|
375
|
+
uploadS3Url: dest,
|
|
376
|
+
url: url,
|
|
377
|
+
};
|
|
378
|
+
}
|