-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
88 lines (76 loc) · 2.56 KB
/
gulpfile.js
File metadata and controls
88 lines (76 loc) · 2.56 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
/**
* Created by Codi Marker on 7/11/15.
*/
'use strict';
var del = require('del');
var gulp = require('gulp');
var header = require('gulp-header');
var footer = require('gulp-footer');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var gulpUglify = require('gulp-uglify');
var jsEscape = require('gulp-js-escape');
var htmlmin = require('gulp-htmlmin');
// toggle build between regular (inline) and newWindow version
var build = "regular";
//build = "newWindow";
var ignoreArray = [];
var outfile = "";
var outfileFull = "";
if (build == "regular") {
ignoreArray = ["!lib/jsonformatNewWindow.js"];
outfile = "jsonbitly.js";
outfileFull = "./dist/jsonbitly.js";
} else if (build == "newWindow") {
ignoreArray = ["!lib/jsonformat.js"];
outfile = "jsonbitlynw.js";
outfileFull = "./dist/jsonbitlynw.js";
}
gulp.task('clean', function(cb) {
del('build', function(){
//del('dist', cb);
cb();
});
});
gulp.task('default', ['clean', 'buildEmbeddedJS', 'buildEmbeddedHTML', 'build1', 'build2', 'postprocess']);
gulp.task('buildEmbeddedJS', ['clean'], function() {
return gulp.src('./lib/embedded.jse')
.pipe(jshint())
.pipe( jsEscape() )
.pipe(header("var embeddedScript = "))
.pipe(footer(";"))
.pipe(concat('embeddedJS.js'))
.pipe(gulp.dest('./build/'));
});
gulp.task('buildEmbeddedHTML', ['clean'], function() {
return gulp.src('./lib/view.html')
.pipe(htmlmin())
.pipe( jsEscape() )
.pipe(header("var embeddedBody = "))
.pipe(footer(";"))
.pipe(jshint())
.pipe(concat('embeddedHTML.js'))
.pipe(gulp.dest('./build/'));
});
gulp.task('build1', ['clean', 'buildEmbeddedJS', 'buildEmbeddedHTML'], function() {
return gulp.src(['lib/*.js'].concat(ignoreArray))
.pipe(jshint())
.pipe(concat('intermediate.js'))
.pipe(gulp.dest('./build/'));
});
gulp.task('build2', ['build1'], function() {
return gulp.src('./build/*.js')
.pipe(jshint())
.pipe(gulpUglify().on('error', function(e) { console.log('\x07',e.message); return this.end(); }))
.pipe(concat(outfile))
.pipe(gulp.dest('./dist/'));
});
//formats as bookmarklet
gulp.task('postprocess', ['build2'], function () {
return gulp.src(outfileFull)
.pipe(gulpUglify().on('error', function(e) { console.log('\x07',e.message); return this.end(); }))
.pipe(header('javascript:(function(){'))
.pipe(footer('})();'))
.pipe(gulp.dest('dist'));
});