Skip to content

Commit

Permalink
Merge pull request #7 from react-native-training/feature/install-pack…
Browse files Browse the repository at this point in the history
…ages

Install Packages using npm or yarn
  • Loading branch information
dabit3 authored Jun 3, 2017
2 parents 6fb243c + 277d76a commit 36b05e3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 16 deletions.
72 changes: 57 additions & 15 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ const paths = require('path');
const fs = require('fs');
const figlet = require('figlet');
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const spawn = require('cross-spawn');

function shouldUseYarn() {
try {
execSync('yarnpkg --version', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}

const installPackages = () => {
console.log(chalk.white.bold('Installing Packages'));
return new Promise((resolve, reject) => {
let command;
let args = ['install'];

if (shouldUseYarn()) {
command = 'yarn';
} else {
command = 'npm';
}

const child = spawn(command, args, { stdio: 'inherit' });
child.on('close', code => {
if (code !== 0) {
reject({
command: `${command} ${args.join(' ')}`
});
return;
}
resolve();
})
})
}

const build = (appName) => {
cp('-r', __dirname + '/../node_modules/rxapp/.', appName);
Expand All @@ -19,21 +55,27 @@ const build = (appName) => {
console.log('----------------------------------------------------------');
console.log(chalk.green.bold('Welcome to ReactXP'));
console.log('----------------------------------------------------------');
console.log(chalk.white.bold('Let\'s get started'));
console.log(chalk.green('Step 1: cd into the newly created ' + appName + ' directory'));
console.log(chalk.green('Step 2: install dependencies using yarn or npm'));
console.log('----------------------------------------------------------');
console.log(chalk.white.bold('For Web'));
console.log(chalk.green('Step 1. npm run web-watch'));
console.log(chalk.black.bold('This compiles the TypeScript code and recompiles it whenever any files are changed.'))
console.log(chalk.green('Step 2. Open index.html in your browser to view the result.'));
console.log('----------------------------------------------------------');
console.log(chalk.white.bold('For React Native'));
console.log(chalk.green('Step 1. run npm run rn-watch'));
console.log(chalk.black.bold('This compiles the TypeScript code and recompiles it whenever any files are changed.'));
console.log(chalk.green('Step 2. run npm start'));
console.log(chalk.black.bold('This starts the React Native Packager.'));
console.log('----------------------------------------------------------');
cd(appName);
installPackages().then(() => {
console.log(chalk.white.bold('Let\'s get started'));
console.log(chalk.green('Step 1: cd into the newly created ' + appName + ' directory'));
console.log('----------------------------------------------------------');
console.log(chalk.white.bold('For Web'));
console.log(chalk.green('Step 1. npm run web-watch'));
console.log(chalk.black.bold('This compiles the TypeScript code and recompiles it whenever any files are changed.'))
console.log(chalk.green('Step 2. Open index.html in your browser to view the result.'));
console.log('----------------------------------------------------------');
console.log(chalk.white.bold('For React Native'));
console.log(chalk.green('Step 1. run npm run rn-watch'));
console.log(chalk.black.bold('This compiles the TypeScript code and recompiles it whenever any files are changed.'));
console.log(chalk.green('Step 2. run npm start'));
console.log(chalk.black.bold('This starts the React Native Packager.'));
console.log('----------------------------------------------------------');
})
.catch(error => {
console.log(chalk.red('An unexpected error occurred'))
console.log(chalk.red(error));
});
});
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"devDependencies": {
"chalk": "^1.1.3",
"commander": "^2.9.0"
"commander": "^2.9.0",
"cross-spawn": "^5.1.0"
}
}
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,14 @@ cross-spawn@^3.0.1:
lru-cache "^4.0.1"
which "^1.2.9"

cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
dependencies:
lru-cache "^4.0.1"
shebang-command "^1.2.0"
which "^1.2.9"

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8"
Expand Down Expand Up @@ -3725,6 +3733,16 @@ setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"

shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
dependencies:
shebang-regex "^1.0.0"

shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"

[email protected]:
version "1.6.1"
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767"
Expand Down

0 comments on commit 36b05e3

Please sign in to comment.