-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
100 lines (82 loc) · 2.33 KB
/
grunt.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
module.exports = function(grunt) {
var pkg = grunt.file.readJSON("package.json");
grunt.initConfig({
pkg: pkg,
buster: {
test: {
config: "test/buster.js"
}
},
clean: {
docs: ["<%= pkg.directories.docs %>/**"],
dataseries: ["dataseries.js", "dataseries.min.js"]
},
lint: {
files: ["<%= pkg.directories.src %>/**/*.js", "<%= pkg.directories.test %>/**/*.test.js"]
},
min: {
"dataseries.min.js": "dataseries.js"
},
replace: {
"gh-pages": {
src: "docs/md/**.md",
dest: "docs/gh-pages/",
replacements: [
{ from: ".html", to: "" },
{ from: /href="(.+)#(.+)?"/g, to: 'href="$1#wiki-$2"' },
{ from: /\[(.+)\]\((ds\..+)#(.+)?\)/g, to: '[$1]($2#wiki-$3)' }
]
}
},
requirejs: {
compile: {
options: {
mainConfigFile: "build.js"
}
}
},
watch: {
files: ["<%= pkg.directories.src %>/**/*.js", "<%= pkg.directories.test %>/**/*.test.js"],
tasks: ["buster"],
options: {
interrupt: true
}
}
});
grunt.loadNpmTasks("grunt-buster");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-requirejs");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-text-replace");
grunt.registerTask("default", "buster requirejs min docs");
grunt.registerTask("docs", "md gh-pages");
grunt.registerTask("test", "buster");
grunt.registerTask("md", "Generate markdown docs from source files", function() {
var markdox = require("markdox");
var path = require("path");
var sources = "<%= pkg.directories.src %>/**/*.js";
var dest = "docs/md/";
var files = grunt.file.expandFiles(sources).sort(function(a, b) {
var _a = a.split('/').length;
var _b = b.split('/').length;
if (_a > _b) {
return 1;
} else if (_a < _b) {
return -1;
} else {
return path.basename(a).localeCompare(path.basename(b));
}
});
var done = this.async();
grunt.file.mkdir("docs/md", 0755);
files.forEach(function(file) {
markdox.process(file, {output: dest + path.basename(file) + ".md", template: "templates/md/module.md.ejs"}, function() {
done();
});
});
markdox.process(files, {output: dest + "dataseries.js.md", template: "templates/md/overview.md.ejs"}, function() {
done();
});
});
grunt.registerTask("gh-pages", "Generate GitHub pages from markdown docs", "replace:gh-pages");
}