Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function updatePods(loader: ora.Ora) {
try {
loader.start(
`Updating CocoaPods repositories ${chalk.dim(
'(this may take a few minutes)',
)}`,
);
await execa('pod', ['repo', 'update']);
} catch (error) {
// "pod" command outputs errors to stdout (at least some of them)
logger.log(error.stderr || error.stdout);
loader.fail();
throw new Error(
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${chalk.dim.underline(
'https://cocoapods.org/',
)}`,
);
}
}
function createInstallError(error: Error & {stderr: string}) {
const stderr = (error.stderr || '').toString();
const docs =
'https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment';
let message = `Make sure you have the Android development environment set up: ${chalk.underline.dim(
docs,
)}`;
// Pass the error message from the command to stdout because we pipe it to
// parent process so it's not visible
logger.log(stderr);
// Handle some common failures and make the errors more helpful
if (stderr.includes('No connected devices')) {
message =
'Make sure you have an Android emulator running or a device connected';
} else if (
stderr.includes('licences have not been accepted') ||
stderr.includes('accept the SDK license')
) {
message = `Please accept all necessary SDK licenses using SDK Manager: "${chalk.bold(
'$ANDROID_HOME/tools/bin/sdkmanager --licenses',
)}"`;
}
return new CLIError(`Failed to install the app. ${message}.`, error);
}
}
if (shouldUpdatePods) {
await updatePods(loader);
}
try {
loader.start(
`Installing CocoaPods dependencies ${chalk.dim(
'(this may take a few minutes)',
)}`,
);
await execa('pod', ['install']);
} catch (error) {
// "pod" command outputs errors to stdout (at least some of them)
logger.log(error.stderr || error.stdout);
throw new Error(
`Failed to install CocoaPods dependencies for iOS project, which is required by this template.\nPlease try again manually: "cd ./${projectName}/ios && pod install".\nCocoaPods documentation: ${chalk.dim.underline(
'https://cocoapods.org/',
)}`,
);
}
} catch (error) {
throw error;
} finally {
process.chdir('..');
}
}
const logMessage = (message?: string) => {
const indentation = ' ';
if (typeof message !== 'string') {
logger.log();
return;
}
const messageByLine = message.split('\n');
return logger.log(`${indentation}${messageByLine.join(`\n${indentation}`)}`);
};
async function createFromTemplate({
projectName,
templateName,
npm,
directory,
projectTitle,
}: TemplateOptions) {
logger.debug('Initializing new project');
logger.log(banner);
const projectDirectory = await setProjectDirectory(directory);
const Loader = getLoader();
const loader = new Loader({text: 'Downloading template'});
const templateSourceDir = fs.mkdtempSync(
path.join(os.tmpdir(), 'rncli-init-template-'),
);
try {
loader.start();
let {uri, name} = await processTemplateName(templateName);
await installTemplatePackage(uri, templateSourceDir, npm);
loader.succeed();
emitter.on('error', error => {
logger.log(formatError(error));
});
}
const printCategory = ({label, key}: {label: string; key: number}) => {
if (key > 0) {
logger.log();
}
logger.log(chalk.dim(label));
};
const printOptions = () => {
logger.log();
logger.log(chalk.bold('Usage'));
printOption(
`${chalk.dim('Press')} ${KEYS.FIX_ALL_ISSUES} ${chalk.dim(
'to try to fix issues.',
)}`,
);
printOption(
`${chalk.dim('Press')} ${KEYS.FIX_ERRORS} ${chalk.dim(
'to try to fix errors.',
)}`,
);
printOption(
`${chalk.dim('Press')} ${KEYS.FIX_WARNINGS} ${chalk.dim(
'to try to fix warnings.',
)}`,
);
const printOptions = () => {
logger.log();
logger.log(chalk.bold('Usage'));
printOption(
`${chalk.dim('Press')} ${KEYS.FIX_ALL_ISSUES} ${chalk.dim(
'to try to fix issues.',
)}`,
);
printOption(
`${chalk.dim('Press')} ${KEYS.FIX_ERRORS} ${chalk.dim(
'to try to fix errors.',
)}`,
);
printOption(
`${chalk.dim('Press')} ${KEYS.FIX_WARNINGS} ${chalk.dim(
'to try to fix warnings.',
)}`,
);
printOption(`${chalk.dim('Press')} Enter ${chalk.dim('to exit.')}`);