@agilecustoms/envctl 0.14.5 → 0.15.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.
@@ -43,11 +43,19 @@ export class CliHelper {
43
43
  }
44
44
  return owner;
45
45
  }
46
+ ensureKind(kind, cwd) {
47
+ if (kind) {
48
+ return kind;
49
+ }
50
+ kind = getDirName(cwd);
51
+ console.log(`Inferred kind from directory name: ${kind}`);
52
+ return kind;
53
+ }
46
54
  async parseEnvInput(input, envName, owner, cwd) {
47
55
  owner = this.ensureOwner(owner);
48
56
  const { size } = input;
49
57
  let { type, kind } = input;
50
- kind = ensureKind(kind, cwd);
58
+ kind = this.ensureKind(kind, cwd);
51
59
  let envSize;
52
60
  if (size) {
53
61
  envSize = ensureEnumValue(EnvSize, size, 'size');
@@ -87,14 +95,6 @@ export class CliHelper {
87
95
  };
88
96
  }
89
97
  }
90
- function ensureKind(kind, cwd) {
91
- if (kind) {
92
- return kind;
93
- }
94
- kind = getDirName(cwd);
95
- console.log(`Inferred kind from directory name: ${kind}`);
96
- return kind;
97
- }
98
98
  function getDirName(cwd) {
99
99
  cwd = resolveCwd(cwd);
100
100
  return path.basename(cwd);
@@ -8,10 +8,11 @@ export function deleteIt(program) {
8
8
  .description('Delete a development environment')
9
9
  .option('--project <project>', _keys.PROJECT)
10
10
  .option('--env <env>', _keys.ENV)
11
+ .option('--cwd <cwd>', _keys.CWD)
11
12
  .action(wrap(handler));
12
13
  }
13
14
  async function handler(options) {
14
- const { project, env } = options;
15
+ const { project, env, cwd } = options;
15
16
  const envName = cliHelper.ensureEnv(env);
16
- await envCtl.delete(project, envName);
17
+ await envCtl.delete(project, envName, cwd);
17
18
  }
@@ -8,10 +8,11 @@ export function status(program) {
8
8
  .description('Get env status')
9
9
  .option('--project <project>', _keys.PROJECT)
10
10
  .option('--env <env>', _keys.ENV)
11
+ .option('--cwd <cwd>', _keys.CWD)
11
12
  .action(wrap(handler));
12
13
  }
13
14
  async function handler(options) {
14
- const { project, env } = options;
15
+ const { project, env, cwd } = options;
15
16
  const envName = cliHelper.ensureEnv(env);
16
- await envCtl.status(project, envName);
17
+ await envCtl.status(project, envName, cwd);
17
18
  }
@@ -12,7 +12,7 @@ export class EnvCtl {
12
12
  key(project, env) {
13
13
  return project ? `${project}-${env}` : env;
14
14
  }
15
- async status(project, envName) {
15
+ async status(project, envName, cwd) {
16
16
  const key = this.key(project, envName);
17
17
  console.log(`Retrieve env ${key}`);
18
18
  const env = await this.envApi.get(key);
@@ -20,7 +20,11 @@ export class EnvCtl {
20
20
  console.log(`Env ${key} does not exist`);
21
21
  return;
22
22
  }
23
+ const kind = this.cliHelper.ensureKind(undefined, cwd);
23
24
  console.log(`Env ${key} status: ${env.status}`);
25
+ if (env.kind && env.kind !== kind) {
26
+ console.warn(`Env ${key} kind (dir-name): ${env.kind} - looks like this env was deployed from a different directory`);
27
+ }
24
28
  }
25
29
  async tryGetEnv(input) {
26
30
  let envName = input.env;
@@ -41,7 +45,7 @@ export class EnvCtl {
41
45
  }
42
46
  return { envName, owner, key, env };
43
47
  }
44
- checkInput(envName, env, input) {
48
+ checkInput(envName, env, input, cwd) {
45
49
  if (env.ephemeral) {
46
50
  throw new KnownException(`Attempted to convert ephemeral env to non-ephemeral`);
47
51
  }
@@ -54,10 +58,11 @@ export class EnvCtl {
54
58
  if (input.type && env.type !== input.type) {
55
59
  throw new KnownException(`Can not change env type ${env.type} -> ${input.type}`);
56
60
  }
57
- if (input.kind && env.kind !== input.kind) {
58
- throw new KnownException(`Can not change env kind ${env.kind} -> ${input.kind}`);
61
+ const kind = this.cliHelper.ensureKind(input.kind, cwd);
62
+ if ((input.kind || env.kind) && kind !== env.kind) {
63
+ throw new KnownException(`Can not change env kind ${env.kind} -> ${kind}`);
59
64
  }
60
- const { owner, size, type, kind } = env;
65
+ const { owner, size, type } = env;
61
66
  return {
62
67
  project: input.project, env: envName,
63
68
  owner, size, type, kind,
@@ -81,7 +86,7 @@ export class EnvCtl {
81
86
  await this.terraformAdapter.plan(envInput, tfArgs, cwd);
82
87
  return;
83
88
  }
84
- const envInput = this.checkInput(envName, env, input);
89
+ const envInput = this.checkInput(envName, env, input, cwd);
85
90
  this.checkStatus(env);
86
91
  await this.promptUnlock(env);
87
92
  if (env.status !== EnvStatus.Active) {
@@ -128,9 +133,18 @@ export class EnvCtl {
128
133
  console.log('Unlock env after db evolution');
129
134
  await this.envApi.activate(env);
130
135
  }
131
- async delete(project, envName) {
136
+ async delete(project, envName, cwd) {
132
137
  const env = await this.get(project, envName);
133
138
  this.checkStatus(env);
139
+ const kind = this.cliHelper.ensureKind(undefined, cwd);
140
+ if (env.kind && env.kind !== kind) {
141
+ const answerYes = await this.cliHelper.promptYesNo(`Env ${env.key} kind (dir-name): ${env.kind} - you're deleting env deployed from different dir\n`
142
+ + 'Do you want to proceed?');
143
+ if (!answerYes) {
144
+ console.log('Aborting deletion');
145
+ return;
146
+ }
147
+ }
134
148
  await this.promptUnlock(env);
135
149
  if (env.status !== EnvStatus.Active) {
136
150
  throw new KnownException(`Env ${env.key} status is ${env.status}, can not delete`);
@@ -141,6 +155,10 @@ export class EnvCtl {
141
155
  }
142
156
  async destroy(project, envName, tfArgs, cwd) {
143
157
  const env = await this.get(project, envName);
158
+ const kind = this.cliHelper.ensureKind(undefined, cwd);
159
+ if (env.kind && env.kind !== kind) {
160
+ throw new KnownException(`Env ${env.key} kind (dir-name): ${env.kind} - make sure you run destroy from the same directory`);
161
+ }
144
162
  this.checkStatus(env);
145
163
  await this.promptUnlock(env, [EnvStatus.Creating]);
146
164
  if (env.status === EnvStatus.Active) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
3
  "description": "node.js CLI client for manage environments",
4
- "version": "0.14.5",
4
+ "version": "0.15.0",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "bin": {
@@ -27,10 +27,10 @@
27
27
  "run": "node dist/index.js",
28
28
  "run-version": "tsc --sourceMap true && npm run run -- --version",
29
29
  "run-configure": "tsc --sourceMap true && npm run run -- configure",
30
- "run-status": "tsc --sourceMap true && npm run run -- status",
30
+ "run-status": "tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
31
31
  "run-plan": "tsc --sourceMap true && npm run run -- plan --size min --cwd ../tt-core",
32
32
  "run-deploy": "tsc --sourceMap true && npm run run -- deploy --size min --cwd ../tt-core",
33
- "run-delete": "tsc --sourceMap true && npm run run -- delete",
33
+ "run-delete": "tsc --sourceMap true && npm run run -- delete --cwd ../tt-web",
34
34
  "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core"
35
35
  },
36
36
  "dependencies": {