carlin 1.19.11 → 1.19.13

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 (73) hide show
  1. package/dist/cli.js +232 -0
  2. package/dist/config.js +10 -0
  3. package/dist/deploy/addDefaults.cloudFormation.js +138 -0
  4. package/dist/deploy/baseStack/command.js +9 -0
  5. package/dist/deploy/baseStack/config.js +30 -0
  6. package/dist/deploy/baseStack/deployBaseStack.js +59 -0
  7. package/dist/deploy/baseStack/getBaseStackResource.js +26 -0
  8. package/dist/deploy/baseStack/getBucket.template.js +44 -0
  9. package/dist/deploy/baseStack/getLambdaImageBuilder.template.js +186 -0
  10. package/dist/deploy/baseStack/getLambdaLayerBuilder.template.js +140 -0
  11. package/dist/deploy/baseStack/getVpc.template.js +169 -0
  12. package/dist/deploy/cicd/cicd.template.js +922 -0
  13. package/dist/deploy/cicd/command.js +27 -0
  14. package/dist/deploy/cicd/command.options.js +71 -0
  15. package/dist/deploy/cicd/config.js +8 -0
  16. package/dist/deploy/cicd/deployCicd.js +93 -0
  17. package/dist/deploy/cicd/ecsTaskReportCommand.js +51 -0
  18. package/dist/deploy/cicd/getCicdStackName.js +11 -0
  19. package/dist/deploy/cicd/getTriggerPipelineObjectKey.js +11 -0
  20. package/dist/deploy/cicd/lambdas/cicdApiV1.handler.js +124 -0
  21. package/dist/deploy/cicd/lambdas/ecsTaskReport.handler.js +126 -0
  22. package/dist/deploy/cicd/lambdas/executeTasks.js +67 -0
  23. package/dist/deploy/cicd/lambdas/getProcessEnvVariable.js +10 -0
  24. package/dist/deploy/cicd/lambdas/githubWebhooksApiV1.handler.js +146 -0
  25. package/dist/deploy/cicd/lambdas/imageUpdaterSchedule.handler.js +44 -0
  26. package/dist/deploy/cicd/lambdas/index.js +13 -0
  27. package/dist/deploy/cicd/lambdas/pipelines.handler.js +134 -0
  28. package/dist/deploy/cicd/lambdas/putApprovalResultManualTask.js +52 -0
  29. package/dist/deploy/cicd/lambdas/shConditionalCommands.js +30 -0
  30. package/dist/deploy/cicd/pipelines.js +76 -0
  31. package/dist/deploy/cicd/readSSHKey.js +10 -0
  32. package/dist/deploy/cloudFormation.core.js +300 -0
  33. package/dist/deploy/cloudFormation.js +182 -0
  34. package/dist/deploy/command.js +185 -0
  35. package/dist/deploy/lambda/buildLambdaSingleFile.js +30 -0
  36. package/dist/deploy/lambda/deployLambdaCode.js +41 -0
  37. package/dist/deploy/lambda/deployLambdaLayers.js +34 -0
  38. package/dist/deploy/lambda/uploadCodeToECR.js +53 -0
  39. package/dist/deploy/lambda/uploadCodeToS3.js +31 -0
  40. package/dist/deploy/lambdaLayer/command.js +48 -0
  41. package/dist/deploy/lambdaLayer/deployLambdaLayer.js +140 -0
  42. package/dist/deploy/readDockerfile.js +18 -0
  43. package/dist/deploy/s3.js +165 -0
  44. package/dist/deploy/stackName.js +78 -0
  45. package/dist/deploy/staticApp/command.js +79 -0
  46. package/dist/deploy/staticApp/deployStaticApp.js +64 -0
  47. package/dist/deploy/staticApp/findDefaultBuildFolder.js +27 -0
  48. package/dist/deploy/staticApp/getOriginShieldRegion.js +30 -0
  49. package/dist/deploy/staticApp/getStaticAppBucket.js +19 -0
  50. package/dist/deploy/staticApp/invalidateCloudFront.js +42 -0
  51. package/dist/deploy/staticApp/removeOldVersions.js +43 -0
  52. package/dist/deploy/staticApp/staticApp.template.js +303 -0
  53. package/dist/deploy/staticApp/uploadBuiltAppToS3.js +27 -0
  54. package/dist/deploy/utils.js +29 -0
  55. package/dist/generateEnv/generateEnv.js +46 -0
  56. package/dist/generateEnv/generateEnvCommand.js +9 -0
  57. package/dist/index.js +5 -0
  58. package/dist/utils/addGroupToOptions.js +11 -0
  59. package/dist/utils/cloudFormationTemplate.js +132 -0
  60. package/dist/utils/codeBuild.js +50 -0
  61. package/dist/utils/environmentVariables.js +11 -0
  62. package/dist/utils/exec.js +22 -0
  63. package/dist/utils/formatCode.js +12 -0
  64. package/dist/utils/getAwsAccountId.js +10 -0
  65. package/dist/utils/getCurrentBranch.js +33 -0
  66. package/dist/utils/getEnvironment.js +6 -0
  67. package/dist/utils/getIamPath.js +6 -0
  68. package/dist/utils/getProjectName.js +35 -0
  69. package/dist/utils/index.js +17 -0
  70. package/dist/utils/packageJson.js +25 -0
  71. package/dist/utils/readCloudFormationTemplate.js +33 -0
  72. package/dist/utils/readObjectFile.js +46 -0
  73. package/package.json +3 -3
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEnv = 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 utils_1 = require("../utils");
8
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
9
+ const logPrefix = 'generate-env';
10
+ const getEnvFilePath = ({ envFileName }) => {
11
+ return path.resolve(process.cwd(), envFileName);
12
+ };
13
+ const readEnvFile = async ({ envFileName }) => {
14
+ try {
15
+ const content = await fs.promises.readFile(getEnvFilePath({ envFileName }), 'utf8');
16
+ return content;
17
+ }
18
+ catch {
19
+ npmlog_1.default.info(logPrefix, "Env file %s doesn't exist.", envFileName);
20
+ return undefined;
21
+ }
22
+ };
23
+ const writeEnvFile = async ({ envFileName, content, }) => {
24
+ return fs.promises.writeFile(getEnvFilePath({ envFileName }), content);
25
+ };
26
+ /**
27
+ * Generate environment for packages using `carlin`. If [environment](/docs/CLI#environment)
28
+ * isn't production, `carlin` will read `.env` file if exists, merge with
29
+ * additional environment variables and write the result to `.env.local` file. If it's `Production`,
30
+ * it'll read `.env.production` file instead.
31
+ *
32
+ * We chose the name `.env.local` because it works for [Next.js](https://nextjs.org/docs/basic-features/environment-variables)
33
+ * and [CRA](https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used) projects.
34
+ */
35
+ const generateEnv = async () => {
36
+ const environment = (0, utils_1.getEnvironment)();
37
+ const isProduction = (environment === null || environment === void 0 ? void 0 : environment.toLocaleLowerCase()) === 'production';
38
+ const envFileName = isProduction ? '.env.production' : '.env';
39
+ const envFile = await readEnvFile({ envFileName });
40
+ if (!envFile) {
41
+ return;
42
+ }
43
+ await writeEnvFile({ content: envFile, envFileName: '.env.local' });
44
+ npmlog_1.default.info(logPrefix, 'Generate env file %s from %s successfully.', '.env.local', envFileName);
45
+ };
46
+ exports.generateEnv = generateEnv;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEnvCommand = void 0;
4
+ const generateEnv_1 = require("./generateEnv");
5
+ exports.generateEnvCommand = {
6
+ command: 'generate-env',
7
+ describe: 'Generate environment files.',
8
+ handler: generateEnv_1.generateEnv,
9
+ };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const cli_1 = tslib_1.__importDefault(require("./cli"));
5
+ (0, cli_1.default)().parse();
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addGroupToOptions = void 0;
4
+ const addGroupToOptions = (options, group) => {
5
+ Object.values(options).forEach((option) => {
6
+ // eslint-disable-next-line no-param-reassign
7
+ option.group = group;
8
+ });
9
+ return options;
10
+ };
11
+ exports.addGroupToOptions = addGroupToOptions;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadCloudFormationTemplate = exports.dumpToYamlCloudFormationTemplate = exports.getSchema = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
6
+ const cloudFormationTypes = [
7
+ {
8
+ tag: '!Equals',
9
+ options: {
10
+ kind: 'sequence',
11
+ construct: (data) => {
12
+ return { 'Fn::Equals': data };
13
+ },
14
+ },
15
+ },
16
+ {
17
+ tag: '!FindInMap',
18
+ options: {
19
+ kind: 'sequence',
20
+ construct: (data) => {
21
+ return { 'Fn::FindInMap': data };
22
+ },
23
+ },
24
+ },
25
+ {
26
+ tag: '!GetAtt',
27
+ options: {
28
+ kind: 'scalar',
29
+ construct: (data) => {
30
+ return { 'Fn::GetAtt': data.split('.') };
31
+ },
32
+ },
33
+ },
34
+ {
35
+ tag: '!GetAtt',
36
+ options: {
37
+ kind: 'sequence',
38
+ construct: (data) => {
39
+ return { 'Fn::GetAtt': data };
40
+ },
41
+ },
42
+ },
43
+ {
44
+ tag: '!If',
45
+ options: {
46
+ kind: 'sequence',
47
+ construct: (data) => {
48
+ return { 'Fn::If': data };
49
+ },
50
+ },
51
+ },
52
+ {
53
+ tag: '!ImportValue',
54
+ options: {
55
+ kind: 'scalar',
56
+ construct: (data) => {
57
+ return { 'Fn::ImportValue': data };
58
+ },
59
+ },
60
+ },
61
+ {
62
+ tag: '!Join',
63
+ options: {
64
+ kind: 'sequence',
65
+ construct: (data) => {
66
+ return { 'Fn::Join': data };
67
+ },
68
+ },
69
+ },
70
+ {
71
+ tag: '!Not',
72
+ options: {
73
+ kind: 'sequence',
74
+ construct: (data) => {
75
+ return { 'Fn::Not': data };
76
+ },
77
+ },
78
+ },
79
+ {
80
+ tag: '!Ref',
81
+ options: {
82
+ kind: 'scalar',
83
+ construct: (data) => {
84
+ return { Ref: data };
85
+ },
86
+ },
87
+ },
88
+ {
89
+ tag: '!Sub',
90
+ options: {
91
+ kind: 'scalar',
92
+ construct: (data) => {
93
+ return { 'Fn::Sub': data };
94
+ },
95
+ },
96
+ },
97
+ {
98
+ tag: '!Sub',
99
+ options: {
100
+ kind: 'sequence',
101
+ construct: (data) => {
102
+ return { 'Fn::Sub': data };
103
+ },
104
+ },
105
+ },
106
+ ];
107
+ const getYamlTypes = (tagAndTypeArr) => tagAndTypeArr.map(({ tag, options }) => new js_yaml_1.default.Type(tag, options));
108
+ /**
109
+ * Transform CloudFormation directives in objects. For example, transform
110
+ * !Ref Something in { Ref: Something }.
111
+ */
112
+ const getSchema = (tagAndTypeArr = []) => js_yaml_1.default.DEFAULT_SCHEMA.extend(getYamlTypes([...tagAndTypeArr, ...cloudFormationTypes]));
113
+ exports.getSchema = getSchema;
114
+ /**
115
+ * Transform a JSON in a YAML string.
116
+ *
117
+ * @param cloudFormationTemplate JSON CloudFormation template
118
+ * @returns YAML as string
119
+ */
120
+ const dumpToYamlCloudFormationTemplate = (cloudFormationTemplate) => js_yaml_1.default.dump(cloudFormationTemplate, { schema: (0, exports.getSchema)() });
121
+ exports.dumpToYamlCloudFormationTemplate = dumpToYamlCloudFormationTemplate;
122
+ /**
123
+ * Transform YAML string in JSON object.
124
+ *
125
+ * @param template template in String format.
126
+ * @param tagAndTypeArr YAML types.
127
+ * @returns JSON template.
128
+ */
129
+ const loadCloudFormationTemplate = (template, tagAndTypeArr = []) => {
130
+ return js_yaml_1.default.load(template, { schema: (0, exports.getSchema)(tagAndTypeArr) });
131
+ };
132
+ exports.loadCloudFormationTemplate = loadCloudFormationTemplate;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startCodeBuildBuild = exports.waitCodeBuildFinish = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const aws_sdk_1 = require("aws-sdk");
6
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
7
+ const logPrefix = 'codebuild';
8
+ const WAIT_TIME = 10 * 1000;
9
+ /**
10
+ * @param param.name name used to identify the build.
11
+ */
12
+ const waitCodeBuildFinish = async ({ buildId, name, }) => {
13
+ const codeBuild = new aws_sdk_1.CodeBuild();
14
+ let result;
15
+ const checkIfBuildIsFinished = async () => {
16
+ const { builds } = await codeBuild
17
+ .batchGetBuilds({ ids: [buildId] })
18
+ .promise();
19
+ return new Promise((resolve, reject) => {
20
+ setTimeout(() => {
21
+ const executedBuild = builds === null || builds === void 0 ? void 0 : builds.find(({ id }) => id === buildId);
22
+ npmlog_1.default.info(logPrefix, `Build status of ${name || buildId}: ${executedBuild === null || executedBuild === void 0 ? void 0 : executedBuild.buildStatus}`);
23
+ if (executedBuild && executedBuild.currentPhase === 'COMPLETED') {
24
+ if (executedBuild.buildStatus === 'SUCCEEDED') {
25
+ resolve(executedBuild);
26
+ }
27
+ else if (['FAILED', 'FAILURE'].includes(executedBuild.buildStatus || '')) {
28
+ reject(new Error(`Cannot execute build ${buildId}.`));
29
+ }
30
+ }
31
+ resolve(undefined);
32
+ }, WAIT_TIME);
33
+ });
34
+ };
35
+ while (!result) {
36
+ // eslint-disable-next-line no-await-in-loop
37
+ result = await checkIfBuildIsFinished();
38
+ }
39
+ return result;
40
+ };
41
+ exports.waitCodeBuildFinish = waitCodeBuildFinish;
42
+ const startCodeBuildBuild = async ({ projectName, }) => {
43
+ const codeBuild = new aws_sdk_1.CodeBuild();
44
+ const { build } = await codeBuild.startBuild({ projectName }).promise();
45
+ if (!build) {
46
+ throw new Error(`Cannot start ${projectName} build`);
47
+ }
48
+ return build;
49
+ };
50
+ exports.startCodeBuildBuild = startCodeBuildBuild;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setEnvVar = exports.getEnvVar = exports.cache = void 0;
4
+ const cache = new Map();
5
+ exports.cache = cache;
6
+ const getEnvVar = (key) => {
7
+ return cache.has(key) && cache.get(key) ? cache.get(key) : undefined;
8
+ };
9
+ exports.getEnvVar = getEnvVar;
10
+ const setEnvVar = (key, value) => cache.set(key, value);
11
+ exports.setEnvVar = setEnvVar;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exec = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const child_process_1 = tslib_1.__importDefault(require("child_process"));
6
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
7
+ npmlog_1.default.heading = 'exec';
8
+ const exec = (cmd) => new Promise((resolve, reject) => {
9
+ child_process_1.default.exec(cmd, (error, stdout, stderr) => {
10
+ if (error) {
11
+ return reject(error);
12
+ }
13
+ if (stdout) {
14
+ return resolve(stdout);
15
+ }
16
+ if (stderr) {
17
+ return reject(stderr);
18
+ }
19
+ return resolve(undefined);
20
+ });
21
+ });
22
+ exports.exec = exec;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uglify = exports.formatCode = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const UglifyJS = tslib_1.__importStar(require("uglify-js"));
6
+ const prettier = tslib_1.__importStar(require("prettier"));
7
+ const formatCode = (code) => {
8
+ return prettier.format(code, { parser: 'babel' });
9
+ };
10
+ exports.formatCode = formatCode;
11
+ const uglify = (code) => UglifyJS.minify(code).code;
12
+ exports.uglify = uglify;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAwsAccountId = void 0;
4
+ const aws_sdk_1 = require("aws-sdk");
5
+ const getAwsAccountId = async () => {
6
+ const sts = new aws_sdk_1.STS();
7
+ const { Account } = await sts.getCallerIdentity().promise();
8
+ return Account;
9
+ };
10
+ exports.getAwsAccountId = getAwsAccountId;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrentBranch = exports.BRANCH_UNDEFINED = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const environmentVariables_1 = require("./environmentVariables");
6
+ const simple_git_1 = tslib_1.__importDefault(require("simple-git"));
7
+ exports.BRANCH_UNDEFINED = '';
8
+ /**
9
+ * Git current branch is used to determine the name of the stack when deploying
10
+ * resources. If we provide a `CARLIN_BRANCH` through `process.env` or by
11
+ * options, these values will be used instead of Git current branch. Example:
12
+ *
13
+ * ```
14
+ * CARLIN_BRANCH=branch-name carlin deploy --destroy
15
+ * carlin deploy --destroy --branch=branch-name
16
+ * ```
17
+ *
18
+ * This parameters is useful when you need to delete a deployment related to
19
+ * some branch but such branch has already beed deleted.
20
+ */
21
+ const getCurrentBranch = async () => {
22
+ try {
23
+ if ((0, environmentVariables_1.getEnvVar)('BRANCH')) {
24
+ return (0, environmentVariables_1.getEnvVar)('BRANCH');
25
+ }
26
+ const { current } = await (0, simple_git_1.default)().branch();
27
+ return current || exports.BRANCH_UNDEFINED;
28
+ }
29
+ catch (err) {
30
+ return exports.BRANCH_UNDEFINED;
31
+ }
32
+ };
33
+ exports.getCurrentBranch = getCurrentBranch;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEnvironment = void 0;
4
+ const environmentVariables_1 = require("./environmentVariables");
5
+ const getEnvironment = () => (0, environmentVariables_1.getEnvVar)('ENVIRONMENT');
6
+ exports.getEnvironment = getEnvironment;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIamPath = void 0;
4
+ const config_1 = require("../config");
5
+ const getIamPath = () => `/${config_1.NAME}/`;
6
+ exports.getIamPath = getIamPath;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProjectName = void 0;
4
+ const environmentVariables_1 = require("./environmentVariables");
5
+ const packageJson_1 = require("./packageJson");
6
+ const change_case_1 = require("change-case");
7
+ /**
8
+ * This variable is used to determine the name of the whole project. If the
9
+ * project is a monorepo, the project name is considered as the
10
+ * [scope](https://docs.npmjs.com/cli/v7/using-npm/scope) of the `package.json`
11
+ * name property. If isn't a monorepo, is considered the package name.
12
+ *
13
+ * This variable is used to set some properties on CloudFormation tags and
14
+ * defining the name of some stacks, for instance, the CICD stack.
15
+ */
16
+ const getProjectName = () => {
17
+ if ((0, environmentVariables_1.getEnvVar)('PROJECT')) {
18
+ return (0, environmentVariables_1.getEnvVar)('PROJECT');
19
+ }
20
+ const name = (0, packageJson_1.getPackageName)();
21
+ /**
22
+ * This case happens when user executes `carlin` outside of project.
23
+ * Even commands like `carlin --help` raise an error.
24
+ */
25
+ if (!name) {
26
+ return '';
27
+ }
28
+ try {
29
+ return (0, change_case_1.pascalCase)(name.split(/[@/]/)[1]);
30
+ }
31
+ catch (err) {
32
+ return (0, change_case_1.pascalCase)(name);
33
+ }
34
+ };
35
+ exports.getProjectName = getProjectName;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./addGroupToOptions"), exports);
5
+ tslib_1.__exportStar(require("./codeBuild"), exports);
6
+ tslib_1.__exportStar(require("./cloudFormationTemplate"), exports);
7
+ tslib_1.__exportStar(require("./environmentVariables"), exports);
8
+ tslib_1.__exportStar(require("./exec"), exports);
9
+ tslib_1.__exportStar(require("./formatCode"), exports);
10
+ tslib_1.__exportStar(require("./getAwsAccountId"), exports);
11
+ tslib_1.__exportStar(require("./getCurrentBranch"), exports);
12
+ tslib_1.__exportStar(require("./getEnvironment"), exports);
13
+ tslib_1.__exportStar(require("./getIamPath"), exports);
14
+ tslib_1.__exportStar(require("./getProjectName"), exports);
15
+ tslib_1.__exportStar(require("./packageJson"), exports);
16
+ tslib_1.__exportStar(require("./readCloudFormationTemplate"), exports);
17
+ tslib_1.__exportStar(require("./readObjectFile"), exports);
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageVersion = exports.getPackageName = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const find_up_1 = tslib_1.__importDefault(require("find-up"));
6
+ const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const readPackageJson = () => {
8
+ const packageJsonDir = find_up_1.default.sync('package.json');
9
+ if (!packageJsonDir) {
10
+ return {};
11
+ }
12
+ return JSON.parse(fs_1.default.readFileSync(packageJsonDir).toString());
13
+ };
14
+ const getPackageJsonProperty = ({ property }) => {
15
+ try {
16
+ return readPackageJson()[property];
17
+ }
18
+ catch {
19
+ return '';
20
+ }
21
+ };
22
+ const getPackageName = () => getPackageJsonProperty({ property: 'name' });
23
+ exports.getPackageName = getPackageName;
24
+ const getPackageVersion = () => getPackageJsonProperty({ property: 'version' });
25
+ exports.getPackageVersion = getPackageVersion;
@@ -0,0 +1,33 @@
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
+ {
10
+ tag: `!SubString`,
11
+ options: {
12
+ kind: 'scalar',
13
+ construct: (filePath) => {
14
+ return fs
15
+ .readFileSync(path.resolve(process.cwd(), filePath))
16
+ .toString();
17
+ },
18
+ },
19
+ },
20
+ ];
21
+ /**
22
+ * CloudFormation
23
+ * @param param0
24
+ */
25
+ const readCloudFormationYamlTemplate = ({ templatePath, }) => {
26
+ const template = fs.readFileSync(templatePath).toString();
27
+ const parsed = (0, cloudFormationTemplate_1.loadCloudFormationTemplate)(template, getTypes());
28
+ if (!parsed || typeof parsed === 'string') {
29
+ throw new Error('Cannot parse CloudFormation template.');
30
+ }
31
+ return parsed;
32
+ };
33
+ exports.readCloudFormationYamlTemplate = readCloudFormationYamlTemplate;
@@ -0,0 +1,46 @@
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "1.19.11",
3
+ "version": "1.19.13",
4
4
  "description": "",
5
5
  "license": "GPL-3.0",
6
6
  "author": "Pedro Arantes <arantespp@gmail.com> (https://twitter.com/arantespp)",
@@ -50,7 +50,7 @@
50
50
  "yargs": "^17.4.1"
51
51
  },
52
52
  "devDependencies": {
53
- "@ttoss/test-utils": "^1.16.10",
53
+ "@ttoss/test-utils": "^1.17.0",
54
54
  "@types/adm-zip": "^0.5.0",
55
55
  "@types/aws-lambda": "^8.10.95",
56
56
  "@types/deep-equal": "^1.0.1",
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "registry": "https://registry.npmjs.org/"
73
73
  },
74
- "gitHead": "b9f9de9b8389be76965f125b593166f10c2171e6"
74
+ "gitHead": "eaf4015635a5476a3b59beb3c35284404c1f07d5"
75
75
  }