forked from StevenLambion/ui-listView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
122 lines (102 loc) · 3.15 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 project = require("./package.json");
var gulp = require("gulp");
var gutil = require("gulp-util");
var debug = require("gulp-debug");
var concat = require("gulp-concat");
var iife = require("gulp-iife");
var uglify = require("gulp-uglify");
var sourcemaps = require("gulp-sourcemaps");
var runSequence = require("run-sequence");
var es = require("event-stream");
var ngAnnotate = require("gulp-ng-annotate");
var templateCache = require("gulp-angular-templatecache");
var babel = require("gulp-babel");
var jshint = require("gulp-jshint");
var stylish = require("jshint-stylish")
var del = require("del");
var karma = require("karma").server;
var paths = {
src: {
root: "src",
javascript: "src/**/*.js",
templates: "src/**/*.tpl.html",
styles: "src/**/*.css"
},
dist: {
root: "dist",
javascript: "dist/",
styles: "dist/",
reports: 'reports'
}
};
var handleError = function (taskName) {
return function (err) {
gutil.log(gutil.colors.bgRed("ERROR: " + taskName), gutil.red(err));
};
};
var tasks = {
clean: function (cb) {
del([paths.dist.root, paths.dist.reports], cb);
},
compileScripts: function () {
return es.merge(
gulp.src(paths.src.javascript),
tasks.compileTemplates()
)
.pipe(sourcemaps.init())
.pipe(babel()).on("error", handleError("babel"))
.pipe(concat(project.name + ".js"))
.pipe(ngAnnotate()).on("error", handleError("ngAnnotate"))
.pipe(iife({ useStrict: false }))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(paths.dist.javascript))
},
uglifyScripts: function () {
return gulp.src(paths.dist.javascript + "**/*.js")
.pipe(concat(project.name + ".min.js"))
.pipe(uglify()).on("error", handleError("uglify"))
.pipe(gulp.dest(paths.dist.javascript))
},
compileTemplates: function () {
return gulp.src(paths.src.templates)
.pipe(templateCache({
base: __dirname + "/" + paths.src.root,
module: "ui-listView.templates",
standalone: true
}))
},
compileStyles: function () {
return gulp.src(paths.src.styles)
.pipe(gulp.dest(paths.dist.styles))
},
lintjs: function () {
return gulp.src(paths.src.javascript)
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter("fail"))
},
test: function (cb) {
new karma.start({
configFile: __dirname + '/karma.conf.js'
}, cb);
}
}
/**
* This task removes all files inside the "dist" directory.
*/
gulp.task("clean", tasks.clean);
gulp.task("lintjs", tasks.lintjs);
gulp.task("compileScripts", ["lintjs"], tasks.compileScripts);
gulp.task("compileStyles", tasks.compileStyles);
gulp.task("uglify", ["compileScripts"], tasks.uglifyScripts);
gulp.task("test", tasks.test);
gulp.task("build", function (cb) {
return runSequence(
"clean",
"test",
["compileScripts", "compileStyles"],
"uglify",
cb
);
});
gulp.task("default", ["build"]);