Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions packages/cli/src/commands/info/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@
*/

// @ts-ignore untyped
import envinfo from 'envinfo';
import getEnvironmentInfo from '../../tools/envinfo';
import {logger} from '@react-native-community/cli-tools';
import {Config} from '@react-native-community/cli-types';
import releaseChecker from '../../tools/releaseChecker';

const info = async function getInfo(_argv: Array<string>, ctx: Config) {
try {
logger.info('Fetching system and libraries information...');
const output = await envinfo.run({
System: ['OS', 'CPU', 'Memory', 'Shell'],
Binaries: ['Node', 'Yarn', 'npm', 'Watchman'],
IDEs: ['Xcode', 'Android Studio'],
SDKs: ['iOS SDK', 'Android SDK'],
npmPackages: ['react', 'react-native', '@react-native-community/cli'],
npmGlobalPackages: '*react-native*',
});
logger.log(output.trim());
const output = await getEnvironmentInfo(false);
logger.log(output);
} catch (err) {
logger.error(`Unable to print environment info.\n${err}`);
} finally {
Expand Down
49 changes: 33 additions & 16 deletions packages/cli/src/tools/envinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@
import envinfo from 'envinfo';
import {EnvironmentInfo} from '../commands/doctor/types';

export default async function getEnvironmentInfo() {
return JSON.parse(
await envinfo.run(
{
Binaries: ['Node', 'Yarn', 'npm', 'Watchman'],
IDEs: ['Xcode', 'Android Studio'],
SDKs: ['iOS SDK', 'Android SDK'],
npmPackages: ['react', 'react-native', '@react-native-community/cli'],
npmGlobalPackages: ['*react-native*'],
},
{
json: true,
showNotFound: true,
},
),
) as EnvironmentInfo;
/**
* Returns information about the running system.
* If `json === true`, or no options are passed,
* the return type will be an `EnvironmentInfo`.
* If set to `false`, it will be a `string`.
*/
async function getEnvironmentInfo(): Promise<EnvironmentInfo>;
async function getEnvironmentInfo(json: true): Promise<EnvironmentInfo>;
async function getEnvironmentInfo(json: false): Promise<string>;
async function getEnvironmentInfo(
json = true,
): Promise<string | EnvironmentInfo> {
const options = {json, showNotFound: true};

const info = (await envinfo.run(
{
System: ['OS', 'CPU', 'Memory', 'Shell'],
Binaries: ['Node', 'Yarn', 'npm', 'Watchman'],
IDEs: ['Xcode', 'Android Studio'],
SDKs: ['iOS SDK', 'Android SDK'],
npmPackages: ['react', 'react-native', '@react-native-community/cli'],
npmGlobalPackages: ['*react-native*'],
},
options,
)) as string;

if (options.json) {
return JSON.parse(info);
}

return info.trim();
}

export default getEnvironmentInfo;