forked from legomushroom/shape-demo3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
130 lines (107 loc) · 3.76 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
var gulp = require('gulp');
var fs = require('fs');
var livereload = require('gulp-livereload');
var changed = require('gulp-changed');
var plumber = require('gulp-plumber');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var sequence = require('run-sequence');
var insert = require('gulp-insert');
var jeditor = require("gulp-json-editor");
var shell = require("gulp-shell");
var babel = require("gulp-babel");
var devFolder = '', distFolder = '', currentVersion = 0;
var distMoFile = devFolder + 'build/app.js';
var libMainFile = devFolder + 'lib/mojs-player.js';
var paths = {
src: {
babel: devFolder + 'js/**/*.babel.js',
index: devFolder + 'index.jade',
css: devFolder + 'css/**/*.styl',
tests: distFolder + 'spec/**/*.coffee'
},
dist:{
js: distFolder + 'js/',
index: distFolder,
css: distFolder + 'css/',
tests: distFolder + 'spec/'
}
}
var credits = ''
gulp.task('babel-lib', function(e){
return gulp.src(paths.src.babel)
.pipe(plumber())
.pipe(babel({ presets: ['es2015-loose'] }))
.pipe(rename(function (path) {
return path.basename = path.basename.replace('.babel', '');
})
).pipe(gulp.dest('lib/'))
});
gulp.task('reload', function() {
return gulp.src(distMoFile)
.pipe(plumber())
.pipe(livereload())
});
gulp.task('minify', function() {
return gulp.src(distMoFile)
.pipe(plumber())
.pipe(insert.transform(function(contents) {
return credits + contents;
}))
.pipe(gulp.dest('./build'))
.pipe(uglify())
.pipe(insert.transform(function(contents) {
return credits + contents;
}))
.pipe(rename('mojs-player.min.js'))
.pipe(gulp.dest('./build'))
});
gulp.task('attribute-lib', function() {
return gulp.src(libMainFile)
.pipe(plumber())
.pipe(insert.transform(function(contents) {
return credits + contents;
}))
.pipe(gulp.dest('./lib'))
});
gulp.task('update-version', function() {
sequence('get-current-version', 'update-bower-version', 'update-main-file-version');
});
gulp.task('get-current-version', function(e){
return gulp.src('package.json')
.pipe(plumber())
.pipe(jeditor(function (json) {
currentVersion = json.version;
credits = '/*! \n\t:: MojsPlayer :: Player controls for [mojs](mojs.io). Intended to help you to craft `mojs` animation sequences.\n\tOleg Solomka @LegoMushroom 2016 MIT\n\t' + currentVersion + ' \n*/\n\n'
return json;
}))
});
gulp.task('update-bower-version', function(e){
return gulp.src('bower.json')
.pipe(plumber())
.pipe(jeditor(function (json) {
json.version = currentVersion;
return json;
}))
.pipe(gulp.dest(''))
});
gulp.task('update-main-file-version', function(e){
return gulp.src('js/mojs-player.babel.js')
.pipe(plumber())
.pipe(insert.transform(function(contents) {
var newString = 'revision = \''+currentVersion+'\'';
return contents
.replace(/revision\s+?\=\s+?(\'|\")\d+\.\d+\.+\d+(\'|\")/i, newString);
}))
.pipe(gulp.dest('js/'))
});
gulp.task('default', function(){
livereload.listen();
gulp.watch(distMoFile, [ 'reload' ]);
// gulp.run('get-current-version');
// gulp.watch(paths.src.babel, [ 'babel-lib' ]);
// gulp.watch(distMoFile, [ 'minify' ]);
// gulp.watch(libMainFile, [ 'attribute-lib' ]);
// gulp.watch('package.json', ['update-version']);
});