-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
142 lines (120 loc) · 3.43 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
// The Great Gulp
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var LOCAL_PORT = 9999;
var SOURCE_ROOT = __dirname + '/app';
var BUILD_ROOT = __dirname + '/dist';
var BROWSER = 'Google Chrome Canary';
/**
* =====================================
* Launch Local Servers
* =====================================
*/
gulp.task('connect:dev', $.connect.server({
livereload: true,
root: [SOURCE_ROOT],
port: LOCAL_PORT,
open: { browser: BROWSER }
}));
gulp.task('connect:dist', $.connect.server({
livereload: true,
root: [BUILD_ROOT],
port: LOCAL_PORT,
open: { browser: BROWSER }
}));
// Log & Notify Livereload
function onchange(event) {
$.util.log($.util.colors.cyan(event.path), 'changed');
return gulp.src(event.path)
.pipe($.connect.reload());
}
gulp.task('server', ['connect:dev'], function () {
gulp.watch([
SOURCE_ROOT + '/**/*',
'!' + SOURCE_ROOT + '/node_modules/**/*'
], onchange);
});
/**
* =====================================
* Building
* =====================================
*/
//var sass = require('gulp-ruby-sass');
//var jshint = require('gulp-jshint');
var usemin = require('gulp-usemin');
var uglify = require('gulp-uglify');
var minifyhtml = require('gulp-minify-html');
var minifycss = require('gulp-minify-css');
var imagemin = require('gulp-imagemin');
var clean = require('gulp-clean');
var rev = require('gulp-rev');
gulp.task('usemin', function () {
gulp.src('./app/*.html')
.pipe(usemin({
css: [minifycss(), rev()],
js: [uglify(), rev()],
html: [minifyhtml({empty: true})]
}))
.pipe(gulp.dest(BUILD_ROOT));
});
gulp.task('imagemin', function () {
gulp.src(SOURCE_ROOT + '/images/*.*', {base: SOURCE_ROOT})
.pipe(imagemin())
.pipe(gulp.dest(BUILD_ROOT));
});
gulp.task('copy', function () {
gulp.src([
'!' + SOURCE_ROOT + '/*.html',
SOURCE_ROOT + '/*.*',
SOURCE_ROOT + '/font/**/*',
SOURCE_ROOT + '/partials/**/*',
SOURCE_ROOT + '/templates/**/*'
], {base: SOURCE_ROOT})
.pipe(gulp.dest(BUILD_ROOT));
});
gulp.task('clean', function () {
return gulp.src([BUILD_ROOT], {read: false})
.pipe(clean());
});
gulp.task('build', ['clean'], function () {
gulp.start('usemin', 'imagemin', 'copy');
});
/**
* =====================================
* Distribution
* =====================================
*/
function sh(commands) {
var exec = require('child_process').exec;
var sys = require('sys');
for (var i = 0, l = arguments.length; i < l; i++) {
exec(arguments[i], function (error, stdout, stderr) {
if (error != null) {
sys.print('exec error: ' + error);
} else {
sys.print(stdout);
sys.print(stderr);
}
});
}
}
function distribution(tar) {
var targets = {
prod: '[email protected]:/usr/local/httpd/htdocs/tohell/html/',
beta: '[email protected]:/usr/local/httpd/htdocs/beta/html/'
};
var rsyncParams = ' -avz -e ssh --delete --exclude=.git* --exclude=*.scss --exclude=node_modules';
sh('rsync ' + BUILD_ROOT + '/ ' + targets[tar].beta + rsyncParams);
}
gulp.task('dist', function () {
distribution('beta');
});
gulp.task('dist:prod', function () {
distribution('prod');
});
/**
* =====================================
* General Tasks
* =====================================
*/
gulp.task('default', ['server']);