Merge pull request #3824 from FreeCodeCamp/fix/init-app-for-dev
Fix first start for new devspull/3869/head
commit
69387e57ee
25
README.md
25
README.md
|
@ -54,19 +54,23 @@ The easiest way to get started is to clone the repository:
|
|||
# Get the latest snapshot
|
||||
git clone --depth=1 https://github.com/freecodecamp/freecodecamp.git freecodecamp
|
||||
|
||||
# Change directory
|
||||
cd freecodecamp
|
||||
|
||||
# Install NPM dependencies
|
||||
npm install
|
||||
|
||||
# Install Gulp globally
|
||||
npm install -g gulp
|
||||
|
||||
# Install Bower globally
|
||||
npm install -g bower
|
||||
|
||||
# Install Bower dependencies
|
||||
bower install
|
||||
|
||||
# Create a .env file and populate it with the necessary API keys and secrets:
|
||||
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.
|
||||
|
@ -107,20 +111,19 @@ DEBUG=true
|
|||
```
|
||||
|
||||
```bash
|
||||
# Start the mongo server
|
||||
# Start the mongo server in a seperate terminal
|
||||
mongod
|
||||
|
||||
# Create your mongo database.
|
||||
# Type "mongo" in your terminal to access the mongo shell
|
||||
use freecodecamp
|
||||
# Exit the mongo shell with control + d
|
||||
|
||||
# Seed your database with the challenges
|
||||
node seed/
|
||||
# Initialize Free Code Camp
|
||||
# This will seed the database for the first time.
|
||||
# This command should only be run once.
|
||||
npm run first-time
|
||||
|
||||
# start the application
|
||||
gulp
|
||||
```
|
||||
Now navigate to your browser and open http://localhost:3001
|
||||
Congradulations! You did it!
|
||||
|
||||
License
|
||||
-------
|
||||
|
|
16
package.json
16
package.json
|
@ -6,6 +6,8 @@
|
|||
"url": "https://github.com/freecodecamp/freecodecamp.git"
|
||||
},
|
||||
"scripts": {
|
||||
"first-time": "npm run create-rev && echo '\n\nseeding database\n\n' && node seed && node seed/nonprofits",
|
||||
"create-rev": "test ! -e server/rev-manifest.json && echo '\n\ncreating manifest\n\n' && touch server/rev-manifest.json && echo '{}' >> server/rev-manifest.json",
|
||||
"build": "gulp build",
|
||||
"start": "babel-node server/server.js",
|
||||
"prestart-production": "bower cache clean && bower install && gulp build",
|
||||
|
@ -49,6 +51,13 @@
|
|||
"forever": "~0.14.1",
|
||||
"frameguard": "^0.2.2",
|
||||
"github-api": "~0.7.0",
|
||||
"gulp": "~3.8.8",
|
||||
"gulp-eslint": "~0.9.0",
|
||||
"gulp-inject": "~1.0.2",
|
||||
"gulp-jsonlint": "^1.1.0",
|
||||
"gulp-nodemon": "^2.0.3",
|
||||
"gulp-notify": "^2.2.0",
|
||||
"gulp-plumber": "^1.0.1",
|
||||
"gulp-less": "^3.0.3",
|
||||
"gulp-minify-css": "~0.5.1",
|
||||
"gulp-reduce-file": "0.0.1",
|
||||
|
@ -114,13 +123,6 @@
|
|||
"browserify": "^10.2.4",
|
||||
"chai": "~1.10.0",
|
||||
"envify": "^3.4.0",
|
||||
"gulp": "~3.8.8",
|
||||
"gulp-eslint": "~0.9.0",
|
||||
"gulp-inject": "~1.0.2",
|
||||
"gulp-jsonlint": "^1.1.0",
|
||||
"gulp-nodemon": "^2.0.3",
|
||||
"gulp-notify": "^2.2.0",
|
||||
"gulp-plumber": "^1.0.1",
|
||||
"istanbul": "^0.3.15",
|
||||
"loopback-explorer": "^1.7.2",
|
||||
"loopback-testing": "^1.1.0",
|
||||
|
|
|
@ -1,55 +1,34 @@
|
|||
/* eslint-disable no-process-exit */
|
||||
require('babel/register');
|
||||
require('dotenv').load();
|
||||
|
||||
var fs = require('fs'),
|
||||
Rx = require('rx'),
|
||||
_ = require('lodash'),
|
||||
path = require('path'),
|
||||
app = require('../server/server'),
|
||||
nonprofits = require('./nonprofits.json'),
|
||||
jobs = require('./jobs.json');
|
||||
app = require('../server/server');
|
||||
|
||||
function getFilesFor(dir) {
|
||||
return fs.readdirSync(path.join(__dirname, '/' + dir));
|
||||
}
|
||||
|
||||
var Challenge = app.models.Challenge;
|
||||
var Nonprofit = app.models.Nonprofit;
|
||||
var Job = app.models.Job;
|
||||
var counter = 0;
|
||||
var challenges = getFilesFor('challenges');
|
||||
// plus two accounts for nonprofits and jobs seed.
|
||||
var numberToSave = challenges.length + 1;
|
||||
var destroy = Rx.Observable.fromNodeCallback(Challenge.destroyAll, Challenge);
|
||||
var create = Rx.Observable.fromNodeCallback(Challenge.create, Challenge);
|
||||
|
||||
function completionMonitor() {
|
||||
// Increment counter
|
||||
counter++;
|
||||
|
||||
// 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) {
|
||||
destroy()
|
||||
.flatMap(function() { return Rx.Observable.from(challenges); })
|
||||
.flatMap(function(file) {
|
||||
var challengeSpec = require('./challenges/' + file);
|
||||
var order = challengeSpec.order;
|
||||
var block = challengeSpec.name;
|
||||
var isBeta = !!challengeSpec.isBeta;
|
||||
console.log('parsed %s successfully', file);
|
||||
|
||||
// challenge file has no challenges...
|
||||
if (challengeSpec.challenges.length === 0) {
|
||||
console.log('file %s has no challenges', file);
|
||||
completionMonitor();
|
||||
return;
|
||||
return Rx.Observable.just([{ block: 'empty ' + block }]);
|
||||
}
|
||||
|
||||
var challenges = challengeSpec.challenges
|
||||
|
@ -73,50 +52,15 @@ Challenge.destroyAll(function(err, info) {
|
|||
return challenge;
|
||||
});
|
||||
|
||||
Challenge.create(
|
||||
challenges,
|
||||
function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
console.log('Successfully parsed %s', file);
|
||||
completionMonitor(err);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
return create(challenges);
|
||||
})
|
||||
.subscribe(
|
||||
function(challenges) {
|
||||
console.log('%s successfully saved', challenges[0].block);
|
||||
},
|
||||
function(err) { throw err; },
|
||||
function() {
|
||||
console.log('challenge seed completed');
|
||||
process.exit(0);
|
||||
}
|
||||
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);
|
||||
});
|
||||
});
|
||||
);
|
||||
|
|
|
@ -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.Nonprofit;
|
||||
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);
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue