-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
103 lines (93 loc) · 2.87 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
const gulp = require("gulp");
const source = require("vinyl-source-stream");
const buffer = require("vinyl-buffer");
const browserify = require("browserify");
const mochaPhantomJS = require("gulp-mocha-phantomjs");
const babelify = require("babelify");
gulp.task("browserify", function() {
return browserify("./src/app.js", {debug: true})
.transform(babelify)
.on("error",function(e) {
console.log("17", e.message);
this.emit("end");
})
.bundle()
.on("error",function(e) {
console.log("22", e.message);
this.emit("end");
})
.pipe(source("bundle.js")) // output filename
.pipe(buffer())
// Start piping stream to tasks!
.pipe(gulp.dest("./build/"))
.pipe(gulp.dest("./docs/dist/"));
});
gulp.task("watch", () => {
gulp.watch("./src/**/*.js", ["browserify", "doc"]);
});
gulp.task("doc", function () {
const fs = require("fs-then-native");
const jsdoc2md = require("jsdoc-to-markdown");
const path = require("path");
/* input and output paths */
const inputFiles = "src/**/*.js";
const outputDir = "./docs/";
const liveDir = "//lemnis.github.io/a20y/";
const partial = [
'./dmd/global-index-dl.hbs',
'./dmd/sig-link-html.hbs'
];
/* get template data */
const templateData = jsdoc2md.getTemplateDataSync({ files: inputFiles });
/* reduce templateData to an array of class names */
const classNames = templateData.filter(item => item.kind === "class").map(item => item.name);
const mixinNames = templateData.filter(item => item.kind === "mixin").map(item => item.name);
/* create indexs */
const output = jsdoc2md.renderSync({
data: templateData,
template: `
<base href="${liveDir}">
{{>main-index~}}
`,
partial,
helper: './dmd/utils.js'
})
fs.writeFileSync(path.resolve(outputDir, 'README.md'), output)
/* create a documentation file for each class */
for (const className of classNames) {
const template = `
<base href="${liveDir}">
<link rel="stylesheet" href="./dist/style.css" />
{{#classes name="${className}"}}{{>docs}}{{/classes}}
<script src="./dist/bundle.js" /></script>
`;
const output = jsdoc2md.renderSync({
data: templateData,
template: template,
partial,
helper: './dmd/utils.js'
})
fs.writeFileSync(path.resolve(outputDir + '/classes/', `${className}.md`), output)
}
/* create a documentation file for each mixin */
for (const mixinName of mixinNames) {
const template = `
<base href="${liveDir}">
<link rel="stylesheet" href="./dist/style.css" />
{{#mixines name="${mixinName}"}}{{>docs}}{{/mixines}}
<script src="./dist/bundle.js" /></script>
`;
const output = jsdoc2md.renderSync({
data: templateData,
template: template,
partial,
helper: './dmd/utils.js'
})
fs.writeFileSync(path.resolve(outputDir + '/mixins/', `${mixinName}.md`), output)
}
});
gulp.task("test", function () {
return gulp
.src("index.html")
.pipe(mochaPhantomJS());
});