@dotcom-tool-kit/upload-assets-to-s3 3.2.0 → 4.0.0-beta.1
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/.toolkitrc.yml +6 -1
- package/README.md +21 -25
- package/lib/tasks/upload-assets-to-s3.d.ts +5 -4
- package/lib/tasks/upload-assets-to-s3.d.ts.map +1 -1
- package/lib/tasks/upload-assets-to-s3.js +15 -18
- package/package.json +7 -6
- package/lib/index.d.ts +0 -3
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -6
package/.toolkitrc.yml
CHANGED
package/README.md
CHANGED
|
@@ -17,32 +17,28 @@ plugins:
|
|
|
17
17
|
- '@dotcom-tool-kit/upload-assets-to-s3'
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
<!-- begin autogenerated docs -->
|
|
21
|
+
## Tasks
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
accessKeyId: AWS_ACCESS
|
|
41
|
-
secretAccessKey: AWS_KEY
|
|
42
|
-
prodBucket: ['ft-next-service-registry-prod']
|
|
43
|
-
reviewBucket: ['ft-next-service-registry-dev']
|
|
44
|
-
destination: ''
|
|
45
|
-
```
|
|
23
|
+
### `UploadAssetsToS3`
|
|
24
|
+
|
|
25
|
+
Upload files to an AWS S3 bucket.
|
|
26
|
+
#### Task options
|
|
27
|
+
|
|
28
|
+
| Property | Description | Type | Default |
|
|
29
|
+
| :---------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------- | :--------------------------------------------------------------------------- |
|
|
30
|
+
| `accessKeyIdEnvVar` | variable name of the project's aws access key id. If uploading to multiple buckets the same credentials will need to work for all | `string` | `'AWS_ACCESS_HASHED_ASSETS'` |
|
|
31
|
+
| `secretAccessKeyEnvVar` | variable name of the project's aws secret access key | `string` | `'AWS_SECRET_HASHED_ASSETS'` |
|
|
32
|
+
| `directory` | the folder in the project whose contents will be uploaded to S3 | `string` | `'public'` |
|
|
33
|
+
| `reviewBucket` | the development or test S3 bucket | `Array<string>` | `["ft-next-hashed-assets-preview"]` |
|
|
34
|
+
| `prodBucket` | production S3 bucket(s). The same files will be uploaded to each. **Note**: most Customer Products buckets that have a `prod` and `prod-us` version are already configured in AWS to replicate file changes from one to the other so you don't need to specify both here. Also, if multiple buckets are specified the same credentials will need to be valid for both for the upload to be successful. | `Array<string>` | `["ft-next-hashed-assets-prod"]` |
|
|
35
|
+
| `region` | the AWS region your buckets are stored in (let the Platforms team know if you need to upload to multiple buckets in multiple regions). | `string` | `'eu-west-1'` |
|
|
36
|
+
| `destination` | the destination folder for uploaded assets. Set to `''` to upload assets to the top level of the bucket | `string` | `'hashed-assets/page-kit'` |
|
|
37
|
+
| `extensions` | file extensions to be uploaded to S3 | `string` | `'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json'` |
|
|
38
|
+
| `cacheControl` | header that controls how long your files stay in a CloudFront cache before CloudFront forwards another request to your origin | `string` | `'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600'` |
|
|
39
|
+
|
|
40
|
+
_All properties are optional._
|
|
41
|
+
<!-- end autogenerated docs -->
|
|
46
42
|
|
|
47
43
|
## Testing uploads using the review bucket
|
|
48
44
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Task } from '@dotcom-tool-kit/
|
|
1
|
+
import { Task } from '@dotcom-tool-kit/base';
|
|
2
2
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
-
import { UploadAssetsToS3Options, UploadAssetsToS3Schema } from '@dotcom-tool-kit/
|
|
4
|
-
export default class UploadAssetsToS3 extends Task<
|
|
5
|
-
|
|
3
|
+
import { UploadAssetsToS3Options, UploadAssetsToS3Schema } from '@dotcom-tool-kit/schemas/lib/tasks/upload-assets-to-s3';
|
|
4
|
+
export default class UploadAssetsToS3 extends Task<{
|
|
5
|
+
task: typeof UploadAssetsToS3Schema;
|
|
6
|
+
}> {
|
|
6
7
|
run(): Promise<void>;
|
|
7
8
|
uploadFile(file: string, options: UploadAssetsToS3Options, s3: S3Client): Promise<void>;
|
|
8
9
|
uploadAssetsToS3(options: UploadAssetsToS3Options): 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,
|
|
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;AAE5C,OAAO,EAAE,QAAQ,EAAoB,MAAM,oBAAoB,CAAA;AAM/D,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,wDAAwD,CAAA;AAE/D,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC;IAAE,IAAI,EAAE,OAAO,sBAAsB,CAAA;CAAE,CAAC;IACnF,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAGpB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDvF,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;CAsCxE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
4
|
+
const base_1 = require("@dotcom-tool-kit/base");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
7
7
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -9,7 +9,7 @@ const mime_1 = tslib_1.__importDefault(require("mime"));
|
|
|
9
9
|
const glob_1 = require("glob");
|
|
10
10
|
const error_1 = require("@dotcom-tool-kit/error");
|
|
11
11
|
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
12
|
-
class UploadAssetsToS3 extends
|
|
12
|
+
class UploadAssetsToS3 extends base_1.Task {
|
|
13
13
|
async run() {
|
|
14
14
|
await this.uploadAssetsToS3(this.options);
|
|
15
15
|
}
|
|
@@ -69,31 +69,28 @@ class UploadAssetsToS3 extends types_1.Task {
|
|
|
69
69
|
if (files.length === 0) {
|
|
70
70
|
throw new error_1.ToolKitError(`no files found at the provided directory: ${options.directory}`);
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
const accessKeyId = process.env[options.accessKeyIdEnvVar];
|
|
73
|
+
const secretAccessKey = process.env[options.secretAccessKeyEnvVar];
|
|
74
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
75
|
+
const missingVars = [
|
|
76
|
+
!accessKeyId ? options.accessKeyIdEnvVar : false,
|
|
77
|
+
!secretAccessKey ? options.secretAccessKeyEnvVar : false
|
|
78
|
+
];
|
|
79
|
+
const error = new error_1.ToolKitError(`environment variable${missingVars.length > 1 ? 's' : ''} ${missingVars.join(' and ')} not set`);
|
|
80
|
+
error.details = `if your AWS credentials are stored in different environment variables, set the ${logger_1.styles.code('accessKeyIdEnvVar')} and ${logger_1.styles.code('secretAccessKeyEnvVar')} options for this task.`;
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
79
83
|
const s3 = new client_s3_1.S3Client({
|
|
80
84
|
region: options.region,
|
|
81
|
-
// will fallback to default value for accessKeyId if neither
|
|
82
|
-
// accessKeyIdEnvVar nor accessKeyId have been provided as options
|
|
83
85
|
credentials: {
|
|
84
|
-
accessKeyId
|
|
85
|
-
|
|
86
|
-
checkUppercaseName(options.accessKeyIdEnvVar ?? options.accessKeyId),
|
|
87
|
-
secretAccessKey:
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
89
|
-
checkUppercaseName(options.secretAccessKeyEnvVar ?? options.secretAccessKey)
|
|
86
|
+
accessKeyId,
|
|
87
|
+
secretAccessKey
|
|
90
88
|
}
|
|
91
89
|
});
|
|
92
90
|
await Promise.all(files.map((file) => this.uploadFile(file, options, s3)));
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
93
|
exports.default = UploadAssetsToS3;
|
|
96
|
-
UploadAssetsToS3.description = '';
|
|
97
94
|
const getFileType = (filename) => {
|
|
98
95
|
// We need to know the original file type so ignore any compression
|
|
99
96
|
const originalFile = filename.replace(/\.(br|gz)$/, '');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcom-tool-kit/upload-assets-to-s3",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@aws-sdk/client-s3": "^3.256.0",
|
|
14
|
-
"@dotcom-tool-kit/
|
|
15
|
-
"@dotcom-tool-kit/
|
|
16
|
-
"@dotcom-tool-kit/
|
|
14
|
+
"@dotcom-tool-kit/base": "4.0.0-beta.0",
|
|
15
|
+
"@dotcom-tool-kit/error": "4.0.0-beta.0",
|
|
16
|
+
"@dotcom-tool-kit/logger": "4.0.0-beta.0",
|
|
17
17
|
"glob": "^7.1.6",
|
|
18
18
|
"mime": "^2.5.2",
|
|
19
19
|
"tslib": "^2.3.1"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/upload-assets-to-s3",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@aws-sdk/types": "^3.13.1",
|
|
30
|
+
"@dotcom-tool-kit/schemas": "2.0.0-beta.0",
|
|
30
31
|
"@jest/globals": "^27.4.6",
|
|
31
32
|
"@types/glob": "^7.1.3",
|
|
32
33
|
"@types/jest": "^27.4.0",
|
|
@@ -41,10 +42,10 @@
|
|
|
41
42
|
"extends": "../../package.json"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"dotcom-tool-kit": "
|
|
45
|
+
"dotcom-tool-kit": "4.0.0-beta.1"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
|
47
|
-
"node": "
|
|
48
|
+
"node": "18.x || 20.x",
|
|
48
49
|
"npm": "7.x || 8.x || 9.x || 10.x"
|
|
49
50
|
}
|
|
50
51
|
}
|
package/lib/index.d.ts
DELETED
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,6BAA6B,CAAA;AAE1D,eAAO,MAAM,KAAK,6BAAqB,CAAA"}
|
package/lib/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tasks = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const upload_assets_to_s3_1 = tslib_1.__importDefault(require("./tasks/upload-assets-to-s3"));
|
|
6
|
-
exports.tasks = [upload_assets_to_s3_1.default];
|