-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (68 loc) · 2.33 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
'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+/]
},
}
},
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() {
let appPrefix = join(this.project.configPath(), '../..');
const rfcs = readdirSync(join(appPrefix, 'text')).map((file) => file.replace(/\.md$/, ''));
return ['/', ...rfcs];
},
treeForPublic() {
let dataDirectory = this.getDataDirectory();
const rfcsJSON = new StaticSiteJson(join(dataDirectory, 'text'), {
contentFolder: 'rfcs',
type: 'rfcs',
});
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, tocFile, pagesJSON]
if(existsSync(join(dataDirectory, 'images'))) {
const images = funnel(join(dataDirectory, 'images'), {
destDir: 'images'
});
trees.push(images);
}
return BroccoliMergeTrees(trees);
}
};