1 | var gulp = require('gulp');
|
2 | var debug = require('gulp-debug');
|
3 | var gulpif = require('gulp-if');
|
4 | var replace = require('gulp-replace');
|
5 | var zip = require('gulp-zip');
|
6 | var concat = require('gulp-concat');
|
7 | var common = require('./common');
|
8 | var _ = require('lodash');
|
9 | var path = require('path');
|
10 | var shelljs = require('shelljs');
|
11 |
|
12 | gulp.task('plugin_concat', ['compile-main', 'templates'], function() {
|
13 | return gulp.src([common.dist.main + "/**/*.js", common.dist.main + "/templates/*.js"])
|
14 | .pipe(concat( common.bundles.main ))
|
15 | .pipe(gulpif(common.watch, replace('/dist/', '/')))
|
16 | .pipe(gulpif(common.watch, replace('http://localhost:' + common.port + '/../', 'http://localhost:' + common.port + '/')))
|
17 | .pipe(debug())
|
18 | .pipe(gulp.dest('build/'))
|
19 | });
|
20 |
|
21 | function packagePlugin() {
|
22 | var file = common.module.main + (common.pkg.plugin ? ".zip" : ".war");
|
23 | var distDir = 'tmp';
|
24 | shelljs.rm('-rf', distDir);
|
25 | var pluginDir = path.join(distDir, "System", "plugins", common.pkg.plugin);
|
26 | shelljs.mkdir("-p", pluginDir);
|
27 | shelljs.cp("build/*.js", pluginDir);
|
28 | var metaInfPluginDir = path.join(distDir, "META-INF");
|
29 | shelljs.mkdir("-p", metaInfPluginDir);
|
30 | shelljs.cp("package.json", metaInfPluginDir);
|
31 | console.log('Deploying to ' + common.deploy + "/" + file);
|
32 | return gulp.src(["tmp/**/*"])
|
33 | .pipe(zip(file))
|
34 | .pipe(gulp.dest(common.deploy))
|
35 | .pipe(gulp.dest('.'))
|
36 | }
|
37 |
|
38 | gulp.task('plugin', ['plugin_concat'], function() {
|
39 | return packagePlugin();
|
40 | });
|
41 |
|
42 | gulp.task('plugin-dev-package', ['dev-bundle-main', 'styles', 'resources'], function() {
|
43 | return packagePlugin();
|
44 | });
|
45 |
|
46 | gulp.task('plugin_watch', ['plugin-dev-package', 'dev-bundle-tests', 'webserver'], function() {
|
47 | _.each(common.bundleKinds, function(kind) {
|
48 | gulp.watch([common.srcDirs[kind] + '/**/*.js'], ['dev-recompile-' + kind]);
|
49 | gulp.watch([common.srcDirs[kind] + '/.lib-exports.js'], ['dev-recompile-' + kind, 'generate-systemjs-' + kind + '-index']);
|
50 | });
|
51 | gulp.watch('src/.dev-loader.js', ['plugin-dev-package']);
|
52 | gulp.watch('src/**/*.hbs', ['templates']);
|
53 | gulp.watch('style/**/*.*', ['styles']);
|
54 | });
|