How to use the @react-native-community/cli-tools.groupFilesByType 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 / platform-ios / src / link / copyAssets.ts View on Github external
export default function linkAssetsIOS(
  files: Array,
  projectConfig: IOSProjectConfig,
) {
  const project = xcode.project(projectConfig.pbxprojPath).parseSync();
  const assets = groupFilesByType(files);
  const plist = getPlist(project, projectConfig.sourceDir);

  createGroupWithMessage(project, 'Resources');

  function addResourceFile(f: Array) {
    return (f || [])
      .map(asset => {
        logger.debug(`Linking asset ${asset}`);
        return project.addResourceFile(
          path.relative(projectConfig.sourceDir, asset),
          {target: project.getFirstTarget().uuid},
        );
      })
      .filter(Boolean) // xcode returns false if file is already there
      .map(file => file.basename);
  }
github react-native-community / cli / packages / platform-android / src / link / copyAssets.ts View on Github external
export default function copyAssetsAndroid(
  files: Array,
  project: {assetsPath: string},
) {
  const assets = groupFilesByType(files);

  logger.debug(`Assets path: ${project.assetsPath}`);
  (assets.font || []).forEach(asset => {
    const fontsDir = path.join(project.assetsPath, 'fonts');
    logger.debug(`Copying asset ${asset}`);
    // @todo: replace with fs.mkdirSync(path, {recursive}) + fs.copyFileSync
    // and get rid of fs-extra once we move to Node 10
    fs.copySync(asset, path.join(fontsDir, path.basename(asset)));
  });
}
github react-native-community / cli / packages / platform-ios / src / link / unlinkAssets.ts View on Github external
export default function unlinkAssetsIOS(
  files: any,
  projectConfig: IOSProjectConfig,
) {
  const project = xcode.project(projectConfig.pbxprojPath).parseSync();
  const assets = groupFilesByType(files);
  const plist = getPlist(project, projectConfig.sourceDir);

  if (!plist) {
    logger.error(
      'Could not locate "Info.plist" file. Check if your project has "INFOPLIST_FILE" set properly',
    );
    return;
  }

  if (!project.pbxGroupByName('Resources')) {
    logger.error(
      'Group "Resources" does not exist in your Xcode project. There is nothing to unlink.',
    );
    return;
  }
github react-native-community / cli / packages / platform-android / src / link / unlinkAssets.ts View on Github external
export default function unlinkAssetsAndroid(
  files: Array,
  project: {assetsPath: string},
) {
  const assets = groupFilesByType(files);

  logger.debug(`Assets path: ${project.assetsPath}`);
  (assets.font || []).forEach(file => {
    const filePath = path.join(
      project.assetsPath,
      'fonts',
      path.basename(file),
    );
    if (fs.existsSync(filePath)) {
      logger.debug(`Removing asset ${filePath}`);
      fs.unlinkSync(filePath);
    }
  });
}