@genoacms/adapter-gcp 0.5.2-fix.2 → 0.5.2-fix.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -10,27 +10,35 @@ const functionsClient = new CloudFunctionsServiceClient({
|
|
10
10
|
});
|
11
11
|
const projectId = config.deployment.projectId;
|
12
12
|
const region = config.deployment.region;
|
13
|
-
async function
|
13
|
+
async function uploadFile(bucketName, filePath, destination) {
|
14
14
|
const bucket = getBucket(bucketName);
|
15
|
+
const fileStream = createReadStream(filePath);
|
16
|
+
const gcsFile = bucket.file(destination);
|
17
|
+
await new Promise((resolve, reject) => {
|
18
|
+
fileStream
|
19
|
+
.pipe(gcsFile.createWriteStream())
|
20
|
+
.on('error', reject)
|
21
|
+
.on('finish', resolve);
|
22
|
+
});
|
23
|
+
}
|
24
|
+
async function uploadFileOrDirectory(bucketName, path, prefix = '') {
|
25
|
+
const isDirectory = (await lstat(path)).isDirectory();
|
26
|
+
if (isDirectory) {
|
27
|
+
await uploadDirectory(bucketName, path, prefix);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
await uploadFile(bucketName, path, prefix);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
async function uploadDirectory(bucketName, directoryPath, prefix = '') {
|
15
34
|
const files = await readdir(directoryPath);
|
35
|
+
const promises = [];
|
16
36
|
for (const file of files) {
|
17
37
|
const filePath = join(directoryPath, file);
|
18
38
|
const destination = join(prefix, file);
|
19
|
-
|
20
|
-
if (isFileDirectory) {
|
21
|
-
await uploadDirectory(bucketName, filePath, destination);
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
const fileStream = createReadStream(filePath);
|
25
|
-
const gcsFile = bucket.file(destination);
|
26
|
-
await new Promise((resolve, reject) => {
|
27
|
-
fileStream
|
28
|
-
.pipe(gcsFile.createWriteStream())
|
29
|
-
.on('error', reject)
|
30
|
-
.on('finish', resolve);
|
31
|
-
});
|
32
|
-
}
|
39
|
+
promises.push(uploadFileOrDirectory(bucketName, filePath, destination));
|
33
40
|
}
|
41
|
+
await Promise.all(promises);
|
34
42
|
}
|
35
43
|
async function zipDirectory(source, out) {
|
36
44
|
await new Promise((resolve, reject) => {
|
@@ -73,6 +81,6 @@ export default async function () {
|
|
73
81
|
const buildArchiveRef = `gs://${bucketName}/${buildArchiveDest}`;
|
74
82
|
await zipDirectory('./build', buildArchiveSrc);
|
75
83
|
await uploadDirectory(bucketName, './static', assetsPath);
|
76
|
-
await
|
84
|
+
await uploadFile(bucketName, buildArchiveSrc, buildArchiveDest);
|
77
85
|
await deployFunction('genoacms', buildArchiveRef);
|
78
86
|
}
|
package/package.json
CHANGED
@@ -12,29 +12,38 @@ const functionsClient = new CloudFunctionsServiceClient({
|
|
12
12
|
const projectId = config.deployment.projectId
|
13
13
|
const region = config.deployment.region
|
14
14
|
|
15
|
-
async function
|
15
|
+
async function uploadFile (bucketName: string, filePath: string, destination: string): Promise<void> {
|
16
16
|
const bucket = getBucket(bucketName)
|
17
|
+
const fileStream = createReadStream(filePath)
|
18
|
+
const gcsFile = bucket.file(destination)
|
19
|
+
|
20
|
+
await new Promise((resolve, reject) => {
|
21
|
+
fileStream
|
22
|
+
.pipe(gcsFile.createWriteStream())
|
23
|
+
.on('error', reject)
|
24
|
+
.on('finish', resolve)
|
25
|
+
})
|
26
|
+
}
|
27
|
+
|
28
|
+
async function uploadFileOrDirectory (bucketName: string, path: string, prefix = ''): Promise<void> {
|
29
|
+
const isDirectory = (await lstat(path)).isDirectory()
|
30
|
+
if (isDirectory) {
|
31
|
+
await uploadDirectory(bucketName, path, prefix)
|
32
|
+
} else {
|
33
|
+
await uploadFile(bucketName, path, prefix)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
async function uploadDirectory (bucketName: string, directoryPath: string, prefix = ''): Promise<void> {
|
17
38
|
const files = await readdir(directoryPath)
|
39
|
+
const promises = []
|
18
40
|
|
19
41
|
for (const file of files) {
|
20
42
|
const filePath = join(directoryPath, file)
|
21
43
|
const destination = join(prefix, file)
|
22
|
-
|
23
|
-
const isFileDirectory = (await lstat(filePath)).isDirectory()
|
24
|
-
if (isFileDirectory) {
|
25
|
-
await uploadDirectory(bucketName, filePath, destination)
|
26
|
-
} else {
|
27
|
-
const fileStream = createReadStream(filePath)
|
28
|
-
const gcsFile = bucket.file(destination)
|
29
|
-
|
30
|
-
await new Promise((resolve, reject) => {
|
31
|
-
fileStream
|
32
|
-
.pipe(gcsFile.createWriteStream())
|
33
|
-
.on('error', reject)
|
34
|
-
.on('finish', resolve)
|
35
|
-
})
|
36
|
-
}
|
44
|
+
promises.push(uploadFileOrDirectory(bucketName, filePath, destination))
|
37
45
|
}
|
46
|
+
await Promise.all(promises)
|
38
47
|
}
|
39
48
|
|
40
49
|
async function zipDirectory (source: string, out: string): Promise<void> {
|
@@ -83,6 +92,6 @@ export default async function (): Promise<void> {
|
|
83
92
|
const buildArchiveRef = `gs://${bucketName}/${buildArchiveDest}`
|
84
93
|
await zipDirectory('./build', buildArchiveSrc)
|
85
94
|
await uploadDirectory(bucketName, './static', assetsPath)
|
86
|
-
await
|
95
|
+
await uploadFile(bucketName, buildArchiveSrc, buildArchiveDest)
|
87
96
|
await deployFunction('genoacms', buildArchiveRef)
|
88
97
|
}
|