@helloao/cli 0.0.7 → 0.0.8

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 CHANGED
@@ -1,125 +1,132 @@
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
- ```
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
+ generate-translation-metadata Generates a metadata file for a translation.
28
+ import-translation [options] <dir> [dirs...] Imports a translation from the given directory into the database.
29
+ import-translations [options] <dir> Imports all translations from the given directory into the database.
30
+ upload-test-translation [options] <input> Uploads a translation to the HelloAO Free Bible API test S3 bucket.
31
+ Requires access to the HelloAO Free Bible API test S3 bucket.
32
+ For inquiries, please contact hello@helloao.org.
33
+ upload-test-translations [options] <input> Uploads all the translations in the given input directory to the HelloAO Free Bible API test S3 bucket.
34
+ Requires access to the HelloAO Free Bible API test S3 bucket.
35
+ For inquiries, please contact hello@helloao.org.
36
+ generate-translation-files [options] <input> <dir> Generates API files from the given input translation.
37
+ generate-translations-files [options] <input> <dir> Generates API files from the given input translations.
38
+ upload-api-files [options] <dest> Uploads API files to the specified destination. For S3, use the format s3://bucket-name/path/to/folder.
39
+ fetch-translations [options] <dir> [translations...] Fetches the specified translations from fetch.bible and places them in the given directory.
40
+ fetch-audio [options] <dir> [translations...] Fetches the specified audio translations and places them in the given directory.
41
+ Translations should be in the format "translationId/audioId". e.g. "BSB/gilbert"
42
+ fetch-bible-metadata <dir> Fetches the Theographic bible metadata and places it in the given directory.
43
+ help [command] display help for command
44
+ ```
45
+
46
+ The `@helloao/cli` package can also be used as a library.
47
+
48
+ The library exports a variety of actions, utilities, and supporting classes designed to assist with generating and managing a Free Use Bible API.
49
+
50
+ There are 6 main exports:
51
+
52
+ - `actions` - This export contains function versions of the CLI commands. They make it easy to call a CLI command from a script.
53
+ - `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.
54
+ - `downloads` - This export contains functions that make downloading files easier.
55
+ - `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.
56
+ - `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.
57
+ - `s3` - This export contains a class that can upload files to S3.
58
+
59
+ Here are some common operations that you might want to perform:
60
+
61
+ #### Get a SQL Database
62
+
63
+ ```typescript
64
+ import { db } from '@helloao/cli';
65
+
66
+ const pathToDb = './bible-database.db';
67
+ const database = await db.getDb(pathToDb);
68
+
69
+ // do work on the database
70
+
71
+ // Close it when you are done.
72
+ database.close();
73
+ ```
74
+
75
+ #### Import a translation into a database from a directory
76
+
77
+ ```typescript
78
+ import { db } from '@helloao/cli';
79
+
80
+ const pathToDb = './bible-database.db';
81
+ const database = await db.getDb(pathToDb);
82
+
83
+ // Get a DOMParser for parsing USX.
84
+ // On Node.js, you may have to import jsdom or linkedom.
85
+ const parser = new DOMParser();
86
+
87
+ const pathToTranslation = './path/to/translation';
88
+
89
+ // Whether to overwrite files that already exist in the database.
90
+ // The system will automatically determine the hashes of the input files and overwrite changed files if needed, so this is only needed
91
+ // when you know that they need to be overwritten.
92
+ const overwrite = false;
93
+ await db.importTranslations(database, pathToTranslation, parser, overwrite);
94
+ ```
95
+
96
+ #### Generate an API from a translation
97
+
98
+ ```typescript
99
+ import { files, uploads } from '@helloao/cli';
100
+ import { generation } from '@helloao/tools';
101
+ import { toAsyncIterable } from '@helloao/tools/parser/iterators';
102
+
103
+ const translationPath = './path/to/translation';
104
+ const translationFiles = await files.loadTranslationFiles(translationPath);
105
+
106
+ // Used to parse XML
107
+ const domParser = new DOMParser();
108
+
109
+ // Generate a dataset from the files
110
+ // Datasets organize all the files and their content
111
+ // by translation, book, chapter, and verse
112
+ const dataset = generation.dataset.generateDataset(files, parser);
113
+
114
+ // You can optionally specifiy a prefix that should be added to all API
115
+ // links
116
+ const pathPrefix = '';
117
+
118
+ // Generate an API representation from the files
119
+ // This adds links between chapters and additional metadata.
120
+ const api = generation.api.generateApiForDataset(dataset, {
121
+ pathPrefix,
122
+ });
123
+
124
+ // Generate output files from the API representation.
125
+ // This will give us a list of files and file paths that represent
126
+ // the entire API.
127
+ const outputFiles = generation.api.generateFilesForApi(api);
128
+
129
+ // Optionally upload files by using:
130
+ // const dest = 's3://my-bucket';
131
+ // await uploads.serializeAndUploadDatasets(dest, toAsyncIterable(outputFiles));
132
+ ```
package/actions.d.ts ADDED
@@ -0,0 +1,126 @@
1
+ import { InputTranslationMetadata } from '@helloao/tools/generation';
2
+ import { UploadApiFromDatabaseOptions, UploadApiOptions } from './uploads';
3
+ export interface InitDbOptions {
4
+ /**
5
+ * The path to the source database to copy the schema from.
6
+ */
7
+ source?: string;
8
+ /**
9
+ * The languages to copy from the source database. If not specified, then all languages will be copied.
10
+ */
11
+ language?: string[];
12
+ }
13
+ /**
14
+ * Initializes a new Bible API DB.
15
+ * @param dbPath The path to the database. If null or empty, then the "bible-api.db" will be used from the current working directory.
16
+ * @param options The options for the initialization.
17
+ */
18
+ export declare function initDb(dbPath: string | null, options: InitDbOptions): Promise<void>;
19
+ export interface ImportTranslationOptions {
20
+ /**
21
+ * Whether to forcibly import the translations, even if they have already been imported.
22
+ */
23
+ overwrite?: boolean;
24
+ }
25
+ /**
26
+ * Imports a translation from the given directory into the database in the current working directory.
27
+ * @param dir The directory that the translation is located in.
28
+ * @param dirs Any extra directories that should be imported.
29
+ * @param options The options for the import.
30
+ */
31
+ export declare function importTranslation(dir: string, dirs: string[], options: ImportTranslationOptions): Promise<void>;
32
+ /**
33
+ * Imports all the translations from the given directory into the database in the current working directory.
34
+ * @param dir The directory that the translations are located in.
35
+ * @param options The options.
36
+ */
37
+ export declare function importTranslations(dir: string, options: ImportTranslationOptions): Promise<void>;
38
+ export interface FetchTranslationsOptions {
39
+ /**
40
+ * Fetch all translations. If omitted, only undownloaded translations will be fetched.
41
+ */
42
+ all?: boolean;
43
+ }
44
+ /**
45
+ * Fetches the specified translations from fetch.bible and places them in the given directory.
46
+ * @param dir The directory that the translations should be placed in.
47
+ * @param translations The translations that should be downloaded. If not specified, then all translations will be downloaded.
48
+ * @param options The options.
49
+ */
50
+ export declare function fetchTranslations(dir: string, translations?: string[], options?: FetchTranslationsOptions): Promise<void>;
51
+ /**
52
+ * Fetches the specified audio translations and places them in the given directory.
53
+ * Translations should be in the format "translationId/audioId". e.g. "BSB/gilbert"
54
+ * @param dir The directory that the translations should be placed in.
55
+ * @param translations The translations that should be downloaded.
56
+ * @param options The options.
57
+ */
58
+ export declare function fetchAudio(dir: string, translations: string[], options?: FetchTranslationsOptions): Promise<void>;
59
+ /**
60
+ * Generates the translation files directly from the translations stored in the given input directory.
61
+ * @param input The input directory that the translations are stored in.
62
+ * @param dest The destination to upload the API files to.
63
+ * @param options The options for the generation.
64
+ */
65
+ export declare function generateTranslationsFiles(input: string, dest: string, options: UploadApiFromDatabaseOptions): Promise<void>;
66
+ /**
67
+ * Generates the translation files directly from the translation stored in the given input directory.
68
+ * @param input The input directory that the translation is stored in.
69
+ * @param dest The destination to upload the API files to.
70
+ * @param options The options for the generation.
71
+ */
72
+ export declare function generateTranslationFiles(input: string, dest: string, options: UploadApiOptions): Promise<void>;
73
+ /**
74
+ * The options for uploading the test translations.
75
+ */
76
+ export interface UploadTestTranslationOptions extends UploadApiOptions {
77
+ /**
78
+ * The s3 URL to upload the translations to.
79
+ * Defaults to "s3://ao-bible-api-public-uploads"
80
+ */
81
+ s3Url?: string;
82
+ }
83
+ export interface UploadTestTranslationResult {
84
+ /**
85
+ * The S3 URL where the translations were uploaded to.
86
+ */
87
+ uploadS3Url: string;
88
+ /**
89
+ * The HTTP URL that the version can be accessed at.
90
+ */
91
+ url: string;
92
+ /**
93
+ * The URL that the available translations can be accessed at.
94
+ */
95
+ availableTranslationsUrl: string;
96
+ /**
97
+ * The version that was uploaded.
98
+ * This is a SHA-256 hash of the input files.
99
+ */
100
+ version: string;
101
+ }
102
+ /**
103
+ * Generates the API files directly from the translations stored in the given input directory and
104
+ * uploads them to the HelloAO test s3 bucket.
105
+ *
106
+ * Requires access to the HelloAO test s3 bucket. Email hello@helloao.org for access.
107
+ *
108
+ * @param input The input directory that the translations are stored in.
109
+ * @param options The options to use for the upload.
110
+ */
111
+ export declare function uploadTestTranslations(input: string, options: UploadTestTranslationOptions): Promise<UploadTestTranslationResult>;
112
+ /**
113
+ * Generates the API files directly from the given translation and
114
+ * uploads them to the HelloAO test s3 bucket.
115
+ *
116
+ * Requires access to the HelloAO test s3 bucket. Email hello@helloao.org for access.
117
+ *
118
+ * @param input The input directory that the translations are stored in.
119
+ * @param options The options to use for the upload.
120
+ */
121
+ export declare function uploadTestTranslation(input: string, options: UploadTestTranslationOptions): Promise<UploadTestTranslationResult | undefined>;
122
+ /**
123
+ * Asks the user for the metadata for the translation.
124
+ */
125
+ export declare function askForMetadata(defaultId?: string): Promise<InputTranslationMetadata>;
126
+ //# sourceMappingURL=actions.d.ts.map