carlin 0.19.0

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 (60) hide show
  1. package/CHANGELOG.md +378 -0
  2. package/bin/carlin +2 -0
  3. package/dist/cli.js +250 -0
  4. package/dist/config.js +10 -0
  5. package/dist/deploy/addDefaults.cloudFormation.js +138 -0
  6. package/dist/deploy/baseStack/command.js +9 -0
  7. package/dist/deploy/baseStack/config.js +30 -0
  8. package/dist/deploy/baseStack/deployBaseStack.js +61 -0
  9. package/dist/deploy/baseStack/getBaseStackResource.js +26 -0
  10. package/dist/deploy/baseStack/getBucket.template.js +44 -0
  11. package/dist/deploy/baseStack/getLambdaImageBuilder.template.js +188 -0
  12. package/dist/deploy/baseStack/getLambdaLayerBuilder.template.js +140 -0
  13. package/dist/deploy/baseStack/getVpc.template.js +169 -0
  14. package/dist/deploy/cicd/cicd.template.js +872 -0
  15. package/dist/deploy/cicd/command.js +84 -0
  16. package/dist/deploy/cicd/config.js +7 -0
  17. package/dist/deploy/cicd/deployCicd.js +114 -0
  18. package/dist/deploy/cicd/ecsTaskReportCommand.js +53 -0
  19. package/dist/deploy/cicd/getCicdStackName.js +11 -0
  20. package/dist/deploy/cicd/getTriggerPipelineObjectKey.js +12 -0
  21. package/dist/deploy/cicd/lambdas/cicdApiV1.handler.js +124 -0
  22. package/dist/deploy/cicd/lambdas/ecsTaskReport.handler.js +79 -0
  23. package/dist/deploy/cicd/lambdas/executeTasks.js +91 -0
  24. package/dist/deploy/cicd/lambdas/getProcessEnvVariable.js +10 -0
  25. package/dist/deploy/cicd/lambdas/githubWebhooksApiV1.handler.js +143 -0
  26. package/dist/deploy/cicd/lambdas/index.js +11 -0
  27. package/dist/deploy/cicd/lambdas/pipelines.handler.js +154 -0
  28. package/dist/deploy/cicd/lambdas/putApprovalResultManualTask.js +52 -0
  29. package/dist/deploy/cicd/pipelines.js +52 -0
  30. package/dist/deploy/cloudFormation.core.js +286 -0
  31. package/dist/deploy/cloudFormation.js +201 -0
  32. package/dist/deploy/command.js +211 -0
  33. package/dist/deploy/lambda.js +177 -0
  34. package/dist/deploy/lambdaLayer/command.js +51 -0
  35. package/dist/deploy/lambdaLayer/deployLambdaLayer.js +142 -0
  36. package/dist/deploy/s3.js +167 -0
  37. package/dist/deploy/stackName.js +78 -0
  38. package/dist/deploy/staticApp/command.js +101 -0
  39. package/dist/deploy/staticApp/getOriginShieldRegion.js +30 -0
  40. package/dist/deploy/staticApp/staticApp.js +206 -0
  41. package/dist/deploy/staticApp/staticApp.template.js +874 -0
  42. package/dist/deploy/utils.js +31 -0
  43. package/dist/index.js +7 -0
  44. package/dist/utils/addGroupToOptions.js +11 -0
  45. package/dist/utils/buildLambdaFiles.js +99 -0
  46. package/dist/utils/cloudFormationTemplate.js +134 -0
  47. package/dist/utils/codeBuild.js +52 -0
  48. package/dist/utils/environmentVariables.js +11 -0
  49. package/dist/utils/exec.js +24 -0
  50. package/dist/utils/formatCode.js +30 -0
  51. package/dist/utils/getAwsAccountId.js +10 -0
  52. package/dist/utils/getCurrentBranch.js +35 -0
  53. package/dist/utils/getEnvironment.js +6 -0
  54. package/dist/utils/getIamPath.js +6 -0
  55. package/dist/utils/getProjectName.js +28 -0
  56. package/dist/utils/index.js +26 -0
  57. package/dist/utils/packageJson.js +46 -0
  58. package/dist/utils/readCloudFormationTemplate.js +35 -0
  59. package/dist/utils/readObjectFile.js +50 -0
  60. package/package.json +83 -0
