-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
153 lines (134 loc) · 4.4 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var gulp = require('gulp');
var htmlReplace = require('gulp-html-replace');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var streamify = require('gulp-streamify');
var server = require('gulp-server-livereload');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-minify-css');
var gulpSequence = require('gulp-sequence');
var autoprefixer = require('gulp-autoprefixer');
// Paths
var path = {
HTML: './client/src/index.html',
HTML_DIST: './client/dist/public',
IMG: './client/src/img/*',
IMG_DIST: './client/dist/public/img',
SASS: './client/src/sass/**/*.scss',
CSS_OUT: './client/build/css/',
CSS_MIN_OUT: './client/dist/public/css/',
ENTRY_POINT: './client/src/js/App.jsx',
ENTRY_POINT_JS: './client/src/js/main.js',
DEST: './client/dist/public/',
OUT: 'bundle.js',
MINIFIED_OUT: 'bundle.min.js',
DEST_BUILD: './client/dist/build'
};
// Watcher
gulp.task('watch', function() {
gulp.watch(path.HTML, []);
gulp.watch(path.SASS, ['styles']);
gulp.watch(path.IMG, ['copyIMG']);
var watcher = watchify(browserify({
entries: [path.ENTRY_POINT],
transform: [reactify],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
}));
return watcher.on('update', function() {
watcher.bundle()
.pipe(source(path.OUT))
.pipe(gulp.dest(path.DEST_BUILD));
console.log('updated');
})
.bundle()
.pipe(source(path.OUT))
.pipe(gulp.dest(path.DEST_BUILD));
});
// Copy image folder to public directory
gulp.task('copyIMG', function() {
gulp.src(path.IMG)
.pipe(gulp.dest(path.IMG_DIST))
});
// Compiles SCSS to CSS and minifies CSS
// autoprefixer adds browser prefixes
gulp.task('styles', function() {
return gulp.src(path.SASS)
.pipe(sass({style: 'expanded'}))
.pipe(autoprefixer())
.pipe(gulp.dest(path.CSS_MIN_OUT))
.pipe(minifyCSS())
.pipe(gulp.dest(path.CSS_MIN_OUT))
});
// Build
gulp.task('build', function() {
browserify({
entries: [path.ENTRY_POINT, path.ENTRY_POINT_JS],
transform: [reactify]
})
.bundle()
.pipe(source(path.OUT))
.pipe(gulp.dest('./client/dist/public/js'))
});
// Creates local web server for testing (port 8000)
gulp.task('webserver', function() {
gulp.src(path.DEST)
.pipe(server({
livereload: true,
directoryListing: false,
defaultFile: '/index.html',
open: true
}));
});
// Injects css and js files into index.html
gulp.task('replaceHTML', function() {
gulp.src(path.HTML)
.pipe(htmlReplace({
css: './css/main.css',
js: './js/' + path.OUT
}))
.pipe(gulp.dest(path.DEST));
});
// Runs all 6 of our main scraping tasks, heroku scheduler runs this every 10 minutes
gulp.task('scrapeAll', gulpSequence('scrapeTwitter', 'scrapeSites', 'updateScores', 'updateTop', 'updateRedis'));
// Scrapes and stores Twitter API data
gulp.task('scrapeTwitter', function() {
return require('./server/workers/twitterScraper')();
});
// Scrapes and stores Facebook API data
gulp.task('scrapeFacebook', function() {
return require('./server/workers/facebookScraper')();
});
// Scrapes and stores news sites data
gulp.task('scrapeSites', function() {
return require('./server/workers/sitesScraper')();
});
// Collectively generates a score for each user based on their corrosponding data in each table
gulp.task('updateScores', function() {
return require('./server/workers/peopleScoreUpdater')();
});
// Using the score grabs the top 200, sorts accordingly and stores in the top table
gulp.task('updateTop', function() {
return require('./server/workers/topUpdater')();
});
// Sends the top table and the top 200 people's details to our redis server
gulp.task('updateRedis', function() {
return require('./server/workers/redisUpdater')();
});
// Loads the users in clientData.json to our database
gulp.task('loadData', function() {
var data = {body: require('./data/data_withoutFB')};
return require('./server/database/people/controller').post(data, {send: function() {}});
});
// Drops all of our database's tables
gulp.task('dropTables', function(){
require('./server/helpers/droptables')();
});
//Sequence tasks
gulp.task('production', ['styles', 'copyIMG', 'build', 'replaceHTML', 'watch']);
gulp.task('heroku', gulpSequence('styles', 'copyIMG', 'build', 'replaceHTML'));
gulp.task('localtest', ['styles', 'copyIMG', 'build', 'replaceHTML', 'webserver']);