How to use the @expo/json-file.setAsync 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 / PublishPackages.ts View on Github external
async function _bumpVersionsAsync({
  pkg,
  newVersion,
  shouldPublish,
}: PipelineConfig): Promise {
  if (!shouldPublish) {
    return;
  }

  console.log(`Updating versions in ${chalk.green(pkg.packageName)} package... ☝️`);

  await JsonFile.setAsync(path.join(pkg.path, 'package.json'), 'version', newVersion);

  console.log(chalk.yellow('>'), `Updated package version in ${chalk.magenta('package.json')}`);

  if (fs.existsSync(path.join(pkg.path, 'android/build.gradle'))) {
    // update version and versionName in android/build.gradle

    const buildGradlePath = path.relative(EXPO_DIR, path.join(pkg.path, 'android/build.gradle'));
    const sedPatterns = [
      `s/version\\s*=\\s*'[^']*'/version = '${newVersion}'/g`,
      `s/versionName\\s*"[^"]*"/versionName "${newVersion}"/g`,
    ];

    for (const sedPattern of sedPatterns) {
      await _spawnAsync(SED, ['-i', '--', sedPattern, buildGradlePath]);
    }
github expo / expo / tools / expotools / src / commands / PublishProjectTemplates.ts View on Github external
},
      },
    ]);

    // Obtain the tag for the template.
    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',
github expo / expo / tools / expotools / src / commands / PublishProjectTemplates.ts View on Github external
// 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)}...`);

    const moreArgs: string[] = [];

    if (tag) {
      // Assign custom tag in the publish command, so we don't accidentally publish as latest.
      moreArgs.push('--tag', tag);
    }

    // Publish to NPM registry
github expo / expo / tools / expotools / src / commands / PublishPackages.ts View on Github external
buildGradlePath,
      ]);

      console.log(
        chalk.yellow('>'),
        `Updated version code ${chalk.cyan(String(versionCodeInt))} -> ${chalk.cyan(
          String(newVersionCode)
        )}`,
        `in ${chalk.magenta('android/build.gradle')}`
      );
    }
  }

  // Add unimodules to bundledNativeModules.json so the correct version will be installed by `expo install`.
  if (pkg.isUnimodule()) {
    await JsonFile.setAsync(
      path.join(EXPO_DIR, 'packages/expo/bundledNativeModules.json'),
      pkg.packageName,
      `~${newVersion}`
    );
    console.log(
      chalk.yellow('>'),
      `Updated package version in`,
      chalk.magenta('packages/expo/bundledNativeModules.json')
    );
  }

  await _updateWorkspaceDependenciesAsync({ pkg, newVersion } as PipelineConfig);
  console.log();
}
github expo / expo-cli / packages / expo-cli / src / commands / generate-universal.js View on Github external
);
      } else {
        await fs.remove(path.join(outputDir, `ios`));
      }

      for (let file of walkSync(outputDir, { nodir: true })) {
        let contents = await fs.readFile(file.path, 'utf8');
        let newContents = contents
          .replace(/expo-module-template/g, configuration.jsName)
          .replace(/expo\.modules\.template/g, configuration.javaModule)
          .replace(/EXModuleTemplate/g, configuration.podName);
        if (newContents !== contents) {
          await fs.writeFile(file.path, newContents);
        }
      }
      await JsonFile.setAsync(path.join(configuration.jsName, 'package.json'), 'version', '1.0.0');

      const javaDir = path.join(
        configuration.jsName,
        'android',
        'src',
        'main',
        'java',
        ...configuration.javaModule.split('.')
      );
      fs.mkdirpSync(javaDir);

      const placeholderPath = path.join(javaDir, `Placeholder.java`);
      fs.appendFileSync(placeholderPath, `package ${configuration.javaModule};\n`);
      fs.appendFileSync(placeholderPath, `class Placeholder {}`);
    });
};
github expo / expo / tools / expotools / src / commands / GenerateSDKDocs.ts View on Github external
console.log(`Importing React Native docs to ${chalk.yellow('unversioned')} directory...\n`);

    await fs.remove(path.join(SDK_DOCS_DIR, 'unversioned', 'react-native'));

    await spawnAsync('yarn', ['run', 'import-react-native-docs'], {
      stdio: 'inherit',
      cwd: DOCS_DIR,
    });
  }

  const targetSdkDirectory = path.join(SDK_DOCS_DIR, `v${sdk}`);
  const targetExampleDirectory = path.join(STATIC_EXAMPLES_DIR, `v${sdk}`);

  console.log(`\nSetting version ${chalk.red(sdk)} in ${chalk.yellow('package.json')}...`);

  await JsonFile.setAsync(path.join(DOCS_DIR, 'package.json'), 'version', sdk);

  if (await fs.exists(targetSdkDirectory)) {
    console.log(chalk.magenta(`v${sdk}`), 'directory already exists. Skipping copy operation.');
  } else {
    console.log(
      `Copying ${chalk.yellow('unversioned')} docs to ${chalk.yellow(`v${sdk}`)} directory...`
    );

    await fs.copy(path.join(SDK_DOCS_DIR, 'unversioned'), targetSdkDirectory);
  };

  if (await fs.exists(targetExampleDirectory)) {
    console.log(chalk.magenta(`v${sdk}`), 'examples directory already exists. Skipping copy operation.');
  } else {
    console.log(
      `Copying ${chalk.yellow('unversioned')} static examples to ${chalk.yellow(`v${sdk}`)} directory...`
github expo / expo / tools / expotools / src / commands / PublishPackages.ts View on Github external
async function _saveGitHeadAsync({ pkg, shouldPublish }: PipelineConfig): Promise {
  if (!shouldPublish) {
    return;
  }

  const packagePath = path.join(pkg.path, 'package.json');
  const child = await _spawnAsync('git', ['rev-parse', '--verify', 'HEAD']);

  await JsonFile.setAsync(packagePath, 'gitHead', child.stdout.trim());
}

@expo/json-file

A module for reading, writing, and manipulating JSON files

MIT
Latest version published 7 months ago

Package Health Score

88 / 100
Full package analysis