UNPKG

2.19 kBJavaScriptView Raw
1var gulp = require('gulp');
2var debug = require('gulp-debug');
3var gulpif = require('gulp-if');
4var replace = require('gulp-replace');
5var zip = require('gulp-zip');
6var concat = require('gulp-concat');
7var common = require('./common');
8var _ = require('lodash');
9var path = require('path');
10var shelljs = require('shelljs');
11
12gulp.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
21function 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
38gulp.task('plugin', ['plugin_concat'], function() {
39 return packagePlugin();
40});
41
42gulp.task('plugin-dev-package', ['dev-bundle-main', 'styles', 'resources'], function() {
43 return packagePlugin();
44});
45
46gulp.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});