carlin 1.21.1 → 1.21.3

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/cli.js CHANGED
@@ -10,6 +10,7 @@ const change_case_1 = require("change-case");
10
10
  const command_1 = require("./deploy/command");
11
11
  const ecsTaskReportCommand_1 = require("./deploy/cicd/ecsTaskReportCommand");
12
12
  const generateEnvCommand_1 = require("./generateEnv/generateEnvCommand");
13
+ const cloudformation_1 = require("@ttoss/cloudformation");
13
14
  const aws_sdk_1 = tslib_1.__importDefault(require("aws-sdk"));
14
15
  const deep_equal_1 = tslib_1.__importDefault(require("deep-equal"));
15
16
  const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
@@ -133,7 +134,7 @@ const cli = () => {
133
134
  }
134
135
  } while (findUpPath);
135
136
  const configs = paths.map((p) => {
136
- return (0, utils_1.readObjectFile)({ path: p }) || {};
137
+ return (0, cloudformation_1.unstable_readObjectFile)({ path: p }) || {};
137
138
  });
138
139
  /**
139
140
  * Using configs.reverser() to get the most far config first. This way the
@@ -225,7 +226,7 @@ const cli = () => {
225
226
  .pkgConf(getPkgConfig())
226
227
  .config(getConfig())
227
228
  .config('config', (configPath) => {
228
- return (0, utils_1.readObjectFile)({ path: configPath });
229
+ return (0, cloudformation_1.unstable_readObjectFile)({ path: configPath });
229
230
  })
230
231
  .command({
231
232
  command: 'print-args',
@@ -6,46 +6,16 @@ const utils_1 = require("../utils");
6
6
  const cloudFormation_core_1 = require("./cloudFormation.core");
7
7
  const deployLambdaCode_1 = require("./lambda/deployLambdaCode");
8
8
  const s3_1 = require("./s3");
9
+ const cloudformation_1 = require("@ttoss/cloudformation");
9
10
  const stackName_1 = require("./stackName");
10
11
  const utils_2 = require("./utils");
11
- const fs_1 = tslib_1.__importDefault(require("fs"));
12
12
  const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
13
- const path_1 = tslib_1.__importDefault(require("path"));
14
13
  const logPrefix = 'cloudformation';
15
14
  npmlog_1.default.addLevel('event', 10000, { fg: 'yellow' });
16
15
  npmlog_1.default.addLevel('output', 10000, { fg: 'blue' });
17
16
  exports.defaultTemplatePaths = ['ts', 'js', 'yaml', 'yml', 'json'].map((extension) => {
18
17
  return `./src/cloudformation.${extension}`;
19
18
  });
20
- const findAndReadCloudFormationTemplate = ({ templatePath: defaultTemplatePath, }) => {
21
- const templatePath = defaultTemplatePath ||
22
- exports.defaultTemplatePaths
23
- /**
24
- * Iterate over extensions. If the template of the current extension is
25
- * found, we save it on the accumulator and return it every time until
26
- * the loop ends.
27
- */
28
- .reduce((acc, cur) => {
29
- if (acc) {
30
- return acc;
31
- }
32
- return fs_1.default.existsSync(path_1.default.resolve(process.cwd(), cur)) ? cur : acc;
33
- }, '');
34
- if (!templatePath) {
35
- throw new Error('Cannot find a CloudFormation template.');
36
- }
37
- const extension = templatePath === null || templatePath === void 0 ? void 0 : templatePath.split('.').pop();
38
- const fullPath = path_1.default.resolve(process.cwd(), templatePath);
39
- /**
40
- * We need to read Yaml first because CloudFormation specific tags aren't
41
- * recognized when parsing a simple Yaml file. I.e., a possible error:
42
- * "Error message: "unknown tag !<!Ref> at line 21, column 34:\n"
43
- */
44
- if (['yaml', 'yml'].includes(extension)) {
45
- return (0, utils_1.readCloudFormationYamlTemplate)({ templatePath });
46
- }
47
- return (0, utils_1.readObjectFile)({ path: fullPath });
48
- };
49
19
  const deployCloudFormation = async ({ lambdaDockerfile, lambdaInput, lambdaImage, lambdaExternals = [], parameters, template, templatePath, }) => {
50
20
  try {
51
21
  const { stackName } = await (0, utils_2.handleDeployInitialization)({ logPrefix });
@@ -53,7 +23,7 @@ const deployCloudFormation = async ({ lambdaDockerfile, lambdaInput, lambdaImage
53
23
  if (template) {
54
24
  return { ...template };
55
25
  }
56
- return findAndReadCloudFormationTemplate({ templatePath });
26
+ return (0, cloudformation_1.findAndReadCloudFormationTemplate)({ templatePath });
57
27
  })();
58
28
  await (0, cloudFormation_core_1.cloudFormationV2)()
59
29
  .validateTemplate({
@@ -13,5 +13,3 @@ tslib_1.__exportStar(require("./getEnvironment"), exports);
13
13
  tslib_1.__exportStar(require("./getIamPath"), exports);
14
14
  tslib_1.__exportStar(require("./getProjectName"), exports);
15
15
  tslib_1.__exportStar(require("./packageJson"), exports);
16
- tslib_1.__exportStar(require("./readCloudFormationTemplate"), exports);
17
- tslib_1.__exportStar(require("./readObjectFile"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "1.21.1",
3
+ "version": "1.21.3",
4
4
  "description": "",
5
5
  "license": "GPL-3.0",
6
6
  "author": "Pedro Arantes <arantespp@gmail.com> (https://twitter.com/arantespp)",
@@ -29,6 +29,7 @@
29
29
  "@aws-sdk/client-cloudformation": "^3.226.0",
30
30
  "@octokit/webhooks": "^10.3.1",
31
31
  "@slack/webhook": "^6.1.0",
32
+ "@ttoss/cloudformation": "^0.2.2",
32
33
  "adm-zip": "^0.5.9",
33
34
  "aws-sdk": "^2.1270.0",
34
35
  "builtin-modules": "^3.3.0",
@@ -50,7 +51,7 @@
50
51
  "yargs": "^17.6.2"
51
52
  },
52
53
  "devDependencies": {
53
- "@ttoss/test-utils": "^1.19.0",
54
+ "@ttoss/test-utils": "^1.20.0",
54
55
  "@types/adm-zip": "^0.5.0",
55
56
  "@types/aws-lambda": "^8.10.109",
56
57
  "@types/deep-equal": "^1.0.1",
@@ -70,5 +71,5 @@
70
71
  "publishConfig": {
71
72
  "access": "public"
72
73
  },
73
- "gitHead": "98cf227311c2f28ab73520c793bfe0bf0df27530"
74
+ "gitHead": "f3b33b88d475925960f557619d710f11f831c144"
74
75
  }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readCloudFormationYamlTemplate = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const path = tslib_1.__importStar(require("path"));
7
- const cloudFormationTemplate_1 = require("./cloudFormationTemplate");
8
- const getTypes = () => {
9
- return [
10
- {
11
- tag: `!SubString`,
12
- options: {
13
- kind: 'scalar',
14
- construct: (filePath) => {
15
- return fs
16
- .readFileSync(path.resolve(process.cwd(), filePath))
17
- .toString();
18
- },
19
- },
20
- },
21
- ];
22
- };
23
- /**
24
- * CloudFormation
25
- * @param param0
26
- */
27
- const readCloudFormationYamlTemplate = ({ templatePath, }) => {
28
- const template = fs.readFileSync(templatePath).toString();
29
- const parsed = (0, cloudFormationTemplate_1.loadCloudFormationTemplate)(template, getTypes());
30
- if (!parsed || typeof parsed === 'string') {
31
- throw new Error('Cannot parse CloudFormation template.');
32
- }
33
- return parsed;
34
- };
35
- exports.readCloudFormationYamlTemplate = readCloudFormationYamlTemplate;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readObjectFile = exports.readYaml = void 0;
4
- const tslib_1 = require("tslib");
5
- /* eslint-disable @typescript-eslint/no-var-requires */
6
- const fs_1 = tslib_1.__importDefault(require("fs"));
7
- const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
8
- const readYaml = ({ path }) => {
9
- const template = fs_1.default.readFileSync(path, 'utf8') || JSON.stringify({});
10
- return js_yaml_1.default.load(template);
11
- };
12
- exports.readYaml = readYaml;
13
- /**
14
- * If your file is `.ts`, you must you must export the final object
15
- * `export default { ... }`. If your file is `.js`, you must you must export
16
- * the final object `module.exports = { ... }`. `.json` and `.yml/yaml` must
17
- * define the resources in [JSON](https://www.json.org/json-en.html) and
18
- * [YAML](https://yaml.org/) format respectively.
19
- */
20
- const readObjectFile = ({ path }) => {
21
- if (!fs_1.default.existsSync(path)) {
22
- return {};
23
- }
24
- const extension = path.split('.').pop();
25
- if (extension === 'ts') {
26
- require('ts-node').register({
27
- compilerOptions: { module: 'commonjs' },
28
- transpileOnly: true,
29
- });
30
- const tsObj = require(path);
31
- const obj = tsObj.default || tsObj;
32
- return typeof obj === 'function' ? obj() : obj;
33
- }
34
- if (extension === 'js') {
35
- const obj = require(path);
36
- return typeof obj === 'function' ? obj() : obj;
37
- }
38
- if (extension === 'json') {
39
- return require(path);
40
- }
41
- if (extension === 'yml' || extension === 'yaml') {
42
- return (0, exports.readYaml)({ path });
43
- }
44
- return {};
45
- };
46
- exports.readObjectFile = readObjectFile;