@hiiretail/gcp-infra-generators 1.0.0 → 1.0.2

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 (74) hide show
  1. package/dist/generators/clan-resources/clan-project/index.js +89 -189
  2. package/dist/generators/common-resources/bigquery/index.js +172 -267
  3. package/dist/generators/common-resources/budget/index.js +67 -153
  4. package/dist/generators/common-resources/cloud-armor/index.js +17 -167
  5. package/dist/generators/common-resources/cloud-storage/index.js +96 -205
  6. package/dist/generators/common-resources/cloudsql/index.js +71 -177
  7. package/dist/generators/common-resources/cloudsql-database/index.js +40 -287
  8. package/dist/generators/common-resources/confluent-cluster/index.js +23 -132
  9. package/dist/generators/common-resources/datastore/index.js +48 -194
  10. package/dist/generators/common-resources/elastic-cloud/index.js +22 -132
  11. package/dist/generators/common-resources/elastic-index-policy/handle-yaml.js +76 -0
  12. package/dist/generators/common-resources/elastic-index-policy/index.js +131 -286
  13. package/dist/generators/common-resources/elastic-template/index.js +52 -162
  14. package/dist/generators/common-resources/firestore/index.js +93 -233
  15. package/dist/generators/common-resources/iam/index.js +35 -157
  16. package/dist/generators/common-resources/iam/valid-prefix.js +8 -0
  17. package/dist/generators/common-resources/kafka-connect/index.js +35 -144
  18. package/dist/generators/common-resources/kafka-topics/index.js +20 -129
  19. package/dist/generators/common-resources/kms/index.js +31 -141
  20. package/dist/generators/common-resources/memorystore/index.js +42 -328
  21. package/dist/generators/common-resources/monitoring/handle-yaml.js +49 -0
  22. package/dist/generators/common-resources/monitoring/index.js +144 -322
  23. package/dist/generators/common-resources/monitoring/templates/alerts/generic-infra.yaml +37 -2
  24. package/dist/generators/common-resources/monitoring/validate.js +58 -0
  25. package/dist/generators/common-resources/pubsub/append.js +130 -0
  26. package/dist/generators/common-resources/pubsub/get-gcp-projects.js +34 -0
  27. package/dist/generators/common-resources/pubsub/handle-subscribers.js +68 -0
  28. package/dist/generators/common-resources/pubsub/index.js +194 -536
  29. package/dist/generators/common-resources/pubsub/validate.js +53 -0
  30. package/dist/generators/common-resources/scheduler/append.js +85 -0
  31. package/dist/generators/common-resources/scheduler/index.js +62 -249
  32. package/dist/generators/common-resources/spanner/append.js +31 -0
  33. package/dist/generators/common-resources/spanner/index.js +102 -269
  34. package/dist/generators/common-resources/spanner/validate.js +38 -0
  35. package/dist/generators/docs/rca/index.js +25 -135
  36. package/dist/generators/docs/runbook/index.js +16 -126
  37. package/dist/generators/docs/srb/index.js +33 -147
  38. package/dist/generators/docs/srb/run-docker.js +2 -0
  39. package/dist/generators/init/clan-infra/gcp-projects.js +47 -0
  40. package/dist/generators/init/clan-infra/index.js +95 -290
  41. package/dist/generators/init/clan-infra/tribe-clan-repo.js +38 -0
  42. package/dist/generators/init/clan-infra/validate.js +8 -0
  43. package/dist/generators/maintenance/manage-states/index.js +142 -219
  44. package/dist/generators/maintenance/update-modules/index.js +56 -155
  45. package/dist/generators/organization/clan-project/googlecloud.js +124 -0
  46. package/dist/generators/organization/clan-project/index.js +81 -303
  47. package/dist/node_modules/.package-lock.json +88 -31
  48. package/dist/node_modules/@google-cloud/storage/build/cjs/src/bucket.js +5 -5
  49. package/dist/node_modules/@google-cloud/storage/build/cjs/src/file.d.ts +1 -0
  50. package/dist/node_modules/@google-cloud/storage/build/cjs/src/file.js +10 -1
  51. package/dist/node_modules/@google-cloud/storage/build/cjs/src/storage.js +1 -1
  52. package/dist/node_modules/@google-cloud/storage/build/cjs/src/transfer-manager.d.ts +4 -4
  53. package/dist/node_modules/@google-cloud/storage/build/cjs/src/transfer-manager.js +4 -4
  54. package/dist/node_modules/@google-cloud/storage/build/cjs/src/util.d.ts +1 -1
  55. package/dist/node_modules/@google-cloud/storage/build/cjs/src/util.js +2 -2
  56. package/dist/node_modules/@google-cloud/storage/build/esm/src/bucket.js +5 -5
  57. package/dist/node_modules/@google-cloud/storage/build/esm/src/file.d.ts +1 -0
  58. package/dist/node_modules/@google-cloud/storage/build/esm/src/file.js +10 -1
  59. package/dist/node_modules/@google-cloud/storage/build/esm/src/storage.js +1 -1
  60. package/dist/node_modules/@google-cloud/storage/build/esm/src/transfer-manager.d.ts +4 -4
  61. package/dist/node_modules/@google-cloud/storage/build/esm/src/transfer-manager.js +4 -4
  62. package/dist/node_modules/@google-cloud/storage/build/esm/src/util.d.ts +1 -1
  63. package/dist/node_modules/@google-cloud/storage/build/esm/src/util.js +2 -2
  64. package/dist/node_modules/@google-cloud/storage/package.json +5 -5
  65. package/dist/package.json +45 -0
  66. package/dist/src/BaseGenerator.js +84 -0
  67. package/dist/src/SecretsGenerator.js +137 -0
  68. package/dist/src/cli.js +54 -255
  69. package/dist/src/dependency-check.js +48 -0
  70. package/dist/src/update-check.js +38 -0
  71. package/dist/src/validators.js +33 -0
  72. package/dist/src/yeoman.js +80 -0
  73. package/package.json +2 -3
  74. package/dist/node_modules/@google-cloud/storage/CHANGELOG.md +0 -1769
