@dotcom-tool-kit/upload-assets-to-s3 1.0.0-beta.29 → 1.0.0-beta.32
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.
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { Task } from '@dotcom-tool-kit/task';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
secretAccessKey: string;
|
|
5
|
-
directory: string;
|
|
6
|
-
bucketByEnv: {
|
|
7
|
-
review: string[] | string;
|
|
8
|
-
prod: string[] | string;
|
|
9
|
-
};
|
|
10
|
-
destination: string;
|
|
11
|
-
extensions: string;
|
|
12
|
-
cacheControl: string;
|
|
13
|
-
};
|
|
14
|
-
export default class UploadAssetsToS3 extends Task<UploadAssetsToS3Options> {
|
|
2
|
+
import { UploadAssetsToS3Options, UploadAssetsToS3Schema } from '@dotcom-tool-kit/types/lib/schema/upload-assets-to-s3';
|
|
3
|
+
export default class UploadAssetsToS3 extends Task<typeof UploadAssetsToS3Schema> {
|
|
15
4
|
static description: string;
|
|
16
5
|
static defaultOptions: UploadAssetsToS3Options;
|
|
17
6
|
run(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-assets-to-s3.d.ts","sourceRoot":"","sources":["../../src/tasks/upload-assets-to-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"upload-assets-to-s3.d.ts","sourceRoot":"","sources":["../../src/tasks/upload-assets-to-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAM5C,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,uDAAuD,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC,OAAO,sBAAsB,CAAC;IAC/E,MAAM,CAAC,WAAW,SAAK;IAEvB,MAAM,CAAC,cAAc,EAAE,uBAAuB,CAS7C;IAEK,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3B"}
|
|
@@ -18,10 +18,8 @@ UploadAssetsToS3.defaultOptions = {
|
|
|
18
18
|
accessKeyId: process.env.aws_access_hashed_assets || '',
|
|
19
19
|
secretAccessKey: process.env.aws_secret_hashed_assets || '',
|
|
20
20
|
directory: 'public',
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
prod: ['ft-next-hashed-assets-prod', 'ft-next-hashed-assets-prod-us']
|
|
24
|
-
},
|
|
21
|
+
reviewBucket: ['ft-next-hashed-assets-preview'],
|
|
22
|
+
prodBucket: ['ft-next-hashed-assets-prod', 'ft-next-hashed-assets-prod-us'],
|
|
25
23
|
destination: 'hashed-assets/page-kit',
|
|
26
24
|
extensions: 'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json',
|
|
27
25
|
cacheControl: 'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600'
|
|
@@ -55,24 +53,42 @@ const uploadFile = async (file, options, s3) => {
|
|
|
55
53
|
ContentEncoding: encoding,
|
|
56
54
|
CacheControl: options.cacheControl
|
|
57
55
|
};
|
|
58
|
-
const
|
|
59
|
-
|
|
56
|
+
const bucketByEnv = process.env.NODE_ENV === 'branch' ? options.reviewBucket : options.prodBucket;
|
|
57
|
+
let currentBucket = '';
|
|
60
58
|
try {
|
|
61
59
|
if (typeof bucketByEnv === 'string') {
|
|
62
|
-
params
|
|
60
|
+
const params = {
|
|
61
|
+
Bucket: bucketByEnv,
|
|
62
|
+
Key: key,
|
|
63
|
+
Body: fs.createReadStream(file),
|
|
64
|
+
ACL: 'public-read',
|
|
65
|
+
ContentType: `${type}; charset=utf-8`,
|
|
66
|
+
ContentEncoding: encoding,
|
|
67
|
+
CacheControl: options.cacheControl
|
|
68
|
+
};
|
|
69
|
+
currentBucket = params.Bucket;
|
|
63
70
|
const data = await s3.upload(params).promise();
|
|
64
71
|
console.log(`Uploaded ${basename} to ${data.Location}`);
|
|
65
72
|
}
|
|
66
73
|
else {
|
|
67
74
|
for (const bucket of bucketByEnv) {
|
|
68
|
-
params
|
|
75
|
+
const params = {
|
|
76
|
+
Bucket: bucket,
|
|
77
|
+
Key: key,
|
|
78
|
+
Body: fs.createReadStream(file),
|
|
79
|
+
ACL: 'public-read',
|
|
80
|
+
ContentType: `${type}; charset=utf-8`,
|
|
81
|
+
ContentEncoding: encoding,
|
|
82
|
+
CacheControl: options.cacheControl
|
|
83
|
+
};
|
|
84
|
+
currentBucket = params.Bucket;
|
|
69
85
|
const data = await s3.upload(params).promise();
|
|
70
86
|
console.log(`Uploaded ${basename} to ${data.Location}`);
|
|
71
87
|
}
|
|
72
88
|
}
|
|
73
89
|
}
|
|
74
90
|
catch (error) {
|
|
75
|
-
console.error(`Upload of ${basename} to ${
|
|
91
|
+
console.error(`Upload of ${basename} to ${currentBucket} failed`);
|
|
76
92
|
throw error;
|
|
77
93
|
}
|
|
78
94
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcom-tool-kit/upload-assets-to-s3",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "jest --silent"
|
|
7
|
+
"test": "cd ../../ ; npx jest --silent --projects packages/upload-assets-to-s3"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [],
|
|
10
10
|
"author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dotcom-tool-kit/task": "^1.0.0-beta.
|
|
13
|
+
"@dotcom-tool-kit/task": "^1.0.0-beta.32",
|
|
14
|
+
"@dotcom-tool-kit/types": "^1.0.0-beta.32",
|
|
14
15
|
"aws-sdk": "^2.901.0",
|
|
15
16
|
"glob": "^7.1.6",
|
|
16
17
|
"mime": "^2.5.2"
|
|
@@ -27,9 +28,7 @@
|
|
|
27
28
|
"@jest/globals": "^26.6.2",
|
|
28
29
|
"@types/glob": "^7.1.3",
|
|
29
30
|
"@types/jest": "^26.0.23",
|
|
30
|
-
"@types/mime": "^2.0.3"
|
|
31
|
-
"jest": "^26.6.3",
|
|
32
|
-
"ts-jest": "^26.5.6"
|
|
31
|
+
"@types/mime": "^2.0.3"
|
|
33
32
|
},
|
|
34
33
|
"files": [
|
|
35
34
|
"/lib",
|