Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/activate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This can be run after examples/deploy.js you just need the service Sid.
// Run this example with:
// node deploy/activate.js SERVICE_SID

const { TwilioServerlessApiClient } = require('../dist');
const serviceSid = process.argv[2];
async function run() {
const config = {
accountSid: process.env.TWILIO_ACCOUNT_SID,
authToken: process.env.TWILIO_AUTH_TOKEN,
};

const client = new TwilioServerlessApiClient(config);
console.log('Activating');
const result = await client.activateBuild({
...config,
env: {
HELLO: 'hello',
WORLD: 'world',
},
serviceSid,
sourceEnvironment: 'test',
targetEnvironment: 'stage',
createEnvironment: true,
});
console.log('Done Activating');
console.dir(result);
}

run().catch(console.error);
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
targetEnvironment,
serviceSid,
sourceEnvironment,
env,
} = activateConfig;

if (!buildSid && !sourceEnvironment) {
Expand Down Expand Up @@ -372,6 +373,12 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
throw new Error('Could not determine build SID');
}

this.emit('status-update', {
status: DeployStatus.SETTING_VARIABLES,
message: 'Setting environment variables',
});
await setEnvironmentVariables(env, targetEnvironment, serviceSid, this);

const { domain_name } = await getEnvironment(
targetEnvironment,
serviceSid,
Expand Down
2 changes: 2 additions & 0 deletions src/types/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { ClientConfig } from './client';
import { Sid } from './serverless-api';
import { EnvironmentVariables } from './generic';

export type ActivateConfig = ClientConfig & {
force?: boolean;
Expand All @@ -10,6 +11,7 @@ export type ActivateConfig = ClientConfig & {
buildSid?: Sid;
targetEnvironment: string | Sid;
sourceEnvironment?: string | Sid;
env: EnvironmentVariables;
};

export type ActivateResult = {
Expand Down