-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
139 lines (121 loc) · 5.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var watch = require('gulp-watch');
var template = require('gulp-template');
var markdown = require('gulp-markdown');
var hsp = require('gulp-hashspace');
var rimraf = require('rimraf');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var noder = require('gulp-noder');
var rename = require('gulp-rename');
var livereload = require('gulp-livereload');
var http = require('http');
var karma = require('karma').server;
var connect = require('connect');
var _ = require('lodash');
var through2 = require('through2');
var karmaConf = require('./build/karma.conf');
var wwwServerPort = 8080;
var _destFolder = "target";
var _devFolder = _destFolder + "/dev";
var _prodFolder = _destFolder + "/prod";
var hspVersion = require('hashspace/package.json').version;
var noderVersion = require('gulp-noder/node_modules/noder-js/package.json').version;
var packages = ['hashspace-bootstrap-noder.min', 'demo-hashspace-bootstrap-noder.min'];
function startWWWServer(folder) {
gutil.log('Starting WWW server at http://localhost:' + wwwServerPort);
http.createServer(connect().use(connect.static('./' + folder))).listen(wwwServerPort);
}
function html2hsp() {
return through2.obj(function(file, encoding, done) {
var content = '<template id="description" export>\r\n' + String(file.contents).replace(/<table>/g, '<table class="table table-bordered">') + "\r\n</template>";
file.contents = new Buffer(content);
file.path = gutil.replaceExtension(file.path, ".hsp");
this.push(file);
done();
});
}
gulp.task('checkstyle', function() {
return gulp.src(['src/**/*.js', 'demo/**/*.js', 'test/**/*.js', '!demo/lib/**/*.*']).
pipe(jshint({eqnull: true})).
pipe(jshint.reporter("default")).
pipe(jshint.reporter("fail"));
});
gulp.task('clean', function (done) {
rimraf(_destFolder, done);
});
gulp.task('build', ['clean'], function() {
gulp.src('src/**/*.+(hsp|js)').pipe(hsp.process()).pipe(gulp.dest(_devFolder));
gulp.src('demo/**/*.+(html)').pipe(template({hspVersion: hspVersion, noderVersion: noderVersion, packages: []})).pipe(gulp.dest(_devFolder));
gulp.src('demo/**/*.md').pipe(markdown()).pipe(html2hsp()).pipe(hsp.compile()).pipe(gulp.dest(_devFolder));
gulp.src('demo/+(css|lib)/**/*.*').pipe(gulp.dest(_devFolder));
return gulp.src('demo/samples/**/*.+(hsp|js)').pipe(hsp.process()).pipe(gulp.dest(_devFolder + '/samples'));
});
gulp.task('test', ['checkstyle'], function (done) {
karma.start(_.assign({}, karmaConf.common, karmaConf.test), done);
});
gulp.task('play', ['build'], function () {
watch({glob: 'demo/**/*.+(html)'}, function (files) {
files.pipe(template({hspVersion: hspVersion, noderVersion: noderVersion, packages: []})).pipe(gulp.dest(_devFolder));
});
watch({glob: 'demo/**/*.md'}, function (files) {
files.pipe(markdown().on('error', gutil.log)).pipe(html2hsp()).pipe(hsp.compile()).pipe(gulp.dest(_devFolder ));
});
watch({glob: 'demo/samples/**/*.+(hsp|js)'}, function (files) {
files.pipe(hsp.process().on('error', gutil.log)).pipe(gulp.dest(_devFolder + '/samples'));
});
watch({glob: 'demo/+(css|lib)/**/*.*'}, function (files) {
files.pipe(gulp.dest(_devFolder));
});
watch({glob: 'src/**/*.+(hsp|js)'}, function (files) {
files.pipe(hsp.process().on('error', gutil.log)).pipe(gulp.dest(_devFolder));
});
livereload.listen();
gulp.watch(_devFolder + '/**').on('change', livereload.changed).on('error', function(e){console.log(e);});
return startWWWServer(_devFolder);
});
gulp.task('tdd', function (done) {
karma.start(_.assign({}, karmaConf.common), done);
});
gulp.task('package', ['build'], function() {
gulp.src(['demo/**/*.+(html)'])
.pipe(template({hspVersion: hspVersion, noderVersion: noderVersion, packages: packages})).pipe(gulp.dest(_prodFolder));
gulp.src('demo/+(css|lib)/**/*.*').pipe(gulp.dest(_prodFolder));
gulp.src([_devFolder + '/**/*.+(hsp|js)', '!' + _devFolder+ '/samples/**/*.*', '!' + _devFolder+ '/lib/**/*.*'])
.pipe(noder.package('/' + _devFolder))
.pipe(concat('hashspace-bootstrap-noder.js')).pipe(noder.wrap())
.pipe(gulp.dest(_prodFolder))
.pipe(uglify())
.pipe(rename('hashspace-bootstrap-noder.min.js'))
.pipe(gulp.dest(_prodFolder));
gulp.src([_devFolder + '/samples/**/*.+(hsp|js)'])
.pipe(noder.package('/' + _devFolder))
.pipe(concat('demo-hashspace-bootstrap-noder.js')).pipe(noder.wrap())
.pipe(gulp.dest(_prodFolder))
.pipe(uglify())
.pipe(rename('demo-hashspace-bootstrap-noder.min.js'))
.pipe(gulp.dest(_prodFolder));
});
gulp.task('www', ['package'], function() {
startWWWServer(_prodFolder);
});
gulp.task('ci1', ['test'], function (done) {
karma.start(_.assign({}, karmaConf.common, karmaConf.ci1), done);
});
gulp.task('ci2', ['ci1'], function (done) {
karma.start(_.assign({}, karmaConf.common, karmaConf.ci2), done);
});
gulp.task('ci3', ['ci2'], function (done) {
karma.start(_.assign({}, karmaConf.common, karmaConf.ci3), done);
});
gulp.task('ci', ['ci3'], function () {
//TODO: remove process.exit() here
process.exit();
});
gulp.task('sauce', ['checkstyle'], function (done) {
return karma.start(_.assign({}, karmaConf.common, karmaConf.sauce), done);
});
gulp.task('default', ['package']);