@helloao/cli 0.0.6 → 0.0.7

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/cli.js DELETED
@@ -1,204 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const path_1 = __importDefault(require("path"));
9
- const promises_1 = require("fs/promises");
10
- const linkedom_1 = require("linkedom");
11
- const downloads_1 = require("./downloads");
12
- const uploads_1 = require("./uploads");
13
- const actions_1 = require("./actions");
14
- const db_1 = require("./db");
15
- const prompts_1 = require("@inquirer/prompts");
16
- async function start() {
17
- const parser = new linkedom_1.DOMParser();
18
- globalThis.DOMParser = linkedom_1.DOMParser;
19
- globalThis.Element = linkedom_1.Element;
20
- globalThis.Node = linkedom_1.Node;
21
- const program = new commander_1.Command();
22
- program
23
- .name('helloao')
24
- .description('A CLI for managing a Free Use Bible API.')
25
- .version('0.0.1');
26
- program
27
- .command('init [path]')
28
- .description('Initialize a new Bible API DB.')
29
- .option('--source <path>', 'The source database to copy from.')
30
- .option('--language <languages...>', 'The language(s) that the database should be initialized with.')
31
- .action(async (dbPath, options) => {
32
- await (0, actions_1.initDb)(dbPath, options);
33
- });
34
- program
35
- .command('import-translation <dir> [dirs...]')
36
- .description('Imports a translation from the given directory into the database.')
37
- .option('--overwrite', 'Whether to overwrite existing files.')
38
- .action(async (dir, dirs, options) => {
39
- await (0, actions_1.importTranslation)(dir, dirs, options);
40
- });
41
- program
42
- .command('import-translations <dir>')
43
- .description('Imports all translations from the given directory into the database.')
44
- .option('--overwrite', 'Whether to overwrite existing files.')
45
- .action(async (dir, options) => {
46
- await (0, actions_1.importTranslations)(dir, options);
47
- });
48
- program
49
- .command('upload-test-translation <input>')
50
- .description(`Uploads a translation to the HelloAO Free Bible API test S3 bucket.\nRequires access to the HelloAO Free Bible API test S3 bucket.\nFor inquiries, please contact hello@helloao.org.`)
51
- .option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
52
- .option('--translations <translations...>', 'The translations to generate API files for.')
53
- .option('--overwrite', 'Whether to overwrite existing files.')
54
- .option('--overwrite-common-files', 'Whether to overwrite only common files.')
55
- .option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are generated.')
56
- .option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
57
- .option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
58
- .option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
59
- .option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
60
- .option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
61
- .option('--pretty', 'Whether to generate pretty-printed JSON files.')
62
- .option('--s3-url <s3Url>', 'The S3 bucket URL to upload the files to.', 's3://ao-bible-api-public-uploads')
63
- .action(async (input, options) => {
64
- const good = await (0, prompts_1.confirm)({
65
- message: 'Uploaded files will be publicly accessible. Continue?',
66
- default: false,
67
- });
68
- if (!good) {
69
- return;
70
- }
71
- const result = await (0, actions_1.uploadTestTranslation)(input, options);
72
- console.log('\n');
73
- console.log('Version: ', result.version);
74
- console.log('Uploaded to: ', result.uploadS3Url);
75
- console.log('URL: ', result.url);
76
- console.log('Available Translations:', result.availableTranslationsUrl);
77
- });
78
- program
79
- .command('upload-test-translations <input>')
80
- .description(`Uploads all the translations in the given input directory to the HelloAO Free Bible API test S3 bucket.\nRequires access to the HelloAO Free Bible API test S3 bucket.\nFor inquiries, please contact hello@helloao.org.`)
81
- .option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
82
- .option('--translations <translations...>', 'The translations to generate API files for.')
83
- .option('--overwrite', 'Whether to overwrite existing files.')
84
- .option('--overwrite-common-files', 'Whether to overwrite only common files.')
85
- .option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are generated.')
86
- .option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
87
- .option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
88
- .option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
89
- .option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
90
- .option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
91
- .option('--pretty', 'Whether to generate pretty-printed JSON files.')
92
- .option('--s3-url <s3Url>', 'The S3 bucket URL to upload the files to.', 's3://ao-bible-api-public-uploads')
93
- .action(async (input, options) => {
94
- const good = await (0, prompts_1.confirm)({
95
- message: 'Uploaded files will be publicly accessible. Continue?',
96
- default: false,
97
- });
98
- if (!good) {
99
- return;
100
- }
101
- const result = await (0, actions_1.uploadTestTranslations)(input, options);
102
- console.log('\nVersion: ', result.version);
103
- console.log('Uploaded to: ', result.uploadS3Url);
104
- console.log('URL: ', result.url);
105
- console.log('Available Translations:', result.availableTranslationsUrl);
106
- });
107
- program
108
- .command('generate-translation-files <input> <dir>')
109
- .description('Generates API files from the given input translation.')
110
- .option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
111
- .option('--translations <translations...>', 'The translations to generate API files for.')
112
- .option('--overwrite', 'Whether to overwrite existing files.')
113
- .option('--overwrite-common-files', 'Whether to overwrite only common files.')
114
- .option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are generated.')
115
- .option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
116
- .option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
117
- .option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
118
- .option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
119
- .option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
120
- .option('--pretty', 'Whether to generate pretty-printed JSON files.')
121
- .action(async (input, dest, options) => {
122
- await (0, actions_1.generateTranslationFiles)(input, dest, options);
123
- });
124
- program
125
- .command('generate-translations-files <input> <dir>')
126
- .description('Generates API files from the given input translations.')
127
- .option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
128
- .option('--translations <translations...>', 'The translations to generate API files for.')
129
- .option('--overwrite', 'Whether to overwrite existing files.')
130
- .option('--overwrite-common-files', 'Whether to overwrite only common files.')
131
- .option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are uploaded.')
132
- .option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
133
- .option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
134
- .option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
135
- .option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
136
- .option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
137
- .option('--pretty', 'Whether to generate pretty-printed JSON files.')
138
- .action(async (input, dest, options) => {
139
- await (0, actions_1.generateTranslationsFiles)(input, dest, options);
140
- });
141
- program
142
- .command('upload-api-files')
143
- .argument('<dest>', 'The destination to upload the API files to.')
144
- .description('Uploads API files to the specified destination. For S3, use the format s3://bucket-name/path/to/folder.')
145
- .option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
146
- .option('--translations <translations...>', 'The translations to generate API files for.')
147
- .option('--overwrite', 'Whether to overwrite existing files.')
148
- .option('--overwrite-common-files', 'Whether to overwrite only common files.')
149
- .option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are uploaded.')
150
- .option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
151
- .option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
152
- .option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
153
- .option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
154
- .option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
155
- .option('--pretty', 'Whether to generate pretty-printed JSON files.')
156
- .action(async (dest, options) => {
157
- const db = (0, db_1.getPrismaDbFromDir)(process.cwd());
158
- try {
159
- await (0, uploads_1.uploadApiFilesFromDatabase)(db, dest, options);
160
- }
161
- finally {
162
- db.$disconnect();
163
- }
164
- });
165
- program
166
- .command('fetch-translations <dir> [translations...]')
167
- .description('Fetches the specified translations from fetch.bible and places them in the given directory.')
168
- .option('-a, --all', 'Fetch all translations. If omitted, only undownloaded translations will be fetched.')
169
- .action(async (dir, translations, options) => {
170
- await (0, actions_1.fetchTranslations)(dir, translations, options);
171
- });
172
- program
173
- .command('fetch-audio <dir> [translations...]')
174
- .description('Fetches the specified audio translations and places them in the given directory.\nTranslations should be in the format "translationId/audioId". e.g. "BSB/gilbert"')
175
- .option('-a, --all', 'Fetch all translations. If omitted, only undownloaded translations will be fetched.')
176
- .action(async (dir, translations, options) => {
177
- await (0, actions_1.fetchAudio)(dir, translations, options);
178
- });
179
- program
180
- .command('fetch-bible-metadata <dir>')
181
- .description('Fetches the Theographic bible metadata and places it in the given directory.')
182
- .action(async (dir) => {
183
- let files = [
184
- 'books.json',
185
- 'chapters.json',
186
- 'easton.json',
187
- 'events.json',
188
- 'people.json',
189
- 'peopleGroups.json',
190
- 'periods.json',
191
- 'places.json',
192
- 'verses.json',
193
- ];
194
- await (0, promises_1.mkdir)(dir, { recursive: true });
195
- let promises = files.map(async (file) => {
196
- const url = `https://raw.githubusercontent.com/robertrouse/theographic-bible-metadata/master/json/${file}`;
197
- const fullPath = path_1.default.resolve(dir, file);
198
- await (0, downloads_1.downloadFile)(url, fullPath);
199
- });
200
- await Promise.all(promises);
201
- });
202
- await program.parseAsync(process.argv);
203
- }
204
- start();
package/db.d.ts DELETED
@@ -1,92 +0,0 @@
1
- import { PrismaClient } from './prisma-gen';
2
- import { Database } from 'better-sqlite3';
3
- import { DatasetOutput, DatasetTranslation, DatasetTranslationBook } from '@helloao/tools/generation/dataset';
4
- import { InputFile, TranslationBookChapter } from '@helloao/tools/generation';
5
- import { GenerateApiOptions } from '@helloao/tools/generation/api';
6
- import { DOMParser } from 'linkedom';
7
- import { Readable } from 'stream';
8
- /**
9
- * Imports the translations from the given directories into the database.
10
- * @param db The database to import the translations into.
11
- * @param dirs The directories to import the translations from.
12
- * @param parser The DOM parser that should be used for USX files.
13
- * @param overwrite Whether to force a reload of the translations.
14
- */
15
- export declare function importTranslations(db: Database, dirs: string[], parser: DOMParser, overwrite: boolean): Promise<void>;
16
- /**
17
- * Imports a batch of translations from the given directories into the database.
18
- * @param db The database to import the translations into.
19
- * @param dirs The directories that contain the translations.
20
- * @param parser The DOM parser that should be used for USX files.
21
- * @param overwrite Whether to force a reload of the translations.
22
- */
23
- export declare function importTranslationBatch(db: Database, dirs: string[], parser: DOMParser, overwrite: boolean): Promise<void>;
24
- /**
25
- * Parses and imports the given files into the database.
26
- * @param db The database to import the files into.
27
- * @param files The files that should be parsed.
28
- * @param parser The DOM parser that should be used for USX files.
29
- * @param overwrite Whether to force a reload of the translations.
30
- */
31
- export declare function importTranslationFileBatch(db: Database, files: InputFile[], parser: DOMParser, overwrite: boolean): Promise<void>;
32
- /**
33
- * Filters the given input files to only include those that have changed.
34
- * @param db The database to check for changes.
35
- * @param files The files to filter.
36
- */
37
- export declare function getChangedOrNewInputFiles(db: Database, files: InputFile[]): InputFile[];
38
- export declare function insertFileMetadata(db: Database, files: InputFile[]): void;
39
- export declare function insertTranslations(db: Database, translations: DatasetTranslation[]): void;
40
- export declare function insertTranslationBooks(db: Database, translation: DatasetTranslation, translationBooks: DatasetTranslationBook[]): void;
41
- export declare function insertTranslationContent(db: Database, translation: DatasetTranslation, book: DatasetTranslationBook, chapters: TranslationBookChapter[]): void;
42
- export declare function getDbPathFromDir(dir: string): string;
43
- export declare function getDbPath(p: string | null): string;
44
- export declare function getPrismaDbFromDir(dir: string): PrismaClient<{
45
- datasources: {
46
- db: {
47
- url: string;
48
- };
49
- };
50
- }, never, import("prisma-gen/runtime/library").DefaultArgs>;
51
- export declare function getDbFromDir(dir: string): Promise<Database>;
52
- export declare function getDb(dbPath: string): Promise<Database>;
53
- export interface SerializedFile {
54
- path: string;
55
- content: string | Readable;
56
- /**
57
- * Gets the base64-encoded SHA256 hash of the content of the file.
58
- */
59
- sha256?(): string;
60
- }
61
- /**
62
- * Loads the datasets from the database in a series of batches.
63
- * @param db The database.
64
- * @param translationsPerBatch The number of translations to load per batch.
65
- * @param translationsToLoad The list of translations to load. If not provided, all translations will be loaded.
66
- */
67
- export declare function loadDatasets(db: PrismaClient, translationsPerBatch?: number, translationsToLoad?: string[]): AsyncGenerator<DatasetOutput>;
68
- export interface SerializeApiOptions extends GenerateApiOptions {
69
- /**
70
- * Whether the output should be pretty-printed.
71
- */
72
- pretty?: boolean;
73
- }
74
- /**
75
- * Generates and serializes the API files for the datasets that are stored in the database.
76
- * Yields each batch of serialized files.
77
- * @param db The database that the dataset should be loaded from.
78
- * @param options The options to use for serializing the files.
79
- * @param apiOptions The options to use for generating the API files.
80
- * @param translationsPerBatch The number of translations that should be loaded and written per batch.
81
- * @param translations The list of translations that should be loaded. If not provided, all translations will be loaded.
82
- */
83
- export declare function serializeFilesFromDatabase(db: PrismaClient, options?: SerializeApiOptions, translationsPerBatch?: number, translations?: string[]): AsyncGenerator<SerializedFile[]>;
84
- /**
85
- * Generates and serializes the API files for the given datasets.
86
- * Yields each batch of serialized files.
87
- *
88
- * @param datasets The datasets to serialize.
89
- * @param options The options to use for generating and serializing the files.
90
- */
91
- export declare function serializeDatasets(datasets: AsyncIterable<DatasetOutput>, options?: SerializeApiOptions): AsyncGenerator<SerializedFile[]>;
92
- //# sourceMappingURL=db.d.ts.map