-
Notifications
You must be signed in to change notification settings - Fork 3
/
Gulpfile.js
120 lines (107 loc) · 2.99 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
var gulp = require('gulp')
var File = require('vinyl')
var Swig = require('swig').Swig
var data = require('gulp-data')
var markdown = require('markdown-it')()
var through = require('through2')
var map = require('through2-map')
var buffer = require('vinyl-buffer')
var replaceExt = require('replace-ext')
var assign = require('object-assign')
var Path = require('path')
var prettify = require('gulp-prettify')
var push = Array.prototype.push
function docs () {
var swig = new Swig()
var renderDoc = swig.compileFile('./templates/doc.swig')
return gulp.src('./docs/*.md')
.pipe(buffer())
.pipe(data(getData))
.pipe(map.obj(function toMarkdown (file) {
var input = String(file.contents)
var output = markdown.render(input)
file.contents = Buffer(output)
file.path = replaceExt(file.path, '.html')
return file
}))
.pipe(map.obj(function toTemplate (file) {
var input = String(file.contents)
var locals = assign({}, file.data, { contents: input })
var output = renderDoc(locals)
file.contents = Buffer(output)
return file
}))
.pipe(prettify())
.pipe(gulp.dest('./.build'))
function getData (file) {
return require(file.path + '.json')
}
}
function ns () {
gulp.src('./ns/*.jsonld')
// bundle into a single context at index.jsonld
.pipe(bundleContext())
.pipe(gulp.dest('./.build/ns'))
function bundleContext () {
var bundle = {
'@context': {},
'@graph': []
}
var base = null
return through.obj(function bundleContext (file, enc, cb) {
//console.log("spying", file)
if (!base) {
base = file.base
}
var input = JSON.parse(file.contents)
if (Array.isArray(input['@context'])) {
input['@context'].forEach(function (item) {
mix(bundle['@context'], item)
})
} else {
mix(bundle['@context'], input['@context'])
}
push.apply(bundle['@graph'], input['@graph'])
cb(null, file)
}, function writeContext (cb) {
var path = Path.join(base, 'index.jsonld')
var contents = new Buffer(JSON.stringify(bundle, null, 2))
//console.log("writing", path, contents)
this.push(new File({
path: path,
base: base,
cwd: process.cwd(),
contents: contents
}))
cb(null)
})
function mix (bundle, input) {
switch (typeof input) {
case 'string':
// TODO fetch from url and re-mix
break
case 'object':
assign(bundle, input)
break
}
}
}
}
function css () {
gulp.src('./css/*.css')
.pipe(gulp.dest('./.build/css'))
}
function server () {
gulp.src(['./server.js', './package.json'])
.pipe(gulp.dest('./.build'))
}
function assets () {
gulp.src('./assets/**/*')
.pipe(gulp.dest('./.build'))
}
gulp.task('docs', docs)
gulp.task('ns', ns)
gulp.task('css', css)
gulp.task('assets', assets)
gulp.task('server', server)
gulp.task('build', ['docs', 'ns', 'css', 'assets', 'server'])