forked from theus/MenuChef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
79 lines (70 loc) · 2.37 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
var gulp = require('gulp');
var twig = require('gulp-twig');
var collect = require('collect.js');
var fs = require('fs');
var exec = require('child_process').exec;
var importFresh = require('import-fresh');
var slugg = require('slugg');
gulp.task('compile', ['doc'], function () {
const { version } = importFresh('./package.json');
let docjson = collect(importFresh('./doc.json'))
let doc = {}
doc.constructor = docjson.where('name', 'constructor').all()
doc.options = docjson.where('name', 'options').all()
doc.theme = docjson.where('name', 'theme').all()
doc.public_methods = docjson.where('name', 'public_methods').all()
doc.public_variables = docjson.where('name', 'public_variables').all()
return gulp.src(['./site/**/*.twig', '!./site/base.twig', '!./site/macros.twig', '!./site/**/_*.twig'])
.pipe(twig({
data: {
doc: doc,
version: version
},
functions: [
{
name: "json",
func: function (obj) {
return JSON.stringify(obj);
}
},
{
name: "search",
func: function (arr, key, val) {
return arr.filter(item => item[key] == val)[0];
}
},
{
name: "label",
func: function (type) {
let types = type.split(',')
let content = []
const tag = (type) => `<span class="label label-default label--${type.trim()}">${type.trim()}</span>`
types.forEach(type => content.push(tag(type)))
return content.join(' ');
}
}
],
filters: [
{
name: 'slugify',
func: function (str) {
return slugg(str)
}
}
]
}))
.pipe(gulp.dest('./'));
});
gulp.task('doc', function (done) {
exec('node .\\node_modules\\documentation\\bin\\documentation.js build src/MenuChef.js -f json --shallow -o doc.json', function (err) {
if (err) return done(err);
done();
});
});
gulp.task('watch', function () {
gulp.watch('./site/**/*.twig', ['compile']);
gulp.watch('./src/**/*', ['doc']);
gulp.watch('./doc.json', ['compile']);
});
gulp.task('default', ['doc' ,'compile']);
gulp.task('dev', ['default' ,'watch']);