@helloao/cli 0.0.8 → 0.0.9
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/dist/cjs/cli.cjs +13399 -0
- package/{actions.d.ts → dist/types/actions.d.ts} +29 -2
- package/{db.d.ts → dist/types/db.d.ts} +7 -6
- package/{files.d.ts → dist/types/files.d.ts} +1 -1
- package/dist/types/index.d.ts +8 -0
- package/{s3.d.ts → dist/types/s3.d.ts} +1 -1
- package/{uploads.d.ts → dist/types/uploads.d.ts} +5 -5
- package/package.json +10 -5
- package/actions.js +0 -468
- package/cli.js +0 -252
- package/db.js +0 -663
- package/downloads.js +0 -12
- package/files.js +0 -362
- package/index.d.ts +0 -8
- package/index.js +0 -38
- package/s3.js +0 -169
- package/uploads.js +0 -180
- /package/{cli.d.ts → dist/types/cli.d.ts} +0 -0
- /package/{downloads.d.ts → dist/types/downloads.d.ts} +0 -0
package/cli.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
const commander_1 = require("commander");
|
|
28
|
-
const path_1 = __importStar(require("path"));
|
|
29
|
-
const promises_1 = require("fs/promises");
|
|
30
|
-
const linkedom_1 = require("linkedom");
|
|
31
|
-
const downloads_1 = require("./downloads");
|
|
32
|
-
const uploads_1 = require("./uploads");
|
|
33
|
-
const actions_1 = require("./actions");
|
|
34
|
-
const db_1 = require("./db");
|
|
35
|
-
const prompts_1 = require("@inquirer/prompts");
|
|
36
|
-
async function start() {
|
|
37
|
-
const parser = new linkedom_1.DOMParser();
|
|
38
|
-
globalThis.DOMParser = linkedom_1.DOMParser;
|
|
39
|
-
globalThis.Element = linkedom_1.Element;
|
|
40
|
-
globalThis.Node = linkedom_1.Node;
|
|
41
|
-
const program = new commander_1.Command();
|
|
42
|
-
program
|
|
43
|
-
.name('helloao')
|
|
44
|
-
.description('A CLI for managing a Free Use Bible API.')
|
|
45
|
-
.version('0.0.1');
|
|
46
|
-
program
|
|
47
|
-
.command('init [path]')
|
|
48
|
-
.description('Initialize a new Bible API DB.')
|
|
49
|
-
.option('--source <path>', 'The source database to copy from.')
|
|
50
|
-
.option('--language <languages...>', 'The language(s) that the database should be initialized with.')
|
|
51
|
-
.action(async (dbPath, options) => {
|
|
52
|
-
await (0, actions_1.initDb)(dbPath, options);
|
|
53
|
-
});
|
|
54
|
-
program
|
|
55
|
-
.command('generate-translation-metadata')
|
|
56
|
-
.description('Generates a metadata file for a translation.')
|
|
57
|
-
.action(async () => {
|
|
58
|
-
const meta = await (0, actions_1.askForMetadata)();
|
|
59
|
-
console.log('Your metadata:', meta);
|
|
60
|
-
const save = await (0, prompts_1.confirm)({
|
|
61
|
-
message: 'Do you want to save this metadata?',
|
|
62
|
-
});
|
|
63
|
-
if (save) {
|
|
64
|
-
let location = await (0, prompts_1.input)({
|
|
65
|
-
message: 'Where would you like to save the metadata?',
|
|
66
|
-
});
|
|
67
|
-
const ext = (0, path_1.extname)(location);
|
|
68
|
-
if (!ext) {
|
|
69
|
-
if (!location.endsWith('/')) {
|
|
70
|
-
location += '/';
|
|
71
|
-
}
|
|
72
|
-
location += 'metadata.json';
|
|
73
|
-
}
|
|
74
|
-
console.log('Saving metadata to:', location);
|
|
75
|
-
const dir = path_1.default.dirname(location);
|
|
76
|
-
await (0, promises_1.mkdir)(dir, { recursive: true });
|
|
77
|
-
await (0, promises_1.writeFile)(location, JSON.stringify(meta, null, 2));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
program
|
|
81
|
-
.command('import-translation <dir> [dirs...]')
|
|
82
|
-
.description('Imports a translation from the given directory into the database.')
|
|
83
|
-
.option('--overwrite', 'Whether to overwrite existing files.')
|
|
84
|
-
.action(async (dir, dirs, options) => {
|
|
85
|
-
await (0, actions_1.importTranslation)(dir, dirs, options);
|
|
86
|
-
});
|
|
87
|
-
program
|
|
88
|
-
.command('import-translations <dir>')
|
|
89
|
-
.description('Imports all translations from the given directory into the database.')
|
|
90
|
-
.option('--overwrite', 'Whether to overwrite existing files.')
|
|
91
|
-
.action(async (dir, options) => {
|
|
92
|
-
await (0, actions_1.importTranslations)(dir, options);
|
|
93
|
-
});
|
|
94
|
-
program
|
|
95
|
-
.command('upload-test-translation <input>')
|
|
96
|
-
.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.`)
|
|
97
|
-
.option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
|
|
98
|
-
.option('--translations <translations...>', 'The translations to generate API files for.')
|
|
99
|
-
.option('--overwrite', 'Whether to overwrite existing files.')
|
|
100
|
-
.option('--overwrite-common-files', 'Whether to overwrite only common files.')
|
|
101
|
-
.option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are generated.')
|
|
102
|
-
.option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
|
|
103
|
-
.option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
|
|
104
|
-
.option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
|
|
105
|
-
.option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
|
|
106
|
-
.option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
|
|
107
|
-
.option('--pretty', 'Whether to generate pretty-printed JSON files.')
|
|
108
|
-
.option('--s3-url <s3Url>', 'The S3 bucket URL to upload the files to.', 's3://ao-bible-api-public-uploads')
|
|
109
|
-
.action(async (input, options) => {
|
|
110
|
-
const good = await (0, prompts_1.confirm)({
|
|
111
|
-
message: 'Uploaded files will be publicly accessible. Continue?',
|
|
112
|
-
default: false,
|
|
113
|
-
});
|
|
114
|
-
if (!good) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const result = await (0, actions_1.uploadTestTranslation)(input, options);
|
|
118
|
-
if (result) {
|
|
119
|
-
console.log('\n');
|
|
120
|
-
console.log('Version: ', result.version);
|
|
121
|
-
console.log('Uploaded to: ', result.uploadS3Url);
|
|
122
|
-
console.log('URL: ', result.url);
|
|
123
|
-
console.log('Available Translations:', result.availableTranslationsUrl);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
program
|
|
127
|
-
.command('upload-test-translations <input>')
|
|
128
|
-
.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.`)
|
|
129
|
-
.option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
|
|
130
|
-
.option('--translations <translations...>', 'The translations to generate API files for.')
|
|
131
|
-
.option('--overwrite', 'Whether to overwrite existing files.')
|
|
132
|
-
.option('--overwrite-common-files', 'Whether to overwrite only common files.')
|
|
133
|
-
.option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are generated.')
|
|
134
|
-
.option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
|
|
135
|
-
.option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
|
|
136
|
-
.option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
|
|
137
|
-
.option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
|
|
138
|
-
.option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
|
|
139
|
-
.option('--pretty', 'Whether to generate pretty-printed JSON files.')
|
|
140
|
-
.option('--s3-url <s3Url>', 'The S3 bucket URL to upload the files to.', 's3://ao-bible-api-public-uploads')
|
|
141
|
-
.action(async (input, options) => {
|
|
142
|
-
const good = await (0, prompts_1.confirm)({
|
|
143
|
-
message: 'Uploaded files will be publicly accessible. Continue?',
|
|
144
|
-
default: false,
|
|
145
|
-
});
|
|
146
|
-
if (!good) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const result = await (0, actions_1.uploadTestTranslations)(input, options);
|
|
150
|
-
console.log('\nVersion: ', result.version);
|
|
151
|
-
console.log('Uploaded to: ', result.uploadS3Url);
|
|
152
|
-
console.log('URL: ', result.url);
|
|
153
|
-
console.log('Available Translations:', result.availableTranslationsUrl);
|
|
154
|
-
});
|
|
155
|
-
program
|
|
156
|
-
.command('generate-translation-files <input> <dir>')
|
|
157
|
-
.description('Generates API files from the given input translation.')
|
|
158
|
-
.option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
|
|
159
|
-
.option('--translations <translations...>', 'The translations to generate API files for.')
|
|
160
|
-
.option('--overwrite', 'Whether to overwrite existing files.')
|
|
161
|
-
.option('--overwrite-common-files', 'Whether to overwrite only common files.')
|
|
162
|
-
.option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are generated.')
|
|
163
|
-
.option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
|
|
164
|
-
.option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
|
|
165
|
-
.option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
|
|
166
|
-
.option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
|
|
167
|
-
.option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
|
|
168
|
-
.option('--pretty', 'Whether to generate pretty-printed JSON files.')
|
|
169
|
-
.action(async (input, dest, options) => {
|
|
170
|
-
await (0, actions_1.generateTranslationFiles)(input, dest, options);
|
|
171
|
-
});
|
|
172
|
-
program
|
|
173
|
-
.command('generate-translations-files <input> <dir>')
|
|
174
|
-
.description('Generates API files from the given input translations.')
|
|
175
|
-
.option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
|
|
176
|
-
.option('--translations <translations...>', 'The translations to generate API files for.')
|
|
177
|
-
.option('--overwrite', 'Whether to overwrite existing files.')
|
|
178
|
-
.option('--overwrite-common-files', 'Whether to overwrite only common files.')
|
|
179
|
-
.option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are uploaded.')
|
|
180
|
-
.option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
|
|
181
|
-
.option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
|
|
182
|
-
.option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
|
|
183
|
-
.option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
|
|
184
|
-
.option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
|
|
185
|
-
.option('--pretty', 'Whether to generate pretty-printed JSON files.')
|
|
186
|
-
.action(async (input, dest, options) => {
|
|
187
|
-
await (0, actions_1.generateTranslationsFiles)(input, dest, options);
|
|
188
|
-
});
|
|
189
|
-
program
|
|
190
|
-
.command('upload-api-files')
|
|
191
|
-
.argument('<dest>', 'The destination to upload the API files to.')
|
|
192
|
-
.description('Uploads API files to the specified destination. For S3, use the format s3://bucket-name/path/to/folder.')
|
|
193
|
-
.option('--batch-size <size>', 'The number of translations to generate API files for in each batch.', '50')
|
|
194
|
-
.option('--translations <translations...>', 'The translations to generate API files for.')
|
|
195
|
-
.option('--overwrite', 'Whether to overwrite existing files.')
|
|
196
|
-
.option('--overwrite-common-files', 'Whether to overwrite only common files.')
|
|
197
|
-
.option('--file-pattern <pattern>', 'The file pattern regex that should be used to filter the files that are uploaded.')
|
|
198
|
-
.option('--use-common-name', 'Whether to use the common name for the book chapter API link. If false, then book IDs are used.')
|
|
199
|
-
.option('--generate-audio-files', 'Whether to replace the audio URLs in the dataset with ones that are hosted locally.')
|
|
200
|
-
.option('--profile <profile>', 'The AWS profile to use for uploading to S3.')
|
|
201
|
-
.option('--access-key-id <accessKeyId>', 'The AWS access key ID to use for uploading to S3.')
|
|
202
|
-
.option('--secret-access-key <secretAccessKey>', 'The AWS Secret Access Key to use for uploading to S3.')
|
|
203
|
-
.option('--pretty', 'Whether to generate pretty-printed JSON files.')
|
|
204
|
-
.action(async (dest, options) => {
|
|
205
|
-
const db = (0, db_1.getPrismaDbFromDir)(process.cwd());
|
|
206
|
-
try {
|
|
207
|
-
await (0, uploads_1.uploadApiFilesFromDatabase)(db, dest, options);
|
|
208
|
-
}
|
|
209
|
-
finally {
|
|
210
|
-
db.$disconnect();
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
program
|
|
214
|
-
.command('fetch-translations <dir> [translations...]')
|
|
215
|
-
.description('Fetches the specified translations from fetch.bible and places them in the given directory.')
|
|
216
|
-
.option('-a, --all', 'Fetch all translations. If omitted, only undownloaded translations will be fetched.')
|
|
217
|
-
.action(async (dir, translations, options) => {
|
|
218
|
-
await (0, actions_1.fetchTranslations)(dir, translations, options);
|
|
219
|
-
});
|
|
220
|
-
program
|
|
221
|
-
.command('fetch-audio <dir> [translations...]')
|
|
222
|
-
.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"')
|
|
223
|
-
.option('-a, --all', 'Fetch all translations. If omitted, only undownloaded translations will be fetched.')
|
|
224
|
-
.action(async (dir, translations, options) => {
|
|
225
|
-
await (0, actions_1.fetchAudio)(dir, translations, options);
|
|
226
|
-
});
|
|
227
|
-
program
|
|
228
|
-
.command('fetch-bible-metadata <dir>')
|
|
229
|
-
.description('Fetches the Theographic bible metadata and places it in the given directory.')
|
|
230
|
-
.action(async (dir) => {
|
|
231
|
-
let files = [
|
|
232
|
-
'books.json',
|
|
233
|
-
'chapters.json',
|
|
234
|
-
'easton.json',
|
|
235
|
-
'events.json',
|
|
236
|
-
'people.json',
|
|
237
|
-
'peopleGroups.json',
|
|
238
|
-
'periods.json',
|
|
239
|
-
'places.json',
|
|
240
|
-
'verses.json',
|
|
241
|
-
];
|
|
242
|
-
await (0, promises_1.mkdir)(dir, { recursive: true });
|
|
243
|
-
let promises = files.map(async (file) => {
|
|
244
|
-
const url = `https://raw.githubusercontent.com/robertrouse/theographic-bible-metadata/master/json/${file}`;
|
|
245
|
-
const fullPath = path_1.default.resolve(dir, file);
|
|
246
|
-
await (0, downloads_1.downloadFile)(url, fullPath);
|
|
247
|
-
});
|
|
248
|
-
await Promise.all(promises);
|
|
249
|
-
});
|
|
250
|
-
await program.parseAsync(process.argv);
|
|
251
|
-
}
|
|
252
|
-
start();
|