-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from joolfe/develop
Add CLI implementation
- Loading branch information
Showing
14 changed files
with
483 additions
and
56 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
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 |
---|---|---|
|
@@ -39,4 +39,6 @@ node_modules/* | |
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.cache | ||
|
||
.idea |
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 @@ | ||
{ | ||
"cSpell.words": [ | ||
"execa" | ||
] | ||
} |
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
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,50 @@ | ||
#!/usr/bin/env node | ||
|
||
const { program } = require('commander') | ||
const { version } = require('../package.json') | ||
const postmanToOpenApi = require('../lib') | ||
const { promises: { readFile } } = require('fs') | ||
|
||
const additionalHelp = ` | ||
Example calls: | ||
$ p2o ./path/to/PostmantoCollection.json -f ./path/to/result.yml -o ./path/to/options.json | ||
For more info about how to use it visit our documentation in <https://joolfe.github.io/postman-to-openapi/> | ||
` | ||
|
||
program | ||
.version(version, '-v, --vers', 'Output the current version of the library.') | ||
.name('p2o') | ||
.usage('<collection> [options]') | ||
.addHelpText('after', additionalHelp) | ||
.arguments('<collection>') | ||
.description('Transform a postman collection to OpenAPI specification yml.', { | ||
collection: 'Relative path to the Postman collection json file' | ||
}) | ||
.option('-f, --file <file>', 'Relative path to the file where result will be saved. If empty result will be returned by cli.') | ||
.option('-o, --options <options>', 'Relative path to json file that contain the optional parameters for the transformation.') | ||
.action(async (collection, { file, options }, command) => { | ||
try { | ||
const parsedOptions = await parseOptions(options) | ||
const result = await postmanToOpenApi(collection, file, parsedOptions) | ||
console.info(result) | ||
} catch (err) { | ||
throw new Error(err) | ||
} | ||
}) | ||
|
||
program | ||
.parseAsync() | ||
.catch(err => { | ||
process.exitCode = 1 | ||
console.error(err.message) | ||
}) | ||
|
||
async function parseOptions (optionsPath) { | ||
try { | ||
return optionsPath ? JSON.parse(await readFile(optionsPath)) : {} | ||
} catch (err) { | ||
throw new Error(`invalid "options" parameter -> ${err.message}`) | ||
} | ||
} |
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
Oops, something went wrong.