-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
118 lines (103 loc) · 2.67 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
var gulp = require('gulp');
// Plugins.
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var rename = require('gulp-rename');
var yaml = require('js-yaml');
var fs = require('fs');
var header = require('gulp-header');
var watch = require('gulp-watch');
var adminBuildDir = 'Resources/public/assets/build';
// Get information for top of minified files.
var pkg = require('./version.json');
var banner = [
'/**',
' * @name <%= pkg.name %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.link %>',
' */',
''
].join('\n');
/**
* Process SCSS using libsass
*/
gulp.task('sass', function () {
'use strict';
var adminBuildDir = 'Resources/public/assets/build';
var sassPath = 'Resources/sass/*.scss';
return gulp.src(sassPath)
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(rename({extname: ".min.css"}))
.pipe(gulp.dest(adminBuildDir));
});
// We only want to process our own non-processed JavaScript files.
var adminJsPath = (function () {
var configFiles = [
'Resources/config/angular.yml'
],
jsFiles = [],
// Breadth-first descend into data to find "files".
buildFiles = function (data) {
if (typeof(data) === 'object') {
for (var p in data) {
if (data.hasOwnProperty(p)) {
if (p === 'files') {
jsFiles = jsFiles.concat(data[p]);
}
else {
buildFiles(data[p]);
}
}
}
}
};
configFiles.forEach(function (path) {
var data = yaml.safeLoad(fs.readFileSync(path, 'utf8'));
buildFiles(data);
});
return jsFiles.map(function (file) {
return 'Resources/public/' + file.split('bundles/os2displaycampaign/')[1];
});
}());
/**
* Run Javascript through JSHint.
*/
gulp.task('jshint', function () {
return gulp.src(adminJsPath)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
/**
* Build single app.js file.
*/
gulp.task('js', function () {
return gulp.src(adminJsPath)
.pipe(concat('os2displaycampaign.js'))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(rename({extname: ".min.js"}))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest(adminBuildDir));
}
);
/**
* Build single app.js file.
*/
gulp.task('js-src', function (done) {
adminJsPath.forEach(function (path) {
process.stdout.write(path + '\n');
});
done();
});
/**
* Watch task for auto compiling changed files
*/
gulp.task('watch', function(){
gulp.watch('Resources/sass/*.scss', ['sass']);
});