This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (56 loc) · 2.04 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var replace = require('gulp-replace');
var rimraf = require('rimraf');
var zip = require('gulp-zip');
var _ = require('lodash');
var fs = require('fs');
var path = require('path');
if (!gutil.env.config) {
gutil.log(gutil.colors.red("error:"), "missing config. Use --config ./config/someconfig.js");
process.exit(1);
}
var configFile = gutil.env.config;
//if (configFile.indexOf('./') !== 0) configFile = './' + configFile;
var cfg = require(configFile);
gutil.log("using config " +configFile);
var commonCfg = require('./config/tpl/common.js');
var headerFields = (function(){
var lis = _.map(cfg.termList.fields, function(field) {
return '<th field-name="' +field.name+ '" enable-filtering="true"></th>';
});
return '\n' + lis.join('\n');
})();
var valueFields = (function(){
var lis = _.map(cfg.termList.fields, function(field, idx) {
var pipe = idx === 0 ? ' | htmlifyTerm:termListFilter'
: ' | mkExternalLinks';
return '<td field-name="' +field.name+ '">\n' +
' <div ng-bind-html="gridItem.' +field.name + pipe +'"></div>\n' +
'</td>';
});
return '\n' + lis.join('\n');
})();
gulp.task('default', ['genConfig'], function(){
return gulp.src('config/tpl/main.html')
.pipe(replace(/@@headerFields/, headerFields))
.pipe(replace(/@@valueFields/, valueFields))
.pipe(gulp.dest('app/views'));
});
gulp.task('genConfig', function(cb) {
if (cfg.mapping === undefined) {
cfg.mapping = commonCfg.mapping;
}
fs.writeFile("app/js/config.js", "var vbrowserConfig = " + JSON.stringify(cfg, null, ' ') + ";", function (err) {
cb(err);
});
});
gulp.task('dist', ['default'], function(cb) {
var zipname = 'vbrowser-' + path.basename(configFile, '.js') + '.zip';
return gulp.src(['app/**'])
.pipe(zip(zipname))
.pipe(gulp.dest('./dist'));
});
gulp.task('clean-dist', function(cb) {
rimraf('dist', cb);
});