carlin 1.31.18 → 1.31.20
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/index.js +242 -412
- package/package.json +7 -4
package/dist/index.js
CHANGED
|
@@ -1,8 +1,45 @@
|
|
|
1
|
+
import AWS from 'aws-sdk';
|
|
2
|
+
import log5 from 'npmlog';
|
|
3
|
+
import yaml4 from 'js-yaml';
|
|
4
|
+
import 'uglify-js';
|
|
5
|
+
import 'prettier';
|
|
6
|
+
import git from 'simple-git';
|
|
7
|
+
import findUpSync from 'findup-sync';
|
|
8
|
+
import * as fs3 from 'fs';
|
|
9
|
+
import fs3__default from 'fs';
|
|
10
|
+
import { pascalCase, constantCase, kebabCase, camelCase } from 'change-case';
|
|
11
|
+
import { stdout } from 'process';
|
|
12
|
+
import childProcess from 'child_process';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import path__default from 'path';
|
|
15
|
+
import { ValidateTemplateCommand, CloudFormationClient, DeleteStackCommand, CreateStackCommand, UpdateStackCommand, UpdateTerminationProtectionCommand, DescribeStacksCommand, DescribeStackEventsCommand, DescribeStackResourceCommand } from '@aws-sdk/client-cloudformation';
|
|
16
|
+
import { glob } from 'glob';
|
|
17
|
+
import mime from 'mime-types';
|
|
18
|
+
import deepmerge from 'deepmerge';
|
|
19
|
+
import { hideBin } from 'yargs/helpers';
|
|
20
|
+
import yargs from 'yargs';
|
|
21
|
+
import * as esbuild from 'esbuild';
|
|
22
|
+
import { typescriptConfig } from '@ttoss/config';
|
|
23
|
+
import builtins from 'builtin-modules';
|
|
24
|
+
import AdmZip from 'adm-zip';
|
|
25
|
+
import importSync from 'import-sync';
|
|
26
|
+
import semver from 'semver';
|
|
27
|
+
import deepEqual from 'deep-equal';
|
|
28
|
+
|
|
29
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
30
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
31
|
+
}) : x)(function(x) {
|
|
32
|
+
if (typeof require !== "undefined")
|
|
33
|
+
return require.apply(this, arguments);
|
|
34
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
35
|
+
});
|
|
36
|
+
|
|
1
37
|
// src/config.ts
|
|
2
38
|
var NAME = "carlin";
|
|
3
39
|
var AWS_DEFAULT_REGION = "us-east-1";
|
|
4
40
|
var CLOUDFRONT_REGION = "us-east-1";
|
|
5
|
-
var
|
|
41
|
+
var NODE_VERSION = "20";
|
|
42
|
+
var NODE_RUNTIME = `nodejs${NODE_VERSION}.x`;
|
|
6
43
|
|
|
7
44
|
// src/utils/addGroupToOptions.ts
|
|
8
45
|
var addGroupToOptions = (options9, group) => {
|
|
@@ -11,10 +48,6 @@ var addGroupToOptions = (options9, group) => {
|
|
|
11
48
|
});
|
|
12
49
|
return options9;
|
|
13
50
|
};
|
|
14
|
-
|
|
15
|
-
// src/utils/codeBuild.ts
|
|
16
|
-
import AWS from "aws-sdk";
|
|
17
|
-
import log from "npmlog";
|
|
18
51
|
var logPrefix = "codebuild";
|
|
19
52
|
var WAIT_TIME = 10 * 1e3;
|
|
20
53
|
var waitCodeBuildFinish = async ({
|
|
@@ -30,7 +63,7 @@ var waitCodeBuildFinish = async ({
|
|
|
30
63
|
const executedBuild = builds?.find(({ id }) => {
|
|
31
64
|
return id === buildId;
|
|
32
65
|
});
|
|
33
|
-
|
|
66
|
+
log5.info(
|
|
34
67
|
logPrefix,
|
|
35
68
|
`Build status of ${name || buildId}: ${executedBuild?.buildStatus}`
|
|
36
69
|
);
|
|
@@ -61,9 +94,6 @@ var startCodeBuildBuild = async ({
|
|
|
61
94
|
return build;
|
|
62
95
|
};
|
|
63
96
|
|
|
64
|
-
// src/utils/cloudFormationTemplate.ts
|
|
65
|
-
import yaml from "js-yaml";
|
|
66
|
-
|
|
67
97
|
// src/utils/environmentVariables.ts
|
|
68
98
|
var cache = /* @__PURE__ */ new Map();
|
|
69
99
|
var getEnvVar = (key) => {
|
|
@@ -75,25 +105,12 @@ var setEnvVar = (key, value) => {
|
|
|
75
105
|
}
|
|
76
106
|
return cache.set(key, value);
|
|
77
107
|
};
|
|
78
|
-
|
|
79
|
-
// src/utils/exec.ts
|
|
80
|
-
import log2 from "npmlog";
|
|
81
|
-
log2.heading = "exec";
|
|
82
|
-
|
|
83
|
-
// src/utils/formatCode.ts
|
|
84
|
-
import * as UglifyJS from "uglify-js";
|
|
85
|
-
import * as prettier from "prettier";
|
|
86
|
-
|
|
87
|
-
// src/utils/getAwsAccountId.ts
|
|
88
|
-
import AWS2 from "aws-sdk";
|
|
108
|
+
log5.heading = "exec";
|
|
89
109
|
var getAwsAccountId = async () => {
|
|
90
|
-
const sts = new
|
|
110
|
+
const sts = new AWS.STS();
|
|
91
111
|
const { Account } = await sts.getCallerIdentity().promise();
|
|
92
112
|
return Account;
|
|
93
113
|
};
|
|
94
|
-
|
|
95
|
-
// src/utils/getCurrentBranch.ts
|
|
96
|
-
import git from "simple-git";
|
|
97
114
|
var BRANCH_UNDEFINED = "";
|
|
98
115
|
var getCurrentBranch = async () => {
|
|
99
116
|
try {
|
|
@@ -114,16 +131,12 @@ var getEnvironment = () => {
|
|
|
114
131
|
|
|
115
132
|
// src/utils/getIamPath.ts
|
|
116
133
|
var getIamPath = () => `/${NAME}/`;
|
|
117
|
-
|
|
118
|
-
// src/utils/packageJson.ts
|
|
119
|
-
import findUpSync from "findup-sync";
|
|
120
|
-
import fs from "fs";
|
|
121
134
|
var readPackageJson = () => {
|
|
122
135
|
const packageJsonDir = findUpSync("package.json");
|
|
123
136
|
if (!packageJsonDir) {
|
|
124
137
|
return {};
|
|
125
138
|
}
|
|
126
|
-
return JSON.parse(
|
|
139
|
+
return JSON.parse(fs3__default.readFileSync(packageJsonDir).toString());
|
|
127
140
|
};
|
|
128
141
|
var getPackageJsonProperty = ({ property }) => {
|
|
129
142
|
try {
|
|
@@ -138,9 +151,6 @@ var getPackageName = () => {
|
|
|
138
151
|
var getPackageVersion = () => {
|
|
139
152
|
return getPackageJsonProperty({ property: "version" });
|
|
140
153
|
};
|
|
141
|
-
|
|
142
|
-
// src/utils/getProjectName.ts
|
|
143
|
-
import { pascalCase } from "change-case";
|
|
144
154
|
var getProjectName = () => {
|
|
145
155
|
if (getEnvVar("PROJECT")) {
|
|
146
156
|
return getEnvVar("PROJECT");
|
|
@@ -155,12 +165,7 @@ var getProjectName = () => {
|
|
|
155
165
|
return pascalCase(name);
|
|
156
166
|
}
|
|
157
167
|
};
|
|
158
|
-
|
|
159
|
-
// src/utils/spawn.ts
|
|
160
|
-
import { stdout } from "process";
|
|
161
|
-
import childProcess from "child_process";
|
|
162
|
-
import log3 from "npmlog";
|
|
163
|
-
log3.heading = "exec";
|
|
168
|
+
log5.heading = "exec";
|
|
164
169
|
var spawn = (cmd) => {
|
|
165
170
|
return new Promise((resolve6, reject) => {
|
|
166
171
|
const [cmdName, ...cmdArgs] = cmd.split(" ");
|
|
@@ -183,13 +188,7 @@ var spawn = (cmd) => {
|
|
|
183
188
|
});
|
|
184
189
|
});
|
|
185
190
|
};
|
|
186
|
-
|
|
187
|
-
// src/cli.ts
|
|
188
|
-
import { constantCase, kebabCase as kebabCase2 } from "change-case";
|
|
189
|
-
|
|
190
|
-
// src/deploy/baseStack/config.ts
|
|
191
|
-
import { pascalCase as pascalCase2 } from "change-case";
|
|
192
|
-
var pascalCaseName = pascalCase2(NAME);
|
|
191
|
+
var pascalCaseName = pascalCase(NAME);
|
|
193
192
|
var BASE_STACK_NAME = `${pascalCaseName}BaseStack`;
|
|
194
193
|
var BASE_STACK_BUCKET_TEMPLATES_FOLDER = "cloudformation-templates";
|
|
195
194
|
var BASE_STACK_BUCKET_LOGICAL_NAME = `${pascalCaseName}Bucket`;
|
|
@@ -203,22 +202,6 @@ var BASE_STACK_VPC_PUBLIC_SUBNET_0_EXPORTED_NAME = `${pascalCaseName}VPCPublicSu
|
|
|
203
202
|
var BASE_STACK_VPC_PUBLIC_SUBNET_1_EXPORTED_NAME = `${pascalCaseName}VPCPublicSubnet1ExportedName`;
|
|
204
203
|
var BASE_STACK_VPC_PUBLIC_SUBNET_2_EXPORTED_NAME = `${pascalCaseName}VPCPublicSubnet2ExportedName`;
|
|
205
204
|
|
|
206
|
-
// src/deploy/cloudformation.core.ts
|
|
207
|
-
import * as fs3 from "fs";
|
|
208
|
-
import * as path2 from "path";
|
|
209
|
-
import {
|
|
210
|
-
CloudFormationClient,
|
|
211
|
-
CreateStackCommand,
|
|
212
|
-
DeleteStackCommand,
|
|
213
|
-
DescribeStackEventsCommand,
|
|
214
|
-
DescribeStackResourceCommand,
|
|
215
|
-
DescribeStacksCommand,
|
|
216
|
-
ListStackResourcesCommand,
|
|
217
|
-
UpdateStackCommand,
|
|
218
|
-
UpdateTerminationProtectionCommand,
|
|
219
|
-
ValidateTemplateCommand
|
|
220
|
-
} from "@aws-sdk/client-cloudformation";
|
|
221
|
-
|
|
222
205
|
// src/deploy/addDefaults.cloudformation.ts
|
|
223
206
|
var addDefaultsParametersAndTagsToParams = async (params) => {
|
|
224
207
|
const branchName = await getCurrentBranch();
|
|
@@ -360,16 +343,8 @@ var addDefaults = async ({
|
|
|
360
343
|
};
|
|
361
344
|
return response;
|
|
362
345
|
};
|
|
363
|
-
|
|
364
|
-
// src/deploy/s3.ts
|
|
365
|
-
import { glob } from "glob";
|
|
366
|
-
import AWS3 from "aws-sdk";
|
|
367
|
-
import fs2 from "fs";
|
|
368
|
-
import log4 from "npmlog";
|
|
369
|
-
import mime from "mime-types";
|
|
370
|
-
import path from "path";
|
|
371
346
|
var logPrefix2 = "s3";
|
|
372
|
-
var s3 = new
|
|
347
|
+
var s3 = new AWS.S3({ apiVersion: "2006-03-01" });
|
|
373
348
|
var getBucketKeyUrl = ({
|
|
374
349
|
bucket,
|
|
375
350
|
key
|
|
@@ -388,16 +363,16 @@ var uploadFileToS3 = async ({
|
|
|
388
363
|
}
|
|
389
364
|
let params = {
|
|
390
365
|
Bucket: bucket,
|
|
391
|
-
Key: key.split(
|
|
366
|
+
Key: key.split(path__default.sep).join("/")
|
|
392
367
|
};
|
|
393
368
|
if (file) {
|
|
394
369
|
params.ContentType = contentType;
|
|
395
370
|
params.Body = file;
|
|
396
371
|
} else if (filePath) {
|
|
397
|
-
const readFile = await
|
|
372
|
+
const readFile = await fs3__default.promises.readFile(filePath);
|
|
398
373
|
params = {
|
|
399
374
|
...params,
|
|
400
|
-
ContentType: contentType || mime.contentType(
|
|
375
|
+
ContentType: contentType || mime.contentType(path__default.extname(filePath)) || void 0
|
|
401
376
|
};
|
|
402
377
|
params.Body = Buffer.from(readFile);
|
|
403
378
|
}
|
|
@@ -414,7 +389,7 @@ var getAllFilesInsideADirectory = async ({
|
|
|
414
389
|
}) => {
|
|
415
390
|
const allFilesAndDirectories = await glob(`${directory}/**/*`);
|
|
416
391
|
const allFiles = allFilesAndDirectories.filter((item) => {
|
|
417
|
-
return
|
|
392
|
+
return fs3__default.lstatSync(item).isFile();
|
|
418
393
|
});
|
|
419
394
|
return allFiles;
|
|
420
395
|
};
|
|
@@ -434,7 +409,7 @@ var copyRoot404To404Index = async ({ bucket }) => {
|
|
|
434
409
|
}).promise();
|
|
435
410
|
}
|
|
436
411
|
} catch (err) {
|
|
437
|
-
|
|
412
|
+
log5.error(logPrefix2, `Cannot copy 404.html to 404/index.html`);
|
|
438
413
|
throw err;
|
|
439
414
|
}
|
|
440
415
|
};
|
|
@@ -443,7 +418,7 @@ var uploadDirectoryToS3 = async ({
|
|
|
443
418
|
bucketKey = "",
|
|
444
419
|
directory
|
|
445
420
|
}) => {
|
|
446
|
-
|
|
421
|
+
log5.info(
|
|
447
422
|
logPrefix2,
|
|
448
423
|
`Uploading directory ${directory}/ to ${bucket}/${bucketKey}...`
|
|
449
424
|
);
|
|
@@ -462,12 +437,12 @@ var uploadDirectoryToS3 = async ({
|
|
|
462
437
|
return acc;
|
|
463
438
|
}, []);
|
|
464
439
|
for (const [index, groupOfFiles] of aoaOfFiles.entries()) {
|
|
465
|
-
|
|
440
|
+
log5.info(logPrefix2, `Uploading group ${index + 1}/${aoaOfFiles.length}...`);
|
|
466
441
|
await Promise.all(
|
|
467
442
|
groupOfFiles.map((file) => {
|
|
468
443
|
return uploadFileToS3({
|
|
469
444
|
bucket,
|
|
470
|
-
key:
|
|
445
|
+
key: path__default.join(bucketKey, path__default.relative(directory, file)),
|
|
471
446
|
filePath: file
|
|
472
447
|
});
|
|
473
448
|
})
|
|
@@ -478,7 +453,7 @@ var emptyS3Directory = async ({
|
|
|
478
453
|
bucket,
|
|
479
454
|
directory = ""
|
|
480
455
|
}) => {
|
|
481
|
-
|
|
456
|
+
log5.info(logPrefix2, `${bucket}/${directory} will be empty`);
|
|
482
457
|
try {
|
|
483
458
|
const { Contents, IsTruncated } = await s3.listObjectsV2({
|
|
484
459
|
Bucket: bucket,
|
|
@@ -517,9 +492,9 @@ var emptyS3Directory = async ({
|
|
|
517
492
|
if (IsTruncated) {
|
|
518
493
|
await emptyS3Directory({ bucket, directory });
|
|
519
494
|
}
|
|
520
|
-
|
|
495
|
+
log5.info(logPrefix2, `${bucket}/${directory} is empty.`);
|
|
521
496
|
} catch (err) {
|
|
522
|
-
|
|
497
|
+
log5.error(logPrefix2, `Cannot empty ${bucket}/${directory}.`);
|
|
523
498
|
throw err;
|
|
524
499
|
}
|
|
525
500
|
};
|
|
@@ -528,12 +503,12 @@ var deleteS3Directory = async ({
|
|
|
528
503
|
directory = ""
|
|
529
504
|
}) => {
|
|
530
505
|
try {
|
|
531
|
-
|
|
506
|
+
log5.info(logPrefix2, `${bucket}/${directory} is being deleted...`);
|
|
532
507
|
await emptyS3Directory({ bucket, directory });
|
|
533
508
|
await s3.deleteObject({ Bucket: bucket, Key: directory }).promise();
|
|
534
|
-
|
|
509
|
+
log5.info(logPrefix2, `${bucket}/${directory} was deleted.`);
|
|
535
510
|
} catch (error) {
|
|
536
|
-
|
|
511
|
+
log5.error(logPrefix2, `Cannot delete ${bucket}/${directory}.`);
|
|
537
512
|
throw error;
|
|
538
513
|
}
|
|
539
514
|
};
|
|
@@ -558,10 +533,6 @@ var getBaseStackResource = async (resource) => {
|
|
|
558
533
|
}
|
|
559
534
|
return resources[resource];
|
|
560
535
|
};
|
|
561
|
-
|
|
562
|
-
// src/deploy/cloudformation.core.ts
|
|
563
|
-
import AWS4 from "aws-sdk";
|
|
564
|
-
import log5 from "npmlog";
|
|
565
536
|
var logPrefix3 = "cloudformation";
|
|
566
537
|
log5.addLevel("event", 1e4, { fg: "yellow" });
|
|
567
538
|
log5.addLevel("output", 1e4, { fg: "blue" });
|
|
@@ -600,7 +571,7 @@ var cloudformation = () => {
|
|
|
600
571
|
return cloudFormationClients[key];
|
|
601
572
|
};
|
|
602
573
|
var cloudFormationV2 = () => {
|
|
603
|
-
return new
|
|
574
|
+
return new AWS.CloudFormation({ apiVersion: "2010-05-15" });
|
|
604
575
|
};
|
|
605
576
|
var describeStacks = async ({
|
|
606
577
|
stackName
|
|
@@ -678,11 +649,11 @@ var saveEnvironmentOutput = async ({
|
|
|
678
649
|
[output.OutputKey]: output
|
|
679
650
|
};
|
|
680
651
|
}, {});
|
|
681
|
-
const dotCarlinFolderPath =
|
|
652
|
+
const dotCarlinFolderPath = path.join(process.cwd(), ".carlin");
|
|
682
653
|
if (!fs3.existsSync(dotCarlinFolderPath)) {
|
|
683
654
|
await fs3.promises.mkdir(dotCarlinFolderPath);
|
|
684
655
|
}
|
|
685
|
-
const filePath =
|
|
656
|
+
const filePath = path.join(dotCarlinFolderPath, `${stackName}.json`);
|
|
686
657
|
await fs3.promises.writeFile(filePath, JSON.stringify(envFile, null, 2));
|
|
687
658
|
};
|
|
688
659
|
var printStackOutputsAfterDeploy = async ({
|
|
@@ -777,11 +748,6 @@ var enableTerminationProtection = async ({
|
|
|
777
748
|
throw err;
|
|
778
749
|
}
|
|
779
750
|
};
|
|
780
|
-
var defaultTemplatePaths = ["ts", "js", "yaml", "yml", "json"].map(
|
|
781
|
-
(extension) => {
|
|
782
|
-
return `src/cloudformation.${extension}`;
|
|
783
|
-
}
|
|
784
|
-
);
|
|
785
751
|
var deploy = async ({
|
|
786
752
|
terminationProtection = false,
|
|
787
753
|
...paramsAndTemplate
|
|
@@ -886,9 +852,6 @@ var getBucketTemplate = () => {
|
|
|
886
852
|
}
|
|
887
853
|
};
|
|
888
854
|
};
|
|
889
|
-
|
|
890
|
-
// src/deploy/baseStack/getLambdaImageBuilderTemplate.ts
|
|
891
|
-
import yaml2 from "js-yaml";
|
|
892
855
|
var getLambdaImageBuilderTemplate = () => {
|
|
893
856
|
const CODE_BUILD_PROJECT_LOGS_LOGICAL_ID2 = "CodeBuildProjectLogsLogGroup";
|
|
894
857
|
const CODE_BUILD_PROJECT_SERVICE_ROLE_LOGICAL_ID2 = "ImageCodeBuildProjectIAMRole";
|
|
@@ -1013,7 +976,7 @@ var getLambdaImageBuilderTemplate = () => {
|
|
|
1013
976
|
"Fn::GetAtt": [CODE_BUILD_PROJECT_SERVICE_ROLE_LOGICAL_ID2, "Arn"]
|
|
1014
977
|
},
|
|
1015
978
|
Source: {
|
|
1016
|
-
BuildSpec:
|
|
979
|
+
BuildSpec: yaml4.dump({
|
|
1017
980
|
version: "0.2",
|
|
1018
981
|
phases: {
|
|
1019
982
|
install: {
|
|
@@ -1077,7 +1040,7 @@ version: 0.2
|
|
|
1077
1040
|
phases:
|
|
1078
1041
|
install:
|
|
1079
1042
|
runtime-versions:
|
|
1080
|
-
nodejs:
|
|
1043
|
+
nodejs: ${NODE_VERSION}
|
|
1081
1044
|
commands:
|
|
1082
1045
|
- npm i --no-bin-links --no-optional --no-package-lock --no-save --no-shrinkwrap $PACKAGE_NAME
|
|
1083
1046
|
- mkdir nodejs
|
|
@@ -1170,7 +1133,11 @@ var getLambdaLayerBuilderTemplate = () => {
|
|
|
1170
1133
|
},
|
|
1171
1134
|
Environment: {
|
|
1172
1135
|
ComputeType: "BUILD_GENERAL1_SMALL",
|
|
1173
|
-
|
|
1136
|
+
/**
|
|
1137
|
+
* Image should match the runtime of the buildspec.
|
|
1138
|
+
* https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
|
|
1139
|
+
*/
|
|
1140
|
+
Image: "aws/codebuild/standard:7.0",
|
|
1174
1141
|
Type: "LINUX_CONTAINER"
|
|
1175
1142
|
},
|
|
1176
1143
|
LogsConfig: {
|
|
@@ -1198,11 +1165,8 @@ var getLambdaLayerBuilderTemplate = () => {
|
|
|
1198
1165
|
}
|
|
1199
1166
|
};
|
|
1200
1167
|
};
|
|
1201
|
-
|
|
1202
|
-
// src/deploy/baseStack/getVpcTemplate.ts
|
|
1203
|
-
import { pascalCase as pascalCase3 } from "change-case";
|
|
1204
1168
|
var getVpcTemplate = () => {
|
|
1205
|
-
const vpcName = `${
|
|
1169
|
+
const vpcName = `${pascalCase(NAME)}VPC`;
|
|
1206
1170
|
const EC2_INTERNET_GATEWAY_LOGICAL_ID = "EC2InternetGateway";
|
|
1207
1171
|
const EC2_ROUTE_TABLE_LOGICAL_ID = "EC2RouteTable";
|
|
1208
1172
|
const EC2_VPC_LOGICAL_ID = "EC2VCP";
|
|
@@ -1363,9 +1327,6 @@ var getVpcTemplate = () => {
|
|
|
1363
1327
|
});
|
|
1364
1328
|
return template;
|
|
1365
1329
|
};
|
|
1366
|
-
|
|
1367
|
-
// src/deploy/stackName.ts
|
|
1368
|
-
import { kebabCase, pascalCase as pascalCase4 } from "change-case";
|
|
1369
1330
|
var setPreDefinedStackName = (stackName) => {
|
|
1370
1331
|
setEnvVar("STACK_NAME", stackName);
|
|
1371
1332
|
};
|
|
@@ -1382,7 +1343,7 @@ var getStackName = async () => {
|
|
|
1382
1343
|
getEnvironment(),
|
|
1383
1344
|
getPackageName()
|
|
1384
1345
|
]);
|
|
1385
|
-
const firstName = packageName ?
|
|
1346
|
+
const firstName = packageName ? pascalCase(packageName) : `Stack-${Math.round(Math.random() * 1e5)}`;
|
|
1386
1347
|
const secondName = (() => {
|
|
1387
1348
|
if (environment) {
|
|
1388
1349
|
return environment;
|
|
@@ -1397,15 +1358,12 @@ var getStackName = async () => {
|
|
|
1397
1358
|
}).join("-");
|
|
1398
1359
|
return limitStackName(name);
|
|
1399
1360
|
};
|
|
1400
|
-
|
|
1401
|
-
// src/deploy/utils.ts
|
|
1402
|
-
import log6 from "npmlog";
|
|
1403
1361
|
var deployErrorLogs = ({
|
|
1404
1362
|
error,
|
|
1405
1363
|
logPrefix: logPrefix22
|
|
1406
1364
|
}) => {
|
|
1407
|
-
|
|
1408
|
-
|
|
1365
|
+
log5.error(logPrefix22, `An error occurred. Cannot deploy ${logPrefix22}.`);
|
|
1366
|
+
log5.error(logPrefix22, "Error message: %j", error?.message);
|
|
1409
1367
|
};
|
|
1410
1368
|
var handleDeployError = ({
|
|
1411
1369
|
error,
|
|
@@ -1418,17 +1376,14 @@ var handleDeployInitialization = async ({
|
|
|
1418
1376
|
logPrefix: logPrefix22,
|
|
1419
1377
|
stackName: preDefinedStackName
|
|
1420
1378
|
}) => {
|
|
1421
|
-
|
|
1379
|
+
log5.info(logPrefix22, `Starting deploy ${logPrefix22}...`);
|
|
1422
1380
|
if (preDefinedStackName) {
|
|
1423
1381
|
setPreDefinedStackName(preDefinedStackName);
|
|
1424
1382
|
}
|
|
1425
1383
|
const stackName = await getStackName();
|
|
1426
|
-
|
|
1384
|
+
log5.info(logPrefix22, `stackName: ${stackName}`);
|
|
1427
1385
|
return { stackName };
|
|
1428
1386
|
};
|
|
1429
|
-
|
|
1430
|
-
// src/deploy/baseStack/deployBaseStack.ts
|
|
1431
|
-
import deepmerge from "deepmerge";
|
|
1432
1387
|
var logPrefix4 = "base-stack";
|
|
1433
1388
|
var baseStackTemplate = deepmerge.all([
|
|
1434
1389
|
getBucketTemplate(),
|
|
@@ -1459,14 +1414,6 @@ var deployBaseStackCommand = {
|
|
|
1459
1414
|
handler: deployBaseStack
|
|
1460
1415
|
};
|
|
1461
1416
|
|
|
1462
|
-
// src/deploy/cicd/deployCicd.ts
|
|
1463
|
-
import * as fs7 from "fs";
|
|
1464
|
-
import * as path6 from "path";
|
|
1465
|
-
|
|
1466
|
-
// src/deploy/cicd/command.options.ts
|
|
1467
|
-
import { camelCase } from "change-case";
|
|
1468
|
-
import { hideBin } from "yargs/helpers";
|
|
1469
|
-
|
|
1470
1417
|
// src/deploy/cicd/config.ts
|
|
1471
1418
|
var ECS_TASK_DEFAULT_CPU = "2048";
|
|
1472
1419
|
var ECS_TASK_DEFAULT_MEMORY = "4096";
|
|
@@ -1475,9 +1422,6 @@ var PIPELINE_ECS_TASK_EXECUTION_MANUAL_APPROVAL_ACTION_NAME = `PipelineRunECSTas
|
|
|
1475
1422
|
|
|
1476
1423
|
// src/deploy/cicd/pipelines.ts
|
|
1477
1424
|
var pipelines = ["pr", "main", "tag"];
|
|
1478
|
-
|
|
1479
|
-
// src/deploy/cicd/command.options.ts
|
|
1480
|
-
import yargs from "yargs";
|
|
1481
1425
|
var options = {
|
|
1482
1426
|
cpu: {
|
|
1483
1427
|
type: "string"
|
|
@@ -1553,10 +1497,6 @@ var getTriggerPipelinesObjectKey = ({
|
|
|
1553
1497
|
}) => {
|
|
1554
1498
|
return `${prefix}/${pipeline}.zip`;
|
|
1555
1499
|
};
|
|
1556
|
-
|
|
1557
|
-
// src/deploy/cicd/cicd.template.ts
|
|
1558
|
-
import { pascalCase as pascalCase5 } from "change-case";
|
|
1559
|
-
import yaml3 from "js-yaml";
|
|
1560
1500
|
var API_LOGICAL_ID = "ApiV1ServerlessApi";
|
|
1561
1501
|
var CODE_BUILD_PROJECT_LOGS_LOGICAL_ID = "RepositoryImageCodeBuildProjectLogsLogGroup";
|
|
1562
1502
|
var CODE_BUILD_PROJECT_SERVICE_ROLE_LOGICAL_ID = "RepositoryImageCodeBuildProjectIAMRole";
|
|
@@ -1687,7 +1627,7 @@ var getRepositoryImageBuilder = () => {
|
|
|
1687
1627
|
"Fn::GetAtt": [CODE_BUILD_PROJECT_SERVICE_ROLE_LOGICAL_ID, "Arn"]
|
|
1688
1628
|
},
|
|
1689
1629
|
Source: {
|
|
1690
|
-
BuildSpec:
|
|
1630
|
+
BuildSpec: yaml4.dump({
|
|
1691
1631
|
version: "0.2",
|
|
1692
1632
|
phases: {
|
|
1693
1633
|
install: {
|
|
@@ -2336,7 +2276,7 @@ var getCicdTemplate = ({
|
|
|
2336
2276
|
}
|
|
2337
2277
|
};
|
|
2338
2278
|
const getCodePipelinePipeline = (pipeline) => {
|
|
2339
|
-
const pipelinePascalCase =
|
|
2279
|
+
const pipelinePascalCase = pascalCase(pipeline);
|
|
2340
2280
|
const pipelineS3SourceOutputName = `Pipeline${pipelinePascalCase}S3SourceOutput`;
|
|
2341
2281
|
return {
|
|
2342
2282
|
Type: "AWS::CodePipeline::Pipeline",
|
|
@@ -2451,12 +2391,6 @@ var getCicdTemplate = ({
|
|
|
2451
2391
|
}
|
|
2452
2392
|
};
|
|
2453
2393
|
};
|
|
2454
|
-
|
|
2455
|
-
// src/deploy/lambda/buildLambdaSingleFile.ts
|
|
2456
|
-
import * as esbuild from "esbuild";
|
|
2457
|
-
import builtins from "builtin-modules";
|
|
2458
|
-
import log7 from "npmlog";
|
|
2459
|
-
import path3 from "path";
|
|
2460
2394
|
var logPrefix5 = "lambda";
|
|
2461
2395
|
var outFolder = "dist";
|
|
2462
2396
|
var outFile = "index.js";
|
|
@@ -2464,13 +2398,13 @@ var buildLambdaSingleFile = async ({
|
|
|
2464
2398
|
lambdaExternals,
|
|
2465
2399
|
lambdaInput
|
|
2466
2400
|
}) => {
|
|
2467
|
-
|
|
2401
|
+
log5.info(logPrefix5, "Building Lambda single file...");
|
|
2468
2402
|
const { errors } = esbuild.buildSync({
|
|
2469
2403
|
banner: {
|
|
2470
2404
|
js: "// Powered by carlin (https://ttoss.dev/docs/carlin/)"
|
|
2471
2405
|
},
|
|
2472
2406
|
bundle: true,
|
|
2473
|
-
entryPoints: [
|
|
2407
|
+
entryPoints: [path__default.resolve(process.cwd(), lambdaInput)],
|
|
2474
2408
|
external: [
|
|
2475
2409
|
/**
|
|
2476
2410
|
* Only AWS SDK v3 on Node.js 18.x or higher.
|
|
@@ -2480,26 +2414,24 @@ var buildLambdaSingleFile = async ({
|
|
|
2480
2414
|
...builtins,
|
|
2481
2415
|
...lambdaExternals
|
|
2482
2416
|
],
|
|
2417
|
+
/**
|
|
2418
|
+
* Some packages as `graphql` are not compatible with ESM yet.
|
|
2419
|
+
* https://github.com/graphql/graphql-js/issues/3603
|
|
2420
|
+
*/
|
|
2421
|
+
format: "cjs",
|
|
2483
2422
|
/**
|
|
2484
2423
|
* https://esbuild.github.io/api/#minify
|
|
2485
2424
|
*/
|
|
2486
2425
|
minifySyntax: true,
|
|
2487
2426
|
platform: "node",
|
|
2488
|
-
outfile:
|
|
2489
|
-
target:
|
|
2427
|
+
outfile: path__default.join(process.cwd(), outFolder, outFile),
|
|
2428
|
+
target: typescriptConfig.target,
|
|
2490
2429
|
treeShaking: true
|
|
2491
2430
|
});
|
|
2492
2431
|
if (errors.length > 0) {
|
|
2493
2432
|
throw errors;
|
|
2494
2433
|
}
|
|
2495
2434
|
};
|
|
2496
|
-
|
|
2497
|
-
// src/deploy/lambda/deployLambdaLayers.ts
|
|
2498
|
-
import * as fs4 from "fs";
|
|
2499
|
-
import * as path4 from "path";
|
|
2500
|
-
|
|
2501
|
-
// src/deploy/lambdaLayer/getPackageLambdaLayerStackName.ts
|
|
2502
|
-
import { pascalCase as pascalCase6 } from "change-case";
|
|
2503
2435
|
var lambdaLayerStackNamePrefix = `LambdaLayer`;
|
|
2504
2436
|
var getPackageLambdaLayerStackName = (packageName) => {
|
|
2505
2437
|
const [scopedName, version] = packageName.split("@").filter((part) => {
|
|
@@ -2507,21 +2439,17 @@ var getPackageLambdaLayerStackName = (packageName) => {
|
|
|
2507
2439
|
});
|
|
2508
2440
|
return [
|
|
2509
2441
|
lambdaLayerStackNamePrefix,
|
|
2510
|
-
|
|
2442
|
+
pascalCase(scopedName),
|
|
2511
2443
|
version.replace(/[^0-9.]/g, "").replace(/\./g, "-")
|
|
2512
2444
|
].join("-");
|
|
2513
2445
|
};
|
|
2514
|
-
|
|
2515
|
-
// src/deploy/lambdaLayer/deployLambdaLayer.ts
|
|
2516
|
-
import AWS5 from "aws-sdk";
|
|
2517
|
-
import log8 from "npmlog";
|
|
2518
2446
|
var logPrefix6 = "lambda-layer";
|
|
2519
2447
|
var createLambdaLayerZipFile = async ({
|
|
2520
2448
|
codeBuildProjectName,
|
|
2521
2449
|
packageName
|
|
2522
2450
|
}) => {
|
|
2523
|
-
|
|
2524
|
-
const codeBuild2 = new
|
|
2451
|
+
log5.info(logPrefix6, `Creating zip file for package ${packageName}...`);
|
|
2452
|
+
const codeBuild2 = new AWS.CodeBuild();
|
|
2525
2453
|
const { build } = await codeBuild2.startBuild({
|
|
2526
2454
|
environmentVariablesOverride: [
|
|
2527
2455
|
{
|
|
@@ -2640,9 +2568,6 @@ var deployLambdaLayer = async ({
|
|
|
2640
2568
|
handleDeployError({ error, logPrefix: logPrefix6 });
|
|
2641
2569
|
}
|
|
2642
2570
|
};
|
|
2643
|
-
|
|
2644
|
-
// src/deploy/lambda/deployLambdaLayers.ts
|
|
2645
|
-
import log9 from "npmlog";
|
|
2646
2571
|
var logPrefix7 = "lambda";
|
|
2647
2572
|
var deployLambdaLayers = async ({
|
|
2648
2573
|
lambdaExternals = []
|
|
@@ -2650,7 +2575,7 @@ var deployLambdaLayers = async ({
|
|
|
2650
2575
|
if (lambdaExternals.length === 0) {
|
|
2651
2576
|
return;
|
|
2652
2577
|
}
|
|
2653
|
-
|
|
2578
|
+
log5.info(
|
|
2654
2579
|
logPrefix7,
|
|
2655
2580
|
`--lambda-externals [${lambdaExternals.join(
|
|
2656
2581
|
", "
|
|
@@ -2659,10 +2584,10 @@ var deployLambdaLayers = async ({
|
|
|
2659
2584
|
const { dependencies = {} } = (() => {
|
|
2660
2585
|
try {
|
|
2661
2586
|
return JSON.parse(
|
|
2662
|
-
|
|
2587
|
+
fs3.readFileSync(path.resolve(process.cwd(), "package.json"), "utf8")
|
|
2663
2588
|
);
|
|
2664
2589
|
} catch (err) {
|
|
2665
|
-
|
|
2590
|
+
log5.error(
|
|
2666
2591
|
logPrefix7,
|
|
2667
2592
|
"Cannot read package.json. Error message: %j",
|
|
2668
2593
|
err.message
|
|
@@ -2682,91 +2607,38 @@ var deployLambdaLayers = async ({
|
|
|
2682
2607
|
});
|
|
2683
2608
|
await deployLambdaLayer({ packages, deployIfExists: false });
|
|
2684
2609
|
};
|
|
2685
|
-
|
|
2686
|
-
// src/deploy/lambda/uploadCodeToECR.ts
|
|
2687
|
-
import AWS6 from "aws-sdk";
|
|
2688
|
-
var codeBuild = new AWS6.CodeBuild({ region: AWS_DEFAULT_REGION });
|
|
2610
|
+
new AWS.CodeBuild({ region: AWS_DEFAULT_REGION });
|
|
2689
2611
|
var uploadCodeToECR = async ({
|
|
2690
2612
|
bucket,
|
|
2691
2613
|
key,
|
|
2692
2614
|
lambdaExternals,
|
|
2693
2615
|
lambdaDockerfile
|
|
2694
2616
|
}) => {
|
|
2695
|
-
|
|
2696
|
-
if (TEMP) {
|
|
2617
|
+
{
|
|
2697
2618
|
throw new Error("uploadCodeToECR not finished yet.");
|
|
2698
2619
|
}
|
|
2699
|
-
const lambdaBuilder = await getBaseStackResource(
|
|
2700
|
-
"BASE_STACK_LAMBDA_IMAGE_BUILDER_LOGICAL_NAME"
|
|
2701
|
-
);
|
|
2702
|
-
const defaultDockerfile = [
|
|
2703
|
-
"FROM public.ecr.aws/lambda/nodejs:14",
|
|
2704
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
2705
|
-
"COPY . ${LAMBDA_TASK_ROOT}",
|
|
2706
|
-
"RUN npm install"
|
|
2707
|
-
].join("\n");
|
|
2708
|
-
const { build } = await codeBuild.startBuild({
|
|
2709
|
-
environmentVariablesOverride: [
|
|
2710
|
-
{
|
|
2711
|
-
name: "DOCKERFILE",
|
|
2712
|
-
value: lambdaDockerfile || defaultDockerfile
|
|
2713
|
-
},
|
|
2714
|
-
{
|
|
2715
|
-
name: "LAMBDA_EXTERNALS",
|
|
2716
|
-
value: lambdaExternals.join(" ")
|
|
2717
|
-
},
|
|
2718
|
-
{
|
|
2719
|
-
name: "IMAGE_TAG",
|
|
2720
|
-
value: getPackageVersion()
|
|
2721
|
-
},
|
|
2722
|
-
{
|
|
2723
|
-
name: "REPOSITORY_ECR_REPOSITORY",
|
|
2724
|
-
value: "testtesteste"
|
|
2725
|
-
}
|
|
2726
|
-
],
|
|
2727
|
-
projectName: lambdaBuilder,
|
|
2728
|
-
sourceLocationOverride: `${bucket}/${key}`,
|
|
2729
|
-
sourceTypeOverride: "S3"
|
|
2730
|
-
}).promise();
|
|
2731
|
-
if (!build?.id) {
|
|
2732
|
-
throw new Error("Cannot start build.");
|
|
2733
|
-
}
|
|
2734
|
-
await waitCodeBuildFinish({ buildId: build.id, name: "lambda-builder" });
|
|
2735
|
-
const imageUri = "178804353523.dkr.ecr.us-east-1.amazonaws.com/testtesteste:0.0.1";
|
|
2736
|
-
return { imageUri };
|
|
2737
2620
|
};
|
|
2738
|
-
|
|
2739
|
-
// src/deploy/lambda/uploadCodeToS3.ts
|
|
2740
|
-
import AdmZip from "adm-zip";
|
|
2741
|
-
import fs5 from "fs";
|
|
2742
|
-
import log10 from "npmlog";
|
|
2743
|
-
import path5 from "path";
|
|
2744
2621
|
var logPrefix8 = "lambda";
|
|
2745
|
-
var
|
|
2746
|
-
var outFile2 = "index.js";
|
|
2622
|
+
var zipFileName = "lambda.zip";
|
|
2747
2623
|
var uploadCodeToS3 = async ({ stackName }) => {
|
|
2748
|
-
|
|
2624
|
+
log5.info(logPrefix8, `Uploading code to S3...`);
|
|
2749
2625
|
const zip = new AdmZip();
|
|
2750
|
-
const code =
|
|
2751
|
-
zip.addFile(
|
|
2752
|
-
if (!
|
|
2753
|
-
|
|
2626
|
+
const code = fs3__default.readFileSync(path__default.join(process.cwd(), outFolder, outFile));
|
|
2627
|
+
zip.addFile(outFile, code);
|
|
2628
|
+
if (!fs3__default.existsSync(outFolder)) {
|
|
2629
|
+
fs3__default.mkdirSync(outFolder);
|
|
2754
2630
|
}
|
|
2755
|
-
zip.writeZip(
|
|
2631
|
+
zip.writeZip(`${outFolder}/${zipFileName}`);
|
|
2756
2632
|
const bucketName = await getBaseStackResource(
|
|
2757
2633
|
"BASE_STACK_BUCKET_LOGICAL_NAME"
|
|
2758
2634
|
);
|
|
2759
2635
|
return uploadFileToS3({
|
|
2760
2636
|
bucket: bucketName,
|
|
2761
2637
|
contentType: "application/zip",
|
|
2762
|
-
key: `lambdas/${stackName}
|
|
2638
|
+
key: `lambdas/${stackName}/${zipFileName}`,
|
|
2763
2639
|
file: zip.toBuffer()
|
|
2764
2640
|
});
|
|
2765
2641
|
};
|
|
2766
|
-
|
|
2767
|
-
// src/deploy/lambda/deployLambdaCode.ts
|
|
2768
|
-
import fs6 from "fs";
|
|
2769
|
-
import log11 from "npmlog";
|
|
2770
2642
|
var logPrefix9 = "lambda";
|
|
2771
2643
|
var deployLambdaCode = async ({
|
|
2772
2644
|
lambdaDockerfile,
|
|
@@ -2775,10 +2647,10 @@ var deployLambdaCode = async ({
|
|
|
2775
2647
|
lambdaInput,
|
|
2776
2648
|
stackName
|
|
2777
2649
|
}) => {
|
|
2778
|
-
if (!
|
|
2650
|
+
if (!fs3__default.existsSync(lambdaInput)) {
|
|
2779
2651
|
return void 0;
|
|
2780
2652
|
}
|
|
2781
|
-
|
|
2653
|
+
log5.info(logPrefix9, "Deploying Lambda code...");
|
|
2782
2654
|
await buildLambdaSingleFile({ lambdaExternals, lambdaInput });
|
|
2783
2655
|
const { bucket, key, versionId } = await uploadCodeToS3({ stackName });
|
|
2784
2656
|
if (!lambdaImage) {
|
|
@@ -2794,26 +2666,20 @@ var deployLambdaCode = async ({
|
|
|
2794
2666
|
});
|
|
2795
2667
|
return { imageUri };
|
|
2796
2668
|
};
|
|
2797
|
-
|
|
2798
|
-
// src/deploy/cicd/getCicdStackName.ts
|
|
2799
|
-
import { pascalCase as pascalCase7 } from "change-case";
|
|
2800
2669
|
var getCicdStackName = () => {
|
|
2801
2670
|
const project = getProjectName();
|
|
2802
|
-
return
|
|
2671
|
+
return pascalCase([NAME, "Cicd", project].join(" "));
|
|
2803
2672
|
};
|
|
2804
|
-
|
|
2805
|
-
// src/deploy/cicd/deployCicd.ts
|
|
2806
|
-
import log12 from "npmlog";
|
|
2807
2673
|
var logPrefix10 = "cicd";
|
|
2808
2674
|
var getLambdaInput = (extension) => {
|
|
2809
|
-
return
|
|
2675
|
+
return path.resolve(__dirname, `lambdas/index.${extension}`);
|
|
2810
2676
|
};
|
|
2811
2677
|
var deployCicdLambdas = async ({ stackName }) => {
|
|
2812
2678
|
const lambdaInput = (() => {
|
|
2813
|
-
if (
|
|
2679
|
+
if (fs3.existsSync(getLambdaInput("js"))) {
|
|
2814
2680
|
return getLambdaInput("js");
|
|
2815
2681
|
}
|
|
2816
|
-
if (
|
|
2682
|
+
if (fs3.existsSync(getLambdaInput("ts"))) {
|
|
2817
2683
|
return getLambdaInput("ts");
|
|
2818
2684
|
}
|
|
2819
2685
|
throw new Error("Cannot read CICD lambdas file.");
|
|
@@ -2836,7 +2702,7 @@ var deployCicdLambdas = async ({ stackName }) => {
|
|
|
2836
2702
|
var waitRepositoryImageUpdate = async ({
|
|
2837
2703
|
stackName
|
|
2838
2704
|
}) => {
|
|
2839
|
-
|
|
2705
|
+
log5.info(logPrefix10, "Starting repository image update...");
|
|
2840
2706
|
const { OutputValue: projectName } = await getStackOutput({
|
|
2841
2707
|
stackName,
|
|
2842
2708
|
outputKey: REPOSITORY_IMAGE_CODE_BUILD_PROJECT_LOGICAL_ID
|
|
@@ -2889,15 +2755,9 @@ var deployCicd = async ({
|
|
|
2889
2755
|
handleDeployError({ error, logPrefix: logPrefix10 });
|
|
2890
2756
|
}
|
|
2891
2757
|
};
|
|
2892
|
-
|
|
2893
|
-
// src/deploy/cicd/readSSHKey.ts
|
|
2894
|
-
import * as fs8 from "fs";
|
|
2895
2758
|
var readSSHKey = (dir) => {
|
|
2896
|
-
return
|
|
2759
|
+
return fs3.readFileSync(dir, "utf-8");
|
|
2897
2760
|
};
|
|
2898
|
-
|
|
2899
|
-
// src/deploy/cicd/command.ts
|
|
2900
|
-
import log13 from "npmlog";
|
|
2901
2761
|
var logPrefix11 = "deploy-cicd";
|
|
2902
2762
|
var deployCicdCommand = {
|
|
2903
2763
|
command: "cicd",
|
|
@@ -2907,7 +2767,7 @@ var deployCicdCommand = {
|
|
|
2907
2767
|
},
|
|
2908
2768
|
handler: ({ destroy: destroy2, ...rest }) => {
|
|
2909
2769
|
if (destroy2) {
|
|
2910
|
-
|
|
2770
|
+
log5.info(logPrefix11, `${NAME} doesn't destroy CICD stack.`);
|
|
2911
2771
|
} else {
|
|
2912
2772
|
deployCicd({
|
|
2913
2773
|
...rest,
|
|
@@ -2916,17 +2776,6 @@ var deployCicdCommand = {
|
|
|
2916
2776
|
}
|
|
2917
2777
|
}
|
|
2918
2778
|
};
|
|
2919
|
-
|
|
2920
|
-
// ../cloudformation/src/findAndReadCloudFormationTemplate.ts
|
|
2921
|
-
import * as fs11 from "fs";
|
|
2922
|
-
import * as path8 from "path";
|
|
2923
|
-
|
|
2924
|
-
// ../cloudformation/src/readCloudFormationYamlTemplate.ts
|
|
2925
|
-
import * as fs9 from "fs";
|
|
2926
|
-
import * as path7 from "path";
|
|
2927
|
-
|
|
2928
|
-
// ../cloudformation/src/cloudFormationYamlTemplate.ts
|
|
2929
|
-
import yaml4 from "js-yaml";
|
|
2930
2779
|
var cloudFormationTypes = [
|
|
2931
2780
|
{
|
|
2932
2781
|
tag: "!Equals",
|
|
@@ -3050,7 +2899,7 @@ var getTypes = () => {
|
|
|
3050
2899
|
options: {
|
|
3051
2900
|
kind: "scalar",
|
|
3052
2901
|
construct: (filePath) => {
|
|
3053
|
-
return
|
|
2902
|
+
return fs3.readFileSync(path.resolve(process.cwd(), filePath)).toString();
|
|
3054
2903
|
}
|
|
3055
2904
|
}
|
|
3056
2905
|
}
|
|
@@ -3059,52 +2908,81 @@ var getTypes = () => {
|
|
|
3059
2908
|
var readCloudFormationYamlTemplate = ({
|
|
3060
2909
|
templatePath
|
|
3061
2910
|
}) => {
|
|
3062
|
-
const template =
|
|
2911
|
+
const template = fs3.readFileSync(templatePath).toString();
|
|
3063
2912
|
const parsed = loadCloudFormationTemplate(template, getTypes());
|
|
3064
2913
|
if (!parsed || typeof parsed === "string") {
|
|
3065
2914
|
throw new Error("Cannot parse CloudFormation template.");
|
|
3066
2915
|
}
|
|
3067
2916
|
return parsed;
|
|
3068
2917
|
};
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
2918
|
+
var loadConfig = (entryPoint) => {
|
|
2919
|
+
const lastEntryPointName = entryPoint.split("/").pop();
|
|
2920
|
+
const filename = lastEntryPointName?.split(".")[0];
|
|
2921
|
+
const outfile = path__default.resolve(process.cwd(), "out", filename + ".js");
|
|
2922
|
+
const projectPackageJsonPath = path__default.resolve(process.cwd(), "package.json");
|
|
2923
|
+
const projectPackageJson = importSync(projectPackageJsonPath);
|
|
2924
|
+
const projectDependencies = Object.keys(
|
|
2925
|
+
projectPackageJson.dependencies || {}
|
|
2926
|
+
);
|
|
2927
|
+
const result = esbuild.buildSync({
|
|
2928
|
+
bundle: true,
|
|
2929
|
+
entryPoints: [entryPoint],
|
|
2930
|
+
external: projectDependencies,
|
|
2931
|
+
format: "cjs",
|
|
2932
|
+
outfile,
|
|
2933
|
+
platform: "node",
|
|
2934
|
+
target: typescriptConfig.target,
|
|
2935
|
+
treeShaking: true
|
|
2936
|
+
});
|
|
2937
|
+
if (result.errors.length > 0) {
|
|
2938
|
+
console.error("Error building config file: ", filename);
|
|
2939
|
+
throw result.errors;
|
|
3082
2940
|
}
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
"carlin.*": "cjs"
|
|
3090
|
-
},
|
|
3091
|
-
transpileOnly: true
|
|
3092
|
-
});
|
|
3093
|
-
const tsObj = require2(path12);
|
|
3094
|
-
const obj = tsObj.default || tsObj;
|
|
3095
|
-
return typeof obj === "function" ? obj() : obj;
|
|
2941
|
+
try {
|
|
2942
|
+
const config = importSync(outfile);
|
|
2943
|
+
return config.default || config.config;
|
|
2944
|
+
} catch (error) {
|
|
2945
|
+
console.error("Failed importing build config file: ", filename);
|
|
2946
|
+
throw error;
|
|
3096
2947
|
}
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
2948
|
+
};
|
|
2949
|
+
var readConfigFileSync = ({
|
|
2950
|
+
configFilePath
|
|
2951
|
+
}) => {
|
|
2952
|
+
const extension = configFilePath.split(".").pop();
|
|
2953
|
+
if (extension === "yaml" || extension === "yml") {
|
|
2954
|
+
const file = fs3__default.readFileSync(configFilePath, "utf8");
|
|
2955
|
+
return yaml4.load(file);
|
|
3100
2956
|
}
|
|
3101
2957
|
if (extension === "json") {
|
|
3102
|
-
|
|
2958
|
+
const file = fs3__default.readFileSync(configFilePath, "utf8");
|
|
2959
|
+
return JSON.parse(file);
|
|
2960
|
+
}
|
|
2961
|
+
if (extension === "js") {
|
|
2962
|
+
return __require(configFilePath);
|
|
3103
2963
|
}
|
|
3104
|
-
if (extension === "
|
|
3105
|
-
|
|
2964
|
+
if (extension === "ts") {
|
|
2965
|
+
let result = loadConfig(configFilePath);
|
|
2966
|
+
if (typeof result === "function") {
|
|
2967
|
+
result = result();
|
|
2968
|
+
}
|
|
2969
|
+
return result;
|
|
2970
|
+
}
|
|
2971
|
+
throw new Error("Unsupported config file extension: " + extension);
|
|
2972
|
+
};
|
|
2973
|
+
var readConfigFile = async ({
|
|
2974
|
+
configFilePath
|
|
2975
|
+
}) => {
|
|
2976
|
+
const extension = configFilePath.split(".").pop();
|
|
2977
|
+
if (extension === "ts") {
|
|
2978
|
+
let result = loadConfig(configFilePath);
|
|
2979
|
+
if (typeof result === "function") {
|
|
2980
|
+
result = result();
|
|
2981
|
+
}
|
|
2982
|
+
result = await Promise.resolve(result);
|
|
2983
|
+
return result;
|
|
3106
2984
|
}
|
|
3107
|
-
return {};
|
|
2985
|
+
return readConfigFileSync({ configFilePath });
|
|
3108
2986
|
};
|
|
3109
2987
|
|
|
3110
2988
|
// ../cloudformation/src/findAndReadCloudFormationTemplate.ts
|
|
@@ -3113,36 +2991,28 @@ var defaultTemplatePaths2 = ["ts", "js", "yaml", "yml", "json"].map(
|
|
|
3113
2991
|
return `./src/cloudformation.${extension}`;
|
|
3114
2992
|
}
|
|
3115
2993
|
);
|
|
3116
|
-
var findAndReadCloudFormationTemplate = ({
|
|
2994
|
+
var findAndReadCloudFormationTemplate = async ({
|
|
3117
2995
|
templatePath: defaultTemplatePath
|
|
3118
2996
|
}) => {
|
|
3119
2997
|
const templatePath = defaultTemplatePath || defaultTemplatePaths2.reduce((acc, cur) => {
|
|
3120
2998
|
if (acc) {
|
|
3121
2999
|
return acc;
|
|
3122
3000
|
}
|
|
3123
|
-
return
|
|
3001
|
+
return fs3.existsSync(path.resolve(process.cwd(), cur)) ? cur : acc;
|
|
3124
3002
|
}, "");
|
|
3125
3003
|
if (!templatePath) {
|
|
3126
3004
|
throw new Error("Cannot find a CloudFormation template.");
|
|
3127
3005
|
}
|
|
3128
3006
|
const extension = templatePath?.split(".").pop();
|
|
3129
|
-
const fullPath = path8.resolve(process.cwd(), templatePath);
|
|
3130
3007
|
if (["yaml", "yml"].includes(extension)) {
|
|
3131
3008
|
return readCloudFormationYamlTemplate({ templatePath });
|
|
3132
3009
|
}
|
|
3133
|
-
|
|
3010
|
+
const configFilePath = path.resolve(process.cwd(), templatePath);
|
|
3011
|
+
return readConfigFile({ configFilePath });
|
|
3134
3012
|
};
|
|
3135
|
-
|
|
3136
|
-
// src/deploy/cloudformation.ts
|
|
3137
|
-
import log14 from "npmlog";
|
|
3138
3013
|
var logPrefix12 = "cloudformation";
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
var defaultTemplatePaths3 = ["ts", "js", "yaml", "yml", "json"].map(
|
|
3142
|
-
(extension) => {
|
|
3143
|
-
return `./src/cloudformation.${extension}`;
|
|
3144
|
-
}
|
|
3145
|
-
);
|
|
3014
|
+
log5.addLevel("event", 1e4, { fg: "yellow" });
|
|
3015
|
+
log5.addLevel("output", 1e4, { fg: "blue" });
|
|
3146
3016
|
var deployCloudFormation = async ({
|
|
3147
3017
|
lambdaDockerfile,
|
|
3148
3018
|
lambdaInput,
|
|
@@ -3154,7 +3024,7 @@ var deployCloudFormation = async ({
|
|
|
3154
3024
|
}) => {
|
|
3155
3025
|
try {
|
|
3156
3026
|
const { stackName } = await handleDeployInitialization({ logPrefix: logPrefix12 });
|
|
3157
|
-
const cloudFormationTemplate = (() => {
|
|
3027
|
+
const cloudFormationTemplate = await (async () => {
|
|
3158
3028
|
if (template) {
|
|
3159
3029
|
return { ...template };
|
|
3160
3030
|
}
|
|
@@ -3298,14 +3168,14 @@ var emptyStackBuckets = async ({ stackName }) => {
|
|
|
3298
3168
|
var destroy = async ({ stackName }) => {
|
|
3299
3169
|
const environment = getEnvironment();
|
|
3300
3170
|
if (environment) {
|
|
3301
|
-
|
|
3171
|
+
log5.info(
|
|
3302
3172
|
logPrefix12,
|
|
3303
3173
|
`Cannot destroy stack when environment (${environment}) is defined.`
|
|
3304
3174
|
);
|
|
3305
3175
|
return;
|
|
3306
3176
|
}
|
|
3307
3177
|
if (!await doesStackExist({ stackName })) {
|
|
3308
|
-
|
|
3178
|
+
log5.info(logPrefix12, `Stack ${stackName} doesn't exist.`);
|
|
3309
3179
|
return;
|
|
3310
3180
|
}
|
|
3311
3181
|
if (!await canDestroyStack({ stackName })) {
|
|
@@ -3319,17 +3189,14 @@ var destroyCloudFormation = async ({
|
|
|
3319
3189
|
stackName: defaultStackName
|
|
3320
3190
|
} = {}) => {
|
|
3321
3191
|
try {
|
|
3322
|
-
|
|
3192
|
+
log5.info(logPrefix12, "CAUTION! Starting CloudFormation destroy...");
|
|
3323
3193
|
const stackName = defaultStackName || await getStackName();
|
|
3324
|
-
|
|
3194
|
+
log5.info(logPrefix12, `stackName: ${stackName}`);
|
|
3325
3195
|
await destroy({ stackName });
|
|
3326
3196
|
} catch (error) {
|
|
3327
3197
|
handleDeployError({ error, logPrefix: logPrefix12 });
|
|
3328
3198
|
}
|
|
3329
3199
|
};
|
|
3330
|
-
|
|
3331
|
-
// src/deploy/lambdaLayer/command.ts
|
|
3332
|
-
import log15 from "npmlog";
|
|
3333
3200
|
var logPrefix13 = "deploy-lambda-layer";
|
|
3334
3201
|
var packageNameRegex = /@[~^]?([\dvx*]+(?:[-.](?:[\dx*]+|alpha|beta))*)/;
|
|
3335
3202
|
var options2 = {
|
|
@@ -3343,23 +3210,27 @@ var options2 = {
|
|
|
3343
3210
|
var deployLambdaLayerCommand = {
|
|
3344
3211
|
command: "lambda-layer",
|
|
3345
3212
|
describe: "Deploy Lambda Layer.",
|
|
3346
|
-
builder: (yargs3) =>
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3213
|
+
builder: (yargs3) => {
|
|
3214
|
+
return yargs3.options(addGroupToOptions(options2, "Deploy Lambda Layer Options")).check(({ packages }) => {
|
|
3215
|
+
const invalidPackages = packages.map((packageName) => {
|
|
3216
|
+
return packageNameRegex.test(packageName) ? void 0 : packageName;
|
|
3217
|
+
}).filter((packageName) => {
|
|
3218
|
+
return !!packageName;
|
|
3219
|
+
});
|
|
3220
|
+
if (invalidPackages.length > 0) {
|
|
3221
|
+
throw new Error(
|
|
3222
|
+
`Some package names are invalid: ${invalidPackages.join(
|
|
3223
|
+
", "
|
|
3224
|
+
)}. The package must follow the pattern: ${packageNameRegex.toString()}.`
|
|
3225
|
+
);
|
|
3226
|
+
} else {
|
|
3227
|
+
return true;
|
|
3228
|
+
}
|
|
3229
|
+
});
|
|
3230
|
+
},
|
|
3360
3231
|
handler: ({ destroy: destroy2, ...rest }) => {
|
|
3361
3232
|
if (destroy2) {
|
|
3362
|
-
|
|
3233
|
+
log5.info(logPrefix13, `${NAME} doesn't destroy lambda layers.`);
|
|
3363
3234
|
} else {
|
|
3364
3235
|
deployLambdaLayer(rest);
|
|
3365
3236
|
}
|
|
@@ -3775,18 +3646,14 @@ var getStaticAppTemplate = ({
|
|
|
3775
3646
|
}
|
|
3776
3647
|
return getBucketStaticWebsiteTemplate({ spa });
|
|
3777
3648
|
};
|
|
3778
|
-
|
|
3779
|
-
// src/deploy/staticApp/invalidateCloudFront.ts
|
|
3780
|
-
import AWS7 from "aws-sdk";
|
|
3781
|
-
import log16 from "npmlog";
|
|
3782
3649
|
var CLOUDFRONT_DISTRIBUTION_ID = "CloudFrontDistributionId";
|
|
3783
3650
|
var logPrefix14 = "static-app";
|
|
3784
3651
|
var invalidateCloudFront = async ({
|
|
3785
3652
|
outputs
|
|
3786
3653
|
}) => {
|
|
3787
|
-
|
|
3654
|
+
log5.info(logPrefix14, "Invalidating CloudFront...");
|
|
3788
3655
|
if (!outputs) {
|
|
3789
|
-
|
|
3656
|
+
log5.info(logPrefix14, "Invalidation: outputs do not exist.");
|
|
3790
3657
|
return;
|
|
3791
3658
|
}
|
|
3792
3659
|
const cloudFrontDistributionIDOutput = outputs.find((output) => {
|
|
@@ -3804,35 +3671,31 @@ var invalidateCloudFront = async ({
|
|
|
3804
3671
|
}
|
|
3805
3672
|
}
|
|
3806
3673
|
};
|
|
3807
|
-
const cloudFront = new
|
|
3674
|
+
const cloudFront = new AWS.CloudFront();
|
|
3808
3675
|
try {
|
|
3809
3676
|
await cloudFront.createInvalidation(params).promise();
|
|
3810
|
-
|
|
3677
|
+
log5.info(
|
|
3811
3678
|
logPrefix14,
|
|
3812
3679
|
`CloudFront Distribution ID ${distributionId} invalidated with success.`
|
|
3813
3680
|
);
|
|
3814
3681
|
} catch (err) {
|
|
3815
|
-
|
|
3682
|
+
log5.error(
|
|
3816
3683
|
logPrefix14,
|
|
3817
3684
|
`Error while trying to invalidate CloudFront distribution ${distributionId}.`
|
|
3818
3685
|
);
|
|
3819
|
-
|
|
3686
|
+
log5.error(logPrefix14, err);
|
|
3820
3687
|
}
|
|
3821
3688
|
} else {
|
|
3822
|
-
|
|
3689
|
+
log5.info(
|
|
3823
3690
|
logPrefix14,
|
|
3824
3691
|
`Cannot invalidate because distribution does not exist.`
|
|
3825
3692
|
);
|
|
3826
3693
|
}
|
|
3827
3694
|
};
|
|
3828
|
-
|
|
3829
|
-
// src/deploy/staticApp/removeOldVersions.ts
|
|
3830
|
-
import log17 from "npmlog";
|
|
3831
|
-
import semver from "semver";
|
|
3832
3695
|
var logPrefix15 = "static-app";
|
|
3833
3696
|
var removeOldVersions = async ({ bucket }) => {
|
|
3834
3697
|
try {
|
|
3835
|
-
|
|
3698
|
+
log5.info(logPrefix15, "Removing old versions...");
|
|
3836
3699
|
const { CommonPrefixes = [] } = await s3.listObjectsV2({ Bucket: bucket, Delimiter: "/" }).promise();
|
|
3837
3700
|
const versions = CommonPrefixes?.map(({ Prefix }) => {
|
|
3838
3701
|
return Prefix?.replace("/", "");
|
|
@@ -3850,7 +3713,7 @@ var removeOldVersions = async ({ bucket }) => {
|
|
|
3850
3713
|
})
|
|
3851
3714
|
);
|
|
3852
3715
|
} catch (error) {
|
|
3853
|
-
|
|
3716
|
+
log5.info(
|
|
3854
3717
|
logPrefix15,
|
|
3855
3718
|
`Cannot remove older versions from "${bucket}" bucket.`
|
|
3856
3719
|
);
|
|
@@ -3929,9 +3792,6 @@ var deployStaticApp = async ({
|
|
|
3929
3792
|
handleDeployError({ error, logPrefix: logPrefix16 });
|
|
3930
3793
|
}
|
|
3931
3794
|
};
|
|
3932
|
-
|
|
3933
|
-
// src/deploy/staticApp/command.ts
|
|
3934
|
-
import AWS8 from "aws-sdk";
|
|
3935
3795
|
var options3 = {
|
|
3936
3796
|
acm: {
|
|
3937
3797
|
describe: "The ARN of the certificate or the name of the exported variable whose value is the ARN of the certificate that will be associated to CloudFront.",
|
|
@@ -3988,7 +3848,7 @@ var deployStaticAppCommand = {
|
|
|
3988
3848
|
describe: "Deploy static app.",
|
|
3989
3849
|
builder: (yargs3) => {
|
|
3990
3850
|
return yargs3.options(addGroupToOptions(options3, "Deploy Static App Options")).middleware(() => {
|
|
3991
|
-
|
|
3851
|
+
AWS.config.region = CLOUDFRONT_REGION;
|
|
3992
3852
|
});
|
|
3993
3853
|
},
|
|
3994
3854
|
handler: ({ destroy: destroy2, ...rest }) => {
|
|
@@ -3999,9 +3859,6 @@ var deployStaticAppCommand = {
|
|
|
3999
3859
|
}
|
|
4000
3860
|
}
|
|
4001
3861
|
};
|
|
4002
|
-
|
|
4003
|
-
// src/deploy/vercel/deployVercel.ts
|
|
4004
|
-
import log18 from "npmlog";
|
|
4005
3862
|
var logPrefix17 = "deploy vercel";
|
|
4006
3863
|
var makeCommand = (cmds) => {
|
|
4007
3864
|
return cmds.filter((cmd) => {
|
|
@@ -4010,7 +3867,7 @@ var makeCommand = (cmds) => {
|
|
|
4010
3867
|
};
|
|
4011
3868
|
var deployVercel = async ({ token }) => {
|
|
4012
3869
|
try {
|
|
4013
|
-
|
|
3870
|
+
log5.info(logPrefix17, "Deploying on Vercel...");
|
|
4014
3871
|
const environment = getEnvironment();
|
|
4015
3872
|
const finalToken = token || process.env.VERCEL_TOKEN;
|
|
4016
3873
|
if (!finalToken) {
|
|
@@ -4041,9 +3898,6 @@ var deployVercel = async ({ token }) => {
|
|
|
4041
3898
|
handleDeployError({ error, logPrefix: logPrefix17 });
|
|
4042
3899
|
}
|
|
4043
3900
|
};
|
|
4044
|
-
|
|
4045
|
-
// src/deploy/vercel/command.ts
|
|
4046
|
-
import log19 from "npmlog";
|
|
4047
3901
|
var logPrefix18 = "deploy vercel";
|
|
4048
3902
|
var options4 = {
|
|
4049
3903
|
token: {
|
|
@@ -4061,26 +3915,19 @@ var deployVercelCommand = {
|
|
|
4061
3915
|
},
|
|
4062
3916
|
handler: ({ destroy: destroy2, ...rest }) => {
|
|
4063
3917
|
if (destroy2) {
|
|
4064
|
-
|
|
3918
|
+
log5.info(logPrefix18, "Destroy Vercel deployment not implemented yet.");
|
|
4065
3919
|
} else {
|
|
4066
3920
|
deployVercel(rest);
|
|
4067
3921
|
}
|
|
4068
3922
|
}
|
|
4069
3923
|
};
|
|
4070
|
-
|
|
4071
|
-
// src/deploy/readDockerfile.ts
|
|
4072
|
-
import * as fs12 from "fs";
|
|
4073
|
-
import * as path9 from "path";
|
|
4074
3924
|
var readDockerfile = (dockerfilePath) => {
|
|
4075
3925
|
try {
|
|
4076
|
-
return
|
|
3926
|
+
return fs3.readFileSync(path.join(process.cwd(), dockerfilePath), "utf8");
|
|
4077
3927
|
} catch {
|
|
4078
3928
|
return "";
|
|
4079
3929
|
}
|
|
4080
3930
|
};
|
|
4081
|
-
|
|
4082
|
-
// src/deploy/command.ts
|
|
4083
|
-
import log20 from "npmlog";
|
|
4084
3931
|
var logPrefix19 = "deploy";
|
|
4085
3932
|
var checkAwsAccountId = async (awsAccountId) => {
|
|
4086
3933
|
try {
|
|
@@ -4094,7 +3941,7 @@ var checkAwsAccountId = async (awsAccountId) => {
|
|
|
4094
3941
|
if (error.code === "CredentialsError") {
|
|
4095
3942
|
return;
|
|
4096
3943
|
}
|
|
4097
|
-
|
|
3944
|
+
log5.error(logPrefix19, error.message);
|
|
4098
3945
|
process.exit();
|
|
4099
3946
|
}
|
|
4100
3947
|
};
|
|
@@ -4106,7 +3953,7 @@ var describeDeployCommand = {
|
|
|
4106
3953
|
const newStackName = stackName || await getStackName();
|
|
4107
3954
|
await printStackOutputsAfterDeploy({ stackName: newStackName });
|
|
4108
3955
|
} catch (error) {
|
|
4109
|
-
|
|
3956
|
+
log5.info(logPrefix19, "Cannot describe stack. Message: %s", error.message);
|
|
4110
3957
|
}
|
|
4111
3958
|
}
|
|
4112
3959
|
};
|
|
@@ -4222,7 +4069,7 @@ var deployCommand = {
|
|
|
4222
4069
|
}
|
|
4223
4070
|
).middleware(({ skipDeploy }) => {
|
|
4224
4071
|
if (skipDeploy) {
|
|
4225
|
-
|
|
4072
|
+
log5.warn(
|
|
4226
4073
|
logPrefix19,
|
|
4227
4074
|
"Skip deploy flag is true, then the deploy command wasn't executed."
|
|
4228
4075
|
);
|
|
@@ -4257,17 +4104,13 @@ var deployCommand = {
|
|
|
4257
4104
|
}
|
|
4258
4105
|
}
|
|
4259
4106
|
};
|
|
4260
|
-
|
|
4261
|
-
// src/deploy/cicd/ecsTaskReportCommand.ts
|
|
4262
|
-
import AWS9 from "aws-sdk";
|
|
4263
|
-
import log21 from "npmlog";
|
|
4264
4107
|
var logPrefix20 = "cicd-ecs-task-report";
|
|
4265
4108
|
var sendEcsTaskReport = async ({ status }) => {
|
|
4266
4109
|
if (!process.env.ECS_TASK_REPORT_HANDLER_NAME) {
|
|
4267
|
-
|
|
4110
|
+
log5.info(logPrefix20, "ECS_TASK_REPORT_HANDLER_NAME not defined.");
|
|
4268
4111
|
return;
|
|
4269
4112
|
}
|
|
4270
|
-
const lambda = new
|
|
4113
|
+
const lambda = new AWS.Lambda();
|
|
4271
4114
|
const payload = { status };
|
|
4272
4115
|
if (process.env.ECS_TASK_ARN) {
|
|
4273
4116
|
payload.ecsTaskArn = process.env.ECS_TASK_ARN;
|
|
@@ -4279,7 +4122,7 @@ var sendEcsTaskReport = async ({ status }) => {
|
|
|
4279
4122
|
FunctionName: process.env.ECS_TASK_REPORT_HANDLER_NAME,
|
|
4280
4123
|
InvokeArgs: JSON.stringify(payload)
|
|
4281
4124
|
}).promise();
|
|
4282
|
-
|
|
4125
|
+
log5.info(logPrefix20, "Report sent.");
|
|
4283
4126
|
};
|
|
4284
4127
|
var options6 = {
|
|
4285
4128
|
status: {
|
|
@@ -4298,19 +4141,14 @@ var ecsTaskReportCommand = {
|
|
|
4298
4141
|
return sendEcsTaskReport(args);
|
|
4299
4142
|
}
|
|
4300
4143
|
};
|
|
4301
|
-
|
|
4302
|
-
// src/generateEnv/generateEnv.ts
|
|
4303
|
-
import * as fs13 from "fs";
|
|
4304
|
-
import * as path10 from "path";
|
|
4305
|
-
import log22 from "npmlog";
|
|
4306
4144
|
var logPrefix21 = "generate-env";
|
|
4307
4145
|
var readEnvFile = async ({
|
|
4308
4146
|
envFileName,
|
|
4309
4147
|
envsPath
|
|
4310
4148
|
}) => {
|
|
4311
4149
|
try {
|
|
4312
|
-
const content = await
|
|
4313
|
-
|
|
4150
|
+
const content = await fs3.promises.readFile(
|
|
4151
|
+
path.resolve(process.cwd(), envsPath, envFileName),
|
|
4314
4152
|
"utf8"
|
|
4315
4153
|
);
|
|
4316
4154
|
return content;
|
|
@@ -4322,8 +4160,8 @@ var writeEnvFile = async ({
|
|
|
4322
4160
|
envFileName,
|
|
4323
4161
|
content
|
|
4324
4162
|
}) => {
|
|
4325
|
-
return
|
|
4326
|
-
|
|
4163
|
+
return fs3.promises.writeFile(
|
|
4164
|
+
path.resolve(process.cwd(), envFileName),
|
|
4327
4165
|
content
|
|
4328
4166
|
);
|
|
4329
4167
|
};
|
|
@@ -4335,7 +4173,7 @@ var generateEnv = async ({
|
|
|
4335
4173
|
const envFileName = `.env.${environment}`;
|
|
4336
4174
|
const envFile = await readEnvFile({ envFileName, envsPath });
|
|
4337
4175
|
if (!envFile) {
|
|
4338
|
-
|
|
4176
|
+
log5.info(
|
|
4339
4177
|
logPrefix21,
|
|
4340
4178
|
"Env file %s doesn't exist. Skip generating env file.",
|
|
4341
4179
|
envFileName
|
|
@@ -4343,7 +4181,7 @@ var generateEnv = async ({
|
|
|
4343
4181
|
return;
|
|
4344
4182
|
}
|
|
4345
4183
|
await writeEnvFile({ content: envFile, envFileName: ".env" });
|
|
4346
|
-
|
|
4184
|
+
log5.info(
|
|
4347
4185
|
logPrefix21,
|
|
4348
4186
|
"Generate env file %s from %s successfully.",
|
|
4349
4187
|
".env",
|
|
@@ -4377,15 +4215,6 @@ var generateEnvCommand = {
|
|
|
4377
4215
|
return generateEnv(args);
|
|
4378
4216
|
}
|
|
4379
4217
|
};
|
|
4380
|
-
|
|
4381
|
-
// src/cli.ts
|
|
4382
|
-
import { hideBin as hideBin2 } from "yargs/helpers";
|
|
4383
|
-
import AWS10 from "aws-sdk";
|
|
4384
|
-
import deepEqual from "deep-equal";
|
|
4385
|
-
import deepMerge from "deepmerge";
|
|
4386
|
-
import findUpSync2 from "findup-sync";
|
|
4387
|
-
import path11 from "path";
|
|
4388
|
-
import yargs2 from "yargs";
|
|
4389
4218
|
var coerceSetEnvVar = (env) => {
|
|
4390
4219
|
return (value) => {
|
|
4391
4220
|
setEnvVar(env, value);
|
|
@@ -4432,31 +4261,31 @@ var getEnv = () => {
|
|
|
4432
4261
|
var cli = () => {
|
|
4433
4262
|
let finalConfig;
|
|
4434
4263
|
const getConfig = () => {
|
|
4435
|
-
const names = ["js", "yml", "yaml", "json"
|
|
4264
|
+
const names = ["ts", "js", "yml", "yaml", "json"].map((ext) => {
|
|
4436
4265
|
return `${NAME}.${ext}`;
|
|
4437
4266
|
});
|
|
4438
4267
|
const paths = [];
|
|
4439
4268
|
let currentPath = process.cwd();
|
|
4440
4269
|
let findUpPath;
|
|
4441
4270
|
do {
|
|
4442
|
-
findUpPath =
|
|
4271
|
+
findUpPath = findUpSync(names, { cwd: currentPath });
|
|
4443
4272
|
if (findUpPath) {
|
|
4444
|
-
currentPath =
|
|
4273
|
+
currentPath = path__default.resolve(findUpPath, "../..");
|
|
4445
4274
|
paths.push(findUpPath);
|
|
4446
4275
|
}
|
|
4447
4276
|
} while (findUpPath);
|
|
4448
4277
|
const configs = paths.map((p) => {
|
|
4449
|
-
return
|
|
4278
|
+
return readConfigFileSync({ configFilePath: p }) || {};
|
|
4450
4279
|
});
|
|
4451
|
-
finalConfig =
|
|
4280
|
+
finalConfig = deepmerge.all(configs.reverse());
|
|
4452
4281
|
return finalConfig;
|
|
4453
4282
|
};
|
|
4454
|
-
|
|
4283
|
+
const handleEnvironments = (argv, { parsed }) => {
|
|
4455
4284
|
const { environment, environments } = argv;
|
|
4456
4285
|
if (environment && environments && environments[environment]) {
|
|
4457
4286
|
Object.entries(environments[environment]).forEach(([key, value]) => {
|
|
4458
4287
|
const isKeyFromCli = (() => {
|
|
4459
|
-
const kebabCaseKey =
|
|
4288
|
+
const kebabCaseKey = kebabCase(key);
|
|
4460
4289
|
if (parsed?.defaulted?.[kebabCaseKey]) {
|
|
4461
4290
|
return false;
|
|
4462
4291
|
}
|
|
@@ -4470,7 +4299,8 @@ var cli = () => {
|
|
|
4470
4299
|
}
|
|
4471
4300
|
});
|
|
4472
4301
|
}
|
|
4473
|
-
}
|
|
4302
|
+
};
|
|
4303
|
+
return yargs(hideBin(process.argv)).strictCommands().scriptName(NAME).env(getEnv()).options(addGroupToOptions(options8, "Common Options")).middleware(handleEnvironments).middleware(({ environment }) => {
|
|
4474
4304
|
if (!["string", "undefined"].includes(typeof environment)) {
|
|
4475
4305
|
throw new Error(
|
|
4476
4306
|
`environment type is invalid. The value: ${JSON.stringify(
|
|
@@ -4479,10 +4309,10 @@ var cli = () => {
|
|
|
4479
4309
|
);
|
|
4480
4310
|
}
|
|
4481
4311
|
}).middleware(({ region }) => {
|
|
4482
|
-
|
|
4312
|
+
AWS.config.region = region;
|
|
4483
4313
|
setEnvVar("REGION", region);
|
|
4484
|
-
}).pkgConf(getPkgConfig()).config(getConfig()).config("config", (
|
|
4485
|
-
return
|
|
4314
|
+
}).pkgConf(getPkgConfig()).config(getConfig()).config("config", (configFilePath) => {
|
|
4315
|
+
return readConfigFileSync({ configFilePath });
|
|
4486
4316
|
}).command({
|
|
4487
4317
|
command: "print-args",
|
|
4488
4318
|
describe: false,
|