@hiiretail/gcp-infra-cli 0.64.1 → 0.65.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.
@@ -7,6 +7,7 @@ const {
7
7
  validSystemName,
8
8
  validVersion,
9
9
  validSubscriberName,
10
+ checkExistingTopicPath,
10
11
  } = require('./validate');
11
12
  const handleSubscribers = require('./handle-subscribers');
12
13
  const { getProjectId, getProdPushEndopint } = require('./get-gcp-projects');
@@ -117,7 +118,7 @@ module.exports = class extends BaseGenerator {
117
118
  type: 'input',
118
119
  name: 'existingTopic',
119
120
  message: 'Please provide the name of the existing topic you want to subscribe to',
120
- validate: required,
121
+ validate: (input) => required(input) && checkExistingTopicPath(input),
121
122
  },
122
123
  {
123
124
  when: (response) => response.createResource === 'subscription' && response.pushOrPull === 'push',
@@ -1,3 +1,6 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
1
4
  const validSystemName = (input) => {
2
5
  if (input.replace(/\s/g, '').length === 3) {
3
6
  return true;
@@ -24,9 +27,18 @@ const validSubscriberName = (input) => {
24
27
  return 'Not supported input for subscriber name';
25
28
  };
26
29
 
30
+ const checkExistingTopicPath = (input) => {
31
+ const topicDirPath = path.join(process.cwd(), 'infra', 'staging', 'pubsub', input);
32
+
33
+ if (fs.existsSync(topicDirPath)) {
34
+ return true;
35
+ }
36
+ return 'Topic does not exist. Check the spelling';
37
+ };
27
38
 
28
39
  module.exports = {
29
40
  validSystemName,
30
41
  validVersion,
31
42
  validSubscriberName,
43
+ checkExistingTopicPath,
32
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiiretail/gcp-infra-cli",
3
- "version": "0.64.1",
3
+ "version": "0.65.0",
4
4
  "description": "Infrastructure as code generator for GCP.",
5
5
  "main": "src/cli.js",
6
6
  "bin": {