@helloao/cli 0.0.3 → 0.0.5
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 -36
- package/actions.js +37 -37
- package/cli.d.ts +1 -0
- package/cli.js +13 -5
- package/db.d.ts +13 -44
- package/db.js +147 -239
- package/files.d.ts +59 -2
- package/files.js +109 -0
- 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 +3 -5
- package/prisma-gen/edge.js +5 -5
- package/prisma-gen/index.js +10 -10
- package/s3.d.ts +1 -1
- package/schema.prisma +154 -154
- package/uploads.d.ts +23 -4
- package/uploads.js +130 -11
package/schema.prisma
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
datasource db {
|
|
2
|
-
provider = "sqlite"
|
|
3
|
-
url = "file:../../bible-api.dev.db"
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
generator client {
|
|
7
|
-
provider = "prisma-client-js"
|
|
8
|
-
output = "./prisma-gen"
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
model Translation {
|
|
12
|
-
id String @id
|
|
13
|
-
name String
|
|
14
|
-
website String
|
|
15
|
-
licenseUrl String
|
|
16
|
-
shortName String?
|
|
17
|
-
englishName String
|
|
18
|
-
language String
|
|
19
|
-
textDirection String
|
|
20
|
-
|
|
21
|
-
// The SHA-256 hash of the translation
|
|
22
|
-
// includes everything about the translation, including the books, chapters, verses, footnotes, etc.
|
|
23
|
-
sha256 String?
|
|
24
|
-
|
|
25
|
-
books Book[]
|
|
26
|
-
chapters Chapter[]
|
|
27
|
-
verses ChapterVerse[]
|
|
28
|
-
footnotes ChapterFootnote[]
|
|
29
|
-
audioUrls ChapterAudioUrl[]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
model InputFile {
|
|
33
|
-
// The ID of the translation that the file is for
|
|
34
|
-
translationId String
|
|
35
|
-
|
|
36
|
-
// The name of the file
|
|
37
|
-
name String
|
|
38
|
-
|
|
39
|
-
format String
|
|
40
|
-
|
|
41
|
-
// The SHA-256 hash of the file
|
|
42
|
-
sha256 String
|
|
43
|
-
|
|
44
|
-
sizeInBytes Int
|
|
45
|
-
|
|
46
|
-
@@id([translationId, name])
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
model Book {
|
|
50
|
-
id String
|
|
51
|
-
|
|
52
|
-
translationId String
|
|
53
|
-
translation Translation @relation(fields: [translationId], references: [id])
|
|
54
|
-
|
|
55
|
-
name String
|
|
56
|
-
commonName String
|
|
57
|
-
title String?
|
|
58
|
-
order Int
|
|
59
|
-
|
|
60
|
-
numberOfChapters Int
|
|
61
|
-
|
|
62
|
-
// The SHA-256 hash of the book
|
|
63
|
-
sha256 String?
|
|
64
|
-
|
|
65
|
-
chapters Chapter[]
|
|
66
|
-
verses ChapterVerse[]
|
|
67
|
-
footnotes ChapterFootnote[]
|
|
68
|
-
audioUrls ChapterAudioUrl[]
|
|
69
|
-
|
|
70
|
-
@@id([translationId, id])
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
model Chapter {
|
|
74
|
-
number Int
|
|
75
|
-
|
|
76
|
-
bookId String
|
|
77
|
-
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
78
|
-
|
|
79
|
-
translationId String
|
|
80
|
-
translation Translation @relation(fields: [translationId], references: [id])
|
|
81
|
-
|
|
82
|
-
json String // The JSON of the chapter
|
|
83
|
-
|
|
84
|
-
// The SHA-256 hash of the chapter
|
|
85
|
-
sha256 String?
|
|
86
|
-
|
|
87
|
-
verses ChapterVerse[]
|
|
88
|
-
footnotes ChapterFootnote[]
|
|
89
|
-
audioUrls ChapterAudioUrl[]
|
|
90
|
-
|
|
91
|
-
@@id([translationId, bookId, number])
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
model ChapterAudioUrl {
|
|
95
|
-
number Int
|
|
96
|
-
bookId String
|
|
97
|
-
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
98
|
-
|
|
99
|
-
translationId String
|
|
100
|
-
translation Translation @relation(fields: [translationId], references: [id])
|
|
101
|
-
|
|
102
|
-
chapter Chapter @relation(fields: [translationId, bookId, number], references: [translationId, bookId, number])
|
|
103
|
-
|
|
104
|
-
reader String
|
|
105
|
-
url String
|
|
106
|
-
|
|
107
|
-
@@id([translationId, bookId, number, reader])
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
model ChapterVerse {
|
|
111
|
-
number Int
|
|
112
|
-
|
|
113
|
-
chapterNumber Int
|
|
114
|
-
chapter Chapter @relation(fields: [translationId, bookId, chapterNumber], references: [translationId, bookId, number])
|
|
115
|
-
|
|
116
|
-
bookId String
|
|
117
|
-
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
118
|
-
|
|
119
|
-
translationId String
|
|
120
|
-
translation Translation @relation(fields: [translationId], references: [id])
|
|
121
|
-
|
|
122
|
-
text String // The text of the verse
|
|
123
|
-
contentJson String // The JSON of the verse content
|
|
124
|
-
|
|
125
|
-
// The SHA-256 hash of the verse
|
|
126
|
-
sha256 String?
|
|
127
|
-
|
|
128
|
-
footnotes ChapterFootnote[]
|
|
129
|
-
|
|
130
|
-
@@id([translationId, bookId, chapterNumber, number])
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
model ChapterFootnote {
|
|
134
|
-
id Int
|
|
135
|
-
|
|
136
|
-
chapterNumber Int
|
|
137
|
-
chapter Chapter @relation(fields: [translationId, bookId, chapterNumber], references: [translationId, bookId, number])
|
|
138
|
-
|
|
139
|
-
bookId String
|
|
140
|
-
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
141
|
-
|
|
142
|
-
translationId String
|
|
143
|
-
translation Translation @relation(fields: [translationId], references: [id])
|
|
144
|
-
|
|
145
|
-
text String
|
|
146
|
-
|
|
147
|
-
// The SHA-256 hash of the footnote
|
|
148
|
-
sha256 String?
|
|
149
|
-
|
|
150
|
-
verseNumber Int?
|
|
151
|
-
verse ChapterVerse? @relation(fields: [translationId, bookId, chapterNumber, verseNumber], references: [translationId, bookId, chapterNumber, number])
|
|
152
|
-
|
|
153
|
-
@@id([translationId, bookId, chapterNumber, id])
|
|
154
|
-
}
|
|
1
|
+
datasource db {
|
|
2
|
+
provider = "sqlite"
|
|
3
|
+
url = "file:../../bible-api.dev.db"
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
generator client {
|
|
7
|
+
provider = "prisma-client-js"
|
|
8
|
+
output = "./prisma-gen"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
model Translation {
|
|
12
|
+
id String @id
|
|
13
|
+
name String
|
|
14
|
+
website String
|
|
15
|
+
licenseUrl String
|
|
16
|
+
shortName String?
|
|
17
|
+
englishName String
|
|
18
|
+
language String
|
|
19
|
+
textDirection String
|
|
20
|
+
|
|
21
|
+
// The SHA-256 hash of the translation
|
|
22
|
+
// includes everything about the translation, including the books, chapters, verses, footnotes, etc.
|
|
23
|
+
sha256 String?
|
|
24
|
+
|
|
25
|
+
books Book[]
|
|
26
|
+
chapters Chapter[]
|
|
27
|
+
verses ChapterVerse[]
|
|
28
|
+
footnotes ChapterFootnote[]
|
|
29
|
+
audioUrls ChapterAudioUrl[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
model InputFile {
|
|
33
|
+
// The ID of the translation that the file is for
|
|
34
|
+
translationId String
|
|
35
|
+
|
|
36
|
+
// The name of the file
|
|
37
|
+
name String
|
|
38
|
+
|
|
39
|
+
format String
|
|
40
|
+
|
|
41
|
+
// The SHA-256 hash of the file
|
|
42
|
+
sha256 String
|
|
43
|
+
|
|
44
|
+
sizeInBytes Int
|
|
45
|
+
|
|
46
|
+
@@id([translationId, name])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
model Book {
|
|
50
|
+
id String
|
|
51
|
+
|
|
52
|
+
translationId String
|
|
53
|
+
translation Translation @relation(fields: [translationId], references: [id])
|
|
54
|
+
|
|
55
|
+
name String
|
|
56
|
+
commonName String
|
|
57
|
+
title String?
|
|
58
|
+
order Int
|
|
59
|
+
|
|
60
|
+
numberOfChapters Int
|
|
61
|
+
|
|
62
|
+
// The SHA-256 hash of the book
|
|
63
|
+
sha256 String?
|
|
64
|
+
|
|
65
|
+
chapters Chapter[]
|
|
66
|
+
verses ChapterVerse[]
|
|
67
|
+
footnotes ChapterFootnote[]
|
|
68
|
+
audioUrls ChapterAudioUrl[]
|
|
69
|
+
|
|
70
|
+
@@id([translationId, id])
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
model Chapter {
|
|
74
|
+
number Int
|
|
75
|
+
|
|
76
|
+
bookId String
|
|
77
|
+
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
78
|
+
|
|
79
|
+
translationId String
|
|
80
|
+
translation Translation @relation(fields: [translationId], references: [id])
|
|
81
|
+
|
|
82
|
+
json String // The JSON of the chapter
|
|
83
|
+
|
|
84
|
+
// The SHA-256 hash of the chapter
|
|
85
|
+
sha256 String?
|
|
86
|
+
|
|
87
|
+
verses ChapterVerse[]
|
|
88
|
+
footnotes ChapterFootnote[]
|
|
89
|
+
audioUrls ChapterAudioUrl[]
|
|
90
|
+
|
|
91
|
+
@@id([translationId, bookId, number])
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
model ChapterAudioUrl {
|
|
95
|
+
number Int
|
|
96
|
+
bookId String
|
|
97
|
+
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
98
|
+
|
|
99
|
+
translationId String
|
|
100
|
+
translation Translation @relation(fields: [translationId], references: [id])
|
|
101
|
+
|
|
102
|
+
chapter Chapter @relation(fields: [translationId, bookId, number], references: [translationId, bookId, number])
|
|
103
|
+
|
|
104
|
+
reader String
|
|
105
|
+
url String
|
|
106
|
+
|
|
107
|
+
@@id([translationId, bookId, number, reader])
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
model ChapterVerse {
|
|
111
|
+
number Int
|
|
112
|
+
|
|
113
|
+
chapterNumber Int
|
|
114
|
+
chapter Chapter @relation(fields: [translationId, bookId, chapterNumber], references: [translationId, bookId, number])
|
|
115
|
+
|
|
116
|
+
bookId String
|
|
117
|
+
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
118
|
+
|
|
119
|
+
translationId String
|
|
120
|
+
translation Translation @relation(fields: [translationId], references: [id])
|
|
121
|
+
|
|
122
|
+
text String // The text of the verse
|
|
123
|
+
contentJson String // The JSON of the verse content
|
|
124
|
+
|
|
125
|
+
// The SHA-256 hash of the verse
|
|
126
|
+
sha256 String?
|
|
127
|
+
|
|
128
|
+
footnotes ChapterFootnote[]
|
|
129
|
+
|
|
130
|
+
@@id([translationId, bookId, chapterNumber, number])
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
model ChapterFootnote {
|
|
134
|
+
id Int
|
|
135
|
+
|
|
136
|
+
chapterNumber Int
|
|
137
|
+
chapter Chapter @relation(fields: [translationId, bookId, chapterNumber], references: [translationId, bookId, number])
|
|
138
|
+
|
|
139
|
+
bookId String
|
|
140
|
+
book Book @relation(fields: [translationId, bookId], references: [translationId, id])
|
|
141
|
+
|
|
142
|
+
translationId String
|
|
143
|
+
translation Translation @relation(fields: [translationId], references: [id])
|
|
144
|
+
|
|
145
|
+
text String
|
|
146
|
+
|
|
147
|
+
// The SHA-256 hash of the footnote
|
|
148
|
+
sha256 String?
|
|
149
|
+
|
|
150
|
+
verseNumber Int?
|
|
151
|
+
verse ChapterVerse? @relation(fields: [translationId, bookId, chapterNumber, verseNumber], references: [translationId, bookId, chapterNumber, number])
|
|
152
|
+
|
|
153
|
+
@@id([translationId, bookId, chapterNumber, id])
|
|
154
|
+
}
|
package/uploads.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { SerializedFile, Uploader } from "./files";
|
|
1
2
|
import { DatasetOutput } from "@helloao/tools/generation/dataset";
|
|
2
|
-
|
|
3
|
+
import { PrismaClient } from "@prisma/client";
|
|
4
|
+
export interface UploadApiFromDatabaseOptions extends UploadApiOptions {
|
|
3
5
|
/**
|
|
4
6
|
* The number of files to upload in each batch.
|
|
5
7
|
*/
|
|
6
|
-
batchSize: string;
|
|
8
|
+
batchSize: string | number;
|
|
9
|
+
}
|
|
10
|
+
export interface UploadApiOptions {
|
|
7
11
|
/**
|
|
8
12
|
* Whether to overwrite existing files.
|
|
9
13
|
*/
|
|
@@ -40,15 +44,30 @@ export interface UploadApiOptions {
|
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
42
46
|
* Loads and generates the API files from the database and uploads them to the specified destination.
|
|
47
|
+
* @param db The database that the datasets should be loaded from.
|
|
43
48
|
* @param dest The destination to upload the API files to. Supported destinations are S3, zip files, and local directories.
|
|
44
49
|
* @param options The options to use for the upload.
|
|
45
50
|
*/
|
|
46
|
-
export declare function uploadApiFilesFromDatabase(dest: string, options:
|
|
51
|
+
export declare function uploadApiFilesFromDatabase(db: PrismaClient, dest: string, options: UploadApiFromDatabaseOptions): Promise<void>;
|
|
47
52
|
/**
|
|
48
53
|
* Generates the API files from the given datasets and uploads them to the specified destination.
|
|
49
54
|
* @param dest The destination to upload the API files to. Supported destinations are S3, zip files, and local directories.
|
|
50
55
|
* @param options The options to use for the upload.
|
|
51
56
|
* @param datasets The datasets to generate the API files from.
|
|
52
57
|
*/
|
|
53
|
-
export declare function
|
|
58
|
+
export declare function serializeAndUploadDatasets(dest: string, datasets: AsyncIterable<DatasetOutput>, options?: UploadApiOptions): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Uploads the given serialized files to the specified destination.
|
|
61
|
+
* @param dest The destination to upload the API files to. Supported destinations are S3, zip files, and local directories.
|
|
62
|
+
* @param options The options to use for the upload.
|
|
63
|
+
* @param datasets The datasets to generate the API files from.
|
|
64
|
+
*/
|
|
65
|
+
export declare function uploadFiles(dest: string, options: UploadApiOptions, serializedFiles: AsyncIterable<SerializedFile[]>): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Uploads the given serialized files using the given uploader.
|
|
68
|
+
* @param uploader The uploader to use.
|
|
69
|
+
* @param options The options to use for the upload.
|
|
70
|
+
* @param datasets The datasets to generate the API files from.
|
|
71
|
+
*/
|
|
72
|
+
export declare function uploadFilesUsingUploader(uploader: Uploader, options: UploadApiOptions, serializedFiles: AsyncIterable<SerializedFile[]>): Promise<void>;
|
|
54
73
|
//# sourceMappingURL=uploads.d.ts.map
|
package/uploads.js
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadApiFilesFromDatabase = uploadApiFilesFromDatabase;
|
|
4
|
-
exports.
|
|
4
|
+
exports.serializeAndUploadDatasets = serializeAndUploadDatasets;
|
|
5
|
+
exports.uploadFiles = uploadFiles;
|
|
6
|
+
exports.uploadFilesUsingUploader = uploadFilesUsingUploader;
|
|
5
7
|
const db_1 = require("./db");
|
|
6
|
-
const db_2 = require("./db");
|
|
7
8
|
const s3_1 = require("./s3");
|
|
8
9
|
const path_1 = require("path");
|
|
9
10
|
const files_1 = require("./files");
|
|
10
11
|
const node_stream_1 = require("node:stream");
|
|
11
12
|
/**
|
|
12
13
|
* Loads and generates the API files from the database and uploads them to the specified destination.
|
|
14
|
+
* @param db The database that the datasets should be loaded from.
|
|
13
15
|
* @param dest The destination to upload the API files to. Supported destinations are S3, zip files, and local directories.
|
|
14
16
|
* @param options The options to use for the upload.
|
|
15
17
|
*/
|
|
16
|
-
async function uploadApiFilesFromDatabase(dest, options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const pageSize = parseInt(options.batchSize);
|
|
20
|
-
await uploadApiFiles(dest, options, (0, db_1.loadDatasets)(db, pageSize, options.translations));
|
|
18
|
+
async function uploadApiFilesFromDatabase(db, dest, options) {
|
|
19
|
+
if (options.overwrite) {
|
|
20
|
+
console.log('Overwriting existing files');
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
if (options.overwriteCommonFiles) {
|
|
23
|
+
console.log('Overwriting only common files');
|
|
24
|
+
}
|
|
25
|
+
if (!!options.filePattern) {
|
|
26
|
+
console.log('Using file pattern:', options.filePattern);
|
|
27
|
+
}
|
|
28
|
+
if (options.translations) {
|
|
29
|
+
console.log('Generating for specific translations:', options.translations);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log('Generating for all translations');
|
|
33
|
+
}
|
|
34
|
+
if (options.pretty) {
|
|
35
|
+
console.log('Generating pretty-printed JSON files');
|
|
24
36
|
}
|
|
37
|
+
const pageSize = typeof options.batchSize === 'number' ? options.batchSize : parseInt(options.batchSize);
|
|
38
|
+
await serializeAndUploadDatasets(dest, (0, db_1.loadDatasets)(db, pageSize, options.translations), options);
|
|
25
39
|
}
|
|
26
40
|
/**
|
|
27
41
|
* Generates the API files from the given datasets and uploads them to the specified destination.
|
|
@@ -29,7 +43,7 @@ async function uploadApiFilesFromDatabase(dest, options) {
|
|
|
29
43
|
* @param options The options to use for the upload.
|
|
30
44
|
* @param datasets The datasets to generate the API files from.
|
|
31
45
|
*/
|
|
32
|
-
async function
|
|
46
|
+
async function serializeAndUploadDatasets(dest, datasets, options = {}) {
|
|
33
47
|
const overwrite = !!options.overwrite;
|
|
34
48
|
if (overwrite) {
|
|
35
49
|
console.log('Overwriting existing files');
|
|
@@ -90,7 +104,7 @@ async function uploadApiFiles(dest, options, datasets) {
|
|
|
90
104
|
process.exit(1);
|
|
91
105
|
}
|
|
92
106
|
try {
|
|
93
|
-
for await (let files of (0, db_1.
|
|
107
|
+
for await (let files of (0, db_1.serializeDatasets)(datasets, {
|
|
94
108
|
useCommonName: !!options.useCommonName,
|
|
95
109
|
generateAudioFiles: !!options.generateAudioFiles,
|
|
96
110
|
pretty: !!options.pretty,
|
|
@@ -139,3 +153,108 @@ async function uploadApiFiles(dest, options, datasets) {
|
|
|
139
153
|
}
|
|
140
154
|
}
|
|
141
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Uploads the given serialized files to the specified destination.
|
|
158
|
+
* @param dest The destination to upload the API files to. Supported destinations are S3, zip files, and local directories.
|
|
159
|
+
* @param options The options to use for the upload.
|
|
160
|
+
* @param datasets The datasets to generate the API files from.
|
|
161
|
+
*/
|
|
162
|
+
async function uploadFiles(dest, options, serializedFiles) {
|
|
163
|
+
let uploader;
|
|
164
|
+
if (dest.startsWith('s3://')) {
|
|
165
|
+
console.log('Uploading to S3');
|
|
166
|
+
// Upload to S3
|
|
167
|
+
const url = dest;
|
|
168
|
+
const s3Url = (0, s3_1.parseS3Url)(url);
|
|
169
|
+
if (!s3Url) {
|
|
170
|
+
throw new Error(`Invalid S3 URL: ${url}`);
|
|
171
|
+
}
|
|
172
|
+
if (!s3Url.bucketName) {
|
|
173
|
+
throw new Error(`Invalid S3 URL: ${url}\nUnable to determine bucket name`);
|
|
174
|
+
}
|
|
175
|
+
uploader = new s3_1.S3Uploader(s3Url.bucketName, s3Url.objectKey, options.profile ?? null);
|
|
176
|
+
}
|
|
177
|
+
else if (dest.startsWith('console://')) {
|
|
178
|
+
console.log('Uploading to console');
|
|
179
|
+
uploader = {
|
|
180
|
+
idealBatchSize: 50,
|
|
181
|
+
async upload(file, _overwrite) {
|
|
182
|
+
console.log(file.path);
|
|
183
|
+
console.log(file.content);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
else if ((0, path_1.extname)(dest) === '.zip') {
|
|
189
|
+
console.log('Writing to zip file:', dest);
|
|
190
|
+
uploader = new files_1.ZipUploader(dest);
|
|
191
|
+
}
|
|
192
|
+
else if (dest) {
|
|
193
|
+
console.log('Writing to local directory:', dest);
|
|
194
|
+
uploader = new files_1.FilesUploader(dest);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.error('Unsupported destination:', dest);
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
await uploadFilesUsingUploader(uploader, options, serializedFiles);
|
|
202
|
+
}
|
|
203
|
+
finally {
|
|
204
|
+
if (uploader && uploader.dispose) {
|
|
205
|
+
await uploader.dispose();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Uploads the given serialized files using the given uploader.
|
|
211
|
+
* @param uploader The uploader to use.
|
|
212
|
+
* @param options The options to use for the upload.
|
|
213
|
+
* @param datasets The datasets to generate the API files from.
|
|
214
|
+
*/
|
|
215
|
+
async function uploadFilesUsingUploader(uploader, options, serializedFiles) {
|
|
216
|
+
const overwrite = !!options.overwrite;
|
|
217
|
+
const overwriteCommonFiles = !!options.overwriteCommonFiles;
|
|
218
|
+
let filePattern;
|
|
219
|
+
if (!!options.filePattern) {
|
|
220
|
+
filePattern = new RegExp(options.filePattern, 'g');
|
|
221
|
+
}
|
|
222
|
+
for await (let files of serializedFiles) {
|
|
223
|
+
const batchSize = uploader.idealBatchSize ?? files.length;
|
|
224
|
+
const totalBatches = Math.ceil(files.length / batchSize);
|
|
225
|
+
console.log('Uploading', files.length, 'total files');
|
|
226
|
+
console.log('Uploading in batches of', batchSize);
|
|
227
|
+
let offset = 0;
|
|
228
|
+
let batchNumber = 1;
|
|
229
|
+
let batch = files.slice(offset, offset + batchSize);
|
|
230
|
+
while (batch.length > 0) {
|
|
231
|
+
console.log('Uploading batch', batchNumber, 'of', totalBatches);
|
|
232
|
+
let writtenFiles = 0;
|
|
233
|
+
const promises = batch.map(async (file) => {
|
|
234
|
+
if (filePattern) {
|
|
235
|
+
if (!filePattern.test(file.path)) {
|
|
236
|
+
console.log('Skipping file:', file.path);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const isAvailableTranslations = file.path.endsWith('available_translations.json');
|
|
241
|
+
const isCommonFile = !isAvailableTranslations;
|
|
242
|
+
if (await uploader.upload(file, overwrite || (overwriteCommonFiles && isCommonFile))) {
|
|
243
|
+
writtenFiles++;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
console.warn('File already exists:', file.path);
|
|
247
|
+
console.warn('Skipping file');
|
|
248
|
+
}
|
|
249
|
+
if (file.content instanceof node_stream_1.Readable) {
|
|
250
|
+
file.content.destroy();
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
await Promise.all(promises);
|
|
254
|
+
console.log('Wrote', writtenFiles, 'files');
|
|
255
|
+
batchNumber++;
|
|
256
|
+
offset += batchSize;
|
|
257
|
+
batch = files.slice(offset, offset + batchSize);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|