hereya-cli 0.13.1 → 0.14.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.
- package/README.md +19 -19
- package/dist/commands/add/index.js +124 -67
- package/dist/commands/deploy/index.js +258 -95
- package/dist/commands/down/index.js +132 -58
- package/dist/commands/remove/index.js +114 -61
- package/dist/commands/undeploy/index.js +179 -51
- package/dist/commands/up/index.js +195 -103
- package/dist/infrastructure/index.d.ts +1 -0
- package/dist/lib/log.js +4 -20
- package/dist/lib/package/common.d.ts +2 -0
- package/dist/lib/package/github.d.ts +1 -0
- package/dist/lib/package/github.js +31 -2
- package/dist/lib/package/index.js +4 -19
- package/dist/lib/shell.d.ts +1 -0
- package/dist/lib/shell.js +8 -0
- package/oclif.manifest.json +40 -40
- package/package.json +3 -3
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { Listr, ListrLogLevels, ListrLogger } from 'listr2';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { getBackend } from '../../backend/index.js';
|
|
4
5
|
import { destroyPackage, provisionPackage } from '../../infrastructure/index.js';
|
|
5
6
|
import { getConfigManager } from '../../lib/config/index.js';
|
|
6
7
|
import { getEnvManager } from '../../lib/env/index.js';
|
|
7
|
-
import { logEnv } from '../../lib/env-utils.js';
|
|
8
|
-
import { getLogger } from '../../lib/log.js';
|
|
9
8
|
import { getParameterManager } from '../../lib/parameter/index.js';
|
|
10
|
-
import { setDebug } from '../../lib/shell.js';
|
|
11
|
-
import Up from '../up/index.js';
|
|
9
|
+
import { delay, setDebug } from '../../lib/shell.js';
|
|
12
10
|
export default class Deploy extends Command {
|
|
13
11
|
static description = 'Deploy a hereya project using the project deployment package';
|
|
14
|
-
static examples = [
|
|
15
|
-
'<%= config.bin %> <%= command.id %>',
|
|
16
|
-
];
|
|
12
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
17
13
|
static flags = {
|
|
18
14
|
chdir: Flags.string({
|
|
19
15
|
description: 'directory to run command in',
|
|
@@ -32,96 +28,263 @@ export default class Deploy extends Command {
|
|
|
32
28
|
async run() {
|
|
33
29
|
const { flags } = await this.parse(Deploy);
|
|
34
30
|
setDebug(flags.debug);
|
|
35
|
-
const logger = getLogger();
|
|
36
31
|
const projectRootDir = path.resolve(flags.chdir || process.env.HEREYA_PROJECT_ROOT_DIR || process.cwd());
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
const myLogger = new ListrLogger({ useIcons: false });
|
|
33
|
+
const task = new Listr([
|
|
34
|
+
{
|
|
35
|
+
async task(ctx) {
|
|
36
|
+
const configManager = getConfigManager();
|
|
37
|
+
const loadConfigOutput = await configManager.loadConfig({ projectRootDir });
|
|
38
|
+
if (!loadConfigOutput.found) {
|
|
39
|
+
throw new Error("Project not initialized. Run 'hereya init' first.");
|
|
40
|
+
}
|
|
41
|
+
ctx.configOutput = loadConfigOutput;
|
|
42
|
+
ctx.deployPackages = Object.keys(loadConfigOutput.config.deploy ?? {});
|
|
43
|
+
ctx.packages = Object.keys(loadConfigOutput.config.packages ?? {});
|
|
44
|
+
await delay(500);
|
|
45
|
+
},
|
|
46
|
+
title: 'Loading project config',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
async task(ctx) {
|
|
50
|
+
const backend = await getBackend();
|
|
51
|
+
const { workspace } = flags;
|
|
52
|
+
const getWorkspaceEnvOutput = await backend.getWorkspaceEnv({
|
|
53
|
+
project: ctx.configOutput.config.project,
|
|
54
|
+
workspace,
|
|
55
|
+
});
|
|
56
|
+
if (!getWorkspaceEnvOutput.success) {
|
|
57
|
+
throw new Error(getWorkspaceEnvOutput.reason);
|
|
58
|
+
}
|
|
59
|
+
ctx.workspaceEnv = getWorkspaceEnvOutput.env;
|
|
60
|
+
ctx.workspace = workspace;
|
|
61
|
+
await delay(500);
|
|
62
|
+
},
|
|
63
|
+
title: 'Loading workspace environment variables',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
async task(ctx) {
|
|
67
|
+
const envManager = getEnvManager();
|
|
68
|
+
const { env: projectEnv } = await envManager.getProjectEnv({
|
|
69
|
+
markSecret: true,
|
|
70
|
+
projectRootDir,
|
|
71
|
+
workspace: ctx.workspace,
|
|
72
|
+
});
|
|
73
|
+
ctx.projectEnv = projectEnv;
|
|
74
|
+
await delay(500);
|
|
75
|
+
},
|
|
76
|
+
title: 'Loading project environment variables',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
async task(ctx) {
|
|
80
|
+
const backend = await getBackend();
|
|
81
|
+
const savedStateOutput = await backend.getState({
|
|
82
|
+
project: ctx.configOutput.config.project,
|
|
83
|
+
});
|
|
84
|
+
if (savedStateOutput.found) {
|
|
85
|
+
ctx.savedStateOutput = savedStateOutput;
|
|
86
|
+
}
|
|
87
|
+
await delay(500);
|
|
88
|
+
},
|
|
89
|
+
title: 'Loading project current state',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
async task(ctx) {
|
|
93
|
+
const savedDeployPackages = Object.keys(ctx.savedStateOutput?.config.deploy ?? {});
|
|
94
|
+
ctx.removedDeployPackages = savedDeployPackages.filter((packageName) => !ctx.deployPackages.includes(packageName));
|
|
95
|
+
const savedPackages = Object.keys(ctx.savedStateOutput?.config.packages ?? {});
|
|
96
|
+
ctx.removedPackages = savedPackages.filter((packageName) => !ctx.packages.includes(packageName));
|
|
97
|
+
await delay(500);
|
|
98
|
+
},
|
|
99
|
+
title: 'Identifying removed packages',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
skip: (ctx) => ctx.removedDeployPackages.length === 0,
|
|
103
|
+
task(ctx, task) {
|
|
104
|
+
return task.newListr(ctx.removedDeployPackages.map((packageName) => ({
|
|
105
|
+
async task() {
|
|
106
|
+
const parameterManager = getParameterManager();
|
|
107
|
+
const { parameters } = await parameterManager.getPackageParameters({
|
|
108
|
+
package: packageName,
|
|
109
|
+
projectRootDir,
|
|
110
|
+
workspace: ctx.workspace,
|
|
111
|
+
});
|
|
112
|
+
const destroyOutput = await destroyPackage({
|
|
113
|
+
env: ctx.workspaceEnv,
|
|
114
|
+
isDeploying: true,
|
|
115
|
+
package: packageName,
|
|
116
|
+
parameters,
|
|
117
|
+
project: ctx.configOutput.config.project,
|
|
118
|
+
projectEnv: ctx.projectEnv,
|
|
119
|
+
projectRootDir,
|
|
120
|
+
workspace: ctx.workspace,
|
|
121
|
+
});
|
|
122
|
+
if (!destroyOutput.success) {
|
|
123
|
+
throw new Error(destroyOutput.reason);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
title: `Destroying package ${packageName}`,
|
|
127
|
+
})), { concurrent: true });
|
|
128
|
+
},
|
|
129
|
+
title: 'Destroying removed deployment packages',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
skip: (ctx) => ctx.removedPackages.length === 0,
|
|
133
|
+
task(ctx, task) {
|
|
134
|
+
return task.newListr(ctx.removedPackages.map((packageName) => ({
|
|
135
|
+
async task() {
|
|
136
|
+
const parameterManager = getParameterManager();
|
|
137
|
+
const { parameters } = await parameterManager.getPackageParameters({
|
|
138
|
+
package: packageName,
|
|
139
|
+
projectRootDir,
|
|
140
|
+
workspace: ctx.workspace,
|
|
141
|
+
});
|
|
142
|
+
const destroyOutput = await destroyPackage({
|
|
143
|
+
env: ctx.workspaceEnv,
|
|
144
|
+
isDeploying: true,
|
|
145
|
+
package: packageName,
|
|
146
|
+
parameters,
|
|
147
|
+
project: ctx.configOutput.config.project,
|
|
148
|
+
workspace: ctx.workspace,
|
|
149
|
+
});
|
|
150
|
+
if (!destroyOutput.success) {
|
|
151
|
+
throw new Error(destroyOutput.reason);
|
|
152
|
+
}
|
|
153
|
+
const { env, metadata } = destroyOutput;
|
|
154
|
+
const output = ctx.removed || [];
|
|
155
|
+
output.push({ env, metadata, packageName });
|
|
156
|
+
ctx.removed = output;
|
|
157
|
+
},
|
|
158
|
+
title: `Destroying ${packageName}`,
|
|
159
|
+
})), { concurrent: true });
|
|
160
|
+
},
|
|
161
|
+
title: 'Destroying removed packages',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
skip: (ctx) => !ctx.packages || ctx.packages.length === 0,
|
|
165
|
+
async task(ctx, task) {
|
|
166
|
+
if (!ctx.packages || ctx.packages.length === 0) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
return task.newListr(ctx.packages.map((packageName) => ({
|
|
170
|
+
async task() {
|
|
171
|
+
const parameterManager = getParameterManager();
|
|
172
|
+
const { parameters } = await parameterManager.getPackageParameters({
|
|
173
|
+
package: packageName,
|
|
174
|
+
projectRootDir,
|
|
175
|
+
workspace: ctx.workspace,
|
|
176
|
+
});
|
|
177
|
+
const provisionOutput = await provisionPackage({
|
|
178
|
+
env: ctx.workspaceEnv,
|
|
179
|
+
isDeploying: true,
|
|
180
|
+
package: packageName,
|
|
181
|
+
parameters,
|
|
182
|
+
project: ctx.configOutput.config.project,
|
|
183
|
+
workspace: ctx.workspace,
|
|
184
|
+
});
|
|
185
|
+
if (!provisionOutput.success) {
|
|
186
|
+
throw new Error(provisionOutput.reason);
|
|
187
|
+
}
|
|
188
|
+
const { env, metadata } = provisionOutput;
|
|
189
|
+
const output = ctx.added || [];
|
|
190
|
+
output.push({ env, metadata, packageName });
|
|
191
|
+
ctx.added = output;
|
|
192
|
+
},
|
|
193
|
+
title: `Provisioning ${packageName}`,
|
|
194
|
+
})), { concurrent: true });
|
|
195
|
+
},
|
|
196
|
+
title: `Provisioning packages`,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
skip: (ctx) => !ctx.removed || ctx.removed.length === 0,
|
|
200
|
+
async task(ctx) {
|
|
201
|
+
if (!ctx.removed || ctx.removed.length === 0) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const envManager = getEnvManager();
|
|
205
|
+
for (const { env, metadata } of ctx.removed) {
|
|
206
|
+
// eslint-disable-next-line no-await-in-loop
|
|
207
|
+
await Promise.all([
|
|
208
|
+
envManager.removeProjectEnv({
|
|
209
|
+
env,
|
|
210
|
+
infra: metadata.originalInfra ?? metadata.infra,
|
|
211
|
+
projectRootDir,
|
|
212
|
+
workspace: ctx.workspace,
|
|
213
|
+
}),
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
await delay(500);
|
|
217
|
+
},
|
|
218
|
+
title: 'Removing env vars from removed packages',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
skip: (ctx) => !ctx.added || ctx.added.length === 0,
|
|
222
|
+
async task(ctx) {
|
|
223
|
+
if (!ctx.added || ctx.added.length === 0) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const envManager = getEnvManager();
|
|
227
|
+
for (const { env, metadata } of ctx.added) {
|
|
228
|
+
// eslint-disable-next-line no-await-in-loop
|
|
229
|
+
await envManager.addProjectEnv({
|
|
230
|
+
env,
|
|
231
|
+
infra: metadata.originalInfra ?? metadata.infra,
|
|
232
|
+
projectRootDir,
|
|
233
|
+
workspace: ctx.workspace,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
await delay(500);
|
|
237
|
+
},
|
|
238
|
+
title: 'Adding env vars from added packages',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
async task() {
|
|
242
|
+
const backend = await getBackend();
|
|
243
|
+
const configManager = getConfigManager();
|
|
244
|
+
const { config: newConfig } = await configManager.loadConfig({ projectRootDir });
|
|
245
|
+
await backend.saveState(newConfig);
|
|
246
|
+
await delay(500);
|
|
247
|
+
},
|
|
248
|
+
title: 'Saving state',
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
skip: (ctx) => ctx.deployPackages.length === 0,
|
|
252
|
+
task(ctx, task) {
|
|
253
|
+
return task.newListr(ctx.deployPackages.map((packageName) => ({
|
|
254
|
+
async task() {
|
|
255
|
+
const parameterManager = getParameterManager();
|
|
256
|
+
const { parameters } = await parameterManager.getPackageParameters({
|
|
257
|
+
package: packageName,
|
|
258
|
+
projectRootDir,
|
|
259
|
+
workspace: ctx.workspace,
|
|
260
|
+
});
|
|
261
|
+
const provisionOutput = await provisionPackage({
|
|
262
|
+
env: ctx.workspaceEnv,
|
|
263
|
+
isDeploying: true,
|
|
264
|
+
package: packageName,
|
|
265
|
+
parameters,
|
|
266
|
+
project: ctx.configOutput.config.project,
|
|
267
|
+
projectEnv: ctx.projectEnv,
|
|
268
|
+
projectRootDir,
|
|
269
|
+
workspace: ctx.workspace,
|
|
270
|
+
});
|
|
271
|
+
if (!provisionOutput.success) {
|
|
272
|
+
throw new Error(provisionOutput.reason);
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
title: `Provisioning package ${packageName}`,
|
|
276
|
+
})), { concurrent: true });
|
|
277
|
+
},
|
|
278
|
+
title: 'Provisioning deployment packages',
|
|
279
|
+
},
|
|
280
|
+
]);
|
|
281
|
+
try {
|
|
282
|
+
await task.run();
|
|
283
|
+
myLogger.log(ListrLogLevels.COMPLETED, 'Deployment completed successfully');
|
|
42
284
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const savedStateOutput = await backend.getState({
|
|
47
|
-
project: config.project,
|
|
48
|
-
});
|
|
49
|
-
let savedPackages = [];
|
|
50
|
-
if (savedStateOutput.found) {
|
|
51
|
-
savedPackages = Object.keys(savedStateOutput.config.deploy ?? {});
|
|
285
|
+
catch (error) {
|
|
286
|
+
myLogger.log(ListrLogLevels.FAILED, error);
|
|
287
|
+
this.error(error.message);
|
|
52
288
|
}
|
|
53
|
-
const removedPackages = savedPackages.filter((packageName) => !deployPackages.includes(packageName));
|
|
54
|
-
const { workspace } = flags;
|
|
55
|
-
const getWorkspaceEnvOutput = await backend.getWorkspaceEnv({
|
|
56
|
-
project: config.project,
|
|
57
|
-
workspace,
|
|
58
|
-
});
|
|
59
|
-
if (!getWorkspaceEnvOutput.success) {
|
|
60
|
-
this.error(getWorkspaceEnvOutput.reason);
|
|
61
|
-
}
|
|
62
|
-
const { env: workspaceEnv } = getWorkspaceEnvOutput;
|
|
63
|
-
const parameterManager = getParameterManager();
|
|
64
|
-
const envManager = getEnvManager();
|
|
65
|
-
const { env: projectEnv } = await envManager.getProjectEnv({
|
|
66
|
-
markSecret: true,
|
|
67
|
-
projectRootDir,
|
|
68
|
-
workspace,
|
|
69
|
-
});
|
|
70
|
-
if (removedPackages.length > 0) {
|
|
71
|
-
logger.log(`Destroying ${removedPackages.length} removed packages`);
|
|
72
|
-
}
|
|
73
|
-
await Promise.all(removedPackages.map(async (packageName) => {
|
|
74
|
-
const { parameters } = await parameterManager.getPackageParameters({
|
|
75
|
-
package: packageName,
|
|
76
|
-
projectRootDir,
|
|
77
|
-
workspace,
|
|
78
|
-
});
|
|
79
|
-
const destroyOutput = await destroyPackage({
|
|
80
|
-
env: workspaceEnv,
|
|
81
|
-
isDeploying: true,
|
|
82
|
-
package: packageName,
|
|
83
|
-
parameters,
|
|
84
|
-
project: config.project,
|
|
85
|
-
projectEnv,
|
|
86
|
-
projectRootDir,
|
|
87
|
-
workspace,
|
|
88
|
-
});
|
|
89
|
-
if (!destroyOutput.success) {
|
|
90
|
-
this.error(destroyOutput.reason);
|
|
91
|
-
}
|
|
92
|
-
}));
|
|
93
|
-
if (removedPackages.length > 0) {
|
|
94
|
-
logger.done(`Destroyed ${removedPackages.length} removed packages`);
|
|
95
|
-
}
|
|
96
|
-
await Up.run(['--chdir', projectRootDir, '--workspace', workspace, '--deploy']);
|
|
97
|
-
logger.log(`Provisioning ${deployPackages.length} deployment packages`);
|
|
98
|
-
const { env: newProjectEnv } = await envManager.getProjectEnv({
|
|
99
|
-
markSecret: true,
|
|
100
|
-
projectRootDir,
|
|
101
|
-
workspace,
|
|
102
|
-
});
|
|
103
|
-
await Promise.all(deployPackages.map(async (packageName) => {
|
|
104
|
-
const { parameters } = await parameterManager.getPackageParameters({
|
|
105
|
-
package: packageName,
|
|
106
|
-
projectRootDir,
|
|
107
|
-
workspace,
|
|
108
|
-
});
|
|
109
|
-
const provisionOutput = await provisionPackage({
|
|
110
|
-
env: workspaceEnv,
|
|
111
|
-
isDeploying: true,
|
|
112
|
-
package: packageName,
|
|
113
|
-
parameters,
|
|
114
|
-
project: config.project,
|
|
115
|
-
projectEnv: newProjectEnv,
|
|
116
|
-
projectRootDir,
|
|
117
|
-
workspace,
|
|
118
|
-
});
|
|
119
|
-
if (!provisionOutput.success) {
|
|
120
|
-
this.error(provisionOutput.reason);
|
|
121
|
-
}
|
|
122
|
-
this.log(`Package ${packageName} deployed successfully`);
|
|
123
|
-
logEnv(provisionOutput.env, this.log.bind(this));
|
|
124
|
-
}));
|
|
125
|
-
logger.done(`Provisioned ${deployPackages.length} deployment packages`);
|
|
126
289
|
}
|
|
127
290
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { Listr, ListrLogLevels, ListrLogger } from 'listr2';
|
|
2
3
|
import { getBackend } from '../../backend/index.js';
|
|
3
4
|
import { destroyPackage } from '../../infrastructure/index.js';
|
|
4
5
|
import { getConfigManager } from '../../lib/config/index.js';
|
|
5
6
|
import { getEnvManager } from '../../lib/env/index.js';
|
|
6
|
-
import { getLogger } from '../../lib/log.js';
|
|
7
7
|
import { getParameterManager } from '../../lib/parameter/index.js';
|
|
8
|
-
import { setDebug } from '../../lib/shell.js';
|
|
8
|
+
import { delay, setDebug } from '../../lib/shell.js';
|
|
9
9
|
export default class Down extends Command {
|
|
10
10
|
static description = 'Destroy all packages in the project.';
|
|
11
|
-
static examples = [
|
|
12
|
-
'<%= config.bin %> <%= command.id %>',
|
|
13
|
-
];
|
|
11
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
14
12
|
static flags = {
|
|
15
13
|
chdir: Flags.string({
|
|
16
14
|
description: 'directory to run command in',
|
|
@@ -33,61 +31,137 @@ export default class Down extends Command {
|
|
|
33
31
|
async run() {
|
|
34
32
|
const { flags } = await this.parse(Down);
|
|
35
33
|
setDebug(flags.debug);
|
|
36
|
-
const logger = getLogger();
|
|
37
34
|
const projectRootDir = flags.chdir || process.env.HEREYA_PROJECT_ROOT_DIR;
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
const myLogger = new ListrLogger({ useIcons: false });
|
|
36
|
+
const task = new Listr([
|
|
37
|
+
{
|
|
38
|
+
async task(ctx, task) {
|
|
39
|
+
return task.newListr([
|
|
40
|
+
{
|
|
41
|
+
async task(ctx) {
|
|
42
|
+
const configManager = getConfigManager();
|
|
43
|
+
const loadConfigOutput = await configManager.loadConfig({ projectRootDir });
|
|
44
|
+
if (!loadConfigOutput.found) {
|
|
45
|
+
throw new Error("Project not initialized. Run 'hereya init' first.");
|
|
46
|
+
}
|
|
47
|
+
ctx.configOutput = loadConfigOutput;
|
|
48
|
+
await delay(500);
|
|
49
|
+
},
|
|
50
|
+
title: 'Loading project config',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
async task(ctx) {
|
|
54
|
+
const backend = await getBackend();
|
|
55
|
+
const workspace = flags.workspace || ctx.configOutput.config.workspace;
|
|
56
|
+
const getWorkspaceEnvOutput = await backend.getWorkspaceEnv({
|
|
57
|
+
project: ctx.configOutput.config.project,
|
|
58
|
+
workspace,
|
|
59
|
+
});
|
|
60
|
+
if (!getWorkspaceEnvOutput.success) {
|
|
61
|
+
throw new Error(getWorkspaceEnvOutput.reason);
|
|
62
|
+
}
|
|
63
|
+
ctx.workspaceEnvOutput = getWorkspaceEnvOutput;
|
|
64
|
+
ctx.workspace = workspace;
|
|
65
|
+
await delay(500);
|
|
66
|
+
},
|
|
67
|
+
title: 'Loading workspace environment variables',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
async task(ctx) {
|
|
71
|
+
const packages = Object.keys(ctx.configOutput.config.packages ?? {});
|
|
72
|
+
const backend = await getBackend();
|
|
73
|
+
const savedStateOutput = await backend.getState({
|
|
74
|
+
project: ctx.configOutput.config.project,
|
|
75
|
+
});
|
|
76
|
+
let removedPackages = [];
|
|
77
|
+
if (savedStateOutput.found) {
|
|
78
|
+
const savedPackages = Object.keys(savedStateOutput.config.packages ?? {});
|
|
79
|
+
removedPackages = savedPackages.filter((packageName) => !packages.includes(packageName));
|
|
80
|
+
}
|
|
81
|
+
ctx.packages = [...packages, ...removedPackages];
|
|
82
|
+
await delay(500);
|
|
83
|
+
},
|
|
84
|
+
title: 'Identifying packages to destroy',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
skip: (ctx) => !ctx.packages || ctx.packages.length === 0,
|
|
88
|
+
async task(ctx) {
|
|
89
|
+
const { configOutput, destroyed, packages, workspace, workspaceEnvOutput } = ctx;
|
|
90
|
+
if (!packages || packages.length === 0) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return task.newListr(packages.map((packageName) => ({
|
|
94
|
+
async task() {
|
|
95
|
+
const parameterManager = getParameterManager();
|
|
96
|
+
const { parameters } = await parameterManager.getPackageParameters({
|
|
97
|
+
package: packageName,
|
|
98
|
+
projectRootDir,
|
|
99
|
+
workspace,
|
|
100
|
+
});
|
|
101
|
+
const destroyOutput = await destroyPackage({
|
|
102
|
+
env: workspaceEnvOutput.env,
|
|
103
|
+
isDeploying: flags.deploy,
|
|
104
|
+
package: packageName,
|
|
105
|
+
parameters,
|
|
106
|
+
project: configOutput.config.project,
|
|
107
|
+
workspace,
|
|
108
|
+
});
|
|
109
|
+
if (!destroyOutput.success) {
|
|
110
|
+
throw new Error(destroyOutput.reason);
|
|
111
|
+
}
|
|
112
|
+
const { env, metadata } = destroyOutput;
|
|
113
|
+
const output = destroyed || [];
|
|
114
|
+
output.push({ env, metadata, packageName });
|
|
115
|
+
ctx.destroyed = output;
|
|
116
|
+
},
|
|
117
|
+
title: `Destroying ${packageName}`,
|
|
118
|
+
})), { concurrent: true });
|
|
119
|
+
},
|
|
120
|
+
title: `Destroying packages`,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
skip: (ctx) => !ctx.destroyed || ctx.destroyed.length === 0,
|
|
124
|
+
async task(ctx) {
|
|
125
|
+
const { destroyed, workspace } = ctx;
|
|
126
|
+
if (!destroyed || destroyed.length === 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const envManager = getEnvManager();
|
|
130
|
+
for (const { env, metadata } of destroyed) {
|
|
131
|
+
// eslint-disable-next-line no-await-in-loop
|
|
132
|
+
await envManager.removeProjectEnv({
|
|
133
|
+
env,
|
|
134
|
+
infra: metadata.originalInfra ?? metadata.infra,
|
|
135
|
+
projectRootDir,
|
|
136
|
+
workspace,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
await delay(500);
|
|
140
|
+
},
|
|
141
|
+
title: 'Removing env vars from destroyed packages',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
async task() {
|
|
145
|
+
const backend = await getBackend();
|
|
146
|
+
const configManager = getConfigManager();
|
|
147
|
+
const { config: newConfig } = await configManager.loadConfig({ projectRootDir });
|
|
148
|
+
await backend.saveState(newConfig);
|
|
149
|
+
await delay(500);
|
|
150
|
+
},
|
|
151
|
+
title: 'Saving state',
|
|
152
|
+
},
|
|
153
|
+
], { concurrent: false });
|
|
154
|
+
},
|
|
155
|
+
title: 'Shutting down the project',
|
|
156
|
+
},
|
|
157
|
+
]);
|
|
158
|
+
try {
|
|
159
|
+
await task.run();
|
|
160
|
+
myLogger.log(ListrLogLevels.COMPLETED, 'Project shut down successfully');
|
|
43
161
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const backend = await getBackend();
|
|
48
|
-
const getWorkspaceEnvOutput = await backend.getWorkspaceEnv({
|
|
49
|
-
project: config.project,
|
|
50
|
-
workspace,
|
|
51
|
-
});
|
|
52
|
-
if (!getWorkspaceEnvOutput.success) {
|
|
53
|
-
this.error(getWorkspaceEnvOutput.reason);
|
|
162
|
+
catch (error) {
|
|
163
|
+
myLogger.log(ListrLogLevels.FAILED, error);
|
|
164
|
+
this.error(error.message);
|
|
54
165
|
}
|
|
55
|
-
const { env: workspaceEnv } = getWorkspaceEnvOutput;
|
|
56
|
-
const parameterManager = getParameterManager();
|
|
57
|
-
logger.log(`Destroying ${packages.length} packages`);
|
|
58
|
-
const result = await Promise.all(packages.map(async (packageName) => {
|
|
59
|
-
const { parameters } = await parameterManager.getPackageParameters({
|
|
60
|
-
package: packageName,
|
|
61
|
-
projectRootDir,
|
|
62
|
-
workspace,
|
|
63
|
-
});
|
|
64
|
-
const destroyOutput = await destroyPackage({
|
|
65
|
-
env: workspaceEnv,
|
|
66
|
-
isDeploying: flags.deploy,
|
|
67
|
-
package: packageName,
|
|
68
|
-
parameters,
|
|
69
|
-
project: config.project,
|
|
70
|
-
workspace,
|
|
71
|
-
});
|
|
72
|
-
if (!destroyOutput.success) {
|
|
73
|
-
this.error(destroyOutput.reason);
|
|
74
|
-
}
|
|
75
|
-
const { env, metadata } = destroyOutput;
|
|
76
|
-
return { env, metadata, packageName };
|
|
77
|
-
}));
|
|
78
|
-
logger.done(`Destroyed ${packages.length} packages`);
|
|
79
|
-
const envManager = getEnvManager();
|
|
80
|
-
for (const { env, metadata } of result) {
|
|
81
|
-
// eslint-disable-next-line no-await-in-loop
|
|
82
|
-
await envManager.removeProjectEnv({
|
|
83
|
-
env,
|
|
84
|
-
infra: metadata.originalInfra ?? metadata.infra,
|
|
85
|
-
projectRootDir,
|
|
86
|
-
workspace,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
logger.done(`Removed environment variables of ${packages.length} packages`);
|
|
90
|
-
const { config: newConfig } = await configManager.loadConfig({ projectRootDir });
|
|
91
|
-
await backend.saveState(newConfig);
|
|
92
166
|
}
|
|
93
167
|
}
|