-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
157 lines (140 loc) · 3.59 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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');
// 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');
// 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 (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/os2displayadmin/')[1];
});
}());
// Only process js asset files.
var adminJsAssets = (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 (p === 'js') {
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/os2displayadmin/')[1];
});
}());
var adminBuildDir = 'Resources/public/assets/build';
var sassPath = 'Resources/sass/*.scss';
var sassWatchPath = 'Resources/sass/**/*.scss';
/**
* Process SCSS using libsass
*/
gulp.task('sass', function () {
return gulp.src(sassPath)
.pipe(sass({
outputStyle: 'compressed',
includePaths: [
'Resources/sass/compass-mixins/lib'
]
}).on('error', sass.logError))
.pipe(rename({extname: ".min.css"}))
.pipe(gulp.dest(adminBuildDir));
});
/**
* 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('os2displayadmin.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 () {
adminJsPath.forEach(function (path) {
process.stdout.write(path + '\n');
});
});
/**
* Build single assets.js file.
*/
gulp.task('assets', function () {
return gulp.src(adminJsAssets)
.pipe(concat('assets.js'))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(rename({extname: ".min.js"}))
.pipe(gulp.dest(adminBuildDir));
});
/**
* Watch files for changes and run tasks.
*/
gulp.task('watch', function () {
gulp.watch(adminJsPath, ['jshint']);
gulp.watch(sassWatchPath, ['sass']);
});