Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!config) {
logError('Internal Error');
process.exit(1);
return;
}
debug('Deploy Config %P', config);
checkConfigForCredentials(config);
printConfigInfo(config);
const spinner = getOraSpinner('Deploying Function').start();
try {
const client = new TwilioServerlessApiClient(config);
client.on('status-update', evt => {
spinner.text = evt.message + '\n';
});
const result = await client.deployLocalProject(config);
spinner.text = 'Serverless project successfully deployed\n';
spinner.succeed();
printDeployedResources(config, result);
const { serviceSid, buildSid } = result;
await saveLatestDeploymentData(
config.cwd,
serviceSid,
buildSid,
config.accountSid.startsWith('AC')
? config.accountSid
: externalCliOptions && externalCliOptions.accountSid
);
process.exit(1);
return;
}
checkConfigForCredentials(config);
printActivateConfig(config);
const details = config.buildSid
? `(${config.buildSid})`
: `from ${config.sourceEnvironment}`;
const spinner = getOraSpinner(
`Activating build ${details} to ${config.targetEnvironment || 'production'}`
).start();
try {
const client = new TwilioServerlessApiClient(config);
const result = await client.activateBuild(config);
spinner.succeed(
`Activated new build ${details} on ${config.targetEnvironment ||
'production'}`
);
printActivateResult(result);
} catch (err) {
handleError(err, spinner);
}
}
if (!config) {
logError('Internal Error');
process.exit(1);
return;
}
checkConfigForCredentials(config);
if (config.types !== 'services' && config.types[0] !== 'services') {
const command = getFullCommand(flags);
checkForValidServiceSid(command, config.serviceSid);
}
try {
const client = new TwilioServerlessApiClient(config);
const result = await client.list({ ...config });
printListResult(result, config);
} catch (err) {
handleError(err);
}
}
export async function doesAnyDirectoryExist(
basePath: string,
directories: string[]
): Promise {
let foundDirectories: string | undefined;
try {
foundDirectories = fsHelpers.getFirstMatchingDirectory(
basePath,
directories
);
} catch {
foundDirectories = undefined;
}
if (typeof foundDirectories !== 'undefined') {
return true;
}
return false;
}
export async function writeFiles(
files: TemplateFileInfo[],
targetDir: string,
namespace: string
): Promise {
const functionsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'functions',
'src',
]);
const assetsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'assets',
'static',
]);
const functionsTargetDir = path.join(functionsDir, namespace);
const assetsTargetDir = path.join(assetsDir, namespace);
if (functionsTargetDir !== functionsDir) {
if (hasFilesOfType(files, 'functions')) {
try {
await mkdir(functionsTargetDir);
} catch (err) {
debug(err);
export async function writeFiles(
files: TemplateFileInfo[],
targetDir: string,
namespace: string
): Promise {
const functionsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'functions',
'src',
]);
const assetsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'assets',
'static',
]);
const functionsTargetDir = path.join(functionsDir, namespace);
const assetsTargetDir = path.join(assetsDir, namespace);
if (functionsTargetDir !== functionsDir) {
if (hasFilesOfType(files, 'functions')) {
try {
await mkdir(functionsTargetDir);
} catch (err) {
debug(err);
throw new Error(
`Template with name "${namespace}" already exists in "${functionsDir}"`
);
}
export async function getFunctionsAndAssets(
baseDir: string
): Promise {
let { functions, assets } = await fsHelpers.getListOfFunctionsAndAssets(
baseDir
);
return { functions, assets };
}