-
Notifications
You must be signed in to change notification settings - Fork 5
/
generateDocs.js
74 lines (57 loc) · 1.82 KB
/
generateDocs.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
/* eslint import/no-extraneous-dependencies: "off" */
/*
* Generate cspace-public-browser documentation.
*/
import fs from 'fs';
import glob from 'glob';
import jsonFile from 'jsonfile';
/*
* Generate documentation for react-intl messages. This must be done after the npm build script has
* executed, so that messages will have been extracted to build/messages.
*/
const generateMessagesDoc = () => {
const messages = [];
glob.sync('build/messages/**/*.json').forEach((filename) => {
jsonFile.readFileSync(filename).forEach((message) => {
messages.push(message);
});
});
messages.sort((messageA, messageB) => {
const a = messageA.id.toLowerCase();
const b = messageB.id.toLowerCase();
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
const docFile = fs.createWriteStream('docs/configuration/messages.js');
docFile.write('/*\n');
docFile.write(' * This file contains all messages used in cspace-public-browser, to be used as a reference for customization\n');
docFile.write(' * or translation. The default export is an object containing the default messages in the\n');
docFile.write(' * application, keyed by message ID. Messages may be customized by supplying overrides via the\n');
docFile.write(' * messages configuration option.\n');
docFile.write(' */\n\n');
docFile.write('export default {');
messages.forEach((message) => {
const {
id,
description,
defaultMessage,
} = message;
docFile.write('\n');
if (description) {
docFile.write(` // ${description}\n`);
}
docFile.write(' ');
docFile.write(JSON.stringify(id));
docFile.write(': ');
docFile.write(JSON.stringify(defaultMessage));
docFile.write(',\n');
});
docFile.write('}');
docFile.end();
};
generateMessagesDoc();