Skip to content

Setup script #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2016
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Why Slingshot?

## Get Started
1. **Initial Machine Setup**. First time running the starter kit? Then complete the [Initial Machine Setup](https://github.com/coryhouse/react-slingshot#initial-machine-setup).
2. **Clone the project**. `git clone https://github.com/coryhouse/react-slingshot.git`.
3. **Install Node packages**. `npm install`
2. **Clone the project**. `git clone https://github.com/coryhouse/react-slingshot.git`.
3. **Run the setup script**. `npm run setup`
4. **Run the example app**. `npm start -s`
This will run the automated build process, start up a webserver, and open the application in your default browser. When doing development with this kit, this command will continue watching all your files. Every time you hit save the code is rebuilt, linting runs, and tests run automatically. Note: The -s flag is optional. It enables silent mode which suppresses unnecessary messages during the build.
5. **Review the example app.** This starter kit includes a working example app that calculates fuel savings. Note how all source code is placed under /src. Tests are placed alongside the file under test. The final built app is placed under /dist. These are the files you run in production.
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "4.0.0",
"description": "Starter kit for creating apps with React and Redux",
"scripts": {
"setup": "node tools/setup/setupMessage.js && npm install && node tools/setup/setup.js",
"remove-demo": "babel-node tools/removeDemo.js",
"start-message": "babel-node tools/startMessage.js",
"prestart": "npm-run-all --parallel start-message remove-dist",
Expand Down Expand Up @@ -61,8 +62,10 @@
"mocha": "2.4.5",
"node-sass": "3.7.0",
"npm-run-all": "1.8.0",
"prompt": "1.0.0",
"react-addons-test-utils": "15.0.2",
"redux-immutable-state-invariant": "1.2.3",
"replace": "0.3.0",
"rimraf": "2.5.2",
"sass-loader": "3.2.0",
"sinon": "1.17.4",
Expand Down
66 changes: 66 additions & 0 deletions tools/setup/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var rimraf = require('rimraf');
var chalk = require('chalk');
var replace = require("replace");
var prompt = require("prompt");

var prompts = require('./setupPrompts');

console.log(chalk.green('Dependencies installed.'));

// remove the original git repository
rimraf('.git', error => {
if (error) throw new Error(error);
});
console.log(chalk.green('Original Git repository removed.\n'));

// prompt the user for updates to package.json
console.log(chalk.blue('Updating package.json settings:'));
prompt.start();
prompt.get(prompts, function(err, result) {
// parse user responses
// (default values provided for fields that will cause npm to complain if left empty)
var responses = [
{
key: 'name',
value: result.projectName || 'new-project'
},
{
key: 'version',
value: result.version || '0.1.0'
},
{
key: 'author',
value: result.author
},
{
key: 'license',
value: result.license || 'MIT'
},
{
key: 'description',
value: result.description
},
// simply use an empty URL here to clear the existing repo URL
{
key: 'url',
value: ''
}
];

// update package.json with the user's values
responses.forEach(res => {
replace({
regex: `("${res.key}"): "(.*?)"`,
replacement: `$1: "${res.value}"`,
paths: ['package.json'],
recursive: false,
silent: true,
});
})

// remove all setup scripts from the 'tools' folder
console.log(chalk.green('\nSetup complete! Cleaning up...\n'));
rimraf('./tools/setup', error => {
if (error) throw new Error(error);
});
});
6 changes: 6 additions & 0 deletions tools/setup/setupMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This script simply displays an intro message for the setup script
console.log('===========================');
console.log('= React Slingshot Setup =');
console.log('===========================\n');
console.log('Installing dependencies.');
console.log('Please be patient, this might take a few minutes...\n');
23 changes: 23 additions & 0 deletions tools/setup/setupPrompts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Define prompts for use with npm 'prompt' module in setup script
module.exports = [
{
name: 'projectName',
description: 'Project name (deafult: new-project)'
},
{
name: 'version',
description: 'Version (default: 0.1.0)'
},
{
name: 'author',
description: 'Author'
},
{
name: 'license',
description: 'License (default: MIT)'
},
{
name: 'description',
description: 'Project description'
}
];