carlin 1.27.0 → 1.27.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/dist/deploy/s3.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.deleteS3Directory = exports.emptyS3Directory = exports.uploadDirectoryToS3 = exports.getAllFilesInsideADirectory = exports.uploadFileToS3 = exports.getBucketKeyUrl = exports.s3 = void 0;
6
+ exports.deleteS3Directory = exports.emptyS3Directory = exports.uploadDirectoryToS3 = exports.copyRoot404To404Index = exports.getAllFilesInsideADirectory = exports.uploadFileToS3 = exports.getBucketKeyUrl = exports.s3 = void 0;
7
7
  /* eslint-disable no-restricted-syntax */
8
8
  /* eslint-disable no-await-in-loop */
9
9
  const aws_sdk_1 = require("aws-sdk");
@@ -62,6 +62,41 @@ const getAllFilesInsideADirectory = async ({ directory, }) => {
62
62
  return allFiles;
63
63
  };
64
64
  exports.getAllFilesInsideADirectory = getAllFilesInsideADirectory;
65
+ /**
66
+ * Docusaurus 2 has a 404.html file in the root of the build folder. This
67
+ * function copies it to 404/index.html so that it can be served by S3 and
68
+ * CloudFront.
69
+ */
70
+ const copyRoot404To404Index = async ({ bucket }) => {
71
+ try {
72
+ const root404Exists = await exports.s3
73
+ .headObject({
74
+ Bucket: bucket,
75
+ Key: '404.html',
76
+ })
77
+ .promise()
78
+ .catch(() => {
79
+ /**
80
+ * If the file does not exist, return false.
81
+ */
82
+ return false;
83
+ });
84
+ if (root404Exists) {
85
+ await exports.s3
86
+ .copyObject({
87
+ Bucket: bucket,
88
+ CopySource: `${bucket}/404.html`,
89
+ Key: '404/index.html',
90
+ })
91
+ .promise();
92
+ }
93
+ }
94
+ catch (err) {
95
+ npmlog_1.default.error(logPrefix, `Cannot copy 404.html to 404/index.html`);
96
+ throw err;
97
+ }
98
+ };
99
+ exports.copyRoot404To404Index = copyRoot404To404Index;
65
100
  const uploadDirectoryToS3 = async ({ bucket, bucketKey = '', directory, }) => {
66
101
  npmlog_1.default.info(logPrefix, `Uploading directory ${directory}/ to ${bucket}/${bucketKey}...`);
67
102
  const allFiles = await (0, exports.getAllFilesInsideADirectory)({ directory });
@@ -29,14 +29,23 @@ const removeOldVersions = async ({ bucket }) => {
29
29
  const { CommonPrefixes = [] } = await s3_1.s3
30
30
  .listObjectsV2({ Bucket: bucket, Delimiter: '/' })
31
31
  .promise();
32
- const versions = CommonPrefixes === null || CommonPrefixes === void 0 ? void 0 : CommonPrefixes.map(({ Prefix }) => Prefix === null || Prefix === void 0 ? void 0 : Prefix.replace('/', '')).filter((version) => semver_1.default.valid(version)).sort((a, b) => (semver_1.default.gt(a, b) ? -1 : 1));
32
+ const versions = CommonPrefixes === null || CommonPrefixes === void 0 ? void 0 : CommonPrefixes.map(({ Prefix }) => {
33
+ return Prefix === null || Prefix === void 0 ? void 0 : Prefix.replace('/', '');
34
+ }).filter((version) => {
35
+ return semver_1.default.valid(version);
36
+ }).sort((a, b) => {
37
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
38
+ return semver_1.default.gt(a, b) ? -1 : 1;
39
+ });
33
40
  /**
34
41
  * Keep the 3 most recent versions.
35
42
  */
36
43
  versions.shift();
37
44
  versions.shift();
38
45
  versions.shift();
39
- await Promise.all(versions.map((version) => (0, s3_1.deleteS3Directory)({ bucket, directory: `${version}` })));
46
+ await Promise.all(versions.map((version) => {
47
+ return (0, s3_1.deleteS3Directory)({ bucket, directory: `${version}` });
48
+ }));
40
49
  }
41
50
  catch (error) {
42
51
  npmlog_1.default.info(logPrefix, `Cannot remove older versions from "${bucket}" bucket.`);
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStaticAppTemplate = exports.ROUTE_53_RECORD_SET_GROUP_LOGICAL_ID = exports.CLOUDFRONT_ORIGIN_ACCESS_CONTROL_LOGICAL_ID = exports.CLOUDFRONT_DISTRIBUTION_LOGICAL_ID = exports.STATIC_APP_BUCKET_LOGICAL_ID = void 0;
3
+ exports.getStaticAppTemplate = exports.ERROR_DOCUMENT = exports.ROUTE_53_RECORD_SET_GROUP_LOGICAL_ID = exports.CLOUDFRONT_ORIGIN_ACCESS_CONTROL_LOGICAL_ID = exports.CLOUDFRONT_DISTRIBUTION_LOGICAL_ID = exports.STATIC_APP_BUCKET_LOGICAL_ID = void 0;
4
4
  const utils_1 = require("../../utils");
5
5
  const PACKAGE_VERSION = (0, utils_1.getPackageVersion)();
6
6
  exports.STATIC_APP_BUCKET_LOGICAL_ID = 'StaticBucket';
7
7
  exports.CLOUDFRONT_DISTRIBUTION_LOGICAL_ID = 'CloudFrontDistribution';
8
8
  exports.CLOUDFRONT_ORIGIN_ACCESS_CONTROL_LOGICAL_ID = 'OriginAccessControl';
9
9
  exports.ROUTE_53_RECORD_SET_GROUP_LOGICAL_ID = 'Route53RecordSetGroup';
10
+ exports.ERROR_DOCUMENT = '404/index.html';
10
11
  /**
11
12
  * Name: Managed-CachingDisabled
12
13
  * ID: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad
@@ -48,7 +49,7 @@ const getBucketStaticWebsiteTemplate = ({ spa, }) => {
48
49
  },
49
50
  WebsiteConfiguration: {
50
51
  IndexDocument: `index.html`,
51
- ErrorDocument: spa ? 'index.html' : '404/index.html',
52
+ ErrorDocument: spa ? 'index.html' : exports.ERROR_DOCUMENT,
52
53
  },
53
54
  },
54
55
  },
@@ -174,7 +175,7 @@ const getCloudFrontTemplate = ({ acm, aliases = [], spa, hostedZoneName, }) => {
174
175
  ErrorCachingMinTTL: 0,
175
176
  ErrorCode: errorCode,
176
177
  ResponseCode: 404,
177
- ResponsePagePath: '/404',
178
+ ResponsePagePath: '/' + exports.ERROR_DOCUMENT,
178
179
  };
179
180
  }),
180
181
  DefaultCacheBehavior: {
@@ -195,7 +196,7 @@ const getCloudFrontTemplate = ({ acm, aliases = [], spa, hostedZoneName, }) => {
195
196
  TargetOriginId: { Ref: exports.STATIC_APP_BUCKET_LOGICAL_ID },
196
197
  ViewerProtocolPolicy: 'redirect-to-https',
197
198
  },
198
- DefaultRootObject: spa ? 'index.html' : undefined,
199
+ DefaultRootObject: 'index.html',
199
200
  Enabled: true,
200
201
  HttpVersion: 'http2',
201
202
  Origins: [
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.uploadBuiltAppToS3 = void 0;
4
- const findDefaultBuildFolder_1 = require("./findDefaultBuildFolder");
5
4
  const s3_1 = require("../s3");
5
+ const findDefaultBuildFolder_1 = require("./findDefaultBuildFolder");
6
6
  const uploadBuiltAppToS3 = async ({ buildFolder: directory, bucket, }) => {
7
7
  /**
8
8
  * Only empty directory if the number of the files inside $directory.
@@ -20,6 +20,7 @@ const uploadBuiltAppToS3 = async ({ buildFolder: directory, bucket, }) => {
20
20
  if (defaultDirectory) {
21
21
  await (0, s3_1.emptyS3Directory)({ bucket });
22
22
  await (0, s3_1.uploadDirectoryToS3)({ bucket, directory: defaultDirectory });
23
+ await (0, s3_1.copyRoot404To404Index)({ bucket });
23
24
  return;
24
25
  }
25
26
  throw new Error(`build-folder option wasn't provided and files weren't found in ${findDefaultBuildFolder_1.defaultBuildFolders.join(', ')} directories.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "1.27.0",
3
+ "version": "1.27.1",
4
4
  "description": "",
5
5
  "license": "GPL-3.0",
6
6
  "author": "Pedro Arantes <arantespp@gmail.com> (https://twitter.com/arantespp)",
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "20c0a3590f47b7c4b6b866080a6d00bc9fb9a0b1"
74
+ "gitHead": "3d6ffa89bf6f83619ac12a3688e8250e47c1a8c6"
75
75
  }