-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
152 lines (131 loc) · 3.72 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
'use strict';
// Initialise Gulp and dependancies
var gulp = require('gulp'),
p = require('gulp-load-plugins')({camelize: true}),
stylish = require('jshint-stylish'),
util = require('gulp-util'),
lr = require('tiny-lr')(),
connect = require('connect'),
pkg = require('./package.json');
// Directory configs
var config = {
port: 8200
};
// Create a banner for distribution builds
var banner = ['/**',
' * ' + pkg.name + ' - ' + pkg.description,
' * @author ' + pkg.author,
' * @version ' + pkg.version,
' * @repository ' + pkg.repository.url,
' * @link ' + pkg.homepage,
' * @license ' + pkg.license,
' */',
'\n\n'].join('\n');
// -----
// Tasks
// -----
gulp.task('scripts', function(){
gulp.src('lib/simple_editor.connector.js')
.pipe(p.preprocess({
context: {
BANNER: banner,
VERSION: pkg.version
}
}))
.pipe(p.rename('simple_editor.js'))
.pipe(gulp.dest('.'))
.pipe(p.rename('simple_editor.min.js'))
.pipe(p.uglify({ preserveComments: 'some' }))
.pipe(gulp.dest('.'));
});
gulp.task('lint', function () {
gulp.src(['simple_editor.js', 'gulpfile.js'])
.pipe(p.jshint('.jshintrc'))
.pipe(p.jshint.reporter(stylish));
});
gulp.task('lr', function(){
lr.listen(config.port + 1, function(err){
if (err) {
return console.log(err);
} else {
util.log(
'Livereload running on:',
util.colors.magenta(config.port + 1)
);
}
});
});
gulp.task('server', ['lr', 'scripts', 'lint'], function(){
var middleware = [
require('connect-livereload')({ port: config.port + 1 }),
connect.static(__dirname),
connect.directory(__dirname)
];
var app = connect.apply(null, middleware),
openPage = require('open'),
server = require('http').createServer(app);
server
.listen(config.port)
.on('listening', function() {
util.log(
'Started connect webserver on: ',
util.colors.magenta('http://localhost:' + (config.port + 1))
);
openPage('http://localhost:' + config.port);
});
});
gulp.task('watch', ['server'], function(){
gulp.watch('lib/*.js', ['scripts', 'lint']);
gulp.watch(
['index.html', 'simple_editor.js'],
function(event){
util.log('file changed:', util.colors.green(event.path));
gulp.src(event.path).pipe(p.livereload(lr));
});
});
gulp.task('dist', ['scripts'], function(){
var distFiles = [
'index.html',
'simple_editor.js',
'bower_components/fundly-style-guide/dist/fundly-style.css'
];
return gulp.src('dist/*', {read: false})
.pipe(p.clean())
.pipe(gulp.src(distFiles))
.pipe(p.replace('bower_components/fundly-style-guide/dist/', ''))
.pipe(gulp.dest('dist'))
.pipe(gulp.src('bower_components/fundly-style-guide/dist/fonts/**/*.*'))
.pipe(gulp.dest('dist/fonts'));
});
// --------
// Tasks for bumping the version
// --------
gulp.task('bump:major', function(){
gulp.src(['./bower.json', './package.json'])
.pipe(p.bump({type:'major'}))
.pipe(gulp.dest('./'));
});
gulp.task('bump:minor', function(){
gulp.src(['./bower.json', './package.json'])
.pipe(p.bump({type:'minor'}))
.pipe(gulp.dest('./'));
});
gulp.task('bump:patch', function(){
gulp.src(['./bower.json', './package.json'])
.pipe(p.bump({type:'patch'}))
.pipe(gulp.dest('./'));
});
// --------
// Task for pushing the project to Github pages
// --------
gulp.task('gh-pages', function(){
var exec = require('child_process').exec,
cmd = 'git push origin :gh-pages && git subtree push --prefix dist origin gh-pages';
exec(cmd, {}, function(err, stdout, stderr){
if(err) {
util.log(err);
} else {
util.log(stdout, stderr);
}
});
});