This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
161 lines (142 loc) · 4.53 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
158
159
160
161
const angularTemplateCache = require('gulp-angular-templatecache');
const argv = require('yargs').argv;
const concat = require('gulp-concat');
const del = require('del');
const eventStream = require('event-stream');
const gulp = require('gulp');
const hawtio = require('@hawtio/node-backend');
const If = require('gulp-if');
const less = require('gulp-less');
const logger = require('js-logger');
const ngAnnotate = require('gulp-ng-annotate');
const path = require('path');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const s = require('underscore.string');
const Server = require('karma').Server;
const sourcemaps = require('gulp-sourcemaps');
const typescript = require('gulp-typescript');
const packageJson = require('./package.json');
const tsconfig = require('./tsconfig.json');
const config = {
targetPath: argv.path || '/jolokia',
logLevel: argv.debug ? logger.DEBUG : logger.INFO,
less: ['plugins/**/*.less'],
templates: ['plugins/**/*.html', 'plugins/**/*.md'],
templateModule: 'hawtio-jmx-templates',
dist: argv.out || './dist/',
js: 'hawtio-jmx.js',
dts: 'hawtio-jmx.d.ts',
css: 'hawtio-jmx.css',
sourceMap: argv.sourcemap,
};
const tsProject = typescript.createProject('tsconfig.json');
gulp.task('tsc', function() {
const tsResult = tsProject.src()
.pipe(If(config.sourceMap, sourcemaps.init()))
.pipe(tsProject());
return eventStream.merge(
tsResult.js
.pipe(ngAnnotate())
.pipe(If(config.sourceMap, sourcemaps.write()))
.pipe(gulp.dest('.')),
tsResult.dts
.pipe(rename(config.dts))
.pipe(gulp.dest(config.dist)));
});
gulp.task('less', function () {
return gulp.src(config.less)
.pipe(less({
paths: [
path.join(__dirname, 'plugins'),
path.join(__dirname, 'node_modules')
]
}))
.pipe(concat(config.css))
.pipe(gulp.dest(config.dist));
});
gulp.task('template', ['tsc'], function() {
return gulp.src(config.templates)
.pipe(angularTemplateCache({
filename: 'templates.js',
root: 'plugins/',
standalone: true,
module: config.templateModule,
templateFooter: '}]); hawtioPluginLoader.addModule("' + config.templateModule + '");'
}))
.pipe(gulp.dest('.'));
});
gulp.task('concat', ['template'], function() {
return gulp.src(['compiled.js', 'templates.js'])
.pipe(concat(config.js))
.pipe(gulp.dest(config.dist));
});
gulp.task('del-images', function () {
return del('img');
});
gulp.task('copy-images', ['del-images'], function () {
return gulp.src('node_modules/@hawtio/core/dist/img/*')
.pipe(gulp.dest('img'));
});
gulp.task('clean-temp-files', ['concat'], function() {
return del(['templates.js', 'compiled.js']);
});
gulp.task('watch', ['build'], function() {
gulp.watch(['index.html', config.dist + '/*'], ['reload']);
gulp.watch([...tsconfig.include, ...(tsconfig.exclude || []).map(e => `!${e}`), config.templates], ['clean-temp-files']);
gulp.watch(config.less, ['less']);
});
gulp.task('connect', ['build'], function() {
hawtio.setConfig({
logLevel: config.logLevel,
port: 2772,
proxy: '/hawtio/proxy',
staticProxies: [{
path: '/jolokia',
targetPath: config.targetPath
}],
staticAssets: [{
path: '/hawtio/',
dir: '.'
}],
fallback: 'index.html',
liveReload: {
enabled: true
}
});
hawtio.use('/', function(req, res, next) {
const path = req.originalUrl;
if (path === '/') {
res.redirect('/hawtio');
} else if (s.startsWith(path, '/plugins/') && s.endsWith(path, 'html')) {
// avoid returning these files, they should get pulled from js
console.log("returning 404 for: ", path);
res.statusCode = 404;
res.end();
} else {
// console.log("allowing: ", path);
next();
}
});
hawtio.listen(function(server) {
const host = server.address().address;
const port = server.address().port;
console.log("started from gulp file at ", host, ":", port);
});
});
gulp.task('reload', function() {
gulp.src('.')
.pipe(hawtio.reload());
});
gulp.task('test', ['build'], function (done) {
new Server({
configFile: __dirname + '/karma.conf.js'
}, done).start();
});
gulp.task('version', function() {
gulp.src(config.dist + config.js)
.pipe(replace('PACKAGE_VERSION_PLACEHOLDER', packageJson.version))
.pipe(gulp.dest(config.dist));
});
gulp.task('build', ['clean-temp-files', 'less', 'copy-images']);
gulp.task('default', ['connect', 'watch']);