Skip to content

Commit 8478f5a

Browse files
authored
Merge pull request #53 from JetJet13/develop
Merge Develop to Master | v1.1.0
2 parents 1fa2f25 + e067688 commit 8478f5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+6329
-4690
lines changed

.eslintrc

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
},
5656
"env": {
5757
"node": true,
58-
"mocha": true,
5958
"es6": true,
6059
"jquery": true
6160
},

.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# vscode
22
.vscode/
33
node_modules
4+
coverage
5+
.nyc_output
46
npm-debug.log
5-
src/logs/
6-
src/public/tags/
7-
src/public/javascripts/all.js
7+
src/server/logs/
8+
src/front-end/public/javascripts/riot-tags.bundle.js
9+
src/front-end/public/dist/*.css
10+
src/front-end/public/dist/*.js
811
config/local.json

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8

.snyk

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2+
version: v1.10.1
3+
ignore: {}
4+
# patches apply the minimum changes required to fix a vulnerability
5+
patch:
6+
'npm:debug:20170905':
7+
- riot > riot-cli > chokidar > fsevents > node-pre-gyp > tar-pack > debug:
8+
patched: '2017-12-16T18:51:09.363Z'
9+
'npm:tough-cookie:20170905':
10+
- riot > riot-cli > chokidar > fsevents > node-pre-gyp > request > tough-cookie:
11+
patched: '2017-12-16T18:51:09.363Z'
12+
'npm:request:20160119':
13+
- github-oauth > request:
14+
patched: '2018-01-07T16:34:19.511Z'

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
notifications:
3+
webhooks:
4+
urls:
5+
- https://webhooks.gitter.im/e/f277e1d11bf3828eec05
6+
on_success: change
7+
on_failure: always
8+
on_start: never
9+
env:
10+
- NODE_ENV=test
11+
before_install:
12+
- npm install -g npm@5
13+
- npm install -g greenkeeper-lockfile@1
14+
before_script:
15+
- greenkeeper-lockfile-update
16+
- npm install -g gulp-cli
17+
- npm install
18+
script: gulp test
19+
after_script: greenkeeper-lockfile-upload

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Mathbook
22

3+
[![Build Status](https://travis-ci.org/JetJet13/mathbook.svg?branch=develop)](https://travis-ci.org/JetJet13/mathbook)
4+
[![Greenkeeper badge](https://badges.greenkeeper.io/JetJet13/mathbook.svg)](https://greenkeeper.io/)
5+
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/mathbook-chat/Lobby)
6+
37
Mathbook is a website that provides peer-reviewed tutorials on topics covering most subjects in mathematics.
48

59
Mathbook is written in JavaScript and built using NodeJS, ExpressJS, Riot and Pug (formerly known as Jade)
@@ -27,6 +31,8 @@ wget http://download.redis.io/redis-stable.tar.gz
2731
tar xvzf redis-stable.tar.gz
2832
cd redis-stable
2933
make
34+
make test
35+
make install
3036

3137
# mac osx users
3238
brew install redis
@@ -51,6 +57,45 @@ gulp serve
5157
gulp serve | bunyan
5258
```
5359

60+
If you want to get the GitHub OAuth Login functionality working, you will need to do the following,
61+
62+
1. Visit github.com and Sign In
63+
2. Navigate to your profile settings page
64+
3. In the side bar, find and click on `Developer Settings`
65+
4. Then click on `New OAuth App`
66+
5. You will then be navigated to a page that looks similar to this,
67+
68+
![screenshot](./setting-up-mathbook-app.png)
69+
70+
6. Confirm that the `Homepage URL` and `Authorization callback URL` you entered match what you see in the screenshot
71+
above.
72+
7. Click `Update Application`
73+
8. Now, copy the `clientId` and `clientSecret` for your newly created Application into your `config/local.json` file.
74+
75+
Your `local.json` file should look something like the following,
76+
77+
```json
78+
{
79+
"bin": {
80+
"protocol": "http",
81+
"host": "127.0.0.1",
82+
"port": 4000,
83+
"domain": "localhost",
84+
"proxyPort": 4001
85+
},
86+
87+
"github": {
88+
"clientId": "<CLIENT_ID>",
89+
"clientSecret": "<CLIENT_SECRET>"
90+
},
91+
"redis": {
92+
"host": "127.0.0.1",
93+
"port": 6379,
94+
"password": "<REDIS_PASSWORD>"
95+
}
96+
}
97+
```
98+
5499
## Testing
55100

56101
```bash

bin/createLogFile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require("fs")
4+
5+
const logFilePath = "./src/server/logs/error-logs.json"
6+
7+
if (fs.existsSync(logFilePath) === false) {
8+
fs.writeFileSync(logFilePath, "", "utf-8")
9+
}
10+
process.exit()

config/config.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const getConfiguration = () => {
1212
config = convict({
1313
env: {
1414
doc: "The application environment.",
15-
format: ["production", "development", "local"],
15+
format: ["production", "development", "local", "test"],
1616
default: "local",
1717
env: "NODE_ENV"
1818
},
@@ -55,11 +55,17 @@ const getConfiguration = () => {
5555
},
5656
bin: {
5757
protocol: {
58-
doc: "The protocol to open a connection",
58+
doc: "The Hypertext Transfer Protocol",
5959
format: ["http", "https"],
6060
default: "https",
6161
env: "PROTOCOL"
6262
},
63+
domain: {
64+
doc: "The domain name",
65+
format: "String",
66+
default: "mathbook.io",
67+
env: "DOMAIN_NAME"
68+
},
6369
host: {
6470
doc: "The IP address to bind.",
6571
format: "ipaddress",
@@ -71,6 +77,12 @@ const getConfiguration = () => {
7177
format: "port",
7278
default: 4000,
7379
env: "PORT"
80+
},
81+
proxyPort: {
82+
doc: "The port that browser-sync will use to proxy the server",
83+
format: "port",
84+
default: 4001,
85+
env: "PROXY_PORT"
7486
}
7587
}
7688
})

config/development.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"bin": {
33
"protocol": "http",
44
"host": "127.0.0.1",
5-
"port": 4000
5+
"port": 4000,
6+
"domain": "127.0.0.1"
67
},
78
"redis": {
89
"host": "127.0.0.1",

config/production.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"bin": {
33
"protocol": "http",
44
"host": "127.0.0.1",
5-
"port": 4000
5+
"port": 4000,
6+
"domain": "mathbook.io"
67
},
78
"redis": {
89
"host": "127.0.0.1",

config/test.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"bin": {
3+
"protocol": "http",
4+
"host": "127.0.0.1",
5+
"port": 4000,
6+
"domain": "127.0.0.1"
7+
}
8+
}

gulpfile.js

+56-53
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
const gulp = require("gulp")
44
const plugins = require("gulp-load-plugins")()
55
const browserSync = require("browser-sync").create()
6+
const config = require("./config/config")()
67

78
const files = {
89
allFiles: ["src/server/**/*.js", "tests/*.spec.js", "!src/front-end/public/javascripts/*.js"],
910
testFiles: ["./tests/**/*.spec.js"],
10-
srcFiles: ["./src/server/**/*.js", "./src/server/**/*.pug", "./src/server/**/*.css"],
11+
watchFiles: ["./src/server/**/*.js", "./src/front-end/**/*.css", "./src/front-end/views/*.pug"],
1112
srcTestFiles: ["./src/server/**/*.js"],
13+
jsFiles: ["!src/front-end/public/javascripts/riot-tags.bundle.js", "src/front-end/public/javascripts/*.js"],
14+
cssFiles: ["./src/front-end/public/stylesheets/*.css"],
1215
tagFiles: ["./src/front-end/tags/**/*.tag"]
1316
}
1417

