forked from node-red/node-red-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
143 lines (124 loc) · 4.51 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
var
gulp = require('gulp'),
concat = require('gulp-concat'),
exec = require('child_process').exec,
fs = require('fs'),
ghtmlSrc = require('gulp-html-src'),
gutil = require('gulp-util'),
gulpif = require('gulp-if'),
header = require("gulp-header"),
htmlreplace = require('gulp-html-replace'),
insertLines = require('gulp-insert-lines'),
manifest = require('gulp-manifest'),
minifyCss = require('gulp-clean-css'),
minifyHTML = require('gulp-htmlmin'),
path = require('path'),
resources = require('gulp-resources'),
removeHtml = require('gulp-remove-html'),
//spawn = require('child_process').spawn,
streamqueue = require('streamqueue'),
templateCache = require('gulp-angular-templatecache'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
jscs = require('gulp-jscs');
//gulp.task('default', ['manifest']);
gulp.task('default', ['lint','jscs'], function() {
gulp.start('manifest');
});
gulp.task('build', ['icon', 'js', 'css', 'less', 'index', 'fonts']);
// gulp.task('publish', ['build'], function (done) {
// spawn('npm', ['publish'], { stdio:'inherit' }).on('close', done);
// });
gulp.task('manifest', ['build'], function() {
gulp.src(['dist/*','dist/css/*','dist/js/*','dist/fonts/*'], { base: 'dist/' })
.pipe(manifest({
hash: true,
//preferOnline: true,
network: ['*'],
filename: 'dashboard.appcache',
exclude: 'dashboard.appcache'
//exclude: ['dashboard.appcache','index.html']
}))
.pipe(gulp.dest('dist/'));
});
gulp.task('lint', function() {
return gulp.src('**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('jscs', function() {
return gulp.src(['*.js','nodes/*.js','src/*.js','src/*/*.js','src/*/*/*.js'])
.pipe(jscs())
//.pipe(jscs({fix: true}))
.pipe(jscs.reporter("inline"))
});
gulp.task('index', function() {
return gulp.src('src/index.html')
.pipe(htmlreplace({
'css': 'css/app.min.css',
'js': 'js/app.min.js',
}))
.pipe(insertLines({
'before': /<\/head>$/,
'lineBefore': '<link rel="stylesheet/less" href="css/app.min.less" />'
}))
.pipe(insertLines({
'before': /<\/body>$/,
'lineBefore': '<script src="js/tinycolor-min.js"></script>'
}))
.pipe(minifyHTML({collapseWhitespace:true, conservativeCollapse:true}))
.pipe(gulp.dest('dist/'));
});
gulp.task('icon', function() {
gulp.src('src/icon192x192.png').pipe(gulp.dest('dist/'));
return gulp.src('src/icon64x64.png').pipe(gulp.dest('dist/'));
});
gulp.task('fonts', function() {
return gulp.src('node_modules/font-awesome/fonts/*').pipe(gulp.dest('dist/fonts/'));
});
gulp.task('js', function () {
var scripts = gulp.src('src/index.html')
.pipe(ghtmlSrc({getFileName:getFileName.bind(this, 'src')}));
var templates = gulp.src(['src/**/*.html', '!src/index.html'])
.pipe(minifyHTML({collapseWhitespace:true, conservativeCollapse:true}))
.pipe(templateCache('templates.js', {root:'', module:'ui'}));
var tiny = gulp.src('node_modules/tinycolor2/dist/tinycolor-min.js')
.pipe(gulp.dest('./dist/js'));
var i18n = gulp.src('src/i18n.js').pipe(gulp.dest('dist/'));
return streamqueue({ objectMode:true }, scripts, templates)
.pipe(gulpif(/[.]min[.]js$/, gutil.noop(), uglify()))
.pipe(concat('app.min.js'))
.pipe(header(fs.readFileSync('license.js')))
.pipe(gulp.dest('dist/js/'));
});
gulp.task('css', function () {
exec('./fixfa.sh', function (err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
}
});
return gulp.src('src/index.html')
.pipe(ghtmlSrc({getFileName:getFileName.bind(this, 'href'), presets:'css'}))
.pipe(minifyCss({compatibility:'ie8'}))
.pipe(concat('app.min.css'))
.pipe(header(fs.readFileSync('license.js')))
.pipe(gulp.dest('dist/css/'));
});
gulp.task('less', function() {
return gulp.src('src/index.html')
.pipe(resources({less:true, css:false, js:false}))
.pipe(removeHtml())
.pipe(gulpif('**/*.less', concat('app.min.less')))
.pipe(header(fs.readFileSync('license.js')))
.pipe(gulp.dest('dist/css'));
});
var vendorPrefix = "vendor/";
function getFileName(attr, node) {
var file = node.attr(attr);
if (file.indexOf(vendorPrefix) === 0) {
file = path.join("..", "node_modules", file.substr(vendorPrefix.length));
}
return file;
}