How to use the @react-native-community/cli-tools.logger.debug 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 / index.ts View on Github external
// when we run `config`, we don't want to output anything to the console. We
    // expect it to return valid JSON
    if (process.argv.includes('config')) {
      logger.disable();
    }

    const ctx = loadConfig();

    logger.enable();

    for (const command of [...projectCommands, ...ctx.commands]) {
      attachCommand(command, ctx);
    }
  } catch (e) {
    logger.enable();
    logger.debug(e.message);
    logger.debug(
      'Failed to load configuration of your project. Only a subset of commands will be available.',
    );
  }

  commander.parse(process.argv);

  if (commander.rawArgs.length === 2) {
    commander.outputHelp();
  }

  // We handle --version as a special case like this because both `commander`
  // and `yargs` append it to every command and we don't want to do that.
  // E.g. outside command `init` has --version flag and we want to preserve it.
  if (commander.args.length === 0 && commander.rawArgs.includes('--version')) {
    console.log(pkgJson.version);
github react-native-community / cli / packages / cli / src / tools / releaseChecker / releaseCacheManager.ts View on Github external
function loadCache(name: string): Cache | undefined {
  try {
    const cacheRaw = fs.readFileSync(
      path.resolve(getCacheRootPath(), name),
      'utf8',
    );
    const cache = JSON.parse(cacheRaw);
    return cache;
  } catch (e) {
    if (e.code === 'ENOENT') {
      // Create cache file since it doesn't exist.
      saveCache(name, {});
    }
    logger.debug('No release cache found');
    return undefined;
  }
}
github react-native-community / cli / packages / cli / src / commands / link / link.ts View on Github external
if (opts.platforms) {
    // @ts-ignore
    platforms = pick(platforms, opts.platforms);
    logger.debug('Skipping selected platforms');
  }

  logger.debug(
    'Available platforms: ' +
      `${Object.keys(platforms)
        .map(getPlatformName)
        .join(', ')}`,
  );

  if (rawPackageName === undefined) {
    logger.debug('No package name provided, will linking all possible assets.');
    return linkAll(ctx, {linkDeps: opts.all, linkAssets: true});
  }

  // Trim the version / tag out of the package name (eg. package@latest)
  const packageName = rawPackageName.replace(/^(.+?)(@.+?)$/gi, '$1');

  if (!Object.keys(ctx.dependencies).includes(packageName)) {
    throw new CLIError(`
      Unknown dependency. Make sure that the package you are trying to link is
      already installed in your "node_modules" and present in your "package.json" dependencies.
    `);
  }

  const {[packageName]: dependency} = ctx.dependencies;

  logger.debug(`Package to link: ${rawPackageName}`);
github react-native-community / cli / packages / cli / src / tools / releaseChecker / index.ts View on Github external
export default async function releaseChecker(root: string) {
  try {
    const {version: currentVersion} = require(path.join(
      resolveNodeModuleDir(root, 'react-native'),
      'package.json',
    ));
    const {name} = require(path.join(root, 'package.json'));
    const latestRelease = await getLatestRelease(name, currentVersion);

    if (latestRelease) {
      printNewRelease(name, latestRelease, currentVersion);
    }
  } catch (e) {
    // We let the flow continue as this component is not vital for the rest of
    // the CLI.
    logger.debug(
      'Cannot detect current version of React Native, ' +
        'skipping check for a newer release',
    );
    logger.debug(e);
  }
}
github react-native-community / cli / packages / cli / src / tools / releaseChecker / getLatestRelease.ts View on Github external
const eTag = cacheManager.get(name, 'eTag');
    const latestVersion = await getLatestRnDiffPurgeVersion(name, eTag);
    logger.debug(`Latest release: ${latestVersion}`);

    if (
      semver.compare(latestVersion, currentVersion) === 1 &&
      !semver.prerelease(latestVersion)
    ) {
      return {
        version: latestVersion,
        changelogUrl: buildChangelogUrl(latestVersion),
        diffUrl: buildDiffUrl(currentVersion),
      };
    }
  } catch (e) {
    logger.debug(
      'Something went wrong with remote version checking, moving on',
    );
    logger.debug(e);
  }
}
github react-native-community / cli / packages / platform-ios / src / link / unregisterNativeModule.ts View on Github external
(libs, dependency) => libs.concat(dependency.sharedLibraries),
      projectConfig.sharedLibraries,
    ),
  );

  removeSharedLibraries(project, sharedLibraries);

  const headers = getHeadersInFolder(dependencyConfig.folder);
  if (!isEmpty(headers)) {
    removeFromHeaderSearchPaths(
      project,
      getHeaderSearchPath(projectConfig.sourceDir, headers),
    );
  }

  logger.debug(`Writing changes to ${projectConfig.pbxprojPath}`);
  fs.writeFileSync(projectConfig.pbxprojPath, project.writeSync());
}
github react-native-community / cli / packages / platform-ios / src / link-pods / savePodFile.ts View on Github external
export default function savePodFile(
  podfilePath: string,
  podLines: Array,
) {
  const newPodfile = podLines.join('\n');
  logger.debug(`Writing changes to ${podfilePath}`);
  fs.writeFileSync(podfilePath, newPodfile);
}
github react-native-community / cli / packages / platform-ios / src / commands / runIOS / index.ts View on Github external
buildProcess.stdout.on('data', (data: Buffer) => {
      const stringData = data.toString();
      buildOutput += stringData;
      if (xcpretty) {
        xcpretty.stdin.write(data);
      } else {
        if (logger.isVerbose()) {
          logger.debug(stringData);
        } else {
          process.stdout.write('.');
        }
      }
    });
    buildProcess.stderr.on('data', (data: Buffer) => {
github react-native-community / cli / packages / platform-android / src / link / patches / applyPatch.ts View on Github external
export default function applyPatch(
  file: string,
  patch: {patch: string; pattern: string | RegExp},
) {
  if (file) {
    logger.debug(`Patching ${file}`);
  }

  fs.writeFileSync(
    file,
    fs
      .readFileSync(file, 'utf8')
      .replace(patch.pattern, match => `${match}${patch.patch}`),
  );
}