@helloao/cli 0.0.6 → 0.0.8-alpha

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();