xref: /OpenGrok/dev/parse.js (revision 193b22045ae1ba0a41d8ba357cf20f323aac284e)
1*193b2204SVladimir Kotalvar drafter = require('drafter');
2*193b2204SVladimir Kotalvar fs = require('fs');
3*193b2204SVladimir Kotal
4*193b2204SVladimir Kotalnew Promise(function(resolve, reject) {
5*193b2204SVladimir Kotal        fs.readFile('apiary.apib', 'utf8', (error, data) => {
6*193b2204SVladimir Kotal            if (error) {
7*193b2204SVladimir Kotal                console.error(error);
8*193b2204SVladimir Kotal                reject(1);
9*193b2204SVladimir Kotal            }
10*193b2204SVladimir Kotal
11*193b2204SVladimir Kotal            resolve(data);
12*193b2204SVladimir Kotal        });
13*193b2204SVladimir Kotal    })
14*193b2204SVladimir Kotal    .then(function(data) {
15*193b2204SVladimir Kotal        return new Promise((resolve, reject) => {
16*193b2204SVladimir Kotal            drafter.parse(data, function(error, result) {
17*193b2204SVladimir Kotal                if (error) {
18*193b2204SVladimir Kotal                    console.log(error);
19*193b2204SVladimir Kotal                    resolve(1);
20*193b2204SVladimir Kotal                    return;
21*193b2204SVladimir Kotal                } else {
22*193b2204SVladimir Kotal                    for (x in result.content) {
23*193b2204SVladimir Kotal                        var d = result.content[x];
24*193b2204SVladimir Kotal                        // console.log(d);
25*193b2204SVladimir Kotal                        if (d['element'] != 'category') {
26*193b2204SVladimir Kotal                            console.log('Error:\n', d);
27*193b2204SVladimir Kotal                            resolve(1);
28*193b2204SVladimir Kotal                            return;
29*193b2204SVladimir Kotal                        }
30*193b2204SVladimir Kotal                    }
31*193b2204SVladimir Kotal                }
32*193b2204SVladimir Kotal
33*193b2204SVladimir Kotal                console.log("Blueprint check passed");
34*193b2204SVladimir Kotal                resolve(0);
35*193b2204SVladimir Kotal            });
36*193b2204SVladimir Kotal        });
37*193b2204SVladimir Kotal    })
38*193b2204SVladimir Kotal    .then(process.exit)
39*193b2204SVladimir Kotal    .catch(process.exit);