@@ -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 = () => 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,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProjectName = void 0;
4
+ const change_case_1 = require("change-case");
5
+ const environmentVariables_1 = require("./environmentVariables");
6
+ const packageJson_1 = require("./packageJson");
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 (environmentVariables_1.getEnvVar('PROJECT')) {
18
+ return environmentVariables_1.getEnvVar('PROJECT');
19
+ }
20
+ const name = packageJson_1.getPackageName();
21
+ try {
22
+ return change_case_1.pascalCase(name.split(/[@/]/)[1]);
23
+ }
24
+ catch (err) {
25
+ return change_case_1.pascalCase(name);
26
+ }
27
+ };
28
+ exports.getProjectName = getProjectName;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./addGroupToOptions"), exports);
14
+ __exportStar(require("./codeBuild"), exports);
15
+ __exportStar(require("./cloudFormationTemplate"), exports);
16
+ __exportStar(require("./environmentVariables"), exports);
17
+ __exportStar(require("./exec"), exports);
18
+ __exportStar(require("./formatCode"), exports);
19
+ __exportStar(require("./getAwsAccountId"), exports);
20
+ __exportStar(require("./getCurrentBranch"), exports);
21
+ __exportStar(require("./getEnvironment"), exports);
22
+ __exportStar(require("./getIamPath"), exports);
23
+ __exportStar(require("./getProjectName"), exports);
24
+ __exportStar(require("./packageJson"), exports);
25
+ __exportStar(require("./readCloudFormationTemplate"), exports);
26
+ __exportStar(require("./readObjectFile"), exports);
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.getPackageVersion = exports.getPackageName = void 0;
26
+ const findUp = __importStar(require("find-up"));
27
+ const fs_1 = __importDefault(require("fs"));
28
+ const readPackageJson = () => {
29
+ const packageJsonDir = findUp.sync('package.json');
30
+ if (!packageJsonDir) {
31
+ return {};
32
+ }
33
+ return JSON.parse(fs_1.default.readFileSync(packageJsonDir).toString());
34
+ };
35
+ const getPackageJsonProperty = ({ property }) => {
36
+ try {
37
+ return readPackageJson()[property];
38
+ }
39
+ catch (_a) {
40
+ return '';
41
+ }
42
+ };
43
+ const getPackageName = () => getPackageJsonProperty({ property: 'name' });
44
+ exports.getPackageName = getPackageName;
45
+ const getPackageVersion = () => getPackageJsonProperty({ property: 'version' });
46
+ exports.getPackageVersion = getPackageVersion;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readCloudFormationYamlTemplate = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const cloudFormationTemplate_1 = require("./cloudFormationTemplate");
10
+ const getTypes = () => [
11
+ {
12
+ tag: `!SubString`,
13
+ options: {
14
+ kind: 'scalar',
15
+ construct: (filePath) => {
16
+ return fs_1.default
17
+ .readFileSync(path_1.default.resolve(process.cwd(), filePath))
18
+ .toString();
19
+ },
20
+ },
21
+ },
22
+ ];
23
+ /**
24
+ * CloudFormation
25
+ * @param param0
26
+ */
27
+ const readCloudFormationYamlTemplate = ({ templatePath, }) => {
28
+ const template = fs_1.default.readFileSync(templatePath).toString();
29
+ const parsed = 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;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readObjectFile = exports.readYaml = void 0;
7
+ /* eslint-disable import/no-dynamic-require */
8
+ /* eslint-disable global-require */
9
+ /* eslint-disable @typescript-eslint/no-var-requires */
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const js_yaml_1 = __importDefault(require("js-yaml"));
12
+ const readYaml = ({ path }) => {
13
+ const template = fs_1.default.readFileSync(path, 'utf8') || JSON.stringify({});
14
+ return js_yaml_1.default.load(template);
15
+ };
16
+ exports.readYaml = readYaml;
17
+ /**
18
+ * If your file is `.ts`, you must you must export the final object
19
+ * `export default { ... }`. If your file is `.js`, you must you must export
20
+ * the final object `module.exports = { ... }`. `.json` and `.yml/yaml` must
21
+ * define the resources in [JSON](https://www.json.org/json-en.html) and
22
+ * [YAML](https://yaml.org/) format respectively.
23
+ */
24
+ const readObjectFile = ({ path }) => {
25
+ if (!fs_1.default.existsSync(path)) {
26
+ return {};
27
+ }
28
+ const extension = path.split('.').pop();
29
+ if (extension === 'ts') {
30
+ require('ts-node').register({
31
+ compilerOptions: { module: 'commonjs' },
32
+ transpileOnly: true,
33
+ });
34
+ const tsObj = require(path);
35
+ const obj = tsObj.default || tsObj;
36
+ return typeof obj === 'function' ? obj() : obj;
37
+ }
38
+ if (extension === 'js') {
39
+ const obj = require(path);
40
+ return typeof obj === 'function' ? obj() : obj;
41
+ }
42
+ if (extension === 'json') {
43
+ return require(path);
44
+ }
45
+ if (extension === 'yml' || extension === 'yaml') {
46
+ return exports.readYaml({ path });
47
+ }
48
+ return {};
49
+ };
50
+ exports.readObjectFile = readObjectFile;
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "carlin",
3
+ "version": "0.19.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "build": "tsc",
9
+ "prepare": "npm run test && npm run build",
10
+ "predeploy": "echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc",
11
+ "deploy": "npm publish"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/ttoss/carlin.git"
16
+ },
17
+ "publishConfig": {
18
+ "registry": "https://registry.npmjs.org/"
19
+ },
20
+ "keywords": [],
21
+ "author": {
22
+ "email": "arantespp@gmail.com",
23
+ "name": "Pedro Arantes",
24
+ "url": "https://twitter.com/arantespp"
25
+ },
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/ttoss/carlin/issues"
29
+ },
30
+ "homepage": "https://github.com/ttoss/carlin#readme",
31
+ "dependencies": {
32
+ "@aws-sdk/client-cloudformation": "^3.18.0",
33
+ "@octokit/webhooks": "^9.6.0",
34
+ "@slack/webhook": "^6.0.0",
35
+ "adm-zip": "^0.5.5",
36
+ "app-root-path": "^3.0.0",
37
+ "aws-sdk": "^2.906.0",
38
+ "builtin-modules": "^3.2.0",
39
+ "change-case": "^4.1.2",
40
+ "deep-equal": "^2.0.5",
41
+ "deepmerge": "^4.2.2",
42
+ "esbuild": "^0.12.26",
43
+ "find-up": "^5.0.0",
44
+ "glob": "^7.1.7",
45
+ "js-yaml": "^4.1.0",
46
+ "mime-types": "^2.1.30",
47
+ "npmlog": "^4.1.2",
48
+ "prettier": "^2.3.0",
49
+ "semver": "^7.3.5",
50
+ "simple-git": "^2.38.1",
51
+ "ts-loader": "^9.1.2",
52
+ "ts-node": "^9.1.1",
53
+ "typescript": "^4.2.4",
54
+ "uglify-js": "^3.13.6",
55
+ "yargs": "^17.0.1"
56
+ },
57
+ "devDependencies": {
58
+ "@types/adm-zip": "^0.4.34",
59
+ "@types/app-root-path": "^1.2.4",
60
+ "@types/aws-lambda": "^8.10.76",
61
+ "@types/deep-equal": "^1.0.1",
62
+ "@types/eslint": "^7.2.10",
63
+ "@types/faker": "^5.5.5",
64
+ "@types/jest": "^26.0.23",
65
+ "@types/js-yaml": "^4.0.1",
66
+ "@types/mime-types": "^2.1.0",
67
+ "@types/node": "^15.0.3",
68
+ "@types/npmlog": "^4.1.2",
69
+ "@types/semver": "^7.3.5",
70
+ "@types/uglify-js": "^3.13.0",
71
+ "@types/yargs": "^16.0.1",
72
+ "faker": "^5.5.3",
73
+ "jest": "^27.0.4",
74
+ "ts-jest": "^27.0.3"
75
+ },
76
+ "bin": {
77
+ "carlin": "./bin/carlin"
78
+ },
79
+ "files": [
80
+ "bin/",
81
+ "dist/"
82
+ ]
83
+ }