-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Prettiered and linted * Update package.json * Update package.json
- Loading branch information
Showing
8 changed files
with
128 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 12 | ||
}, | ||
"rules": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
// List of extensions which should be recommended for users of this workspace. | ||
"recommendations": [ | ||
"hbenl.vscode-mocha-test-adapter", | ||
"hbenl.vscode-test-explorer", | ||
"redhat.vscode-xml" | ||
] | ||
} | ||
"recommendations": [ | ||
"bierner.github-markdown-preview", | ||
"dbaeumer.vscode-eslint", | ||
"eg2.vscode-npm-script", | ||
"esbenp.prettier-vscode", | ||
"hbenl.vscode-mocha-test-adapter", | ||
"hbenl.vscode-test-explorer", | ||
"redhat.vscode-xml" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,68 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
"use strict"; | ||
|
||
//console.dir(argv); | ||
|
||
const csdl = require('odata-csdl'); | ||
const lib = require('./csdl2markdown'); | ||
const minimist = require('minimist'); | ||
const fs = require('fs'); | ||
const csdl = require("odata-csdl"); | ||
const lib = require("./csdl2markdown"); | ||
const minimist = require("minimist"); | ||
const fs = require("fs"); | ||
|
||
var unknown = false; | ||
|
||
var argv = minimist(process.argv.slice(2), { | ||
string: ["t", "target"], | ||
boolean: ["h", "help"], | ||
alias: { | ||
h: "help", | ||
t: "target" | ||
}, | ||
unknown: (arg) => { | ||
if (arg.substring(0, 1) == '-') { | ||
console.error('Unknown option: ' + arg); | ||
unknown = true; | ||
return false; | ||
} | ||
string: ["t", "target"], | ||
boolean: ["h", "help"], | ||
alias: { | ||
h: "help", | ||
t: "target", | ||
}, | ||
unknown: (arg) => { | ||
if (arg.substring(0, 1) == "-") { | ||
console.error("Unknown option: " + arg); | ||
unknown = true; | ||
return false; | ||
} | ||
}, | ||
}); | ||
|
||
if (unknown || argv._.length == 0 || argv.h) { | ||
console.log(`Usage: odata-vocab2md <options> <source file> | ||
console.log(`Usage: odata-vocab2md <options> <source file> | ||
Options: | ||
-h, --help show this info | ||
-t, --target target file (default: source file basename + .md)`); | ||
} else { | ||
//TODO: further input parameters reserved for e.g. referenced CSDL documents | ||
// for (var i = 0; i < argv._.length; i++) { | ||
// convert(argv._[i]); | ||
// } | ||
convert(argv._[0]); | ||
//TODO: further input parameters reserved for e.g. referenced CSDL documents | ||
// for (var i = 0; i < argv._.length; i++) { | ||
// convert(argv._[i]); | ||
// } | ||
convert(argv._[0]); | ||
} | ||
|
||
function convert(source) { | ||
if (!fs.existsSync(source)) { | ||
console.error('Source file not found: ' + source); | ||
return; | ||
} | ||
if (!fs.existsSync(source)) { | ||
console.error("Source file not found: " + source); | ||
return; | ||
} | ||
|
||
const text = fs.readFileSync(source, 'utf8'); | ||
//TODO: for JSON input use parser that produces line numbers | ||
const json = text.startsWith('<') ? csdl.xml2json(text, true) : JSON.parse(text); | ||
if (json.$Version < '4.0') { | ||
console.error('Only OData Version 4.0 or greater is supported'); | ||
return; | ||
} | ||
const text = fs.readFileSync(source, "utf8"); | ||
//TODO: for JSON input use parser that produces line numbers | ||
const json = text.startsWith("<") | ||
? csdl.xml2json(text, true) | ||
: JSON.parse(text); | ||
if (json.$Version < "4.0") { | ||
console.error("Only OData Version 4.0 or greater is supported"); | ||
return; | ||
} | ||
|
||
const target = argv.target || (source.lastIndexOf('.') <= 0 ? source : source.substring(0, source.lastIndexOf('.'))) + '.md'; | ||
console.log(target); | ||
const target = | ||
argv.target || | ||
(source.lastIndexOf(".") <= 0 | ||
? source | ||
: source.substring(0, source.lastIndexOf("."))) + ".md"; | ||
console.log(target); | ||
|
||
const markdown = lib.csdl2markdown(source, json); | ||
const markdown = lib.csdl2markdown(source, json); | ||
|
||
fs.writeFileSync(target, markdown.join('\n')); | ||
} | ||
fs.writeFileSync(target, markdown.join("\n")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,69 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
"use strict"; | ||
|
||
const csdl = require('odata-csdl'); | ||
const lib = require('./csdl2markdown'); | ||
const fs = require('fs'); | ||
const csdl = require("odata-csdl"); | ||
const lib = require("./csdl2markdown"); | ||
const fs = require("fs"); | ||
|
||
const vocabFolder = './vocabularies/'; | ||
const exampleFolder = './examples/'; | ||
const vocabFolder = "./vocabularies/"; | ||
const exampleFolder = "./examples/"; | ||
|
||
const vocabs = {}; | ||
|
||
fs.readdirSync(vocabFolder).filter(fn => fn.endsWith('.xml')).forEach(filename => { | ||
const vocab = filename.substring(0, filename.lastIndexOf('.')); | ||
console.log(vocab + '.json'); | ||
fs.readdirSync(vocabFolder) | ||
.filter((fn) => fn.endsWith(".xml")) | ||
.forEach((filename) => { | ||
const vocab = filename.substring(0, filename.lastIndexOf(".")); | ||
console.log(vocab + ".json"); | ||
|
||
const xml = fs.readFileSync(vocabFolder + filename, 'utf8'); | ||
const xml = fs.readFileSync(vocabFolder + filename, "utf8"); | ||
const json = csdl.xml2json(xml, true); | ||
|
||
vocabs[filename] = json | ||
vocabs[filename] = json; | ||
|
||
// swap URLs of latest-version and alternate links | ||
const links = json[vocab]['@Core.Links']; | ||
const latestVersion = links.findIndex(l => l.rel == 'latest-version'); | ||
const alternate = links.findIndex(l => l.rel == 'alternate'); | ||
const links = json[vocab]["@Core.Links"]; | ||
const latestVersion = links.findIndex((l) => l.rel == "latest-version"); | ||
const alternate = links.findIndex((l) => l.rel == "alternate"); | ||
if (latestVersion != -1 && alternate != -1) { | ||
links[latestVersion].rel = 'alternate'; | ||
links[alternate].rel = 'latest-version'; | ||
links[latestVersion].rel = "alternate"; | ||
links[alternate].rel = "latest-version"; | ||
} | ||
fs.writeFileSync(vocabFolder + vocab + '.json', JSON.stringify(json, omitLineNumbers, 4)); | ||
}); | ||
fs.writeFileSync( | ||
vocabFolder + vocab + ".json", | ||
JSON.stringify(json, omitLineNumbers, 4) | ||
); | ||
}); | ||
|
||
console.log(); | ||
|
||
for (const [filename, csdl] of Object.entries(vocabs)) { | ||
const vocab = filename.substring(0, filename.lastIndexOf('.')); | ||
console.log(vocab + '.md'); | ||
const vocab = filename.substring(0, filename.lastIndexOf(".")); | ||
console.log(vocab + ".md"); | ||
|
||
const markdown = lib.csdl2markdown(filename, csdl, vocabs); | ||
fs.writeFileSync(vocabFolder + vocab + '.md', markdown.join('\n')); | ||
const markdown = lib.csdl2markdown(filename, csdl, vocabs); | ||
fs.writeFileSync(vocabFolder + vocab + ".md", markdown.join("\n")); | ||
} | ||
|
||
console.log(); | ||
|
||
fs.readdirSync(exampleFolder).filter(fn => fn.endsWith('.xml')).forEach(xmlfile => { | ||
const example = xmlfile.substring(0, xmlfile.lastIndexOf('.')); | ||
console.log(example + '.json'); | ||
fs.readdirSync(exampleFolder) | ||
.filter((fn) => fn.endsWith(".xml")) | ||
.forEach((xmlfile) => { | ||
const example = xmlfile.substring(0, xmlfile.lastIndexOf(".")); | ||
console.log(example + ".json"); | ||
|
||
const xml = fs.readFileSync(exampleFolder + xmlfile, 'utf8'); | ||
const xml = fs.readFileSync(exampleFolder + xmlfile, "utf8"); | ||
const json = csdl.xml2json(xml, false); | ||
fs.writeFileSync(exampleFolder + example + '.json', JSON.stringify(json, null, 4)); | ||
}); | ||
fs.writeFileSync( | ||
exampleFolder + example + ".json", | ||
JSON.stringify(json, null, 4) | ||
); | ||
}); | ||
|
||
function omitLineNumbers(key, value) { | ||
if (key.endsWith('@parser.line')) { | ||
return undefined; | ||
} | ||
return value; | ||
} | ||
if (key.endsWith("@parser.line")) { | ||
return undefined; | ||
} | ||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"env": { | ||
"mocha": true | ||
} | ||
} |