-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (66 loc) · 3.13 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
/**
* Created by Gaurav MphRx on 2/16/2015.
*/
var gulp = require('gulp');
var replace = require('gulp-replace-task');
var fs = require('fs');
var minifyCSS = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat-util');
require('es6-promise').polyfill(); // Added because promise was not found for gulp-autoprefixer
var autoprefixer = require('gulp-autoprefixer');
var rename = require('gulp-rename');
var argv = require('yargs').argv
gulp.task("inject:css", function () {
var packageVersion = require("./package.json").version
var injectCss = function (sources) {
return target.pipe(require('gulp-inject')(sources))
.pipe(gulp.dest('app'));
}
var css_files = require("./config/dependencies.json").css
var sources = css_files.thirdParty.concat(css_files.self)
var target = gulp.src('app/index.html');
if (argv.production) {
var minified_stream = gulp.src(sources).pipe(minifyCSS({relativeTo:"app",target:"src/css"}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9'))
.pipe(concat('style.min.' + packageVersion + '.css'))
.pipe(concat.header("\n/**\n" + sources + "\n*/\n"))
.pipe(minifyCSS())
.pipe(gulp.dest('app/src/css/'))
minified_stream.on("end", function () {
injectCss(gulp.src('app/src/css/style.min.' + packageVersion + '.css'))
})
} else {
injectCss(gulp.src(sources))
}
})
gulp.task("inject:js", function () {
var packageVersion = require("./package.json").version
var injectJs = function (sources) {
return target.pipe(require('gulp-inject')(sources))
.pipe(gulp.dest('app'));
}
var js_files = require("./config/dependencies.json").js
var third_party_sources = js_files.thirdParty
var self_sources = js_files.self
var target = gulp.src('app/index.html');
if (argv.production) {
var minified_third_party_stream = gulp.src(third_party_sources)
.pipe(concat('app.min.external.' + packageVersion + '.js'))
.pipe(concat.header("\n/**\n" + third_party_sources + "\n*/\n")).pipe(uglify())
.pipe(gulp.dest('app/src/JS/'))
minified_third_party_stream.on("end", function () {
var self_source_stream = gulp.src(self_sources)
.pipe(concat("app.min.internal." + packageVersion + ".js"))
.pipe(concat.header("\n/**\n" + self_sources + "\n*/\n")).pipe(uglify())
.pipe(gulp.dest('app/src/JS/'))
self_source_stream.on("end", function () {
var clientSpecificFileContent = "/**\nThis file is reserved for client specific changes.\nUse the redirect rule to do the client level customization \n*/"
fs.writeFileSync("app/src/JS/app.client.js" , clientSpecificFileContent)
injectJs(gulp.src([('app/src/JS/app.min.external.' + packageVersion + '.js'), ('app/src/JS/app.min.internal.' + packageVersion + '.js'), ('app/src/JS/app.client.js')]))
})
})
} else {
injectJs(gulp.src(third_party_sources.concat(self_sources)))
}
})