forked from mojs/mojs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
151 lines (128 loc) · 4.39 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
var gulp = require('gulp');
var stylus = require('gulp-stylus');
var autoprefixer = require('gulp-autoprefixer');
var notify = require('gulp-notify');
var livereload = require('gulp-livereload');
var coffee = require('gulp-coffee');
var changed = require('gulp-changed');
var jade = require('gulp-jade');
var watch = require('gulp-jade');
var coffeelint = require('gulp-coffeelint');
var plumber = require('gulp-plumber');
var concat = require('gulp-concat');
var csslint = require('gulp-csslint');
var browserify = require('gulp-browserify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var sequence = require('run-sequence');
var coffeeify = require('gulp-coffeeify');
var insert = require('gulp-insert');
var devFolder = '', distFolder = '';
var paths = {
src: {
js: devFolder + 'js/**/*.coffee',
index: devFolder + 'index.jade',
css: devFolder + 'css/**/*.styl',
tests: distFolder + 'spec/**/*.coffee'
},
dist:{
js: distFolder + 'js/',
index: distFolder,
css: distFolder + 'css/',
tests: distFolder + 'spec/'
}
}
gulp.task('coffee:tests', function(e){
return gulp.src(paths.src.tests)
.pipe(plumber())
.pipe(changed(paths.src.tests))
.pipe(coffeelint())
.pipe(coffeelint.reporter())
.pipe(coffee())
.pipe(gulp.dest(paths.dist.tests))
.pipe(livereload())
});
gulp.task('stylus', function(){
return gulp.src(devFolder + 'css/main.styl')
.pipe(plumber())
.pipe(stylus())
.pipe(autoprefixer('last 4 version'))
.pipe(gulp.dest(paths.dist.css))
.pipe(livereload())
});
gulp.task('coffee-all + cofee:mojs', function() {
sequence('coffee-all', 'coffee:mojs');
});
var startString = 'function s(o,u){if(!n[o]){if(!t[o]){var a',
istanbulIgnore = '/* istanbul ignore next */\n',
regex = new RegExp('\/\* istanbul ignore next \*\/', 'gm');
var credits = '/*! \n\t:: mo · js :: motion graphics toolbelt for the web\n\tOleg Solomka @LegoMushroom 2015 MIT\n\tv0.110.1 \n*/\n\n'
gulp.task('coffeeify', function(e){
return gulp.src(['js/mojs.coffee'])
.pipe(plumber())
.pipe(coffeeify({options: {
standalone: 'yes'
// debug: true
}}))
// remove browserfy sudo code
.pipe(rename('mo.spec.js'))
.pipe(insert.transform(function(contents) {
return contents.replace(startString, istanbulIgnore+startString);
}))
.pipe(gulp.dest('./spec'))
.pipe(rename('mo.js'))
.pipe(insert.transform(function(contents) {
var str = contents.replace(/\/\* istanbul ignore next \*\//gm, '\r\r');
str = str.replace(/^\s*[\r\n]/gm, '\n');
return credits + str;
}))
.pipe(gulp.dest('./build'))
.pipe(livereload())
.pipe(uglify())
.pipe(insert.transform(function(contents) {
return credits + contents;
}))
.pipe(rename('mo.min.js'))
.pipe(gulp.dest('./build'))
});
gulp.task('coffee:mojs', function(e){
return gulp.src('dist/mojs.js', { read: false })
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
.pipe(browserify())
.pipe(rename('mo.js'))
.pipe(gulp.dest('./build/'))
.pipe(gulp.src('./build/mo.js'))
.pipe(uglify())
.pipe(rename('mo.min.js'))
.pipe(gulp.dest('./build/'))
.pipe(livereload())
});
gulp.task('coffee-all', function(e){
return gulp.src(['js/**/*.coffee'])
.pipe(plumber())
.pipe(coffee({ bare: true }))
.pipe(gulp.dest('dist/'))
// .pipe(livereload())
});
gulp.task('coffee-lint', function(e){
return gulp.src(paths.src.js)
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
.pipe(changed(paths.src.js), { extension: '.js'} )
.pipe(coffeelint())
.pipe(coffeelint.reporter())
.pipe(coffeelint.reporter('fail'))
});
gulp.task('index:jade', function(e){
return gulp.src(paths.src.index)
.pipe(plumber())
.pipe(jade({pretty:true}))
.pipe(gulp.dest(paths.dist.index))
.pipe(livereload())
});
gulp.task('default', function(){
var server = livereload();
gulp.watch(paths.src.tests,['coffee:tests']);
gulp.watch(paths.src.css, ['stylus']);
gulp.watch(paths.src.js, ['coffeeify', 'coffee-lint']);
gulp.watch(paths.src.index,['index:jade']);
});