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;
}
}
export default (...extras: string[]) => {
const nameColor = logger.coloredStrings.name;
const headline = logger.coloredStrings.headline;
logger.info(`Please follow these steps to possibly ${headline('fix')} this issue:`);
const lines = [
`Delete your ${nameColor('node_modules')} directory`,
`Delete ${nameColor('package-lock.json')} and/or ${nameColor('yarn.lock')}`,
...extras,
`Run ${nameColor('npm install')} or ${nameColor('yarn install')} again`,
];
printList(...lines);
};
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();
export default (packageName: string) => {
const nameColor = logger.coloredStrings.name;
const flexUIName = nameColor('@twilio/flex-ui');
logger.newline();
logger.error('An expected package was not found.');
logger.newline();
logger.info(`Expected package ${nameColor(packageName)} was not found in ${flexUIName}.`);
logger.newline();
instructionToReinstall();
};
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();
export default (...extras: string[]) => {
const nameColor = logger.coloredStrings.name;
const headline = logger.coloredStrings.headline;
logger.info(`Please follow these steps to possibly ${headline('fix')} this issue:`);
const lines = [
`Delete your ${nameColor('node_modules')} directory`,
`Delete ${nameColor('package-lock.json')} and/or ${nameColor('yarn.lock')}`,
...extras,
`Run ${nameColor('npm install')} or ${nameColor('yarn install')} again`,
];
printList(...lines);
};
export default (foundPackages: PackageDetail[], notFoundPackages: PackageDetail[]) => {
const headline = logger.coloredStrings.headline;
logger.info('Your plugin has the following packages installed:');
logger.newline();
foundPackages
.forEach((detail) => {
logger.info(`\t ${headline(`"${detail.name}": "${detail.package.version}"`)}`);
});
if (notFoundPackages.length) {
logger.newline();
logger.error('However, some required packages were not found:');
logger.newline();
notFoundPackages
.forEach((detail) => {
logger.info(`\t ${headline(`"${detail.name}"`)}`);
});
const validate = async (config: FlexPluginArguments): Promise => {
config.name = config.name || '';
if (!isValidPluginName(config.name)) {
const coloredName = logger.coloredStrings.name;
const msg = `Invalid plugin name ${coloredName(config.name)}; plugin name must start with plugin-`;
throw new ValidationError(msg);
}
if (config.accountSid && !isSidOfType(config.accountSid, SidPrefix.AccountSid)) {
config.accountSid = await _promptForAccountSid();
}
if (config.template && !isValidUrl(config.template)) {
config.template = await _promptForTemplateUrl();
}
return config;
};
import { logger } from 'flex-dev-utils';
import { info as boxedInfo } from 'flex-dev-utils/dist/boxen';
import { multilineString } from 'flex-dev-utils/dist/strings';
import { FlexPluginArguments } from '../lib/create-flex-plugin';
const headline = logger.coloredStrings.headline;
/**
* Prints the final message after the successful creation of a new project
* @param config
*/
export default (config: FlexPluginArguments) => {
const tool = config.yarn ? 'yarn' : 'npm';
const installCommand = config.yarn ? 'yarn' : 'npm install';
const setupMessage = multilineString(
`${headline('Setup:')}`,
`$ cd ${config.name}/`,
`$ ${installCommand}`,
);
const startCommand = `${tool} start`;
export default (url: string, isPublic: boolean, account: Account) => {
const availability = isPublic ? 'publicly' : 'privately';
const nameLogger = logger.coloredStrings.name;
logger.newline();
logger.success(singleLineString(
'🚀 Your plugin has been successfully deployed to your Flex project',
`${nameLogger(account.friendly_name)} (${nameLogger(account.sid)}).`,
`It is hosted (${availability}) as a Twilio Asset on ${logger.coloredStrings.link(url)}.`,
));
logger.newline();
};