UNPKG

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