How to use the @expo/json-file.getAsync function in @expo/json-file

To help you get started, we’ve selected a few @expo/json-file 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 expo / expo / tools / expotools / src / commands / PublishProjectTemplates.ts View on Github external
const { tag } = await inquirer.prompt<{ tag: string }>([
      {
        type: 'input',
        name: 'tag',
        message: `How to tag ${chalk.green(template.name)}@${chalk.red(newVersion)}?`,
        default: semver.prerelease(newVersion) ? 'next' : `sdk-${semver.major(options.sdkVersion)}`,
      },
    ]);

    // Update package version in `package.json`
    await JsonFile.setAsync(path.join(template.path, 'package.json'), 'version', newVersion);

    const appJsonPath = path.join(template.path, 'app.json');
    if (
      (await fs.exists(appJsonPath)) &&
      (await JsonFile.getAsync(appJsonPath, 'expo.sdkVersion', null))
    ) {
      // Make sure SDK version in `app.json` is correct
      console.log(
        `Setting ${chalk.magenta('expo.sdkVersion')} to ${chalk.green(
          options.sdkVersion
        )} in template's app.json...`
      );

      await JsonFile.setAsync(
        path.join(template.path, 'app.json'),
        'expo.sdkVersion',
        options.sdkVersion
      );
    }

    console.log(`Publishing ${chalk.green(template.name)}@${chalk.red(newVersion)}...`);
github expo / expo / tools / expotools / src / commands / GenerateSDKDocs.ts View on Github external
async function action(options) {
  const { sdk, updateReactNativeDocs } = options;

  if (!sdk) {
    throw new Error('Must run with `--sdk SDK_VERSION`.');
  }

  if (updateReactNativeDocs) {
    const reactNativeWebsiteDir = path.join(DOCS_DIR, 'react-native-website');
    const reactNativePackageJsonPath = path.join(
      EXPO_DIR,
      'react-native-lab',
      'react-native',
      'package.json'
    );
    const reactNativeVersion = await JsonFile.getAsync(reactNativePackageJsonPath, 'version', null);

    if (!reactNativeVersion) {
      throw new Error(`React Native version not found at ${reactNativePackageJsonPath}`);
    }

    console.log(`Updating ${chalk.cyan('react-native-website')} submodule...`);

    await spawnAsync('git', ['checkout', 'master'], {
      cwd: reactNativeWebsiteDir,
    });

    await spawnAsync('git', ['pull'], {
      cwd: reactNativeWebsiteDir,
    });

    console.log(`Importing React Native docs to ${chalk.yellow('unversioned')} directory...\n`);
github expo / expo-cli / packages / expo-cli / src / commands / utils / ProjectUtils.ts View on Github external
export async function findProjectRootAsync(
  base: string
): Promise<{ projectRoot: string; workflow: 'managed' | 'bare' }> {
  let previous = null;
  let dir = base;

  do {
    let pkgPath = path.join(dir, 'package.json');
    let appJsonPath = path.join(dir, 'app.json');
    let pkgExists = fs.existsSync(pkgPath);
    let appJsonExists = fs.existsSync(appJsonPath);

    if (pkgExists && appJsonExists) {
      let pkg = await JsonFile.readAsync(pkgPath);
      let expo = await JsonFile.getAsync(path.join(dir, 'app.json'), 'expo', null);

      let workflow: 'managed' | 'bare';
      if (expo && pkg.dependencies && pkg.dependencies.hasOwnProperty('react-native-unimodules')) {
        workflow = 'bare';
      } else if (!expo) {
        workflow = 'bare';
      } else {
        workflow = 'managed';
      }

      return { projectRoot: dir, workflow };
    } else if (pkgExists && !appJsonExists) {
      return { projectRoot: dir, workflow: 'bare' };
    }

    previous = dir;

@expo/json-file

A module for reading, writing, and manipulating JSON files

MIT
Latest version published 27 days ago

Package Health Score

92 / 100
Full package analysis