-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
95 lines (82 loc) · 2.94 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
var fs = require('fs');
var gulp = require('gulp');
var browserSync = require('browser-sync');
var historyApiFallback = require('connect-history-api-fallback');
var ini = require('ini');
var less = require('gulp-less');
// var rename = require('gulp-rename');
var shell = require('gulp-shell');
// var uglify = require('gulp-uglify');
var webpack = require('webpack-stream');
var webpackConfig = require('./webpack.config.js');
var tempStorageWorkerConfig = require('./tempstorageworker.webpack.config.js');
gulp.task('webpack-app', ['webpack-tempstorage-worker'], function() {
return gulp.src('./src/js/index.js')
.pipe(webpack(webpackConfig))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream());
});
gulp.task('serve', ['config-create', 'webpack-app', 'less', 'fonts', 'images'], function(){
browserSync.init({
open: false,
server: {
baseDir: './dist',
middleware: [ historyApiFallback() ]
}
});
gulp.watch('src/less/**/*.less', ['less']);
// Re-build app and run tests on app change.
gulp.watch('src/js/**/*.js', ['webpack-app', 'test-run']);
// Run tests on test change.
gulp.watch('src/__tests__/**/*.js', ['test-run']);
gulp.watch('src/*.html').on('change', browserSync.reload);
});
gulp.task('less', function () {
return gulp.src('./src/less/base.less')
.pipe(less())
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.stream());
});
gulp.task('fonts', function() {
var bootstrapFonts = 'node_modules/bootstrap/fonts/*';
var patternflyFonts = 'node_modules/patternfly/dist/fonts/*';
var fontAwesomeFonts = 'node_modules/patternfly/components/font-awesome/fonts/*';
return gulp.src([bootstrapFonts, patternflyFonts, fontAwesomeFonts])
.pipe(gulp.dest('./dist/fonts'));
});
gulp.task('images', function() {
var imagesPath = 'src/img/*';
var patternFlyImagesPath = 'node_modules/patternfly/dist/img/*';
return gulp.src([patternFlyImagesPath, imagesPath])
.pipe(gulp.dest('./dist/img'));
});
gulp.task('webpack-tempstorage-worker', function() {
return gulp.src('./src/js/workers/TempStorageWorker.js')
.pipe(webpack(tempStorageWorkerConfig))
.pipe(gulp.dest('./dist/js'));
});
gulp.task('config-create', function() {
try {
fs.mkdirSync(__dirname + '/dist/js');
}
catch(err) {};
try {
var config = ini.parse(fs.readFileSync('./app.conf', 'utf-8'));
config.app = config.app || {};
var json = JSON.stringify(config.app);
}
catch (err) {
var json = '{}';
};
fs.writeFileSync(
'./dist/js/tripleo_ui_config.js',
'window.tripleOUiConfig = ' + json + ';'
);
});
// Start test server, run tests once, then quit.
gulp.task('test', shell.task('karma start --single-run'));
// Start test server, run tests, keep server running..
gulp.task('test-start', shell.task('karma start'));
// Do a single test run (expects Karma server to be running).
gulp.task('test-run', shell.task('karma run'));
gulp.task('default', [ 'serve', 'test-start' ], function() {});