forked from hawtio/hawtio-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
192 lines (172 loc) · 5.36 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
let angularTemplatecache = require('gulp-angular-templatecache');
let argv = require('yargs').argv;
let concat = require('gulp-concat');
let del = require('del');
let eventStream = require('event-stream');
let gulp = require('gulp');
let hawtio = require('@hawtio/node-backend');
let If = require('gulp-if');
let less = require('gulp-less');
let logger = require('js-logger');
let maven = require('maven');
let ngAnnotate = require('gulp-ng-annotate');
let path = require('path');
let rename = require("gulp-rename");
let replace = require("gulp-replace");
let sourcemaps = require('gulp-sourcemaps');
let typescript = require('gulp-typescript');
let Server = require('karma').Server;
let packageJson = require('./package.json');
const config = {
targetPath: argv.path || '/hawtio/jolokia',
logLevel: argv.debug ? logger.DEBUG : logger.INFO,
templates: ['plugins/**/*.html', 'plugins/**/*.md'],
less: ['plugins/**/*.less', 'vendor/**/*.less', 'vendor/**/*.css'],
templateModule: 'hawtio-integration-templates',
dist: argv.out || './dist/',
js: 'hawtio-integration.js',
dts: 'hawtio-integration.d.ts',
css: 'hawtio-integration.css',
sourceMap: argv.sourcemap,
vendorJs: './vendor/**/*.js',
vendorCss: './vendor/**/*.css',
sourceMap: argv.sourcemap,
srcImg: './plugins/img/**/*',
distImg: './dist/img',
tempImg: './img'
};
const tsProject = typescript.createProject('tsconfig.json');
gulp.task('camel-model', function () {
let mvn = maven.create({
cwd: 'vendor/apache-camel'
});
mvn.execute('compile');
});
gulp.task('tsc', function () {
var 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('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([config.vendorJs, 'compiled.js', 'templates.js'])
.pipe(concat(config.js))
.pipe(gulp.dest(config.dist));
});
gulp.task('clean', ['concat'], function () {
del(['templates.js', 'compiled.js']);
});
gulp.task('less', function () {
let pluginsCss = gulp.src(config.less)
.pipe(less({
paths: [
path.join(__dirname, 'plugins'),
path.join(__dirname, 'node_modules')
]
}));
let vendorCss = gulp.src(config.vendorCss);
return eventStream.merge(pluginsCss, vendorCss)
.pipe(concat(config.css))
.pipe(gulp.dest(config.dist));
});
gulp.task('copy-images', function () {
gulp.src(config.srcImg)
.pipe(gulp.dest(config.distImg))
.pipe(gulp.dest(config.tempImg));
return gulp.src('node_modules/@hawtio/core/dist/img/*')
.pipe(gulp.dest(config.tempImg));
});
gulp.task('watch-less', function () {
gulp.watch(config.less, ['less']);
});
gulp.task('watch', ['build', 'watch-less'], function () {
gulp.watch(['index.html', config.dist + config.js], ['reload']);
const tsconfig = require('./tsconfig.json');
gulp.watch([...tsconfig.include, ...(tsconfig.exclude || []).map(e => `!${e}`), config.templates],
['tsc', 'template', 'concat', 'clean']);
});
gulp.task('connect', ['watch'], function () {
hawtio.setConfig({
logLevel: config.logLevel,
port: 2772,
proxy: '/integration/proxy',
staticProxies: [{
path: '/integration/jolokia',
targetPath: config.targetPath
}],
staticAssets: [{
path: '/integration/',
dir: '.'
}],
fallback: 'index.html',
liveReload: {
enabled: true
}
});
hawtio.use('/', function (req, res, next) {
var path = req.originalUrl;
if (path === '/') {
res.redirect('/integration');
} else if (path.startsWith('/plugins/') && path.endsWith('html')) {
// avoid returning these files, they should get pulled from js
if (argv.debug) {
console.log("returning 404 for: ", path);
}
res.statusCode = 404;
res.end();
} else if (path === '/integration/proxy/enabled') {
res.set('Content-Type', 'application/json');
res.send('true\n');
} else {
if (argv.debug) {
console.log("allowing: ", path);
}
next();
}
});
hawtio.listen(function (server) {
var host = server.address().address;
var 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', ['tsc', 'less', 'template', 'concat', 'clean', 'copy-images']);
gulp.task('default', ['connect']);
gulp.task('camel-test', ['default'], function () {
let mvn = maven.create({
cwd: 'test'
});
mvn.execute('hawtio:spring');
});