forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·218 lines (160 loc) · 7.33 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* NB: All tasks are initialized lazily, even plugins are required lazily,
* running 1 task does not require all tasks' files
*/
const gulp = require('gulp');
const glob = require('glob');
const path = require('path');
const fs = require('fs');
const assert = require('assert');
const runSequence = require('run-sequence');
const ll = require('gulp-ll');
const config = require('config');
const mongoose = require('lib/mongoose');
process.on('uncaughtException', function(err) {
console.error(err.message, err.stack, err.errors);
process.exit(255);
});
const jsSources = [
'handlers/**/*.js', 'modules/**/*.js', 'tasks/**/*.js', '*.js'
];
function lazyRequireTask(path) {
var args = [].slice.call(arguments, 1);
return function(callback) {
var task = require(path).apply(this, args);
return task(callback);
};
}
ll.tasks('nodemon', 'client:webpack', 'server');
gulp.task('lint-once', lazyRequireTask('./tasks/lint', { src: jsSources }));
gulp.task('lint-or-die', lazyRequireTask('./tasks/lint', { src: jsSources, dieOnError: true }));
// usage: gulp db:load --from fixture/init --harmony
gulp.task('db:load', lazyRequireTask('./tasks/dbLoad'));
gulp.task('db:clear', lazyRequireTask('./tasks/dbClear'));
gulp.task('migrate:play', lazyRequireTask('./tasks/migratePlay'));
gulp.task('migrate:md', lazyRequireTask('./tasks/migrateMd'));
gulp.task('migrate:tutorial', lazyRequireTask('./tasks/migrateTutorial'));
gulp.task('migrate:up', lazyRequireTask('migrate/tasks/up'));
gulp.task('migrate:down', lazyRequireTask('migrate/tasks/down'));
gulp.task('migrate:create', lazyRequireTask('migrate/tasks/create'));
gulp.task('courses:webinar:add', lazyRequireTask('courses/tasks/webinarAdd'));
gulp.task('courses:invite:remind', lazyRequireTask('courses/tasks/inviteRemind'));
gulp.task("nodemon", lazyRequireTask('./tasks/nodemon', {
// shared client/server code has require('template.jade) which precompiles template on run
// so I have to restart server to pickup the template change
ext: "js,jade",
nodeArgs: process.env.NODE_DEBUG ? ['--debug'] : [],
script: "./bin/server.js",
//ignoreRoot: ['.git', 'node_modules'].concat(glob.sync('{handlers,modules}/**/client')), // ignore handlers' client code
ignore: ['**/client/', '**/photoCut/'], // ignore handlers' client code
watch: ["handlers", "modules"]
}));
gulp.task("client:livereload", lazyRequireTask("./tasks/livereload", {
// watch files *.*, not directories, no need to reload for new/removed files,
// we're only interested in changes
watch: [
"public/pack/**/*.*",
// not using this file, using only styles.css (extracttextplugin)
"!public/pack/styles.js",
// this file changes every time we update styles
// don't watch it, so that the page won't reload fully on style change
"!public/pack/head.js"
]
}));
gulp.task("tutorial:import:watch", lazyRequireTask('tutorial/tasks/importWatch', {
root: process.env.TUTORIAL_ROOT
}));
gulp.task("tutorial:beautify", lazyRequireTask('tutorial/tasks/beautify', {
root: process.env.TUTORIAL_ROOT
}));
gulp.task("tutorial:edit", lazyRequireTask('tutorial/tasks/edit'));
gulp.task("payments:order:paid", lazyRequireTask('payments/tasks/orderPaid'));
gulp.task("payments:transaction:paid", lazyRequireTask('payments/tasks/transactionPaid'));
gulp.task("payments:order:cancelPending", lazyRequireTask('payments/tasks/orderCancelPending'));
gulp.task('payments:yakassa:listOrders', lazyRequireTask('payments/yakassa/tasks/listOrders'));
gulp.task('payments:yakassa:listReturns', lazyRequireTask('payments/yakassa/tasks/listReturns'));
gulp.task('payments:yakassa:returnPayment', lazyRequireTask('payments/yakassa/tasks/returnPayment'));
gulp.task("newsletter:send", lazyRequireTask('newsletter/tasks/send'));
var testSrcs = ['{handlers,modules}/**/test/**/*.js'];
// on Travis, keys are required for E2E Selenium tests
// for PRs there are no keys, so we disable E2E
if (!process.env.TEST_E2E || process.env.CI && process.env.TRAVIS_SECURE_ENV_VARS=="false") {
testSrcs.push('!{handlers,modules}/**/test/e2e/*.js');
}
gulp.task("test", lazyRequireTask('./tasks/test', {
src: testSrcs,
reporter: 'spec',
timeout: 100000 // big timeout for webdriver e2e tests
}));
gulp.task('watch', lazyRequireTask('./tasks/watch', {
root: __dirname,
// for performance, watch only these dirs under root
dirs: ['assets', 'styles'],
taskMapping: [
{
watch: 'assets/**',
task: 'client:sync-resources'
}
]
}));
// init deploy (kill all and recreate)
gulp.task('deploy:init', lazyRequireTask('deploy/tasks/init'));
// build on remote
gulp.task('deploy:build', lazyRequireTask('deploy/tasks/build'));
// apply db migrations
gulp.task('deploy:migrate', lazyRequireTask('deploy/tasks/migrate'));
// update remote working site & repo
gulp.task('deploy:update', lazyRequireTask('deploy/tasks/update'));
gulp.task('deploy', function(callback) {
runSequence("deploy:build", "deploy:update", callback);
});
gulp.task("client:sync-resources", lazyRequireTask('./tasks/syncResources', {
assets: 'public'
}));
gulp.task("videoKey:load", lazyRequireTask('videoKey/tasks/load'));
// show errors if encountered
gulp.task('client:compile-css',
lazyRequireTask('./tasks/compileCss', {
src: './styles/base.styl',
dst: './public/styles',
publicDst: process.env.STATIC_HOST + '/styles/', // from browser point of view
manifest: path.join(config.manifestRoot, 'styles.versions.json'),
assetVersioning: config.assetVersioning
})
);
gulp.task('client:minify', lazyRequireTask('./tasks/minify'));
gulp.task('client:resize-retina-images', lazyRequireTask('./tasks/resizeRetinaImages'));
gulp.task('client:webpack', lazyRequireTask('./tasks/webpack'));
// gulp.task('client:webpack-dev-server', lazyRequireTask('./tasks/webpackDevServer'));
gulp.task('build', function(callback) {
runSequence("client:sync-resources", 'client:webpack', callback);
});
gulp.task('server', lazyRequireTask('./tasks/server'));
// no build
gulp.task('edit', ['tutorial:import:watch', "client:sync-resources", 'client:livereload', 'server']);
gulp.task('dev', function(callback) {
runSequence("client:sync-resources", ['nodemon', 'client:livereload', 'client:webpack', 'watch'], callback);
});
gulp.task('tutorial:import', ['cache:clean'], lazyRequireTask('tutorial/tasks/tutorialImport'));
gulp.task('quiz:import', ['cache:clean'], lazyRequireTask('quiz/tasks/quizImport'));
gulp.task('tutorial:remote:update', lazyRequireTask('tutorial/tasks/remoteUpdate'));
gulp.task('figures:import', lazyRequireTask('tutorial/tasks/figuresImport'));
gulp.task('tutorial:kill:content', ['cache:clean'], lazyRequireTask('tutorial/tasks/killContent'));
gulp.task('tutorial:cache:regenerate', lazyRequireTask('tutorial/tasks/cacheRegenerate'));
gulp.task('cloudflare:clean', lazyRequireTask('./tasks/cloudflareClean', {
domains: [config.domain.main, config.domain.static]
}));
gulp.task('cache:clean', lazyRequireTask('./tasks/cacheClean'));
gulp.task('config:nginx', lazyRequireTask('./tasks/configNginx'));
// when queue finished successfully or aborted, close db
// orchestrator events (sic!)
gulp.on('stop', function() {
mongoose.disconnect();
});
gulp.on('err', function(gulpErr) {
if (gulpErr.err) {
// cause
console.error("Gulp error details", [gulpErr.err.message, gulpErr.err.stack, gulpErr.err.errors].filter(Boolean));
}
mongoose.disconnect();
});