carlin 4.0.0 → 5.0.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.
Files changed (2) hide show
  1. package/dist/index.mjs +218 -194
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { builtinModules, createRequire } from "node:module";
2
- import path, * as path$2 from "node:path";
3
- import * as fs$3 from "node:fs";
2
+ import path, * as path$1 from "node:path";
3
+ import * as fs$1 from "node:fs";
4
4
  import fs, { chmodSync, createReadStream, existsSync, statSync } from "node:fs";
5
5
  import { CORE_SCHEMA, defineScalarTag, defineSequenceTag, dump, load, mergeTag } from "js-yaml";
6
6
  import * as esbuild from "esbuild";
@@ -15,11 +15,10 @@ import { InvokeCommand, LambdaClient } from "@aws-sdk/client-lambda";
15
15
  import { format, styleText } from "node:util";
16
16
  import { BatchGetBuildsCommand, CodeBuildClient, StartBuildCommand } from "@aws-sdk/client-codebuild";
17
17
  import { spawn } from "node:child_process";
18
- import "uglify-js";
19
18
  import "prettier";
19
+ import "uglify-js";
20
20
  import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
21
21
  import { simpleGit } from "simple-git";
22
- import fs$1, * as fs$2 from "fs";
23
22
  import { CloudFormationClient, CreateStackCommand, DeleteStackCommand, DescribeStackEventsCommand, DescribeStackResourceCommand, DescribeStacksCommand, ListStackResourcesCommand, UpdateStackCommand, UpdateTerminationProtectionCommand, ValidateTemplateCommand, waitUntilStackCreateComplete, waitUntilStackDeleteComplete, waitUntilStackUpdateComplete } from "@aws-sdk/client-cloudformation";
24
23
  import { CopyObjectCommand, DeleteObjectsCommand, HeadObjectCommand, ListObjectVersionsCommand, ListObjectsV2Command, S3Client } from "@aws-sdk/client-s3";
25
24
  import { Upload } from "@aws-sdk/lib-storage";
@@ -27,7 +26,6 @@ import { glob } from "glob";
27
26
  import mime from "mime-types";
28
27
  import { typescriptConfig } from "@ttoss/config";
29
28
  import AdmZip from "adm-zip";
30
- import * as path$1 from "path";
31
29
  import { CloudFrontClient, CreateInvalidationCommand } from "@aws-sdk/client-cloudfront";
32
30
  //#region \0rolldown/runtime.js
33
31
  var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
