-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
225 lines (201 loc) · 5.68 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
217
218
219
220
221
222
223
224
225
const gulp = require('gulp');
const runSequence = require('run-sequence');
const spawn = require('child_process').spawn;
const conventionalChangelog = require('gulp-conventional-changelog');
const bump = require('gulp-bump');
const gutil = require('gulp-util');
const git = require('gulp-git');
const fse = require('fs-extra');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const rename = require("gulp-rename");
const terser = require('gulp-terser');
const minimist = require('minimist');
const args = minimist(process.argv.slice(2), {string: 'git-version', default: {'git-version': 'patch'}});
/**
* -------- BUILDING CODE [BEGIN] ------->
*
* Define initial variables
*/
const gulpSrc = 'src/app/classes/',
gulpDest = 'wice.js/',
gulpDestDist = gulpDest + 'dist/',
sourceFiles = [
gulpSrc + 'CanvasExercise.js',
gulpSrc + 'AssociateCanvasExercise.js',
gulpSrc + 'GapMatchCanvasExercise.js',
gulpSrc + 'OrderCanvasExercise.js',
gulpSrc + 'PositionObjectCanvasExercise.js',
gulpSrc + 'script.js'
];
/**
* Concatenate JS files and transpile to ES5 with Babel
*/
gulp.task('compile', function () {
return gulp.src(sourceFiles)
.pipe(sourcemaps.init())
.pipe(concat('wice.js'))
.pipe(babel({
presets: ["env"]
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(gulpDestDist));
});
/**
* Minify the code with Terser
*/
gulp.task('minify', function () {
return gulp.src(gulpDestDist + 'wice.js')
.pipe(terser())
.pipe(rename('wice.min.js'))
.pipe(gulp.dest(gulpDestDist));
});
/**
* Build task that combine compilation and minification
*/
gulp.task('build', ['compile', 'minify']);
/**
* -------- BUILDING CODE [END] ------->
*/
/**
* -------- RELEASING TASKS [BEGIN] ------->
*
* Bumping version
*/
gulp.task('bump-version', function () {
// We hardcode the version change type to 'patch' but it may be a good idea to
// use minimist (https://www.npmjs.com/package/minimist) to determine with a
// command argument whether you are doing a 'major', 'minor' or a 'patch' change.
return gulp.src(['./package.json'])
.pipe(bump({type: args['git-version']}).on('error', gutil.log))
.pipe(gulp.dest('./'));
});
function getPackageJsonVersion() {
// We parse the json file instead of using require because require caches
// multiple calls so the version number won't be updated
return fse.readJsonSync('./package.json').version;
}
/**
* update CHANGELOG.md
*/
gulp.task('changelog', function () {
return gulp.src('CHANGELOG.md', {
buffer: true
})
.pipe(conventionalChangelog({
releaseCount: 1
}))
.pipe(gulp.dest('./'));
});
/**
* Bumping version of dist
*/
gulp.task('bump-version-dist', function () {
// Similar to bump-version
return gulp.src([gulpDest + './package.json'])
.pipe(bump({type: args['git-version']}).on('error', gutil.log))
.pipe(gulp.dest(gulpDest));
});
/**
* Copy files to dist
*/
gulp.task('prepare-dist', function () {
fse.copySync('CHANGELOG.md', gulpDest + 'CHANGELOG.md');
fse.copySync('README.md', gulpDest + 'README.md');
fse.copySync('LICENSE', gulpDest + 'LICENSE');
});
/**
* Commit and push changes
*/
gulp.task('commit-changes', function () {
var version = getPackageJsonVersion();
return gulp.src('.')
.pipe(git.add())
.pipe(git.commit('[Prerelease] Bumped version number ' + version));
});
gulp.task('push-changes', function (cb) {
git.push('origin', 'master', cb);
});
/**
* Creating tag for the current version
*/
gulp.task('create-new-tag', function (cb) {
var version = getPackageJsonVersion();
git.tag(version, 'Created Tag for version: ' + version, function (error) {
if (error) {
return cb(error);
}
git.push('origin', 'master', {args: '--tags'}, cb);
});
});
/**
* Make the GitHub release
*/
gulp.task('github-release', function (callback) {
runSequence(
'bump-version',
'bump-version-dist',
'prepare-dist',
'commit-changes',
'push-changes',
'create-new-tag',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('RELEASE TO GITHUB FINISHED SUCCESSFULLY');
}
callback(error);
});
});
/**
* -------- RELEASING TASKS [END] ------->
*/
/**
* -------- RELEASING NPMJS.COM TASKS [END] ------->
*
* Make publish in npmjs.com
*/
gulp.task('npm-publish', function (done) {
process.chdir('./wice.js/');
spawn('npm', ['publish'], { stdio: 'inherit' }).on('close', done);
});
/**
* Make the NPM release
*/
gulp.task('npm-release', function (callback) {
runSequence(
'npm-publish',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('RELEASE TO NPMJS FINISHED SUCCESSFULLY');
}
callback(error);
});
});
/**
* -------- RELEASING NPMJS.COM TASKS [END] ------->
*/
/**
* -------- FINAL COMPLETE RELEASING TASKS [BEGIN] ------->
*/
gulp.task('release', function (callback) {
runSequence(
'github-release',
'npm-release',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('COMPLETE RELEASE FINISHED SUCCESSFULLY');
}
callback(error);
});
});
/**
* -------- FINAL COMPLETE RELEASING TASKS [END] ------->
*/
gulp.task('default', ['build']);