Skip to content

Commit

Permalink
FEATURE: Enable new and old conversion
Browse files Browse the repository at this point in the history
- renames standard convert to convert-classic
- updates the existing convert to call new updated composable version
  • Loading branch information
ericmaino committed Feb 12, 2021
1 parent af6bbaa commit aa6237f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/apps/convert .ts
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.

0 comments on commit aa6237f

Please sign in to comment.