@@ -24,21 +27,34 @@ gulp.task("lint", () => {
2427
)
2528
})
2629

27-
gulp.task("test:config", () => {
28-
return (
29-
gulp
30-
.src(files.srcTestFiles)
31-
// Covering files
32-
.pipe(plugins.istanbul())
33-
// Force `require` to return covered files
34-
.pipe(plugins.istanbul.hookRequire())
35-
)
30+
gulp.task("bundle:js", ["riot"], () => {
31+
const jsFiles = ["src/front-end/public/javascripts/*.js", "!src/front-end/public/javascripts/riotInit.js"]
32+
const jsDest = "src/front-end/public/dist/"
33+
34+
return gulp
35+
.src(jsFiles)
36+
.pipe(plugins.babel({ presets: ["env"] }))
37+
.pipe(plugins.concat("bundle.min.js"))
38+
.pipe(gulp.dest(jsDest))
39+
.pipe(plugins.uglify())
40+
.pipe(gulp.dest(jsDest))
3641
})
3742

38-
gulp.task("test", ["test:config"], () => {
43+
gulp.task("bundle:css", () => {
44+
const cssDest = "src/front-end/public/dist/"
45+
46+
return gulp
47+
.src(files.cssFiles)
48+
.pipe(plugins.concat("bundle.min.css"))
49+
.pipe(gulp.dest(cssDest))
50+
.pipe(plugins.uglifycss())
51+
.pipe(gulp.dest(cssDest))
52+
})
53+
54+
gulp.task("test", () => {
3955
gulp
4056
.src(files.testFiles)
41-
.pipe(plugins.mocha())
57+
.pipe(plugins.ava())
4258
.once("error", () => {
4359
process.exit(1)
4460
})
@@ -47,66 +63,53 @@ gulp.task("test", ["test:config"], () => {
4763
})
4864
})
4965

50-
// we'd need a slight delay to reload browsers
51-
// connected to browser-sync after restarting nodemon
52-
const BROWSER_SYNC_RELOAD_DELAY = 500
53-
54-
gulp.task("nodemon", function(cb) {
66+
gulp.task("nodemon", function(done) {
5567
let called = false
5668
return plugins
5769
.nodemon({
5870
// nodemon our expressjs server
59-
script: "./bin/www"
71+
script: "./bin/www",
72+
ignore: ["src/front-end/public", "src/front-end/tags"]
6073
})
6174
.on("start", function onStart() {
6275
// ensure start only got called once
6376
if (!called) {
64-
cb()
77+
const host = config.get("bin.host")
78+
const port = config.get("bin.port")
79+
const proxyPort = config.get("bin.proxyPort")
80+
setTimeout(() => {
81+
browserSync.init({
82+
proxy: `${host}:${port}`,
83+
port: proxyPort
84+
})
85+
}, 2000)
86+
done()
6587
}
6688
called = true
67-
})
68-
.on("restart", function onRestart() {
69-
// reload connected browsers after a slight delay
70-
setTimeout(function reload() {
71-
browserSync.reload({
72-
stream: false
73-
})
74-
}, BROWSER_SYNC_RELOAD_DELAY)
89+
// for more browser-sync config options: http://www.browsersync.io/docs/options/
7590
})
7691
})
7792

7893
gulp.task("riot", function() {
79-
gulp
94+
return gulp
8095
.src(files.tagFiles)
8196
.pipe(plugins.riot())
82-
.pipe(plugins.concat("all.js"))
97+
.pipe(plugins.concat("riot-tags.bundle.js"))
8398
.pipe(gulp.dest("./src/front-end/public/javascripts"))
84-
// .pipe(gulp.dest('./src/public/tags'))
8599
})
86100

87101
gulp.task("serve", ["nodemon"], function() {
88-
// for more browser-sync config options: http://www.browsersync.io/docs/options/
89-
browserSync.init({
90-
// informs browser-sync to proxy our expressjs app which would run at the following location
91-
proxy: "http://192.168.2.22:3000",
92-
93-
// informs browser-sync to use the following port for the proxied app
94-
// notice that the default port is 3000, which would clash with our expressjs
95-
port: 4000
96-
})
97-
98-
gulp.watch(files.tagFiles, ["riot"])
99-
gulp.watch(files.srcFiles).on("change", browserSync.reload)
102+
gulp.watch(files.tagFiles, ["reload:js"])
103+
gulp.watch(files.jsFiles, ["reload:js"])
104+
gulp.watch(files.cssFiles, ["reload:css"])
105+
gulp.watch(files.watchFiles).on("change", browserSync.reload)
100106
})
101107

102-
gulp.task("default", () =>
103-
gulp
104-
.src(files.testFiles)
105-
.pipe(plugins.mocha())
106-
.once("error", () => {
107-
process.exit(1)
108-
})
109-
.once("end", () => {
110-
process.exit()
111-
})
112-
)
108+
gulp.task("reload:js", ["bundle:js"], done => {
109+
browserSync.reload()
110+
done()
111+
})
112+
gulp.task("reload:css", ["bundle:css"], done => {
113+
browserSync.reload()
114+
done()
115+
})

0 commit comments

Comments
 (0)