@@ -1,202 +1,92 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __commonJS = (cb, mod) => function __require() {
5
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
- };
7
-
8
- // src/validators.js
9
- var require_validators = __commonJS({
10
- "src/validators.js"(exports2, module2) {
11
- var path2 = require("path");
12
- module2.exports = {
13
- chain: /* @__PURE__ */ __name((input, ...validators) => {
14
- let msg = "";
15
- validators.every((validator) => {
16
- msg = validator(input);
17
- return msg === true;
18
- });
19
- return msg === true ? true : msg;
20
- }, "chain"),
21
- filename: /* @__PURE__ */ __name((input) => {
22
- if (!input) {
23
- return true;
24
- }
25
- return path2.basename(input) === input ? true : "Invalid filename";
26
- }, "filename"),
27
- maxLength: /* @__PURE__ */ __name((input, maxLength) => !input || input.length <= maxLength ? true : `Exceeds max \
28
- length: ${maxLength}`, "maxLength"),
29
- required: /* @__PURE__ */ __name((input) => {
30
- const msg = "Required";
31
- if (Array.isArray(input)) {
32
- return input.length > 0 ? true : msg;
33
- }
34
- if (input) {
35
- return input.trim().length > 0 ? true : msg;
36
- }
37
- return msg;
38
- }, "required")
39
- };
40
- }
41
- });
1
+ const path = require('path');
2
+ const chalk = require('chalk');
3
+ const BaseGenerator = require('../../../src/BaseGenerator');
4
+ const { required } = require('../../../src/validators');
42
5
 
