Skip to content

Commit

Permalink
Check in all places for react-native (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou authored Jun 8, 2017
1 parent 48ff8cd commit 6180ccd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const dedent = require('dedent');
const ora = require('ora');
const chalk = require('chalk');
const inquirer = require('inquirer');
const isReactNativeProject = require('../utils/isReactNativeProject');

const messages = require('../messages');

Expand All @@ -22,21 +23,7 @@ async function init() {
const cwd = process.cwd();

// Are we inside a React Native project?
let valid = false;

try {
const pak = JSON.parse(
fs.readFileSync(path.join(cwd, 'package.json')).toString(),
);

if (pak.dependencies['react-native']) {
valid = true;
}
} catch (e) {
// Ignore
}

if (valid) {
if (isReactNativeProject(cwd)) {
progress.succeed(messages.verifiedProject());
} else {
progress.fail(messages.invalidProject());
Expand Down
29 changes: 29 additions & 0 deletions src/utils/isReactNativeProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2017-present, Callstack.
* All rights reserved.
*
* @flow
*/
const fs = require('fs');
const path = require('path');

module.exports = function isReactNativeProject(cwd: string) {
try {
const pak = JSON.parse(
fs.readFileSync(path.join(cwd, 'package.json')).toString(),
);

const deps = {
...(pak.dependencies || {}),
...(pak.devDependencies || {}),
...(pak.peerDependencies || {}),
};

if (deps['react-native']) {
return true;
}
} catch (e) {
// Ignore
}
return false;
};

0 comments on commit 6180ccd

Please sign in to comment.