@@ -254,9 +252,7 @@ const ecsTaskReportCommand = {
254
252
  //#endregion
255
253
  //#region src/utils/addGroupToOptions.ts
256
254
  const addGroupToOptions = (options, group) => {
257
- Object.values(options).forEach((option) => {
258
- option.group = group;
259
- });
255
+ for (const option of Object.values(options)) option.group = group;
260
256
  return options;
261
257
  };
262
258
  //#endregion
@@ -331,13 +327,15 @@ const getEnvironment = () => {
331
327
  };
332
328
  //#endregion
333
329
  //#region src/utils/getIamPath.ts
334
- const getIamPath = () => `/${NAME}/`;
330
+ const getIamPath = () => {
331
+ return `/${NAME}/`;
332
+ };
335
333
  //#endregion
336
334
  //#region src/utils/packageJson.ts
337
335
  const readPackageJson = () => {
338
336
  const packageJsonDir = findUpSync("package.json");
339
337
  if (!packageJsonDir) return {};
340
- return JSON.parse(fs$1.readFileSync(packageJsonDir).toString());
338
+ return JSON.parse(fs.readFileSync(packageJsonDir).toString());
341
339
  };
342
340
  const getPackageJsonProperty = ({ property }) => {
343
341
  try {
@@ -373,7 +371,7 @@ const getProjectName = () => {
373
371
  if (!name) return "";
374
372
  try {
375
373
  return pascalCase(name.split(/[@/]/)[1]);
376
- } catch (err) {
374
+ } catch {
377
375
  return pascalCase(name);
378
376
  }
379
377
  };
@@ -492,9 +490,7 @@ const CRITICAL_RESOURCES_TYPES = ["AWS::Cognito::UserPool", "AWS::DynamoDB::Tabl
492
490
  */
493
491
  const addRetainToCriticalResources = async (template) => {
494
492
  const environment = getEnvironment();
495
- for (const [, resource] of Object.entries(template.Resources)) if (CRITICAL_RESOURCES_TYPES.includes(resource.Type)) {
496
- if (!resource.DeletionPolicy && environment) resource.DeletionPolicy = "Retain";
497
- }
493
+ for (const [, resource] of Object.entries(template.Resources)) if (CRITICAL_RESOURCES_TYPES.includes(resource.Type) && !resource.DeletionPolicy && environment) resource.DeletionPolicy = "Retain";
498
494
  };
499
495
  /**
500
496
  * Base URL for the AWS AppSync Console page.
@@ -885,12 +881,12 @@ const saveEnvironmentOutput = async ({ outputs, stackName }) => {
885
881
  [output.OutputKey]: output
886
882
  };
887
883
  }, {});
888
- const dotCarlinFolderPath = path$2.join(process.cwd(), ".carlin");
889
- if (!fs$3.existsSync(dotCarlinFolderPath)) await fs$3.promises.mkdir(dotCarlinFolderPath);
890
- const filePath = path$2.join(dotCarlinFolderPath, `${stackName}.json`);
891
- await fs$3.promises.writeFile(filePath, JSON.stringify(envFile, null, 2));
892
- const latestFilePath = path$2.join(dotCarlinFolderPath, LATEST_DEPLOY_OUTPUTS_FILENAME);
893
- await fs$3.promises.writeFile(latestFilePath, JSON.stringify(envFile, null, 2));
884
+ const dotCarlinFolderPath = path$1.join(process.cwd(), ".carlin");
885
+ if (!fs$1.existsSync(dotCarlinFolderPath)) await fs$1.promises.mkdir(dotCarlinFolderPath);
886
+ const filePath = path$1.join(dotCarlinFolderPath, `${stackName}.json`);
887
+ await fs$1.promises.writeFile(filePath, JSON.stringify(envFile, null, 2));
888
+ const latestFilePath = path$1.join(dotCarlinFolderPath, LATEST_DEPLOY_OUTPUTS_FILENAME);
889
+ await fs$1.promises.writeFile(latestFilePath, JSON.stringify(envFile, null, 2));
894
890
  };
895
891
  //#endregion
896
892
  //#region src/deploy/cloudformation.core.ts
@@ -1521,196 +1517,224 @@ artifacts:
1521
1517
  name: $PACKAGE_NAME.zip
1522
1518
  `.trim();
1523
1519
  };
1520
+ const getS3BucketArn = (suffix) => {
1521
+ return { "Fn::Sub": [`arn:aws:s3:::\${BucketName}${suffix}`, { BucketName: { Ref: BASE_STACK_BUCKET_LOGICAL_NAME } }] };
1522
+ };
1523
+ const getCodeBuildProjectIamRole = () => {
1524
+ return {
1525
+ Type: "AWS::IAM::Role",
1526
+ Properties: {
1527
+ AssumeRolePolicyDocument: {
1528
+ Version: "2012-10-17",
1529
+ Statement: [{
1530
+ Effect: "Allow",
1531
+ Principal: { Service: ["codebuild.amazonaws.com"] },
1532
+ Action: ["sts:AssumeRole"]
1533
+ }]
1534
+ },
1535
+ Path: getIamPath(),
1536
+ Policies: [{
1537
+ PolicyName: `${CODE_BUILD_PROJECT_IAM_ROLE_LOGICAL_ID}Policy`,
1538
+ PolicyDocument: {
1539
+ Version: "2012-10-17",
1540
+ Statement: [{
1541
+ Effect: "Allow",
1542
+ Action: ["logs:CreateLogStream", "logs:PutLogEvents"],
1543
+ Resource: "*"
1544
+ }, {
1545
+ Effect: "Allow",
1546
+ Action: ["s3:*"],
1547
+ Resource: [getS3BucketArn(""), getS3BucketArn("/*")]
1548
+ }]
1549
+ }
1550
+ }]
1551
+ }
1552
+ };
1553
+ };
1554
+ const getCodeBuildProject = ({ runtime }) => {
1555
+ return {
1556
+ Type: "AWS::CodeBuild::Project",
1557
+ Properties: {
1558
+ Artifacts: {
1559
+ Location: { Ref: BASE_STACK_BUCKET_LOGICAL_NAME },
1560
+ NamespaceType: "NONE",
1561
+ OverrideArtifactName: true,
1562
+ Packaging: "ZIP",
1563
+ Path: "lambda-layers/packages",
1564
+ Type: "S3"
1565
+ },
1566
+ Environment: {
1567
+ ComputeType: "BUILD_GENERAL1_SMALL",
1568
+ /**
1569
+ * Image should match the runtime of the buildspec.
1570
+ * https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
1571
+ */
1572
+ Image: "aws/codebuild/standard:7.0",
1573
+ Type: "LINUX_CONTAINER"
1574
+ },
1575
+ LogsConfig: { CloudWatchLogs: {
1576
+ GroupName: { Ref: `${CODE_BUILD_PROJECT_LOGS_GROUP_LOGICAL_ID}` },
1577
+ Status: "ENABLED"
1578
+ } },
1579
+ ServiceRole: { "Fn::GetAtt": `${CODE_BUILD_PROJECT_IAM_ROLE_LOGICAL_ID}.Arn` },
1580
+ Source: {
1581
+ BuildSpec: getBuildSpec({ runtime }),
1582
+ Type: "NO_SOURCE"
1583
+ }
1584
+ }
1585
+ };
1586
+ };
1524
1587
  /**
1525
1588
  * https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codebuild-project.html
1526
1589
  */
