Skip to content

Commit

Permalink
feat(doctor): Try installing packages with Homebrew (react-native-com…
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored and Esemesek committed Sep 4, 2019
1 parent a97c5ab commit 722c08c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
13 changes: 7 additions & 6 deletions packages/cli/src/commands/doctor/healthchecks/packageManagers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {
PACKAGE_MANAGERS,
doesSoftwareNeedToBeFixed,
} from '../checkInstallation';
import {install} from '../../../tools/install';

const identifyPackageManager = () => {
const packageManager = (() => {
if (fs.existsSync('yarn.lock')) {
return PACKAGE_MANAGERS.YARN;
}
Expand All @@ -15,9 +16,7 @@ const identifyPackageManager = () => {
}

return undefined;
};

const packageManager = identifyPackageManager();
})();

const yarn = {
label: 'yarn',
Expand All @@ -32,7 +31,8 @@ const yarn = {
// or if we can't identify that the user uses yarn or npm
visible:
packageManager === PACKAGE_MANAGERS.YARN || packageManager === undefined,
runAutomaticFix: () => console.log('should fix node'),
runAutomaticFix: async ({loader}) =>
await install('yarn', 'https://yarnpkg.com/docs/install', loader),
};

const npm = {
Expand All @@ -47,7 +47,8 @@ const npm = {
// or if we can't identify that the user uses yarn or npm
visible:
packageManager === PACKAGE_MANAGERS.NPM || packageManager === undefined,
runAutomaticFix: () => console.log('should fix node'),
runAutomaticFix: async ({loader}) =>
await install('node', 'https://nodejs.org/', loader),
};

export {packageManager, yarn, npm};
8 changes: 7 additions & 1 deletion packages/cli/src/commands/doctor/healthchecks/watchman.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import versionRanges from '../versionRanges';
import {doesSoftwareNeedToBeFixed} from '../checkInstallation';
import {install} from '../../../tools/install';

export default {
label: 'Watchman',
Expand All @@ -9,5 +10,10 @@ export default {
versionRange: versionRanges.WATCHMAN,
}),
}),
runAutomaticFix: () => console.log('should fix watchman'),
runAutomaticFix: async ({loader}) =>
await install(
'watchman',
'https://facebook.github.io/watchman/docs/install.html',
loader,
),
};
19 changes: 19 additions & 0 deletions packages/cli/src/tools/brewInstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow
import {logger} from '@react-native-community/cli-tools';
import execa from 'execa';
import Ora from 'ora';

async function brewInstall(pkg: string, loader: typeof Ora) {
loader.start(`Installing ${pkg}`);
try {
await execa('brew', ['install', pkg]);
loader.succeed();
} catch (error) {
logger.log(error.stderr);
loader.fail(
`An error occured while trying to install ${pkg}. Please try again manually: brew install ${pkg}`,
);
}
}

export {brewInstall};
19 changes: 19 additions & 0 deletions packages/cli/src/tools/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow
import Ora from 'ora';
import {brewInstall} from './brewInstall';

async function install(pkg: string, source: string, loader: typeof Ora) {
try {
switch (process.platform) {
case 'darwin':
await brewInstall(pkg, loader);
break;
default:
throw new Error('Not implemented yet');
}
} catch (_error) {
loader.info(`Please download and install '${pkg}' from ${source}.`);
}
}

export {install};

0 comments on commit 722c08c

Please sign in to comment.