Skip to content

Commit

Permalink
fix(cli-plugin-deploy-components): send "stack-deploy-end" event on C…
Browse files Browse the repository at this point in the history
…trl+C
  • Loading branch information
Pavel910 committed Jul 7, 2020
1 parent ffa453a commit 3feb6e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
5 changes: 2 additions & 3 deletions packages/cli-plugin-deploy-components/execute/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const randomId = () =>
.substring(6);

class Context {
constructor(config) {
constructor(config, context) {
this.logger = config.logger;
this.stackName = config.stackName;
this.stateRoot = config.stateRoot;
Expand All @@ -23,9 +23,8 @@ class Context {
this.projectName = config.projectName;

// Control + C
process.on("SIGINT", async () => {
context.onExit(() => {
this._status.stop("cancel");
process.exit(1);
});

this._status = new Status();
Expand Down
8 changes: 0 additions & 8 deletions packages/cli-plugin-deploy-components/execute/Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class Status {

stop(reason) {
if (!this.isRunning()) {
console.log();
process.exit(0);
return;
}

Expand All @@ -64,12 +62,6 @@ class Status {
console.log(os.EOL);
process.stdout.write(ansiEscapes.cursorLeft);
process.stdout.write(ansiEscapes.cursorShow);

if (reason === "error") {
process.exit(1);
} else {
process.exit(0);
}
}

async render(status) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-deploy-components/execute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports.execute = async (inputs, method, context) => {
stackName: `${context.projectName}_${stack}`,
env,
debug
});
}, context);
componentContext.projectName = context.projectName;
await componentContext.init();

Expand Down
13 changes: 12 additions & 1 deletion packages/cli-plugin-deploy-components/execute/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ class Template extends Component {
return await this.deployAll({ ...inputs, template }, context);
}

async deployAll(inputs = {}) {
async deployAll(inputs = {}, cliContext) {
this.context.status("Deploying");

cliContext.onExit(async code => {
if (code === "SIGINT") {
await sendEvent({
event: "stack-deploy-end",
data: {
stack: inputs.stack
}
});
}
});

await sendEvent({
event: "stack-deploy-start",
data: {
Expand Down

0 comments on commit 3feb6e3

Please sign in to comment.