twilio-run
Advanced tools
Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4
{ | ||
"name": "twilio-run", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-alpha.4", | ||
"bin": { | ||
@@ -31,3 +31,3 @@ "twilio-functions": "./bin/twilio-run.js", | ||
"dependencies": { | ||
"@twilio-labs/serverless-api": "^1.0.0-alpha.0", | ||
"@twilio-labs/serverless-api": "^1.0.0-alpha.3", | ||
"body-parser": "^1.18.3", | ||
@@ -45,3 +45,3 @@ "boxen": "^1.3.0", | ||
"ngrok": "^3.0.1", | ||
"ora": "^3.3.0", | ||
"ora": "^3.3.1", | ||
"pkg-install": "^1.0.0", | ||
@@ -48,0 +48,0 @@ "prompts": "^2.0.4", |
@@ -26,6 +26,10 @@ const path = require('path'); | ||
async function saveFunctionServiceSid(cwd, serviceSid) { | ||
async function saveLatestDeploymentData(cwd, serviceSid, buildSid) { | ||
const configPath = path.join(cwd, '.twilio-functions'); | ||
if (!(await fileExists(configPath))) { | ||
const output = JSON.stringify({ serviceSid }, null, 2); | ||
const output = JSON.stringify( | ||
{ serviceSid, latestBuild: buildSid }, | ||
null, | ||
2 | ||
); | ||
return writeFile(configPath, output, 'utf8'); | ||
@@ -70,5 +74,5 @@ } | ||
...localEnv, | ||
ACCOUNT_SID: undefined, | ||
AUTH_TOKEN: undefined, | ||
}; | ||
delete env.ACCOUNT_SID; | ||
delete env.AUTH_TOKEN; | ||
@@ -92,11 +96,53 @@ return { | ||
function printDeployedFunctions(output) { | ||
const msg = output.functionResources | ||
.map(fn => { | ||
return `| https://${output.domain}${fn.functionPath}`; | ||
}) | ||
.join('\n'); | ||
console.log('\n' + msg); | ||
function printDeployedResources(config, output) { | ||
console.log( | ||
chalk` | ||
{bold Deployment Details} | ||
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ | ||
{bold Domain:} ${output.domain} | ||
{bold Service:} | ||
${config.projectName} {dim (${output.serviceSid})} | ||
{bold Environment:} | ||
${config.functionsEnv} {dim (${output.environmentSid})} | ||
{bold Build SID:} | ||
${output.buildSid} | ||
`.trim() | ||
); | ||
if (output.functionResources) { | ||
const functionMessage = output.functionResources | ||
.map(fn => { | ||
return chalk` {dim https://${output.domain}}${fn.functionPath}`; | ||
}) | ||
.join('\n'); | ||
console.log(chalk.bold('Functions:')); | ||
console.log(functionMessage); | ||
} | ||
if (output.assetResources) { | ||
const assetMessage = output.assetResources | ||
.map(fn => { | ||
return chalk` {dim https://${output.domain}}${fn.assetPath}`; | ||
}) | ||
.join('\n'); | ||
console.log(chalk.bold('Assets:')); | ||
console.log(assetMessage); | ||
} | ||
} | ||
function printConfigInfo(config) { | ||
console.log( | ||
chalk` | ||
Deploying functions & assets to Twilio Serverless | ||
{bold Account}\t\t${config.accountSid} | ||
{bold Project Name}\t${config.projectName} | ||
{bold Environment}\t${config.functionsEnv} | ||
{bold Root Directory}\t${config.cwd} | ||
{bold Dependencies}\t${Object.keys(config.pkgJson.dependencies).join(', ')} | ||
{bold Env Variables}\t${Object.keys(config.env).join(', ')} | ||
` | ||
); | ||
} | ||
async function handler(flags) { | ||
@@ -117,2 +163,4 @@ let config; | ||
printConfigInfo(config); | ||
const spinner = ora('Deploying Function').start(); | ||
@@ -122,9 +170,10 @@ try { | ||
client.on('status-update', evt => { | ||
spinner.text = evt.message; | ||
spinner.text = evt.message + '\n'; | ||
}); | ||
const result = await client.deployLocalProject(); | ||
spinner.succeed('Project successfully deployed'); | ||
printDeployedFunctions(result); | ||
const { serviceSid } = result; | ||
await saveFunctionServiceSid(config.cwd, serviceSid); | ||
const result = await client.deployLocalProject(config); | ||
spinner.text = 'Project successfully deployed\n'; | ||
spinner.succeed(); | ||
printDeployedResources(config, result); | ||
const { serviceSid, buildSid } = result; | ||
await saveLatestDeploymentData(config.cwd, serviceSid, buildSid); | ||
} catch (err) { | ||
@@ -131,0 +180,0 @@ log(err); |
@@ -9,3 +9,3 @@ jest.unmock('twilio'); | ||
const TEST_DIR = resolve(__dirname, '../fixtures'); | ||
const TEST_DIR = resolve(__dirname, '../../fixtures'); | ||
const TEST_FUNCTIONS_DIR = resolve(TEST_DIR, 'functions'); | ||
@@ -12,0 +12,0 @@ const TEST_ENV = {}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
51890
26
1420
0
Updatedora@^3.3.1