forked from apiaryio/mson-zoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.js
27 lines (23 loc) · 796 Bytes
/
generate.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
var drafter = require('drafter.js');
var fs = require('fs');
var path = require('path');
var SAMPLES_PATH = path.join(__dirname, 'samples');
var PARSED_PATH = path.join(__dirname, 'samples-parsed');
fs.readdirSync(SAMPLES_PATH).map(function (filePath) {
var mson = fs.readFileSync(path.join(SAMPLES_PATH, filePath), 'utf8');
var apib = '# My API\n# Data Structures\n';
if (mson[0] !== '#') {
apib += '# Example\n';
}
apib += mson;
console.log('Processing ' + filePath);
var result = drafter.parseSync(apib);
var structures = result.content[0].content[0].content.map(function (struct) {
return struct.content[0];
});
fs.writeFileSync(
path.join(PARSED_PATH, filePath.replace('.md', '.json')),
JSON.stringify(structures, null, 2) + '\n',
'utf8'
);
});