-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
119 lines (97 loc) · 3.46 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
var gulp = require('gulp');
var zip = require('gulp-zip');
var join = require('path').join;
var merge = require('merge-stream');
var Promise = require('promise');
var yargs = require('yargs');
var clean = require('gulp-clean');
var rename = require('gulp-rename');
var buildWidget = require('widget-builder');
var runKarma = require('./script/run-karma');
var dir = require('./script/dir');
var deploy = require('./script/deploy');
gulp.task('clean', function() {
return gulp.src('dist').pipe(clean());
});
gulp.task('build', function() {
return merge(dir('src/widgets').map(function(widget) {
return merge(
gulp.src(join('src/widgets', widget, '*.json')).pipe(buildWidget()),
gulp.src(join('src/widgets', widget, 'assets/**/*')).pipe(rename(function(path) {
path.dirname = join(widget, 'assets', path.dirname);
})))
.pipe(gulp.dest(join('dist', widget, 'resources')));
}));
});
gulp.task('deployAll', ['zip'], function() {
var argv = getDeploymentAllArguments();
return dir('dist').map(function(widget) {
return gulp.src(join('dist', widget + '.zip')).pipe(deploy(argv.host, argv.force));
});
});
gulp.task('test', ['build'], function(done) {
let watch = yargs.argv.watch;
if (watch) {
gulp.watch('src/widgets/**/(!*.spec.js)', ['build']);
}
Promise
.all(dir('src/widgets').map(runKarma.bind(null, {
watch
})))
.then(done.bind(null, null));
});
gulp.task('zip', ['build'], function() {
return merge(dir('dist').map(function(widget) {
return gulp.src(join('dist', widget, '**/*'))
.pipe(zip(widget + '.zip'))
.pipe(gulp.dest('dist'));
}));
});
gulp.task('deploy:single', ['zip'], function() {
var argv = getDeploymentArguments();
return gulp.src(join('dist', argv.widget + '.zip')).pipe(deploy(argv.host, argv.force));
});
gulp.task('deploy:watch', ['deploy:single'], function() {
var argv = getDeploymentArguments();
return gulp.watch(join('src/widgets', argv.widget, '**/*'), ['deploy:single']);
});
gulp.task('deploy', function() {
return yargs.argv.watch ? gulp.start('deploy:watch') : gulp.start('deploy:single');
});
gulp.task('default', ['clean'], function() {
return gulp.start(['test', 'zip']);
});
function getDeploymentArguments() {
//console.log(sing)
return yargs
.usage('Usage: npm run deploy -- --widget customWidget [--host http://127.0.0.1:8080/designer] [--force] [--watch]')
.demand('widget')
.alias('widget', 'w')
.choices('widget', dir('dist'))
.describe('widget', 'Widget directory name to deploy')
.demand('host', false)
.alias('host', 'h')
.default('host', 'http://127.0.0.1:8080/designer')
.describe('host', 'UI Designer URL')
.demand('force', false)
.alias('force', 'f')
.default('force', false)
.describe('force', 'Override the widget if it already exist at destination')
.demand('watch', false)
.default('watch', false)
.describe('watch', 'Watch source files and redeploy widget whenever a source file changes')
.argv;
}
function getDeploymentAllArguments(singleWidget) {
return yargs
.usage('Usage: npm run deployAll -- [--host http://127.0.0.1:8080/designer] [--force] ')
.demand('host', false)
.alias('host', 'h')
.default('host', 'http://127.0.0.1:8080/designer')
.describe('host', 'UI Designer URL')
.demand('force', false)
.alias('force', 'f')
.default('force', false)
.describe('force', 'Override the widget if it already exist at destination')
.argv;
}