-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
105 lines (84 loc) · 2.84 KB
/
index.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
'use strict';
const StaticSiteJson = require('broccoli-static-site-json');
const BroccoliMergeTrees = require('broccoli-merge-trees');
const funnel = require('broccoli-funnel');
const writeFile = require('broccoli-file-creator');
const { Serializer } = require('jsonapi-serializer');
const { readdirSync, existsSync } = require('fs');
const { join } = require('path');
const TocSerializer = new Serializer('toc', {
attributes: [
'links',
],
});
module.exports = {
name: require('./package').name,
config() {
return {
fastboot: {
hostWhitelist: [/localhost:\d+/]
},
showdown: {
tables: true
}
}
},
getDataDirectory() {
if (this.app.options.rfcProcess && this.app.options.rfcProcess.textLocation) {
return this.app.options.rfcProcess.textLocation;
} else if(this.app.options.rfcProcess && this.app.options.rfcProcess.source) {
try {
return resolve.sync(this.app.options.rfcProcess.source, { basedir: process.cwd() });
} catch (e) {
// try getting node_modules directly
let fullPath = join(process.cwd(), 'node_modules', this.app.options.rfcProcess.source);
if(existsSync(fullPath)) {
return fullPath;
}
}
}
return join(this.project.configPath(), '../..');
},
urlsForPrember() {
const rfcs = readdirSync(join(this.getDataDirectory(), 'text'))
.map((file) => file.replace(/\.md$/, ''))
.map(file => `/id/${file}`);
return ['/', ...rfcs];
},
treeForPublic() {
let dataDirectory = this.getDataDirectory();
const rfcsJSON = new StaticSiteJson(join(dataDirectory, 'text'), {
contentFolder: 'rfcs',
type: 'rfcs',
attributes: ['start-date', 'release-date', 'release-versions', 'proposal-pr', 'tracking-link'],
references: ['teams', 'stage']
});
const teamsJSON = new StaticSiteJson(join(dataDirectory, 'teams'), {
contentFolder: 'teams',
type: 'teams',
attributes: ['name'],
});
const stagesJSON = new StaticSiteJson(join(dataDirectory, 'stages'), {
contentFolder: 'stages',
type: 'stages',
attributes: ['name'],
});
const readmeFile = funnel(dataDirectory, {
files: ['README.md']
});
const pagesJSON = new StaticSiteJson(readmeFile, {
contentFolder: 'pages',
type: 'pages',
})
const rfcs = readdirSync(join(dataDirectory, 'text')).map((file) => file.replace(/\.md$/, ''));
const tocFile = writeFile('/tocs/rfc.json', JSON.stringify(TocSerializer.serialize({ id: 'rfc', links: rfcs })));
const trees = [rfcsJSON, teamsJSON, stagesJSON, tocFile, pagesJSON]
if(existsSync(join(dataDirectory, 'images'))) {
const images = funnel(join(dataDirectory, 'images'), {
destDir: 'images'
});
trees.push(images);
}
return BroccoliMergeTrees(trees);
}
};