Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 nodeArgs = scriptIndex > 0 ? argv.slice(0, scriptIndex) : [];
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 nodeArgs = scriptIndex > 0 ? argv.slice(0, scriptIndex) : [];
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);
};
.catch((e) => {
if (e instanceof FlexPluginError) {
e.print();
if (process.env.DEBUG) {
e.details();
}
} else {
logger.error(e);
}
return process.exit(1);
});
}
const spawn = (processArgs: string[]): number => {
const child = spawnSync('node', processArgs, { stdio: 'inherit' });
if (child.signal) {
if (child.signal === 'SIGKILL') {
logger.error([
'The build failed because the process exited too early. ',
'This probably means the system ran out of memory or someone called ',
'`kill -9` on the process.',
].join('\n'));
} else if (child.signal === 'SIGTERM') {
logger.warning([
'The build failed because the process exited too early. ',
'Someone might have called `kill` or `killall`, or the system could ',
'be shutting down.',
].join('\n'));
}
process.exit(1);
}
return child.status || 0;
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 (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}"`)}`);
});
logger.newline();
instructionToReinstall();
}
};