forked from BrowserSync/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crossbow.js
78 lines (66 loc) · 1.91 KB
/
crossbow.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
var fs = require('fs');
var crossbow = require('crossbow');
var path = require('path');
var prefix = "https://github.com/Browsersync/recipes/tree/master/recipes";
var dirs = fs.readdirSync("./recipes")
.map(function (item) {
return {
dir: item,
name: item.split(".")
};
})
.map(function (item) {
item.pkg = require("./recipes/"+item.dir+"/package.json");
item.link = [prefix, item.dir].join("/");
item.title = item.name.map(function (item) {
return item.charAt(0).toUpperCase() + item.slice(1);
}).join(" ");
return item;
});
fs.writeFileSync("./manifest.json", JSON.stringify(dirs, null, 4));
var site = crossbow.builder({
config: {
markdown: false
},
data: {
config: "file:config.yml",
recipes: dirs
}
});
var readme = site.add({
type: "page",
key: "_src/readme.md",
content: fs.readFileSync("_src/readme.md", "utf8")
});
site.freeze();
site.compile({
item: readme,
cb: function (err, out) {
if (err) {
return site.logger.error(site.getErrorString(err));
}
fs.writeFileSync("readme.md", out.get("compiled"));
}
});
dirs.forEach(function (item) {
var key = path.join("recipes", item.dir, "desc.md");
var output = path.join("recipes", item.dir, "readme.md");
var site = crossbow.builder({config: {base: "recipes/" + item.dir, markdown: false}});
var page = site.add({
key: key,
content: fs.readFileSync(path.join("_src", "template.md"), "utf8")
});
site.freeze();
site.compile({
item: page,
data: {
example: item
},
cb: function (err, out) {
if (err) {
return site.logger.error(site.getErrorString(err));
}
fs.writeFileSync(output, out.get("compiled"));
}
});
});