Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ios: config.ios,
android: config.android,
},
assets: config.assets,
commands: [],
dependencies: {},
// @ts-ignore - TODO: platforms can be empty, adjust types
platforms: {},
get reactNativePath() {
return config.reactNativePath
? path.resolve(rootFolder, config.reactNativePath)
: resolveReactNativePath(rootFolder);
},
};
logger.warn(
`Your project is using deprecated "${chalk.bold(
'rnpm',
)}" config that will stop working from next release. Please use a "${chalk.bold(
'react-native.config.js',
)}" file to configure the React Native CLI. ${MIGRATION_GUIDE}`,
);
return transformedConfig;
}
function saveAssets(
assets: AssetData[],
platform: string,
assetsDest: string | undefined,
) {
if (!assetsDest) {
logger.warn('Assets destination folder is not set, skipping...');
return Promise.resolve();
}
const getAssetDestPath =
platform === 'android' ? getAssetDestPathAndroid : getAssetDestPathIOS;
const filesToCopy: CopiedFiles = Object.create(null); // Map src -> dest
assets.forEach(asset => {
const validScales = new Set(
filterPlatformAssetScales(platform, asset.scales),
);
asset.scales.forEach((scale, idx) => {
if (!validScales.has(scale)) {
return;
}
const src = asset.files[idx];
try {
fs.writeFileSync(tmpPatchFile, patch);
patchSuccess = await applyPatch(currentVersion, newVersion, tmpPatchFile);
} catch (error) {
throw new Error(error.stderr || error);
} finally {
try {
fs.unlinkSync(tmpPatchFile);
} catch (e) {
// ignore
}
const {stdout} = await execa('git', ['status', '-s']);
if (!patchSuccess) {
if (stdout) {
logger.warn(
'Continuing after failure. Some of the files are upgraded but you will need to deal with conflicts manually',
);
await installDeps(newVersion);
logger.info('Running "git status" to check what changed...');
await execa('git', ['status'], {stdio: 'inherit'});
} else {
logger.error(
'Patch failed to apply for unknown reason. Please fall back to manual way of upgrading',
);
}
} else {
await installDeps(newVersion);
await installCocoaPodsDeps(projectDir, thirdPartyIOSDeps);
logger.info('Running "git status" to check what changed...');
await execa('git', ['status'], {stdio: 'inherit'});
}
) {
try {
const adbPath = getAdbPath();
const adbArgs = ['reverse', `tcp:${packagerPort}`, `tcp:${packagerPort}`];
// If a device is specified then tell adb to use it
if (device) {
adbArgs.unshift('-s', device);
}
logger.info('Connecting to the development server...');
logger.debug(`Running command "${adbPath} ${adbArgs.join(' ')}"`);
execFileSync(adbPath, adbArgs, {stdio: 'inherit'});
} catch (e) {
logger.warn(
`Failed to connect to development server using "adb reverse": ${
e.message
}`,
);
}
}
export default function createGroupWithMessage(project: any, path: string) {
let group = getGroup(project, path);
if (!group) {
group = createGroup(project, path);
logger.warn(
`Group '${path}' does not exist in your Xcode project. We have created it automatically for you.`,
);
}
return group;
}
function checkAdbPath() {
const adbPath = getAdbPath();
const adbPathExists = fs.existsSync(adbPath);
const adbCmdExists = checkCommandExists('adb');
const adbNotFoundError = `"adb" not found in $location$. APK installation $prediction$ fail. Make sure you installed the Android SDK correctly. Read more at ${chalk.underline.dim(
'https://facebook.github.io/react-native/docs/getting-started',
)}`;
if (!adbPathExists || !adbCmdExists) {
const notFoundLocation = `${
!adbCmdExists ? 'PATH environment variable' : adbPath
}`;
logger.warn(
adbNotFoundError
.replace('$location$', notFoundLocation)
.replace('$prediction$', 'might'),
);
} else if (!adbPathExists && !adbCmdExists) {
throw new CLIError(
adbNotFoundError
.replace('$location$', `PATH environment variable or ${adbPath}`)
.replace('$prediction$', 'will'),
);
}
}
packageNameWithSuffix: string,
packageName: string,
adbPath: string,
) {
let devices = adb.getDevices(adbPath);
if (devices.length === 0) {
logger.info('Launching emulator...');
const result = await tryLaunchEmulator(adbPath);
if (result.success) {
logger.info('Successfully launched emulator.');
devices = adb.getDevices(adbPath);
} else {
logger.error(
`Failed to launch emulator. Reason: ${chalk.dim(result.error || '')}.`,
);
logger.warn(
'Please launch an emulator manually or connect a device. Otherwise app may fail to launch.',
);
}
}
try {
const tasks = args.tasks || ['install' + toPascalCase(args.variant)];
const gradleArgs = getTaskNames(args.appFolder, tasks);
if (args.port != null) {
gradleArgs.push('-PreactNativeDevServerPort=' + args.port);
}
logger.info('Installing the app...');
logger.debug(
`Running command "cd android && ${cmd} ${gradleArgs.join(' ')}"`,
platforms: {
...acc.platforms,
...config.platforms,
},
haste: {
providesModuleNodeModules: [
...acc.haste.providesModuleNodeModules,
...haste.providesModuleNodeModules,
],
platforms: [...acc.haste.platforms, ...haste.platforms],
},
}) as Config;
}, initialConfig);
if (depsWithWarnings.length) {
logger.warn(
`The following packages use deprecated "rnpm" config that will stop working from next release:\n${depsWithWarnings
.map(
([name, link]) =>
` - ${chalk.bold(name)}: ${chalk.dim(chalk.underline(link))}`,
)
.join(
'\n',
)}\nPlease notify their maintainers about it. You can find more details at ${chalk.dim.underline(
'https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide',
)}.`,
);
}
return finalConfig;
}
function checkAndroidSDKPath() {
logger.info('here');
const {ANDROID_HOME} = process.env;
if (!ANDROID_HOME || !fs.existsSync(ANDROID_HOME)) {
throw new CLIError(
`Android SDK not found. Make sure you have set ANDROID_HOME environment variable in the system. Read more at ${chalk.underline.dim(
'https://facebook.github.io/react-native/docs/getting-started#3-configure-the-android_home-environment-variable',
)}`,
);
}
if (ANDROID_HOME.includes(' ')) {
logger.warn(
`Android SDK path "${ANDROID_HOME}" contains whitespaces which can cause build and install errors. Consider moving the Android SDK to a non-whitespace path.`,
);
}
}