forked from bigmonkeyboy/node-red-contrib-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (58 loc) · 2.15 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
var
gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
templateCache = require('gulp-angular-templatecache'),
ghtmlSrc = require('gulp-html-src'),
gutil = require('gulp-util'),
minifyCss = require('gulp-minify-css'),
gulpif = require('gulp-if'),
htmlreplace = require('gulp-html-replace'),
minifyHTML = require('gulp-minify-html'),
path = require('path'),
spawn = require('child_process').spawn,
streamqueue = require('streamqueue');
gulp.task('build', ['icon', 'js', 'css', 'index', 'fonts']);
gulp.task('publish', ['build'], function (done) {
spawn('npm', ['publish'], { stdio: 'inherit' }).on('close', done);
});
gulp.task('index', function() {
return gulp.src('src/index.html')
.pipe(htmlreplace({
'css': 'css/app.min.css',
'js': 'js/app.min.js'
}))
.pipe(minifyHTML({spare: true, quotes: true}))
.pipe(gulp.dest('dist/'));
});
gulp.task('icon', function() {
return gulp.src('src/icon.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({spare: true, quotes: true}))
.pipe(templateCache('templates.js', {root: '', module: 'ui'}));
return streamqueue({ objectMode: true }, scripts, templates)
.pipe(gulpif(/[.]min[.]js$/, gutil.noop(), uglify()))
.pipe(concat('app.min.js'))
.pipe(gulp.dest('dist/js/'));
});
gulp.task('css', function () {
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(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;
}