-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
122 lines (110 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
120
121
122
'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('couchdb-push');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var source = require('vinyl-source-stream');
var rework = require('gulp-rework');
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('rework', function() {
// TODO: call `gulp build` in `src/semantic/` first
return gulp.src('src/semantic/dist/semantic.css')
.pipe(rework(function (style) {
var walk = require('rework-walk');
walk(style, function(rule, node) {
if (!rule.selectors) return rule;
rule.selectors = rule.selectors.map(function(selector) {
if (selector[0] === '.') {
return selector.replace(/\.ui/g, '.blueink-ui');
} else {
// for reset / tag-named stuff
if (selector.substr(0,4) !== 'html'
&& selector.substr(0,4) !== 'body') {
if (selector === '*') {
// add .blueink-ui into the * space
return '.blueink-ui, .blueink-ui ' + selector;
} else {
return '.blueink-ui ' + selector;
}
}
}
});
// remove html & body specific reset styles
// to avoid overriding template styles excessively
if (undefined === rule.selectors[0]) {
rule.selectors = [];
rule.declarations = [];
}
});
}, {sourcemap: true}))
.pipe(rename('app.css'))
.pipe(gulp.dest('_design/blueink/_attachments/ui/'));
});
gulp.task('blueink', function() {
var b = browserify({
entries: './src/main.js',
debug: true,
transform: [partialify]
});
return b.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./_design/blueink/_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) {
console.log(doc);
console.log(JSON.stringify(err));
console.log(JSON.stringify(resp));
throw 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('blueink', ['apps', 'docs'], function() { console.log(Date()); });
});