Repository navigation
Expand file tree
/
Copy pathGulpfile.js
More file actions
150 lines (123 loc) · 3.49 KB
/
Copy pathGulpfile.js
File metadata and controls
150 lines (123 loc) · 3.49 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
// Gulpfile.js
// Require the needed packages
var gulp = require('gulp'),
gutil = require('gulp-util'),
clean = require('gulp-clean'),
stylus = require('gulp-stylus'),
browserify = require('gulp-browserify'),
rename = require('gulp-rename'),
livereload = require('gulp-livereload'),
ejs = require("gulp-ejs"),
path = require("path");
var baseAppPath = path.join(__dirname, 'app'),
baseStaticPath = path.join(__dirname, '.generated'),
baseJsPath = path.join(baseAppPath, 'js'),
baseCssPath = path.join(baseAppPath, 'css');
var paths = {
cssPath: [path.join(baseCssPath, '**', '*.styl*')],
cssInput: path.join(baseCssPath, 'main.styl'),
cssOutput: path.join(baseStaticPath, 'css'),
coffeePath: [path.join(baseJsPath, '**', '*.coffee')],
coffeeInput: path.join(baseJsPath, 'main.coffee'),
coffeeOutput: path.join(baseStaticPath, 'js'),
ejsPath: path.join(baseAppPath, '**', '*.ejs'),
assetsBasePath: baseAppPath,
assetsPaths: [
path.join(baseAppPath, 'img', '**', '*'),
path.join(baseAppPath, 'fonts', '**', '*'),
path.join(baseAppPath, '**', '*.html')
],
assetsOutput: baseStaticPath
};
var testFiles = [
'.generated/js/app.js',
'test/client/*.js'
];
gulp.task('test', function() {
// Be sure to return the stream
return gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
});
gulp.task('default', function () {
console.log("default task does nothing, hombre.")
});
//
// Stylus
//
// Get and render all .styl files recursively
gulp.task('stylus', function () {
gulp.src(paths.cssInput)
.pipe(stylus()
.on('error', gutil.log)
.on('error', gutil.beep))
.pipe(gulp.dest(paths.cssOutput));
});
//
// Coffee
//
gulp.task('coffee', function() {
gulp.src(paths.coffeeInput, { read: false })
.pipe(browserify({
basedir: __dirname,
transform: ['coffeeify'],
extensions: ['.coffee']
})
.on('error', gutil.log)
.on('error', gutil.beep))
.pipe(rename('main.js'))
.pipe(gulp.dest(paths.coffeeOutput))
gulp.src(path.join(__dirname, 'app', 'js', 'app.coffee'), { read: false })
.pipe(browserify({
transform: ['coffeeify'],
extensions: ['.coffee']
}).on('error', gutil.log).on('error', gutil.beep))
.pipe(rename('app.js'))
.pipe(gulp.dest(paths.coffeeOutput))
});
//
// Static Assets
//
gulp.task('assets', function() {
gulp.src(paths.assetsPaths, {base: paths.assetsBasePath})
.on('error', gutil.log)
.on('error', gutil.beep)
.pipe(gulp.dest(paths.assetsOutput));
});
//
// EJS
//
gulp.task('ejs', function() {
gulp.src(paths.ejsPath)
.pipe(ejs()
.on('error', gutil.log)
.on('error', gutil.beep))
.pipe(gulp.dest(paths.assetsOutput));
});
//
// Clean
//
gulp.task('clean', function() {
gulp.src(path.join(baseStaticPath, '**', '*'), {read: false})
.pipe(clean());
});
//
// Watch
//
gulp.task('watch', ['clean','stylus','coffee','assets', 'ejs'], function() {
var server = livereload();
gulp.watch(paths.cssPath, ['stylus']);
gulp.watch(paths.coffeePath, ['coffee']);
gulp.watch(paths.assetsPaths, ['assets']);
gulp.watch(paths.ejsPath, ['ejs']);
gulp.watch(path.join(baseStaticPath, '**')).on('change', function(file) {
server.changed(file.path);
});
});
gulp.task('default', ['stylus', 'coffee', 'assets']);