Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const createFlexPlugin = async (config: FlexPluginArguments) => {
config = await validate(config);
config = setupConfiguration(config);
// Check folder does not exist
if (fs.existsSync(config.targetDirectory)) {
throw new FlexPluginError(singleLineString(
`Path ${logger.coloredStrings.link(config.targetDirectory)} already exists;`,
'please remove it and try again.',
));
}
// Setup the directories
if (!await _scaffold(config)) {
throw new FlexPluginError('Failed to scaffold project');
}
// Install NPM dependencies
if (config.install) {
if (!await _install(config)) {
logger.error('Failed to install dependencies. Please run `npm install` manually.');
config.install = false;
}
}
finalMessage(config);
};
export const _getPortAndUrl = (...argv: string[]) => {
const url = argv.find((a) => a.indexOf('localhost:') !== -1);
if (!url) {
throw new FlexPluginError('No localhost server was found running.');
}
return {
url,
port: _getPort(url),
};
};
export const _doDeploy = async (nextVersion: string, options: Options) => {
if (!checkFilesExist(paths.localBundlePath)) {
throw new FlexPluginError('Could not find build file. Did you run `npm run build` first?');
}
logger.info('Uploading your Flex plugin to Twilio Assets\n');
const pluginBaseUrl = paths.assetBaseUrlTemplate.replace('%PLUGIN_VERSION%', nextVersion);
const bundleUri = `${pluginBaseUrl}/bundle.js`;
const sourceMapUri = `${pluginBaseUrl}/bundle.js.map`;
const credentials = await getCredential();
const runtime = await getRuntime(credentials);
const pluginUrl = `https://${runtime.environment.domain_name}${bundleUri}`;
const configurationClient = new ConfigurationClient(credentials);
const buildClient = new BuildClient(credentials, runtime.service.sid);
const assetClient = new AssetClient(credentials, runtime.service.sid);
const list = async (...argv: string[]) => {
const publicOnly = argv.includes('--public-only');
const privateOnly = argv.includes('--private-only');
const order = argv.includes('--desc') ? 'desc' : 'asc';
if (publicOnly && privateOnly) {
throw new FlexPluginError('You cannot use --public-only and --private-only flags together.');
}
const visibilities: Visibility[] = [];
if (publicOnly) {
visibilities.push(Visibility.Public);
} else if (privateOnly) {
visibilities.push(Visibility.Protected);
} else {
visibilities.push(Visibility.Public);
visibilities.push(Visibility.Protected);
}
await _doList(visibilities, order);
};
const disallowVersioning = argv.includes('--disallow-versioning');
let nextVersion = argv[1] as string;
const bump = argv[0];
const opts = {
isPublic: argv.includes('--public'),
overwrite: argv.includes('--overwrite') || disallowVersioning,
disallowVersioning,
};
if (!disallowVersioning) {
if (!allowedBumps.includes(bump)) {
throw new FlexPluginError(`Version bump can only be one of ${allowedBumps.join(', ')}`);
}
if (bump === 'custom' && !argv[1]) {
throw new FlexPluginError('Custom version bump requires the version value.');
}
if (bump === 'overwrite') {
opts.overwrite = true;
nextVersion = readPackageJson().version;
} else if (bump !== 'custom') {
nextVersion = semver.inc(paths.version, bump as ReleaseType) as any;
}
} else {
nextVersion = '0.0.0';
}
await _doDeploy(nextVersion, opts);
};