-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
214 lines (191 loc) · 5.14 KB
/
gulpfile.js
File metadata and controls
214 lines (191 loc) · 5.14 KB
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
'use strict';
var gulp = require('gulp');
var gulpConfig = require('./gulp.config.json');
var paths = gulpConfig.paths;
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var stylish = require('gulp-jscs-stylish');
var mocha = require('gulp-mocha');
var shell = require('gulp-shell');
var rename = require('gulp-rename');
var path = require('path');
var del = require('del');
var exec = require('child_process').exec;
/**
* The default task (called when you run `gulp` from cli)
*/
gulp.task('default', ['test']);
/**
* Task to run complete test for deployment
*/
gulp.task('test', ['dist', 'test-js', 'docs']);
/**
* Task to generate dist build
*/
gulp.task('dist', ['clean:dist'], function () {
start();
function start() {
// wrap core source code in AMD-friendly format
gulp.src('')
.pipe(shell([
'<%= rjs %> -convert <%= src %> <%= dest %>'
], {
templateData: {
rjs: paths.tools.rjs,
src: paths.core.src,
dest: paths.core.dest
}
}))
.on('end', convertLibBcrypt);
}
function convertLibBcrypt() {
// copy vendor lib, wrapping in AMD format if necessary
gulp.src(paths.vendor.libs.bcrypt)
.pipe(gulp.dest(paths.vendor.dest))
.on('end', convertLibBluebird);
}
function convertLibBluebird() {
// copy vendor lib, wrapping in AMD format if necessary
gulp.src(paths.vendor.libs.bluebird)
.pipe(gulp.dest(paths.vendor.dest))
.on('end', convertLibChai);
}
function convertLibChai() {
// copy vendor lib, wrapping in AMD format if necessary
gulp.src(paths.vendor.libs.chai)
.pipe(gulp.dest(paths.vendor.dest))
.on('end', convertLibUuid);
}
function convertLibUuid() {
// copy vendor lib, wrapping in AMD format if necessary
gulp.src(paths.vendor.libs.uuid)
.pipe(gulp.dest(paths.vendor.dest))
.on('end', convertLibUtil);
}
function convertLibUtil() {
// copy vendor lib, wrapping in AMD format if necessary
gulp.src(paths.vendor.libs.util)
.pipe(rename('util.js'))
.pipe(gulp.dest(paths.vendor.dest))
.on('end', convertLibPath);
}
function convertLibPath() {
// copy vendor lib, wrapping in AMD format if necessary
var tmpConvertDir = path.join(paths.build.tmp, 'tmpConvert');
gulp.src('')
.pipe(shell([
'<%= rjs %> -convert <%= src %> <%= dest %>'
], {
templateData: {
rjs: paths.tools.rjs,
src: paths.vendor.libs.path,
dest: tmpConvertDir
}
}))
.on('end', function () {
gulp.src(path.join(tmpConvertDir, 'index.js'))
.pipe(rename('path.js'))
.pipe(gulp.dest(paths.vendor.dest))
.on('end', buildMainBundle);
});
}
function buildMainBundle() {
// bundle all files and minify
gulp.src('')
.pipe(shell([
'<%= rjs %> -o build/config.json'
], {
templateData: {
rjs: paths.tools.rjs
}
}))
.on('end', copyFilesToDist);
}
function copyFilesToDist() {
// copy bundle and index files to dist folder
var bundle = path.join(paths.build.tmp, 'back4app-entity-bundle.js');
gulp.src(bundle)
.pipe(gulp.dest(paths.build.dest))
.on('end', function () {
var mainJS = path.join(paths.build.src, 'back4app-entity.js');
gulp.src(mainJS)
.pipe(gulp.dest(paths.build.dest))
.on('end', function () {
var textJS = path.join(paths.build.src, 'text.js');
gulp.src(textJS)
.pipe(gulp.dest(paths.build.dest))
.on('end', removeTempBuildFiles);
});
});
}
function removeTempBuildFiles() {
// remove temporary build folder
del([paths.build.tmp]);
}
});
/**
* Task to clean dist folder
*/
gulp.task('clean:dist', function () {
return del(['dist/**/*']);
});
/**
* Task to run all linters and tests
*/
gulp.task('test-js', ['lint', 'mocha']);
/**
* Task to run link checks
*/
gulp.task('lint', function () {
var noop = function () {};
return gulp.src(paths.lintCheckFiles)
.pipe(jshint())
.pipe(jscs())
.on('error', noop)
.pipe(stylish.combineWithHintResults())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
/**
* Task to run mocha tests
*/
gulp.task('mocha', function () {
return gulp.src(paths.mochaSrc, {read: false})
.pipe(mocha({
reporter: 'spec'
}));
});
/**
* Task to create docs
*/
gulp.task('docs', ['docs:back', 'docs:guide']);
/**
* Task to create back docs
*/
gulp.task('docs:back', function () {
exec(
'./node_modules/jsdoc/jsdoc.js ' +
'-d ' + paths.backDocsDist + ' ' +
'-r ' + paths.backDocsSrc + ' ' +
'--private',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
}
);
});
/**
* Task to create guide docs
*/
gulp.task('docs:guide', function () {
exec(
'./node_modules/jsdoc/jsdoc.js ' +
'-u ' + paths.guideDocsSrc + ' ' +
'-d ' + paths.guideDocsDist + ' ' +
'-r ' + paths.guideDocsSrc,
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
}
);
});