43
- // src/BaseGenerator.js
44
- var require_BaseGenerator = __commonJS({
45
- "src/BaseGenerator.js"(exports2, module2) {
46
- var Generator = require("yeoman-generator");
47
- var path2 = require("path");
48
- var fs = require("fs");
49
- var inquirer = require("inquirer");
50
- var { chain, required: required2, filename } = require_validators();
51
- module2.exports = class extends Generator {
52
- constructor(args, opts) {
53
- super(args, opts);
54
- this.baseDir = path2.resolve(path2.join(__dirname, ".."));
55
- this.destinationRoot(process.cwd());
56
- const [command, generator] = opts.namespace.split(":").slice(-2);
57
- this.generatorId = path2.join(command, generator);
58
- this.sourceRoot(
59
- path2.join(this.baseDir, "generators", this.generatorId, "templates")
60
- );
61
- this.copyDir = (templateDir, targetDir, answers = this.answers, skipIfExists = false) => {
62
- if (skipIfExists && fs.existsSync(targetDir)) {
63
- return;
64
- }
65
- this.fs.copyTpl(
66
- this.templatePath(`${templateDir}/**/*`),
67
- this.destinationPath(targetDir),
68
- answers
69
- );
70
- };
71
- this.listSubDirectories = (parent) => fs.readdirSync(parent).filter((f) => !f.startsWith(".")).filter((f) => fs.
72
- lstatSync(path2.join(parent, f)).isDirectory()).sort((a, b) => a.localeCompare(b));
73
- this.kebabCase = (input) => input.replace(/\s|_/g, "-");
74
- this.chooseOrCreatePrompts = (name, getChoicesDirectory) => [
75
- {
76
- when: /* @__PURE__ */ __name((answers) => fs.existsSync(getChoicesDirectory(answers)), "when"),
77
- type: "list",
78
- name,
79
- message: `Choose ${name}`,
80
- store: true,
81
- choices: /* @__PURE__ */ __name((answers) => [
82
- ...this.listSubDirectories(getChoicesDirectory(answers)),
83
- new inquirer.Separator(),
84
- `Create new ${name}`
85
- ], "choices"),
86
- validate: required2,
87
- filter: this.kebabCase
88
- },
89
- {
90
- when: /* @__PURE__ */ __name((answers) => !fs.existsSync(getChoicesDirectory(answers)) || answers[name] === `\
91
- Create-new-${name}`, "when"),
92
- type: "input",
93
- name: `new-${name}`,
94
- message: `New ${name} name`,
95
- store: false,
96
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
97
- filter: this.kebabCase
98
- },
99
- {
100
- when: /* @__PURE__ */ __name((answers) => !fs.existsSync(getChoicesDirectory(answers)) || answers[name] === "\
101
- Create-new-tribe", "when"),
102
- type: "input",
103
- name: "costCenter",
104
- message: "Please provide the Cost Center of the Tribe",
105
- store: false,
106
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
107
- filter: this.kebabCase
108
- }
109
- ];
110
- }
111
- };
112
- }
113
- });
114
-
115
- // generators/common-resources/elastic-template/index.js
116
- var path = require("path");
117
- var chalk = require("chalk");
118
- var BaseGenerator = require_BaseGenerator();
119
- var { required } = require_validators();
120
6
  module.exports = class extends BaseGenerator {
121
7
  prompting() {
122
8
  const prompts = [
123
9
  {
124
- type: "input",
125
- name: "indexName",
126
- message: "Please provide the name of the index",
127
- validate: required
10
+ type: 'input',
11
+ name: 'indexName',
12
+ message: 'Please provide the name of the index',
13
+ validate: required,
128
14
  },
129
15
  {
130
- type: "input",
131
- name: "numberOfShards",
132
- message: "Please provide the number of shards for the index",
133
- validate: required
16
+ type: 'input',
17
+ name: 'numberOfShards',
18
+ message: 'Please provide the number of shards for the index',
19
+ validate: required,
134
20
  },
135
21
  {
136
- type: "input",
137
- name: "numberOfReplicas",
138
- message: "Please provide the number of shard replicas",
139
- validate: required
22
+ type: 'input',
23
+ name: 'numberOfReplicas',
24
+ message: 'Please provide the number of shard replicas',
25
+ validate: required,
140
26
  },
141
27
  {
142
- type: "input",
143
- name: "aliasName",
144
- message: "Please provide the alias name of the index or leave empty"
28
+ type: 'input',
29
+ name: 'aliasName',
30
+ message: 'Please provide the alias name of the index or leave empty',
145
31
  },
146
32
  {
147
- type: "list",
148
- name: "isWriteIndex",
149
- message: "Please select true if the index is the write index for the alias. If previous step is empty this one w\
150
- ill be considered empty as well",
151
- choices: ["true", "false"]
33
+ type: 'list',
34
+ name: 'isWriteIndex',
35
+ message:
36
+ 'Please select true if the index is the write index for the alias. If previous step is empty this one will be considered empty as well',
37
+ choices: ['true', 'false'],
152
38
  },
153
39
  {
154
- type: "input",
155
- name: "policyName",
156
- message: "Please provide the lifecycle policy name for the index that has been previously created or leave empty\
157
- to add later"
158
- }
40
+ type: 'input',
41
+ name: 'policyName',
42
+ message:
43
+ 'Please provide the lifecycle policy name for the index that has been previously created or leave empty to add later',
44
+ },
159
45
  ];
46
+
160
47
  return this.prompt(prompts).then((props) => {
161
48
  this.answers = props;
162
49
  });
163
50
  }
51
+
164
52
  writing() {
165
53
  const { indexName } = this.answers;
166
- ["prod", "staging"].forEach((env) => {
54
+
55
+ ['prod', 'staging'].forEach((env) => {
167
56
  this.copyDir(
168
- "elastic-template",
169
- path.join("infra", env, "elastic-template", indexName),
57
+ 'elastic-template',
58
+ path.join('infra', env, 'elastic-template', indexName),
170
59
  {
171
60
  ...this.answers,
172
61
  env,
173
- indexName
174
- }
62
+ indexName,
63
+ },
175
64
  );
176
65
  });
177
66
  }
67
+
178
68
  end() {
179
69
  const { indexName } = this.answers;
70
+
180
71
  const specStageFile = path.join(
181
- "infra",
182
- "staging",
183
- "elastic-template",
184
- indexName
72
+ 'infra',
73
+ 'staging',
74
+ 'elastic-template',
75
+ indexName,
185
76
  );
186
77
  const specProdFile = path.join(
187
- "infra",
188
- "prod",
189
- "elastic-template",
190
- indexName
78
+ 'infra',
79
+ 'prod',
80
+ 'elastic-template',
81
+ indexName,
191
82
  );
192
83
  this.log(`
193
- ${chalk.green(`Your Elastic Cloud index configurations have now been created. To finalize your configuration, please con\
194
- tinue
84
+ ${chalk.green(`Your Elastic Cloud index configurations have now been created. To finalize your configuration, please continue
195
85
  with manual editing of the generated files.`)}
196
- ${chalk.green("1.")} Review Mappings configuration
197
- \u2192 ${chalk.cyan(path.join(specStageFile, "mappings.json"))}
198
- \u2192 ${chalk.cyan(path.join(specProdFile, "mappings.json"))}
199
- ${chalk.green("2.")} Push this change in a feature branch and open a pull request.
86
+ ${chalk.green('1.')} Review Mappings configuration
87
+ \u2192 ${chalk.cyan(path.join(specStageFile, 'mappings.json'))}
88
+ \u2192 ${chalk.cyan(path.join(specProdFile, 'mappings.json'))}
89
+ ${chalk.green('2.')} Push this change in a feature branch and open a pull request.
200
90
  `);
201
91
  }
202
92
  };
@@ -1,294 +1,154 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __commonJS = (cb, mod) => function __require() {
5
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
- };
7
-
8
- // src/validators.js
9
- var require_validators = __commonJS({
10
- "src/validators.js"(exports2, module2) {
11
- var path2 = require("path");
12
- module2.exports = {
13
- chain: /* @__PURE__ */ __name((input, ...validators) => {
14
- let msg = "";
15
- validators.every((validator) => {
16
- msg = validator(input);
17
- return msg === true;
18
- });
19
- return msg === true ? true : msg;
20
- }, "chain"),
21
- filename: /* @__PURE__ */ __name((input) => {
22
- if (!input) {
23
- return true;
24
- }
25
- return path2.basename(input) === input ? true : "Invalid filename";
26
- }, "filename"),
27
- maxLength: /* @__PURE__ */ __name((input, maxLength) => !input || input.length <= maxLength ? true : `Exceeds max \
28
- length: ${maxLength}`, "maxLength"),
29
- required: /* @__PURE__ */ __name((input) => {
30
- const msg = "Required";
31
- if (Array.isArray(input)) {
32
- return input.length > 0 ? true : msg;
33
- }
34
- if (input) {
35
- return input.trim().length > 0 ? true : msg;
36
- }
37
- return msg;
38
- }, "required")
39
- };
40
- }
41
- });
42
-
43
- // src/BaseGenerator.js
44
- var require_BaseGenerator = __commonJS({
45
- "src/BaseGenerator.js"(exports2, module2) {
46
- var Generator = require("yeoman-generator");
47
- var path2 = require("path");
48
- var fs = require("fs");
49
- var inquirer = require("inquirer");
50
- var { chain, required: required2, filename } = require_validators();
51
- module2.exports = class extends Generator {
52
- constructor(args, opts) {
53
- super(args, opts);
54
- this.baseDir = path2.resolve(path2.join(__dirname, ".."));
55
- this.destinationRoot(process.cwd());
56
- const [command, generator] = opts.namespace.split(":").slice(-2);
57
- this.generatorId = path2.join(command, generator);
58
- this.sourceRoot(
59
- path2.join(this.baseDir, "generators", this.generatorId, "templates")
60
- );
61
- this.copyDir = (templateDir, targetDir, answers = this.answers, skipIfExists = false) => {
62
- if (skipIfExists && fs.existsSync(targetDir)) {
63
- return;
64
- }
65
- this.fs.copyTpl(
66
- this.templatePath(`${templateDir}/**/*`),
67
- this.destinationPath(targetDir),
68
- answers
69
- );
70
- };
71
- this.listSubDirectories = (parent) => fs.readdirSync(parent).filter((f) => !f.startsWith(".")).filter((f) => fs.
72
- lstatSync(path2.join(parent, f)).isDirectory()).sort((a, b) => a.localeCompare(b));
73
- this.kebabCase = (input) => input.replace(/\s|_/g, "-");
74
- this.chooseOrCreatePrompts = (name, getChoicesDirectory) => [
75
- {
76
- when: /* @__PURE__ */ __name((answers) => fs.existsSync(getChoicesDirectory(answers)), "when"),
77
- type: "list",
78
- name,
79
- message: `Choose ${name}`,
80
- store: true,
81
- choices: /* @__PURE__ */ __name((answers) => [
82
- ...this.listSubDirectories(getChoicesDirectory(answers)),
83
- new inquirer.Separator(),
84
- `Create new ${name}`
85
- ], "choices"),
86
- validate: required2,
87
- filter: this.kebabCase
88
- },
89
- {
90
- when: /* @__PURE__ */ __name((answers) => !fs.existsSync(getChoicesDirectory(answers)) || answers[name] === `\
91
- Create-new-${name}`, "when"),
92
- type: "input",
93
- name: `new-${name}`,
94
- message: `New ${name} name`,
95
- store: false,
96
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
97
- filter: this.kebabCase
98
- },
99
- {
100
- when: /* @__PURE__ */ __name((answers) => !fs.existsSync(getChoicesDirectory(answers)) || answers[name] === "\
101
- Create-new-tribe", "when"),
102
- type: "input",
103
- name: "costCenter",
104
- message: "Please provide the Cost Center of the Tribe",
105
- store: false,
106
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
107
- filter: this.kebabCase
108
- }
109
- ];
110
- }
111
- };
112
- }
113
- });
114
-
115
- // generators/init/clan-infra/tribe-clan-repo.js
116
- var require_tribe_clan_repo = __commonJS({
117
- "generators/init/clan-infra/tribe-clan-repo.js"(exports2, module2) {
118
- var path2 = require("path");
119
- var fs = require("fs");
120
- var getKeyValue = /* @__PURE__ */ __name((content, key) => {
121
- let value = "";
122
- content.split(/\r?\n/).forEach((line) => {
123
- if (line.includes(key)) {
124
- value = line.split("=")[1].replace('"', "").replace('"', "").trim();
125
- }
126
- });
127
- return value;
128
- }, "getKeyValue");
129
- var getTribeAndClanName2 = /* @__PURE__ */ __name(() => {
130
- const repoName = path2.basename(path2.resolve());
131
- const isClanInfraRepo = /^(?:\w+-){2}common(?:$|\W)$/.test(repoName);
132
- let tribe = "";
133
- let clan = "";
134
- if (isClanInfraRepo) {
135
- [tribe, clan] = repoName.split("-");
136
- } else {
137
- const commonHCL = path2.join("infra", "common.hcl");
138
- if (fs.existsSync(commonHCL)) {
139
- const commonHCLContent = fs.readFileSync(commonHCL, "utf8");
140
- tribe = getKeyValue(commonHCLContent, "tribe_name");
141
- clan = getKeyValue(commonHCLContent, "clan_name");
142
- }
143
- }
144
- return {
145
- tribe,
146
- clan
147
- };
148
- }, "getTribeAndClanName");
149
- module2.exports = getTribeAndClanName2;
150
- }
151
- });
1
+ const path = require('path');
2
+ const chalk = require('chalk');
3
+ const BaseGenerator = require('../../../src/BaseGenerator');
4
+ const { required } = require('../../../src/validators');
5
+ const getTribeAndClanName = require('../../init/clan-infra/tribe-clan-repo');
152
6
 
153
- // generators/common-resources/firestore/index.js
154
- var path = require("path");
155
- var chalk = require("chalk");
156
- var BaseGenerator = require_BaseGenerator();
157
- var { required } = require_validators();
158
- var getTribeAndClanName = require_tribe_clan_repo();
159
7
  module.exports = class extends BaseGenerator {
160
8
  prompting() {
161
9
  const prompts = [
162
10
  {
163
- type: "input",
164
- name: "databaseName",
11
+ type: 'input',
12
+ name: 'databaseName',
165
13
  default: getTribeAndClanName().clan,
166
- message: "Please provide the database name or leave blank for common database.",
167
- validate: required
14
+ message:
15
+ 'Please provide the database name or leave blank for common database.',
16
+ validate: required,
168
17
  },
169
18
  {
170
- type: "list",
171
- name: "databaseType",
172
- message: "Select the type of database.",
173
- default: "FIRESTORE_NATIVE",
174
- choices: ["FIRESTORE_NATIVE", "DATASTORE_MODE"]
19
+ type: 'list',
20
+ name: 'databaseType',
21
+ message: 'Select the type of database.',
22
+ default: 'FIRESTORE_NATIVE',
23
+ choices: ['FIRESTORE_NATIVE', 'DATASTORE_MODE'],
175
24
  },
176
25
  {
177
- type: "list",
178
- name: "databaseConcurrencyMode",
179
- message: "Select the database concurrency mode.",
180
- default: "OPTIMISTIC",
181
- choices: ["OPTIMISTIC", "PESSIMISTIC"]
26
+ type: 'list',
27
+ name: 'databaseConcurrencyMode',
28
+ message: 'Select the database concurrency mode.',
29
+ default: 'OPTIMISTIC',
30
+ choices: ['OPTIMISTIC', 'PESSIMISTIC'],
182
31
  },
183
32
  {
184
- type: "list",
185
- name: "databaseBackupEnabled",
186
- message: "Enable database backup?",
187
- default: "true",
188
- choices: ["true", "false"]
33
+ type: 'list',
34
+ name: 'databaseBackupEnabled',
35
+ message: 'Enable database backup?',
36
+ default: 'true',
37
+ choices: ['true', 'false'],
189
38
  },
190
39
  {
191
- when: /* @__PURE__ */ __name((response) => response.databaseBackupEnabled === "true", "when"),
192
- type: "list",
193
- name: "databaseBackupSchedule",
194
- message: "Select the backup schedule.",
195
- default: "daily-backup",
196
- choices: ["daily-backup", "weekly-backup"]
40
+ when: (response) => response.databaseBackupEnabled === 'true',
41
+ type: 'list',
42
+ name: 'databaseBackupSchedule',
43
+ message: 'Select the backup schedule.',
44
+ default: 'daily-backup',
45
+ choices: ['daily-backup', 'weekly-backup'],
197
46
  },
198
47
  {
199
- when: /* @__PURE__ */ __name((response) => response.databaseBackupSchedule === "weekly-backup", "when"),
200
- type: "list",
201
- name: "databaseBackupWeeklyRecurrence",
202
- message: "Please provide the day of the week the backup must be created.",
203
- default: "SUNDAY",
48
+ when: (response) => response.databaseBackupSchedule === 'weekly-backup',
49
+ type: 'list',
50
+ name: 'databaseBackupWeeklyRecurrence',
51
+ message:
52
+ 'Please provide the day of the week the backup must be created.',
53
+ default: 'SUNDAY',
204
54
  choices: [
205
- "MONDAY",
206
- "TUESDAY",
207
- "WEDNESDAY",
208
- "THURSDAY",
209
- "FRIDAY",
210
- "SATURDAY",
211
- "SUNDAY"
212
- ]
55
+ 'MONDAY',
56
+ 'TUESDAY',
57
+ 'WEDNESDAY',
58
+ 'THURSDAY',
59
+ 'FRIDAY',
60
+ 'SATURDAY',
61
+ 'SUNDAY',
62
+ ],
213
63
  },
214
64
  {
215
- when: /* @__PURE__ */ __name((response) => response.databaseBackupEnabled === "true", "when"),
216
- type: "input",
217
- name: "databaseBackupRetention",
218
- default: "259200s",
219
- message: 'Please provide how long to keep the backups in seconds. ex. "259200s" is 3 days',
220
- validate: required
65
+ when: (response) => response.databaseBackupEnabled === 'true',
66
+ type: 'input',
67
+ name: 'databaseBackupRetention',
68
+ default: '259200s',
69
+ message:
70
+ 'Please provide how long to keep the backups in seconds. ex. "259200s" is 3 days',
71
+ validate: required,
221
72
  },
222
73
  {
223
- type: "input",
224
- name: "databaseCollectionName",
225
- message: "Please provide the name of the collection being indexed.",
226
- validate: required
74
+ type: 'input',
75
+ name: 'databaseCollectionName',
76
+ message: 'Please provide the name of the collection being indexed.',
77
+ validate: required,
227
78
  },
228
79
  {
229
- type: "input",
230
- name: "databaseCollectionIndexName",
231
- message: "Please provide the name of the index.",
232
- validate: required
80
+ type: 'input',
81
+ name: 'databaseCollectionIndexName',
82
+ message: 'Please provide the name of the index.',
83
+ validate: required,
233
84
  },
234
85
  {
235
- type: "input",
236
- name: "databaseCollectionFieldPath",
237
- message: "Please provide the name of the field.",
238
- validate: required
86
+ type: 'input',
87
+ name: 'databaseCollectionFieldPath',
88
+ message: 'Please provide the name of the field.',
89
+ validate: required,
239
90
  },
240
91
  {
241
- type: "list",
242
- name: "databaseCollectionFieldorder",
243
- message: "Select the specified order for the field.",
244
- default: "ASCENDING",
245
- choices: ["ASCENDING", "DESCENDING"]
246
- }
92
+ type: 'list',
93
+ name: 'databaseCollectionFieldorder',
94
+ message: 'Select the specified order for the field.',
95
+ default: 'ASCENDING',
96
+ choices: ['ASCENDING', 'DESCENDING'],
97
+ },
247
98
  ];
99
+
248
100
  return this.prompt(prompts).then((props) => {
249
101
  this.answers = props;
250
102
  });
251
103
  }
104
+
252
105
  writing() {
253
106
  const { databaseName, databaseCollectionName, ...rest } = this.answers;
254
- ["prod", "staging"].forEach((env) => {
107
+
108
+ ['prod', 'staging'].forEach((env) => {
255
109
  const context = {
256
110
  ...rest,
257
111
  databaseName,
258
112
  databaseCollectionName,
259
- env
113
+ env,
260
114
  };
261
- const baseDest = path.join("infra", env, "firestore", databaseName);
115
+ const baseDest = path.join('infra', env, 'firestore', databaseName);
262
116
  const collectionDest = path.join(
263
117
  baseDest,
264
- "indexes",
265
- databaseCollectionName
118
+ 'indexes',
119
+ databaseCollectionName,
266
120
  );
267
- ["spec.hcl", "terragrunt.hcl"].forEach((file) => {
121
+
122
+ // Files to copy at database root
123
+ ['spec.hcl', 'terragrunt.hcl'].forEach((file) => {
268
124
  this.fs.copyTpl(
269
- this.templatePath("firestore", file),
125
+ this.templatePath('firestore', file),
270
126
  this.destinationPath(baseDest, file),
271
- context
127
+ context,
272
128
  );
273
129
  });
274
- ["indexes.yaml", "terragrunt.hcl"].forEach((file) => {
130
+
131
+ // Files to copy inside indexes/<databaseCollectionName>/
132
+ ['indexes.yaml', 'terragrunt.hcl'].forEach((file) => {
275
133
  this.fs.copyTpl(
276
- this.templatePath("firestore/indexes", file),
134
+ this.templatePath('firestore/indexes', file),
277
135
  this.destinationPath(collectionDest, file),
278
- context
136
+ context,
279
137
  );
280
138
  });
281
139
  });
282
140
  }
141
+
283
142
  end() {
284
143
  const { databaseName } = this.answers;
144
+
285
145
  const firestoreDir = path.join(databaseName);
286
146
  this.log(`
287
147
  ${chalk.green(`Your Firestore database has now been created. To finalize your configuration, please continue
288
148
  with manual editing of the generated files.`)}
289
- ${chalk.green("1.")} Review and add more indexes as the firestore module requires at least two.
290
- \u2192 ${chalk.cyan(path.join(firestoreDir, "indexes.yaml"))}
291
- ${chalk.green("2.")} Push this change in a feature branch and open a pull request.
149
+ ${chalk.green('1.')} Review and add more indexes as the firestore module requires at least two.
150
+ \u2192 ${chalk.cyan(path.join(firestoreDir, 'indexes.yaml'))}
151
+ ${chalk.green('2.')} Push this change in a feature branch and open a pull request.
292
152
  `);
293
153
  }
294
154
  };