How to use the @react-native-community/cli-tools.CLIError function in @react-native-community/cli-tools

To help you get started, we’ve selected a few @react-native-community/cli-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-native-community / cli / packages / cli / src / commands / link / unlink.ts View on Github external
try {
    if (dependency.hooks.preunlink) {
      await makeHook(dependency.hooks.preunlink)();
    }
    unlinkDependency(
      platforms,
      ctx.project,
      dependency,
      packageName,
      dependencies,
    );
    if (dependency.hooks.postunlink) {
      await makeHook(dependency.hooks.postunlink)();
    }
  } catch (error) {
    throw new CLIError(
      `Something went wrong while unlinking. Reason ${error.message}`,
      error,
    );
  }

  // @todo move all these to above try/catch
  // @todo it is possible we could be unlinking some project assets in case of duplicate
  const assets = difference(
    dependency.assets,
    flatMap(dependencies, d => d.assets),
  );

  if (assets.length === 0) {
    return;
  }
github react-native-community / cli / packages / platform-android / src / commands / runAndroid / index.ts View on Github external
function buildApk(gradlew: string) {
  try {
    // using '-x lint' in order to ignore linting errors while building the apk
    const gradleArgs = ['build', '-x', 'lint'];
    logger.info('Building the app...');
    logger.debug(`Running command "${gradlew} ${gradleArgs.join(' ')}"`);
    execa.sync(gradlew, gradleArgs, {stdio: 'inherit'});
  } catch (error) {
    throw new CLIError('Failed to build the app.', error);
  }
}
github react-native-community / cli / packages / platform-android / src / commands / runAndroid / runOnAllDevices.ts View on Github external
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);
}
github react-native-community / cli / packages / platform-android / src / commands / runAndroid / index.ts View on Github external
appFolder,
      adbPath,
      variant,
      device,
      buildDirectory,
    );

    const pathToApk = `${buildDirectory}/${apkFile}`;
    const adbArgs = ['-s', device, 'install', '-r', '-d', pathToApk];
    logger.info(`Installing the app on the device "${device}"...`);
    logger.debug(
      `Running command "cd android && adb -s ${device} install -r -d ${pathToApk}"`,
    );
    execa.sync(adbPath, adbArgs, {stdio: 'inherit'});
  } catch (error) {
    throw new CLIError('Failed to install the app on the device.', error);
  }
}
github react-native-community / cli / packages / platform-ios / src / commands / runIOS / index.ts View on Github external
getBuildPath(args.configuration, appName, true, scheme),
    '--id',
    selectedDevice.udid,
    '--justlaunch',
  ];

  logger.info(`Installing and launching your app on ${selectedDevice.name}`);

  const iosDeployOutput = child_process.spawnSync(
    'ios-deploy',
    iosDeployInstallArgs,
    {encoding: 'utf8'},
  );

  if (iosDeployOutput.error) {
    throw new CLIError(
      `Failed to install the app on the device. We've encountered an error in "ios-deploy" command: ${
        iosDeployOutput.error.message
      }`,
    );
  }

  return logger.success('Installed the app on the device.');
}
github react-native-community / cli / packages / cli / src / commands / link / linkAll.ts View on Github external
'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md',
      )}`,
    );

    for (let key in config.dependencies) {
      const dependency = config.dependencies[key];
      try {
        if (dependency.hooks.prelink) {
          await makeHook(dependency.hooks.prelink)();
        }
        await linkDependency(config.platforms, config.project, dependency);
        if (dependency.hooks.postlink) {
          await makeHook(dependency.hooks.postlink)();
        }
      } catch (error) {
        throw new CLIError(
          `Linking "${chalk.bold(dependency.name)}" failed.`,
          error,
        );
      }
    }
  }
  if (options.linkAssets) {
    logger.debug('Linking all assets');
    const projectAssets = config.assets;
    const assets = dedupeAssets(
      Object.keys(config.dependencies).reduce(
        (acc, dependency) => acc.concat(config.dependencies[dependency].assets),
        projectAssets,
      ),
    );
    try {
github react-native-community / cli / packages / cli / src / commands / init / init.ts View on Github external
default: false,
      },
    ]);

    if (!shouldReplaceprojectDirectory) {
      throw new DirectoryAlreadyExistsError(directory);
    }

    fs.emptyDirSync(directory);
  }

  try {
    mkdirp.sync(directory);
    process.chdir(directory);
  } catch (error) {
    throw new CLIError(
      `Error occurred while trying to ${
        directoryExists ? 'replace' : 'create'
      } project directory.`,
      error,
    );
  }

  return process.cwd();
}
github react-native-community / cli / packages / cli / src / commands / link / linkAll.ts View on Github external
}
    }
  }
  if (options.linkAssets) {
    logger.debug('Linking all assets');
    const projectAssets = config.assets;
    const assets = dedupeAssets(
      Object.keys(config.dependencies).reduce(
        (acc, dependency) => acc.concat(config.dependencies[dependency].assets),
        projectAssets,
      ),
    );
    try {
      linkAssets(config.platforms, config.project, assets);
    } catch (error) {
      throw new CLIError('Linking assets failed.', error);
    }
  }
}
github react-native-community / cli / packages / platform-ios / src / link-pods / registerNativeModule.ts View on Github external
function getLinesToAddEntry(
  podLines: Array,
  {projectName}: IOSProjectConfig,
) {
  const linesToAddPodWithMarker = findMarkedLinesInPodfile(podLines);
  if (linesToAddPodWithMarker.length > 0) {
    return linesToAddPodWithMarker;
  }
  const firstTargetLined = findPodTargetLine(podLines, projectName);
  if (firstTargetLined === null) {
    throw new CLIError(`
      We couldn't find a target to add a CocoaPods dependency.

      Make sure that you have a "${chalk.dim(
        `target '${projectName.replace('.xcodeproj', '')}' do`,
      )}" line in your Podfile.

      Alternatively, include "${chalk.dim(
        MARKER_TEXT,
      )}" in a Podfile where we should add
      linked dependencies.
    `);
  }
  return findLineToAddPod(podLines, firstTargetLined);
}