Fix first start for new devs

also removes job seed
This commit is contained in:
Berkeley Martinez
2015-10-20 19:53:08 -07:00
parent 7f86c71cb2
commit 0522ec8b13
4 changed files with 66 additions and 88 deletions

View File

@ -54,19 +54,23 @@ The easiest way to get started is to clone the repository:
# Get the latest snapshot # Get the latest snapshot
git clone --depth=1 https://github.com/freecodecamp/freecodecamp.git freecodecamp git clone --depth=1 https://github.com/freecodecamp/freecodecamp.git freecodecamp
# Change directory
cd freecodecamp cd freecodecamp
# Install NPM dependencies # Install NPM dependencies
npm install npm install
# Install Gulp globally
npm install -g gulp
# Install Bower globally
npm install -g bower
# Install Bower dependencies # Install Bower dependencies
bower install bower install
# Create a .env file and populate it with the necessary API keys and secrets: # Create a .env file and populate it with the necessary API keys and secrets:
touch .env touch .env
# Install Gulp globally
npm install -g gulp
``` ```
Edit your `.env` file with the following API keys accordingly (if you only use email login, only the `MONGOHQ_URL`, `SESSION_SECRET`, `MANDRILL_USER` and `MANDRILL_PASSWORD` fields are necessary. Keep in mind if you want to use more services you'll have to get your own API keys for those services. Edit your `.env` file with the following API keys accordingly (if you only use email login, only the `MONGOHQ_URL`, `SESSION_SECRET`, `MANDRILL_USER` and `MANDRILL_PASSWORD` fields are necessary. Keep in mind if you want to use more services you'll have to get your own API keys for those services.
@ -107,20 +111,19 @@ DEBUG=true
``` ```
```bash ```bash
# Start the mongo server # Start the mongo server in a seperate terminal
mongod mongod
# Create your mongo database. # Initialize Free Code Camp
# Type "mongo" in your terminal to access the mongo shell # This will seed the database for the first time.
use freecodecamp # This command should only be run once.
# Exit the mongo shell with control + d npm run init
# Seed your database with the challenges
node seed/
# start the application # start the application
gulp gulp
``` ```
Now navigate to your browser and open http://localhost:3001
Congradulations! You did it!
License License
------- -------

View File

@ -6,6 +6,8 @@
"url": "https://github.com/freecodecamp/freecodecamp.git" "url": "https://github.com/freecodecamp/freecodecamp.git"
}, },
"scripts": { "scripts": {
"init": "npm run create-rev && echo '\n\nseeding database\n\n' && node seed && node seed/nonprofits",
"create-rev": "test ! -e server/rev-manifest.json && echo 'creating manifest' && touch server/rev-manifest.json && echo '{}' >> server/rev-manifest.json",
"build": "gulp build", "build": "gulp build",
"start": "babel-node server/server.js", "start": "babel-node server/server.js",
"prestart-production": "bower cache clean && bower install && gulp build", "prestart-production": "bower cache clean && bower install && gulp build",

View File

@ -1,55 +1,34 @@
/* eslint-disable no-process-exit */ /* eslint-disable no-process-exit */
require('babel/register'); require('babel/register');
require('dotenv').load(); require('dotenv').load();
var fs = require('fs'), var fs = require('fs'),
Rx = require('rx'),
_ = require('lodash'), _ = require('lodash'),
path = require('path'), path = require('path'),
app = require('../server/server'), app = require('../server/server');
nonprofits = require('./nonprofits.json'),
jobs = require('./jobs.json');
function getFilesFor(dir) { function getFilesFor(dir) {
return fs.readdirSync(path.join(__dirname, '/' + dir)); return fs.readdirSync(path.join(__dirname, '/' + dir));
} }
var Challenge = app.models.Challenge; var Challenge = app.models.Challenge;
var Nonprofit = app.models.Nonprofit;
var Job = app.models.Job;
var counter = 0;
var challenges = getFilesFor('challenges'); var challenges = getFilesFor('challenges');
// plus two accounts for nonprofits and jobs seed. var destroy = Rx.Observable.fromNodeCallback(Challenge.destroyAll, Challenge);
var numberToSave = challenges.length + 1; var create = Rx.Observable.fromNodeCallback(Challenge.create, Challenge);
function completionMonitor() { destroy()
// Increment counter .flatMap(function() { return Rx.Observable.from(challenges); })
counter++; .flatMap(function(file) {
// Exit if all challenges have been checked
if (counter >= numberToSave) {
process.exit(0);
}
// Log where in the seed order we're currently at
console.log('Call: ' + counter + '/' + numberToSave);
}
Challenge.destroyAll(function(err, info) {
if (err) {
throw err;
} else {
console.log('Deleted ', info);
}
challenges.forEach(function(file) {
var challengeSpec = require('./challenges/' + file); var challengeSpec = require('./challenges/' + file);
var order = challengeSpec.order; var order = challengeSpec.order;
var block = challengeSpec.name; var block = challengeSpec.name;
var isBeta = !!challengeSpec.isBeta; var isBeta = !!challengeSpec.isBeta;
console.log('parsed %s successfully', file);
// challenge file has no challenges... // challenge file has no challenges...
if (challengeSpec.challenges.length === 0) { if (challengeSpec.challenges.length === 0) {
console.log('file %s has no challenges', file); return Rx.Observable.just([{ block: 'empty ' + block }]);
completionMonitor();
return;
} }
var challenges = challengeSpec.challenges var challenges = challengeSpec.challenges
@ -73,50 +52,15 @@ Challenge.destroyAll(function(err, info) {
return challenge; return challenge;
}); });
Challenge.create( return create(challenges);
challenges, })
function(err) { .subscribe(
if (err) { function(challenges) {
throw err; console.log('%s successfully saved', challenges[0].block);
} else { },
console.log('Successfully parsed %s', file); function(err) { throw err; },
completionMonitor(err); function() {
} console.log('challenge seed completed');
} process.exit(0);
);
});
});
Nonprofit.destroyAll(function(err, info) {
if (err) {
console.error(err);
} else {
console.log('Deleted ', info);
}
Nonprofit.create(nonprofits, function(err, data) {
if (err) {
throw err;
} else {
console.log('Saved ', data);
} }
completionMonitor(err); );
console.log('nonprofits');
});
});
Job.destroyAll(function(err, info) {
if (err) {
throw err;
} else {
console.log('Deleted ', info);
}
Job.create(jobs, function(err, data) {
if (err) {
console.log('error: ', err);
} else {
console.log('Saved ', data);
}
console.log('jobs');
completionMonitor(err);
});
});

29
seed/nonprofits.js Normal file
View File

@ -0,0 +1,29 @@
/* eslint-disable no-process-exit */
require('babel/register');
require('dotenv').load();
var Rx = require('rx');
var app = require('../server/server');
var Nonprofits = app.models.Challenge;
var nonprofits = require('./nonprofits.json');
var destroy = Rx.Observable.fromNodeCallback(Nonprofits.destroyAll, Nonprofits);
var create = Rx.Observable.fromNodeCallback(Nonprofits.create, Nonprofits);
destroy()
.flatMap(function() {
if (!nonprofits) {
return Rx.Observable.throw(new Error('No nonprofits found'));
}
return create(nonprofits);
})
.subscribe(
function(nonprofits) {
console.log('successfully saved %d nonprofits', nonprofits.length);
},
function(err) { throw err; },
function() {
console.log('nonprofit seed completed');
process.exit(0);
}
);