-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
79 lines (69 loc) · 1.98 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
'use strict';
var fs = require('fs');
var browserify = require('browserify');
var glob = require('glob');
var gulp = require('gulp');
var partialify = require('partialify');
var push = require('couch-push');
var runSequence = require('run-sequence');
var source = require('vinyl-source-stream');
var argv = require('yargs').argv;
var config = require('./config.json');
var couch_url;
if (argv.url) {
couch_url = argv.url;
} else if (config.env && config.env['default'] && config.env['default'].db) {
couch_url = config.env['default'].db;
} else {
// TODO: make this hault
console.log('You must supply the URL to your CouchDB instance (via --url or config.json');
}
gulp.task('sprung', function() {
var b = browserify({
entries: './src/main.js',
debug: true,
transform: [partialify]
});
return b.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./_design/sprung/_attachments/'));
});
gulp.task('docs', function() {
glob('_docs/*', function(err, matches) {
if (err) throw err;
matches.forEach(function(doc) {
var type = doc.split('~')[0];
if (type === '_docs/type' && fs.existsSync(doc + '/index.js')) {
// we have a type definition, build its component
browserify({
entries: './' + doc + '/index.js',
debug: true,
transform: [partialify]
})
.bundle()
.pipe(source('component.js'))
.pipe(gulp.dest('./' + doc + '/_attachments/'));
}
push(couch_url, doc,
function(err, resp) {
if (err) throw JSON.stringify(err);
console.log(resp);
});
});
});
});
gulp.task('apps', function() {
glob('_design/*', function(err, matches) {
if (err) throw err;
matches.forEach(function(ddoc) {
push(couch_url, ddoc,
function(err, resp) {
if (err) throw JSON.stringify(err);
console.log(resp);
});
});
});
});
gulp.task('default', function() {
runSequence('sprung', ['apps', 'docs']);
});