@dotcom-tool-kit/upload-assets-to-s3 4.2.7 → 4.3.0
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,6 +1,38 @@
|
|
|
1
1
|
import { Task, TaskRunContext } from '@dotcom-tool-kit/base';
|
|
2
2
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
-
import
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
export declare const UploadAssetsToS3Schema: z.ZodObject<{
|
|
5
|
+
accessKeyIdEnvVar: z.ZodDefault<z.ZodString>;
|
|
6
|
+
secretAccessKeyEnvVar: z.ZodDefault<z.ZodString>;
|
|
7
|
+
directory: z.ZodDefault<z.ZodString>;
|
|
8
|
+
reviewBucket: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
9
|
+
prodBucket: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
10
|
+
region: z.ZodDefault<z.ZodString>;
|
|
11
|
+
destination: z.ZodDefault<z.ZodString>;
|
|
12
|
+
extensions: z.ZodDefault<z.ZodString>;
|
|
13
|
+
cacheControl: z.ZodDefault<z.ZodString>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
accessKeyIdEnvVar: string;
|
|
16
|
+
secretAccessKeyEnvVar: string;
|
|
17
|
+
directory: string;
|
|
18
|
+
reviewBucket: string[];
|
|
19
|
+
prodBucket: string[];
|
|
20
|
+
region: string;
|
|
21
|
+
destination: string;
|
|
22
|
+
extensions: string;
|
|
23
|
+
cacheControl: string;
|
|
24
|
+
}, {
|
|
25
|
+
accessKeyIdEnvVar?: string | undefined;
|
|
26
|
+
secretAccessKeyEnvVar?: string | undefined;
|
|
27
|
+
directory?: string | undefined;
|
|
28
|
+
reviewBucket?: string[] | undefined;
|
|
29
|
+
prodBucket?: string[] | undefined;
|
|
30
|
+
region?: string | undefined;
|
|
31
|
+
destination?: string | undefined;
|
|
32
|
+
extensions?: string | undefined;
|
|
33
|
+
cacheControl?: string | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export { UploadAssetsToS3Schema as schema };
|
|
4
36
|
export default class UploadAssetsToS3 extends Task<{
|
|
5
37
|
task: typeof UploadAssetsToS3Schema;
|
|
6
38
|
}> {
|
|
@@ -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,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,EAAE,QAAQ,EAAoB,MAAM,oBAAoB,CAAA;AAM/D,OAAO,
|
|
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,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,EAAE,QAAQ,EAAoB,MAAM,oBAAoB,CAAA;AAM/D,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmDa,CAAA;AAChD,OAAO,EAAE,sBAAsB,IAAI,MAAM,EAAE,CAAA;AAE3C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC;IAAE,IAAI,EAAE,OAAO,sBAAsB,CAAA;CAAE,CAAC;IACnF,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAkDrD,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAyClD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = exports.UploadAssetsToS3Schema = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const base_1 = require("@dotcom-tool-kit/base");
|
|
5
6
|
const fs = tslib_1.__importStar(require("fs"));
|
|
@@ -9,6 +10,50 @@ const mime_1 = tslib_1.__importDefault(require("mime"));
|
|
|
9
10
|
const glob_1 = require("glob");
|
|
10
11
|
const error_1 = require("@dotcom-tool-kit/error");
|
|
11
12
|
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
13
|
+
const z = tslib_1.__importStar(require("zod"));
|
|
14
|
+
exports.UploadAssetsToS3Schema = z
|
|
15
|
+
.object({
|
|
16
|
+
accessKeyIdEnvVar: z
|
|
17
|
+
.string()
|
|
18
|
+
.default('AWS_ACCESS_HASHED_ASSETS')
|
|
19
|
+
.describe("variable name of the project's aws access key id. If uploading to multiple buckets the same credentials will need to work for all"),
|
|
20
|
+
secretAccessKeyEnvVar: z
|
|
21
|
+
.string()
|
|
22
|
+
.default('AWS_SECRET_HASHED_ASSETS')
|
|
23
|
+
.describe("variable name of the project's aws secret access key"),
|
|
24
|
+
directory: z
|
|
25
|
+
.string()
|
|
26
|
+
.default('public')
|
|
27
|
+
.describe('the folder in the project whose contents will be uploaded to S3'),
|
|
28
|
+
reviewBucket: z
|
|
29
|
+
.string()
|
|
30
|
+
.array()
|
|
31
|
+
.default(['ft-next-hashed-assets-preview'])
|
|
32
|
+
.describe('the development or test S3 bucket'),
|
|
33
|
+
prodBucket: z
|
|
34
|
+
.string()
|
|
35
|
+
.array()
|
|
36
|
+
.default(['ft-next-hashed-assets-prod'])
|
|
37
|
+
.describe("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."),
|
|
38
|
+
region: z
|
|
39
|
+
.string()
|
|
40
|
+
.default('eu-west-1')
|
|
41
|
+
.describe('the AWS region your buckets are stored in (let the Platforms team know if you need to upload to multiple buckets in multiple regions).'),
|
|
42
|
+
destination: z
|
|
43
|
+
.string()
|
|
44
|
+
.default('hashed-assets/page-kit')
|
|
45
|
+
.describe("the destination folder for uploaded assets. Set to `''` to upload assets to the top level of the bucket"),
|
|
46
|
+
extensions: z
|
|
47
|
+
.string()
|
|
48
|
+
.default('js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json')
|
|
49
|
+
.describe('file extensions to be uploaded to S3'),
|
|
50
|
+
cacheControl: z
|
|
51
|
+
.string()
|
|
52
|
+
.default('public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600')
|
|
53
|
+
.describe('header that controls how long your files stay in a CloudFront cache before CloudFront forwards another request to your origin')
|
|
54
|
+
})
|
|
55
|
+
.describe('Upload files to an AWS S3 bucket.');
|
|
56
|
+
exports.schema = exports.UploadAssetsToS3Schema;
|
|
12
57
|
class UploadAssetsToS3 extends base_1.Task {
|
|
13
58
|
async uploadFile(file, s3) {
|
|
14
59
|
const type = getFileType(file);
|
|
@@ -60,7 +105,9 @@ class UploadAssetsToS3 extends base_1.Task {
|
|
|
60
105
|
}
|
|
61
106
|
async run({ cwd }) {
|
|
62
107
|
// Wrap extensions in braces if there are multiple
|
|
63
|
-
const extensions = this.options.extensions.includes(',')
|
|
108
|
+
const extensions = this.options.extensions.includes(',')
|
|
109
|
+
? `{${this.options.extensions}}`
|
|
110
|
+
: this.options.extensions;
|
|
64
111
|
const globFile = `**/*${extensions}`;
|
|
65
112
|
const resolvedDirectory = path_1.default.resolve(cwd, this.options.directory);
|
|
66
113
|
const files = glob_1.glob.sync(globFile, { cwd: resolvedDirectory, nodir: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcom-tool-kit/upload-assets-to-s3",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@aws-sdk/client-s3": "^3.256.0",
|
|
14
|
-
"@dotcom-tool-kit/base": "^1.1.
|
|
14
|
+
"@dotcom-tool-kit/base": "^1.1.10",
|
|
15
15
|
"@dotcom-tool-kit/error": "^4.1.0",
|
|
16
16
|
"@dotcom-tool-kit/logger": "^4.1.1",
|
|
17
17
|
"glob": "^7.1.6",
|
|
18
18
|
"mime": "^2.5.2",
|
|
19
|
-
"tslib": "^2.3.1"
|
|
19
|
+
"tslib": "^2.3.1",
|
|
20
|
+
"zod": "^3.24.1"
|
|
20
21
|
},
|
|
21
22
|
"repository": {
|
|
22
23
|
"type": "git",
|
|
@@ -27,7 +28,6 @@
|
|
|
27
28
|
"homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/upload-assets-to-s3",
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@aws-sdk/types": "^3.13.1",
|
|
30
|
-
"@dotcom-tool-kit/schemas": "^1.9.0",
|
|
31
31
|
"@jest/globals": "^27.4.6",
|
|
32
32
|
"@types/glob": "^7.1.3",
|
|
33
33
|
"@types/jest": "^27.4.0",
|