-
Notifications
You must be signed in to change notification settings - Fork 47
/
gulpfile.js
199 lines (171 loc) · 5.6 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
'use strict';
require('babel/register');
var plugins = require('gulp-load-plugins')();
var gulp = require('gulp');
var del = require('del');
var fs = require('fs');
var browserify = require('browserify');
var babelify = require("babelify");
var release = require('gulp-github-release');
var notifierReporter = require('mocha-notifier-reporter');
var getPackageJson = function () {
return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
};
// Shortcut to the build task
gulp.task('build', ['package-build'], function(){});
// General build task, cleans up after real build
gulp.task('cleanup-tmp',['build-afterglow'], function(){
return del(['./dist/tmp']);
});
gulp.task('package-build', ['cleanup-tmp'], function(){
return gulp.src('./dist/afterglow.min.js')
.pipe(plugins.zip('afterglow.zip'))
.pipe(gulp.dest('dist'));
});
// Helper task for building the release
gulp.task('build-afterglow', ['compileES6'], function(){
var pkg = getPackageJson();
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @link <%= pkg.homepage %>',
' * @version <%= pkg.version %>',
' * @license <%= pkg.license %>',
' * ',
' * <%= pkg.name %> includes some scripts provided under different licenses by their authors. Please see the project sources via <%= pkg.homepage %> in order to learn which projects are included and how you may use them.',
' */',
''].join('\n');
// Loading LESS files
return gulp.src([
"./src/less/skins/*.less",
"./src/less/components/*.less"
])
// Convert LESS files to CSS
.pipe(plugins.less())
// Add normal css which doesn't need to be compiled
.pipe(plugins.addSrc.prepend('./vendor/videojs/video-js.css'))
// Minify the CSS
.pipe(plugins.cssmin())
// Now convert it to JavaScript and specify options
.pipe(plugins.css2js({
splitOnNewline: false
}))
// Add all the javascript files in the correct order
.pipe(plugins.addSrc.append([
'./vendor/videojs/video.js',
]))
.pipe(plugins.addSrc.append([
'./vendor/videojs/plugins/videojs.hotkeys.js',
'./vendor/videojs/plugins/Youtube.js',
'./vendor/videojs/plugins/videojs-vimeo.js'
]))
.pipe(plugins.addSrc.append([
'./dist/tmp/afterglow-bundle.js'
]))
// Concatenate into a single large file
.pipe(plugins.concat("afterglow.min.js"))
// Minify the JavaScript
.pipe(plugins.uglify().on('error', plugins.util.log))
.pipe(plugins.header(banner, { pkg : pkg } ))
// Finally write it to our destination (./dist/afterglow.min.js)
.pipe(gulp.dest("./dist/"));
});
// Task to compile ES6 components
gulp.task('compileES6',['compileVJSComponents'], function(){
// Create empty file
gulp.src(__dirname+'/dist/tmp/components/*.js')
.pipe(plugins.concat("afterglow-bundle.js"))
.pipe(gulp.dest(__dirname+"/dist/tmp/"));
// Compile
var extensions = ['.js','.json','.es6'];
return browserify({ debug: true, extensions:extensions })
.transform(babelify.configure({
extensions: extensions
}))
.require(__dirname+"/src/js/init.js", { entry: true })
.bundle()
.on("error", function (err) { console.log("Error : " + err.message); })
.pipe(fs.createWriteStream(__dirname+"/dist/tmp/afterglow-bundle.js",{flags: 'a'}));
});
gulp.task('compileVJSComponents', function(){
// Compile VIDEO.js components
return gulp.src('./src/js/vjs-components/*.js')
.pipe(plugins.babel())
.pipe(gulp.dest(__dirname+'/dist/tmp/components'));
})
// Patch version bump
gulp.task('bump', function(){
return gulp.src('.')
.pipe(plugins.prompt.prompt({
type: 'list',
name: 'bump',
message: 'What type of bump would you like to do?',
choices: ['cancel','patch', 'minor', 'major']
}, function(res){
if(res.bump == 'cancel'){
plugins.util.log(plugins.util.colors.red('Version bump canceled.'));
}
else{
gulp.src('./package.json')
.pipe(plugins.bump({type:res.bump}))
.pipe(gulp.dest('./'));
}
}));
});
// Release to github
gulp.task('release', function(){
var pkg = getPackageJson();
gulp.src('.')
.pipe(plugins.prompt.confirm({
message: 'Did you commit and push/sync all changes you made to the code?',
default: false
}))
.pipe(plugins.prompt.prompt([{
type: 'input',
name: 'releasename',
message: 'How shall the release be named?',
default: ['afterglow v'+pkg.version]
},
{
type: 'input',
name: 'notes',
message: 'Provide a release note, if you want to.'
},
{
type: 'list',
name: 'type',
message: 'What do you want to release?',
choices: ['Prerelease','Release'],
default: 1,
}],function(res){
// Build the options object
var releaseoptions = {
name: res.releasename,
notes: res.notes,
manifest: require('./package.json'),
owner: 'moay',
repo: 'afterglow',
tag: pkg.version,
draft: true
};
if(res.type == "Prerelease")
{
releaseoptions.prerelease = true;
}
// LAST CHANGE TO CANCEL NOTICE
plugins.util.log('');
plugins.util.log('Your are going to release', plugins.util.colors.yellow(res.releasename), plugins.util.colors.cyan('(Version tag: '+pkg.version+')'), 'as a', plugins.util.colors.white(res.type));
// Remember to set an env var called GITHUB_TOKEN
gulp.src('./dist/afterglow.zip')
.pipe(plugins.prompt.confirm({
message: 'Do you really want this? Last chance!',
default: false
}))
.pipe(release(releaseoptions));
}));
});
gulp.task('test', function(){
return gulp.src('./test/*.js')
.pipe(plugins.mocha({
reporter: notifierReporter.decorate('spec')
}));
});