Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const files = readdirSync(join(dir, 'scripts'));
let scripts = files
.filter((f) => {
const ext = f.split('.').pop();
return ext === 'js' || ext === 'ts';
})
.map((f) => f.split('.')[0])
.filter((f) => f !== 'run');
scripts = [...new Set(scripts)];
const scriptIndex = argv.findIndex((x) => scripts.includes(x));
const script = scriptIndex !== -1 && argv[scriptIndex];
if (!script) {
const options = logger.colors.blue(scripts.join(', '));
logger.error(`Unknown script '${script}'; please choose from one of: ${options}.`);
return process.exit(1);
}
// Print help doc and quit
if (argv.includes('--help') && script) {
const docPath = join(dir, '../docs', script) + '.md';
if (!existsSync(docPath)) {
logger.warning(`No documentation was found for ${script}`);
return process.exit(1);
}
markedRender(docPath);
return process.exit(0);
}
const files = readdirSync(join(dir, 'scripts'));
let scripts = files
.filter((f) => {
const ext = f.split('.').pop();
return ext === 'js' || ext === 'ts';
})
.map((f) => f.split('.')[0])
.filter((f) => f !== 'run');
scripts = [...new Set(scripts)];
const scriptIndex = argv.findIndex((x) => scripts.includes(x));
const script = scriptIndex !== -1 && argv[scriptIndex];
if (!script) {
const options = logger.colors.blue(scripts.join(', '));
logger.error(`Unknown script '${script}'; please choose from one of: ${options}.`);
return process.exit(1);
}
// Print help doc and quit
if (argv.includes('--help') && script) {
const docPath = join(dir, '../docs', script) + '.md';
if (!existsSync(docPath)) {
logger.warning(`No documentation was found for ${script}`);
return process.exit(1);
}
markedRender(docPath);
return process.exit(0);
}
export const _doRemove = async () => {
const pluginName = logger.colors.blue(paths.packageName);
const credentials = await getCredential();
const runtime = await _getRuntime(credentials);
await progress(`Deleting plugin ${pluginName}`, async () => {
const environmentClient = new EnvironmentClient(credentials, runtime.service.sid);
await environmentClient.remove(runtime.environment.sid);
});
logger.newline();
logger.info(`🎉️ Plugin ${pluginName} was successfully removed.`);
process.exit(0);
};
export const _getRuntime = async (credentials: AuthConfig): Promise => {
const runtime = await getRuntime(credentials, true);
const environmentClient = new EnvironmentClient(credentials, runtime.service.sid);
try {
const environment = await environmentClient.get(false);
return {
environment,
service: runtime.service,
};
} catch (e) {
const pluginName = logger.colors.blue(paths.packageName);
logger.newline();
logger.info(`⚠️ Plugin ${pluginName} was not found or was already removed.`);
return process.exit(0);
}
};
export default (packageName: string, installedVersion: string, requiredVersion: string, skip: boolean) => {
const nameColor = logger.coloredStrings.name;
const headline = logger.coloredStrings.headline;
const red = logger.colors.red;
const flexUIName = nameColor('@twilio/flex-ui');
const scriptName = nameColor('flex-plugin-scripts');
logger.newline();
logger.error(singleLineString(
'There might be a problem with your project dependency tree.',
));
logger.newline();
logger.info(`The ${flexUIName} requires the following package:`);
logger.newline();
logger.info(`\t ${headline(`"${packageName}": "${requiredVersion}"`)}`);
logger.newline();
const versionPrint = red(installedVersion);