1527
1590
  const getLambdaLayerBuilderTemplate = ({ runtime } = {}) => {
1528
1591
  return {
1529
1592
  Resources: {
1530
- [CODE_BUILD_PROJECT_IAM_ROLE_LOGICAL_ID]: {
1531
- Type: "AWS::IAM::Role",
1532
- Properties: {
1533
- AssumeRolePolicyDocument: {
1534
- Version: "2012-10-17",
1535
- Statement: [{
1536
- Effect: "Allow",
1537
- Principal: { Service: ["codebuild.amazonaws.com"] },
1538
- Action: ["sts:AssumeRole"]
1539
- }]
1540
- },
1541
- Path: getIamPath(),
1542
- Policies: [{
1543
- PolicyName: `${CODE_BUILD_PROJECT_IAM_ROLE_LOGICAL_ID}Policy`,
1544
- PolicyDocument: {
1545
- Version: "2012-10-17",
1546
- Statement: [{
1547
- Effect: "Allow",
1548
- Action: ["logs:CreateLogStream", "logs:PutLogEvents"],
1549
- Resource: "*"
1550
- }, {
1551
- Effect: "Allow",
1552
- Action: ["s3:*"],
1553
- Resource: [{ "Fn::Sub": ["arn:aws:s3:::${BucketName}", { BucketName: { Ref: BASE_STACK_BUCKET_LOGICAL_NAME } }] }, { "Fn::Sub": ["arn:aws:s3:::${BucketName}/*", { BucketName: { Ref: BASE_STACK_BUCKET_LOGICAL_NAME } }] }]
1554
- }]
1555
- }
1556
- }]
1557
- }
1558
- },
1593
+ [CODE_BUILD_PROJECT_IAM_ROLE_LOGICAL_ID]: getCodeBuildProjectIamRole(),
1559
1594
  [CODE_BUILD_PROJECT_LOGS_GROUP_LOGICAL_ID]: {
1560
1595
  Type: "AWS::Logs::LogGroup",
1561
1596
  DeletionPolicy: "Delete",
1562
1597
  Properties: {}
1563
1598
  },
1564
- [BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME]: {
1565
- Type: "AWS::CodeBuild::Project",
1566
- Properties: {
1567
- Artifacts: {
1568
- Location: { Ref: BASE_STACK_BUCKET_LOGICAL_NAME },
1569
- NamespaceType: "NONE",
1570
- OverrideArtifactName: true,
1571
- Packaging: "ZIP",
1572
- Path: "lambda-layers/packages",
1573
- Type: "S3"
1574
- },
1575
- Environment: {
1576
- ComputeType: "BUILD_GENERAL1_SMALL",
1577
- /**
1578
- * Image should match the runtime of the buildspec.
1579
- * https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
1580
- */
1581
- Image: "aws/codebuild/standard:7.0",
1582
- Type: "LINUX_CONTAINER"
1583
- },
1584
- LogsConfig: { CloudWatchLogs: {
1585
- GroupName: { Ref: `${CODE_BUILD_PROJECT_LOGS_GROUP_LOGICAL_ID}` },
1586
- Status: "ENABLED"
1587
- } },
1588
- ServiceRole: { "Fn::GetAtt": `${CODE_BUILD_PROJECT_IAM_ROLE_LOGICAL_ID}.Arn` },
1589
- Source: {
1590
- BuildSpec: getBuildSpec({ runtime }),
1591
- Type: "NO_SOURCE"
1592
- }
1593
- }
1594
- }
1599
+ [BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME]: getCodeBuildProject({ runtime })
1595
1600
  },
1596
1601
  Outputs: { [BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME]: { Value: { Ref: BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME } } }
1597
1602
  };
1598
1603
  };
