-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
140 lines (122 loc) · 3.45 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
var fs = require('fs')
var gulp = require('gulp-help')(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 adminBuildDir = 'Resources/public/assets/build';
var templatesPath = 'Resources/public/templates/';
// 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');
// @TODO: Discover this structure automatically
var templates = {
'ding2': {
'screens': [
'four-sections'
],
'slides': [
'podcast',
'event',
'ding-events',
'opening-hours'
]
}
};
/**
* Process SCSS using libsass
*/
gulp.task('sass', 'Compile the sass for each templates into minified css files.', function () {
'use strict';
// Iterates through the screen and slide templates defined in templates variable, and compresses each one.
for (var folder in templates) {
for (var templateType in templates[folder]) {
var arr = templates[folder][templateType];
arr.forEach(function (element) {
var path = templatesPath + folder + '/' + templateType + '/' + element + '/';
console.log(path);
gulp.src(path + element + '.scss')
.pipe(sass({
outputStyle: 'compressed',
includePaths: [
'../../os2display/default-template-bundle/Resources/sass/compass-mixins/lib'
]
}).on('error', sass.logError))
.pipe(gulp.dest(path));
});
}
}
});
// 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/kkbding2integration/')[1];
});
}());
/**
* Run Javascript through JSHint.
*/
gulp.task('jshint', 'Runs JSHint on js', function () {
return gulp.src(adminJsPath)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
/**
* Build single app.js file.
*/
gulp.task('js', 'Build all custom js files into one minified js file.', function () {
return gulp.src(adminJsPath)
.pipe(concat('kkbding2integration'))
.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', 'Report all source files for "js" task.', function () {
adminJsPath.forEach(function (path) {
process.stdout.write(path + '\n');
});
});
gulp.task('js:watch', function () {
gulp.watch(['gulpfile.js', adminJsPath], ['js']);
});