-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Enable new and old conversion
- renames standard convert to convert-classic - updates the existing convert to call new updated composable version
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 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,88 @@ | ||
import commandLineUsage from 'command-line-usage'; | ||
import {Section} from 'command-line-usage'; | ||
import minimist from 'minimist'; | ||
import path from 'path'; | ||
import {AnyAzureObject} from '../conversion/azure'; | ||
import {AzureConverter} from '../conversion/azure/azure_converter'; | ||
|
||
import {fail, handleError, succeed} from '../utilities'; | ||
import fs from 'fs'; | ||
import * as yaml from 'js-yaml'; | ||
|
||
function main() { | ||
const args = minimist(process.argv.slice(2)); | ||
|
||
if (args.h || args.help) { | ||
showUsage(); | ||
return succeed(false); | ||
} | ||
|
||
if (args._.length !== 2) { | ||
return fail('Error: expected <azure.json> and <labyrinth.yaml> files.'); | ||
} | ||
|
||
try { | ||
const infile = args._[0]; | ||
const outfile = args._[1]; | ||
console.log(`Azure resource graph input file: ${infile}`); | ||
console.log(`Labyrinth graph output file: ${outfile}`); | ||
const text = fs.readFileSync(infile, 'utf8'); | ||
const root = JSON.parse(text) as AnyAzureObject[]; | ||
const converter = new AzureConverter(); | ||
const graph = converter.Convert(root); | ||
const yamlText = yaml.dump(graph); | ||
fs.writeFileSync(outfile, yamlText, 'utf8'); | ||
|
||
console.log('Conversion complete.'); | ||
} catch (e) { | ||
handleError(e); | ||
} | ||
|
||
return succeed(true); | ||
} | ||
|
||
function showUsage() { | ||
const program = path.basename(process.argv[1]); | ||
|
||
const usage: Section[] = [ | ||
{ | ||
header: 'Azure resource graph conversion tool', | ||
content: | ||
'Utility for generating Labyrinth graph from an Azure resource graph.', | ||
}, | ||
{ | ||
header: 'Usage', | ||
content: [ | ||
`node ${program} {underline <azure.json>} {underline <labyrinth.yaml>} [...options]`, | ||
], | ||
}, | ||
{ | ||
header: 'Required Parameters', | ||
content: [ | ||
{ | ||
name: '{underline <azure.json>}', | ||
summary: 'Path to a JSON Azure resource graph.', | ||
}, | ||
{ | ||
name: '{underline <labyrinth.yaml>}', | ||
summary: 'Path to output file.', | ||
}, | ||
], | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: [ | ||
{ | ||
name: 'help', | ||
alias: 'h', | ||
description: 'Display help message.', | ||
type: Boolean, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
console.log(commandLineUsage(usage)); | ||
} | ||
|
||
main(); |
File renamed without changes.