1599
1604
  //#endregion
1600
1605
  //#region src/deploy/baseStack/getVpcTemplate.ts
1601
- const getVpcTemplate = () => {
1602
- const vpcName = `${pascalCase(NAME)}VPC`;
1603
- const EC2_INTERNET_GATEWAY_LOGICAL_ID = "EC2InternetGateway";
1604
- const EC2_ROUTE_TABLE_LOGICAL_ID = "EC2RouteTable";
1605
- const EC2_VPC_LOGICAL_ID = "EC2VCP";
1606
- const template = {
1607
- AWSTemplateFormatVersion: "2010-09-09",
1608
- Mappings: { CidrMappings: { VPC: { CIDR: "10.0.0.0/16" } } },
1609
- Resources: {
1610
- [EC2_VPC_LOGICAL_ID]: {
1611
- Type: "AWS::EC2::VPC",
1612
- Properties: {
1613
- CidrBlock: { "Fn::FindInMap": [
1614
- "CidrMappings",
1615
- "VPC",
1616
- "CIDR"
1617
- ] },
1618
- EnableDnsHostnames: true,
1619
- EnableDnsSupport: true,
1620
- Tags: [{
1621
- Key: "Name",
1622
- Value: vpcName
1623
- }]
1624
- }
1625
- },
1626
- [EC2_INTERNET_GATEWAY_LOGICAL_ID]: {
1627
- Type: "AWS::EC2::InternetGateway",
1628
- Properties: {}
1629
- },
1630
- EC2VPCGatewayAttachment: {
1631
- Type: "AWS::EC2::VPCGatewayAttachment",
1632
- Properties: {
1633
- InternetGatewayId: { Ref: EC2_INTERNET_GATEWAY_LOGICAL_ID },
1634
- VpcId: { Ref: EC2_VPC_LOGICAL_ID }
1635
- }
1636
- },
1637
- [EC2_ROUTE_TABLE_LOGICAL_ID]: {
1638
- Type: "AWS::EC2::RouteTable",
1639
- Properties: {
1640
- Tags: [{
1641
- Key: "Name",
1642
- Value: { "Fn::Join": [" ", [
1643
- vpcName,
1644
- "-",
1645
- EC2_ROUTE_TABLE_LOGICAL_ID
1646
- ]] }
1647
- }],
1648
- VpcId: { Ref: EC2_VPC_LOGICAL_ID }
1649
- }
1650
- },
1651
- EC2Route: {
1652
- Type: "AWS::EC2::Route",
1653
- Properties: {
1654
- DestinationCidrBlock: "0.0.0.0/0",
1655
- GatewayId: { Ref: EC2_INTERNET_GATEWAY_LOGICAL_ID },
1656
- RouteTableId: { Ref: EC2_ROUTE_TABLE_LOGICAL_ID }
1657
- }
1658
- }
1659
- },
1660
- Outputs: {
1661
- VPCId: {
1662
- Value: { Ref: EC2_VPC_LOGICAL_ID },
1663
- Export: { Name: BASE_STACK_VPC_ID_EXPORTED_NAME }
1664
- },
1665
- VPCDefaultSecurityGroup: {
1666
- Value: { "Fn::GetAtt": [EC2_VPC_LOGICAL_ID, "DefaultSecurityGroup"] },
1667
- Export: { Name: BASE_STACK_VPC_DEFAULT_SECURITY_GROUP_EXPORTED_NAME }
1668
- }
1669
- }
1670
- };
1671
- for (const [index, publicSubnetExportedName] of [
1672
- BASE_STACK_VPC_PUBLIC_SUBNET_0_EXPORTED_NAME,
1673
- BASE_STACK_VPC_PUBLIC_SUBNET_1_EXPORTED_NAME,
1674
- BASE_STACK_VPC_PUBLIC_SUBNET_2_EXPORTED_NAME
1675
- ].entries()) {
1676
- const publicSubnetLogicalId = `PublicSubnet${index}EC2Subnet`;
1677
- const publicSubnetCidrMappings = `PublicSubnet${index}`;
1678
- if (!template.Mappings) template.Mappings = {};
1679
- template.Mappings.CidrMappings[publicSubnetCidrMappings] = { CIDR: `10.0.${index}.0/24` };
1680
- template.Resources[publicSubnetLogicalId] = {
1681
- Type: "AWS::EC2::Subnet",
1606
+ const EC2_INTERNET_GATEWAY_LOGICAL_ID = "EC2InternetGateway";
1607
+ const EC2_ROUTE_TABLE_LOGICAL_ID = "EC2RouteTable";
1608
+ const EC2_VPC_LOGICAL_ID = "EC2VCP";
1609
+ const PUBLIC_SUBNETS_EXPORTED_NAMES = [
1610
+ BASE_STACK_VPC_PUBLIC_SUBNET_0_EXPORTED_NAME,
1611
+ BASE_STACK_VPC_PUBLIC_SUBNET_1_EXPORTED_NAME,
1612
+ BASE_STACK_VPC_PUBLIC_SUBNET_2_EXPORTED_NAME
1613
+ ];
1614
+ const getVpcResources = ({ vpcName }) => {
1615
+ return {
1616
+ [EC2_VPC_LOGICAL_ID]: {
1617
+ Type: "AWS::EC2::VPC",
1682
1618
  Properties: {
1683
- AvailabilityZone: { "Fn::Select": [index, { "Fn::GetAZs": { Ref: "AWS::Region" } }] },
1684
1619
  CidrBlock: { "Fn::FindInMap": [
1685
1620
  "CidrMappings",
1686
- publicSubnetCidrMappings,
1621
+ "VPC",
1687
1622
  "CIDR"
1688
1623
  ] },
1689
- MapPublicIpOnLaunch: true,
1624
+ EnableDnsHostnames: true,
1625
+ EnableDnsSupport: true,
1626
+ Tags: [{
1627
+ Key: "Name",
1628
+ Value: vpcName
1629
+ }]
1630
+ }
1631
+ },
1632
+ [EC2_INTERNET_GATEWAY_LOGICAL_ID]: {
1633
+ Type: "AWS::EC2::InternetGateway",
1634
+ Properties: {}
1635
+ },
1636
+ EC2VPCGatewayAttachment: {
1637
+ Type: "AWS::EC2::VPCGatewayAttachment",
1638
+ Properties: {
1639
+ InternetGatewayId: { Ref: EC2_INTERNET_GATEWAY_LOGICAL_ID },
1640
+ VpcId: { Ref: EC2_VPC_LOGICAL_ID }
1641
+ }
1642
+ },
1643
+ [EC2_ROUTE_TABLE_LOGICAL_ID]: {
1644
+ Type: "AWS::EC2::RouteTable",
1645
+ Properties: {
1690
1646
  Tags: [{
1691
1647
  Key: "Name",
1692
1648
  Value: { "Fn::Join": [" ", [
1693
- EC2_VPC_LOGICAL_ID,
1649
+ vpcName,
1694
1650
  "-",
1695
- publicSubnetLogicalId
1651
+ EC2_ROUTE_TABLE_LOGICAL_ID
1696
1652
  ]] }
1697
1653
  }],
1698
1654
  VpcId: { Ref: EC2_VPC_LOGICAL_ID }
1699
1655
  }
1700
- };
1701
- template.Resources[`PublicSubnet${index}EC2SubnetRouteTableAssociation`] = {
1702
- Type: "AWS::EC2::SubnetRouteTableAssociation",
1656
+ },
1657
+ EC2Route: {
1658
+ Type: "AWS::EC2::Route",
1703
1659
  Properties: {
1704
- RouteTableId: { Ref: EC2_ROUTE_TABLE_LOGICAL_ID },
1705
- SubnetId: { Ref: publicSubnetLogicalId }
1660
+ DestinationCidrBlock: "0.0.0.0/0",
1661
+ GatewayId: { Ref: EC2_INTERNET_GATEWAY_LOGICAL_ID },
1662
+ RouteTableId: { Ref: EC2_ROUTE_TABLE_LOGICAL_ID }
1706
1663
  }
1707
- };
1708
- if (!template.Outputs) template.Outputs = {};
1709
- template.Outputs[publicSubnetLogicalId] = {
1710
- Value: { Ref: publicSubnetLogicalId },
1711
- Export: { Name: publicSubnetExportedName }
1712
- };
1713
- }
1664
+ }
1665
+ };
1666
+ };
1667
+ const getVpcOutputs = () => {
1668
+ return {
1669
+ VPCId: {
1670
+ Value: { Ref: EC2_VPC_LOGICAL_ID },
1671
+ Export: { Name: BASE_STACK_VPC_ID_EXPORTED_NAME }
1672
+ },
1673
+ VPCDefaultSecurityGroup: {
1674
+ Value: { "Fn::GetAtt": [EC2_VPC_LOGICAL_ID, "DefaultSecurityGroup"] },
1675
+ Export: { Name: BASE_STACK_VPC_DEFAULT_SECURITY_GROUP_EXPORTED_NAME }
1676
+ }
1677
+ };
1678
+ };
1679
+ const getPublicSubnetResource = ({ index, publicSubnetLogicalId, publicSubnetCidrMappings }) => {
1680
+ return {
1681
+ Type: "AWS::EC2::Subnet",
1682
+ Properties: {
1683
+ AvailabilityZone: { "Fn::Select": [index, { "Fn::GetAZs": { Ref: "AWS::Region" } }] },
1684
+ CidrBlock: { "Fn::FindInMap": [
1685
+ "CidrMappings",
1686
+ publicSubnetCidrMappings,
1687
+ "CIDR"
1688
+ ] },
1689
+ MapPublicIpOnLaunch: true,
1690
+ Tags: [{
1691
+ Key: "Name",
1692
+ Value: { "Fn::Join": [" ", [
1693
+ EC2_VPC_LOGICAL_ID,
1694
+ "-",
1695
+ publicSubnetLogicalId
1696
+ ]] }
1697
+ }],
1698
+ VpcId: { Ref: EC2_VPC_LOGICAL_ID }
1699
+ }
1700
+ };
1701
+ };
1702
+ const addPublicSubnet = ({ template, index, publicSubnetExportedName }) => {
1703
+ const publicSubnetLogicalId = `PublicSubnet${index}EC2Subnet`;
1704
+ const publicSubnetCidrMappings = `PublicSubnet${index}`;
1705
+ if (!template.Mappings) template.Mappings = {};
1706
+ template.Mappings.CidrMappings[publicSubnetCidrMappings] = { CIDR: `10.0.${index}.0/24` };
1707
+ template.Resources[publicSubnetLogicalId] = getPublicSubnetResource({
1708
+ index,
1709
+ publicSubnetLogicalId,
1710
+ publicSubnetCidrMappings
1711
+ });
1712
+ template.Resources[`PublicSubnet${index}EC2SubnetRouteTableAssociation`] = {
1713
+ Type: "AWS::EC2::SubnetRouteTableAssociation",
1714
+ Properties: {
1715
+ RouteTableId: { Ref: EC2_ROUTE_TABLE_LOGICAL_ID },
1716
+ SubnetId: { Ref: publicSubnetLogicalId }
1717
+ }
1718
+ };
1719
+ if (!template.Outputs) template.Outputs = {};
1720
+ template.Outputs[publicSubnetLogicalId] = {
1721
+ Value: { Ref: publicSubnetLogicalId },
1722
+ Export: { Name: publicSubnetExportedName }
1723
+ };
1724
+ };
1725
+ const getVpcTemplate = () => {
1726
+ const vpcName = `${pascalCase(NAME)}VPC`;
1727
+ const template = {
1728
+ AWSTemplateFormatVersion: "2010-09-09",
1729
+ Mappings: { CidrMappings: { VPC: { CIDR: "10.0.0.0/16" } } },
1730
+ Resources: getVpcResources({ vpcName }),
1731
+ Outputs: getVpcOutputs()
1732
+ };
1733
+ for (const [index, publicSubnetExportedName] of PUBLIC_SUBNETS_EXPORTED_NAMES.entries()) addPublicSubnet({
1734
+ template,
1735
+ index,
1736
+ publicSubnetExportedName
1737
+ });
1714
1738
  return template;
1715
1739
  };
1716
1740
  //#endregion
@@ -2025,7 +2049,7 @@ const deployLambdaLayers = async ({ lambdaExternal = [] }) => {
2025
2049
  log.info(logPrefix$13, `--lambda-externals [${lambdaExternal.join(", ")}] was found. Creating other layers...`);
2026
2050
  const { dependencies = {} } = (() => {
2027
2051
  try {
2028
- return JSON.parse(fs$3.readFileSync(path$2.resolve(process.cwd(), "package.json"), "utf8"));
2052
+ return JSON.parse(fs$1.readFileSync(path$1.resolve(process.cwd(), "package.json"), "utf8"));
2029
2053
  } catch (error) {
2030
2054
  log.error(logPrefix$13, "Cannot read package.json. Error message: %j", error.message);
2031
2055
  return {};
@@ -2803,7 +2827,7 @@ const getCicdStackName = () => {
2803
2827
  //#region src/deploy/cicd/deployCicd.ts
2804
2828
  const logPrefix$10 = "cicd";
2805
2829
  const getLambdaInput = (extension) => {
2806
- return path$2.resolve(__dirname, `lambdas/index.${extension}`);
2830
+ return path$1.resolve(__dirname, `lambdas/index.${extension}`);
2807
2831
  };
2808
2832
  const deployCicdLambdas = async ({ stackName }) => {
2809
2833
  const lambdaInput = (() => {
@@ -2811,11 +2835,11 @@ const deployCicdLambdas = async ({ stackName }) => {
2811
2835
  * This case happens when carlin command is executed when the package is
2812
2836
  * built.
2813
2837
  */
2814
- if (fs$3.existsSync(getLambdaInput("js"))) return getLambdaInput("js");
2838
+ if (fs$1.existsSync(getLambdaInput("js"))) return getLambdaInput("js");
2815
2839
  /**
2816
2840
  * The package isn't built.
2817
2841
  */
2818
- if (fs$3.existsSync(getLambdaInput("ts"))) return getLambdaInput("ts");
2842
+ if (fs$1.existsSync(getLambdaInput("ts"))) return getLambdaInput("ts");
2819
2843
  throw new Error("Cannot read CICD lambdas file.");
2820
2844
  })();
2821
2845
  const s3 = await deployLambdaCode({
@@ -2883,7 +2907,7 @@ const deployCicd = async ({ cpu, memory, pipelines, updateRepository, slackWebho
2883
2907
  * Created to allow mocking.
2884
2908
  */
2885
2909
  const readSSHKey = (dir) => {
2886
- return fs$2.readFileSync(dir, "utf-8");
2910
+ return fs$1.readFileSync(dir, "utf-8");
2887
2911
  };
2888
2912
  //#endregion
2889
2913
  //#region src/deploy/cicd/command.ts
@@ -3058,7 +3082,7 @@ const getTypes = () => {
3058
3082
  options: {
3059
3083
  kind: "scalar",
3060
3084
  construct: (filePath) => {
3061
- return fs$3.readFileSync(path$2.resolve(process.cwd(), filePath)).toString();
3085
+ return fs$1.readFileSync(path$1.resolve(process.cwd(), filePath)).toString();
3062
3086
  }
3063
3087
  }
3064
3088
  }];
@@ -3068,7 +3092,7 @@ const getTypes = () => {
3068
3092
  * @param param0
3069
3093
  */
3070
3094
  const readCloudFormationYamlTemplate = ({ templatePath }) => {
3071
- const template = fs$3.readFileSync(templatePath).toString();
3095
+ const template = fs$1.readFileSync(templatePath).toString();
3072
3096
  const parsed = loadCloudFormationTemplate(template, getTypes());
3073
3097
  if (!parsed || typeof parsed === "string") throw new Error("Cannot parse CloudFormation template.");
3074
3098
  return parsed;
@@ -3087,7 +3111,7 @@ const defaultTemplatePaths$1 = [
3087
3111
  const findAndReadCloudFormationTemplate = async ({ templatePath: defaultTemplatePath, options = {} }) => {
3088
3112
  const templatePath = defaultTemplatePath || defaultTemplatePaths$1.reduce((acc, cur) => {
3089
3113
  if (acc) return acc;
3090
- return fs$3.existsSync(path$2.resolve(process.cwd(), cur)) ? cur : acc;
3114
+ return fs$1.existsSync(path$1.resolve(process.cwd(), cur)) ? cur : acc;
3091
3115
  }, "");
3092
3116
  if (!templatePath) throw new Error("Cannot find a CloudFormation template.");
3093
3117
  const extension = templatePath?.split(".").pop();
@@ -3097,7 +3121,7 @@ const findAndReadCloudFormationTemplate = async ({ templatePath: defaultTemplate
3097
3121
  * "Error message: "unknown tag !<!Ref> at line 21, column 34:\n"
3098
3122
  */
3099
3123
  if (["yaml", "yml"].includes(extension)) return readCloudFormationYamlTemplate({ templatePath });
3100
- const configFilePath = path$2.resolve(process.cwd(), templatePath);
3124
+ const configFilePath = path$1.resolve(process.cwd(), templatePath);
3101
3125
  return readConfigFile({
3102
3126
  configFilePath,
3103
3127
  options
@@ -3384,7 +3408,7 @@ const deployLambdaLayerCommand = {
3384
3408
  */
3385
3409
  const readDockerfile = (dockerfilePath) => {
3386
3410
  try {
3387
- return fs$2.readFileSync(path$1.join(process.cwd(), dockerfilePath), "utf8");
3411
+ return fs$1.readFileSync(path$1.join(process.cwd(), dockerfilePath), "utf8");
3388
3412
  } catch {
3389
3413
  return "";
3390
3414
  }
@@ -3407,11 +3431,11 @@ const readAllDeployFiles = async () => {
3407
3431
  });
3408
3432
  const results = [];
3409
3433
  for (const file of files) try {
3410
- const raw = await fs$3.promises.readFile(file, "utf-8");
3434
+ const raw = await fs$1.promises.readFile(file, "utf-8");
3411
3435
  const content = JSON.parse(raw);
3412
3436
  if (content.stackName && content.outputs) results.push(content);
3413
3437
  } catch {
3414
- log.warn(logPrefix$6, `Could not read deploy file: ${path$2.basename(file)}`);
3438
+ log.warn(logPrefix$6, `Could not read deploy file: ${path$1.basename(file)}`);
3415
3439
  }
3416
3440
  return results.sort((a, b) => {
3417
3441
  return a.packageName.localeCompare(b.packageName);
@@ -5080,21 +5104,21 @@ const deployCommand = {
5080
5104
  const logPrefix = "generate-env";
5081
5105
  const readEnvFile = async ({ envFileName, envsPath }) => {
5082
5106
  try {
5083
- return await fs$3.promises.readFile(path$2.resolve(process.cwd(), envsPath, envFileName), "utf8");
5107
+ return await fs$1.promises.readFile(path$1.resolve(process.cwd(), envsPath, envFileName), "utf8");
5084
5108
  } catch {
5085
5109
  return;
5086
5110
  }
5087
5111
  };
5088
5112
  const writeEnvFile = async ({ envFileName, content }) => {
5089
- return fs$3.promises.writeFile(path$2.resolve(process.cwd(), envFileName), content);
5113
+ return fs$1.promises.writeFile(path$1.resolve(process.cwd(), envFileName), content);
5090
5114
  };
5091
5115
  const readDeployOutputLines = async ({ envFromDeployOutputs }) => {
5092
5116
  const lines = [];
5093
5117
  for (const { dir, variables } of envFromDeployOutputs) {
5094
- const latestDeployPath = path$2.resolve(process.cwd(), dir, ".carlin", LATEST_DEPLOY_OUTPUTS_FILENAME);
5118
+ const latestDeployPath = path$1.resolve(process.cwd(), dir, ".carlin", LATEST_DEPLOY_OUTPUTS_FILENAME);
5095
5119
  let latestDeploy;
5096
5120
  try {
5097
- const raw = await fs$3.promises.readFile(latestDeployPath, "utf8");
5121
+ const raw = await fs$1.promises.readFile(latestDeployPath, "utf8");
5098
5122
  latestDeploy = JSON.parse(raw);
5099
5123
  } catch {
5100
5124
  log.warn(logPrefix, "Could not read latest-deploy.json from %s. Skipping.", latestDeployPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "4.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://ttoss.dev/docs/carlin/",
@@ -61,9 +61,9 @@
61
61
  "ts-node": "^10.9.2",
62
62
  "uglify-js": "^3.19.3",
63
63
  "yargs": "^18.2.0",
64
- "@ttoss/cloudformation": "^0.18.0",
65
- "@ttoss/read-config-file": "^3.0.0",
66
- "@ttoss/config": "^2.0.0"
64
+ "@ttoss/cloudformation": "^0.19.0",
65
+ "@ttoss/config": "^3.0.0",
66
+ "@ttoss/read-config-file": "^3.0.1"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/aws-lambda": "^8.10.164",
@@ -79,7 +79,7 @@
79
79
  "jest": "^30.5.2",
80
80
  "tsdown": "^0.23.1",
81
81
  "typescript": "~6.0.3",
82
- "@ttoss/test-utils": "^5.0.0"
82
+ "@ttoss/test-utils": "^6.0.0"
83
83
  },
84
84
  "publishConfig": {
85
85
  "access": "public",