This repository has been archived by the owner on Sep 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (65 loc) · 2.09 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
(function () {
"use strict";
var fs = require('fs');
var glob = require("glob");
var Q = require('q');
// TODO: Make command line option or similar
var path = 'schemas';
var debug = true;
var globOptions = [];
var schemaFiles = [];
var schemas = [];
// Get all schemas as array of file paths relative to $path
function globPathForSchemas() {
var deferred = Q.defer();
var globPath = path + "/**/*.json-schema";
if (debug) {
console.log('Globbing for files in [' + globPath + ']');
console.log(schemaFiles);
}
glob(globPath, globOptions, function (err, files) {
// TODO: Deal with errors as described here
// If the `nonull` option is set, and nothing
// was found, then files is ["**/*.js"]
// er is an error object or null.
schemaFiles = files;
if (debug) {
console.log('Globbed files');
console.log(schemaFiles);
}
deferred.resolve();
});
return deferred.promise;
}
function getInfoFromSchemas() {
var deferred = Q.defer();
for (var i in schemaFiles) {
extractSchemaDetails(schemaFiles[i]);
}
deferred.resolve();
return deferred.promise;
}
function extractSchemaDetails(schemaFilePath) {
if (debug) {
console.log('Extracting schema details from [' + schemaFilePath + ']');
}
var schema = JSON.parse(fs.readFileSync(schemaFilePath, 'utf8'));
if (debug) {
console.log('Full schema contents as JSON object');
console.log(schema);
}
// Extract schema details
var schemaInfo = {};
if (schema.hasOwnProperty('id')) {
schemaInfo.id = schema.id;
}
schemas.push(schemaInfo);
}
// Run main process
globPathForSchemas()
.then(getInfoFromSchemas)
.then(function() {
console.log('Rencia');
console.log(schemas);
});
}());