forked from rngtng/postman2httpyac
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ad4be
commit 5fb8036
Showing
8 changed files
with
168 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 +1,58 @@ | ||
import { parse } from 'ts-command-line-args'; | ||
import { rootLogger } from './logging'; | ||
|
||
const logger = rootLogger.getSubLogger(); | ||
|
||
export interface IOptions { | ||
sourcePath: string; | ||
targetPath: string; | ||
ignoreHeaders?: string[]; | ||
splitRequests?: boolean, | ||
help?: boolean; | ||
} | ||
|
||
export function parseOptions(): IOptions { | ||
const options = parse<IOptions>({ | ||
sourcePath: { | ||
type: String, alias: 's', optional: true as const, description: 'Path to the exported postman_collection.json' | ||
}, | ||
targetPath: { | ||
type: String, alias: 'd', optional: true as const, description: 'Path to the root directory to output the .http files' | ||
}, | ||
ignoreHeaders: { | ||
type: String, | ||
alias: 'i', | ||
multiple: true, | ||
optional: true as const, | ||
description: 'List of headers to ignore, useful when using default headers. Supports regex patterns', | ||
defaultValue: [] | ||
}, | ||
splitRequests: { | ||
type: Boolean, alias: 'f', optional: true as const, description: 'Determines whether to split requests into separate files [default: true]' | ||
}, | ||
help: { | ||
type: Boolean, optional: true, alias: 'h', description: 'Prints this usage guide' | ||
}, | ||
}, | ||
{ | ||
helpArg: 'help', | ||
headerContentSections: [{ header: 'HttpYac Import', content: 'Converts Postman collections to HttpYac format' }] | ||
}); | ||
|
||
if (options.sourcePath === undefined) { | ||
logger.error('Source path must be supplied with --sourcePath=path'); | ||
process.exit(1); | ||
} | ||
|
||
if (options.targetPath === undefined) { | ||
logger.error('Target path must be supplied with --targetPath=path'); | ||
process.exit(2); | ||
} | ||
|
||
if (options.splitRequests === undefined) { | ||
logger.warn('One file will be created per request'); | ||
options.splitRequests = true; | ||
} | ||
|
||
return options; | ||
} |
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 |
---|---|---|
@@ -1,7 +1,30 @@ | ||
import { IOptions } from './Options'; | ||
import { join } from 'path'; | ||
import { Item } from 'postman-collection'; | ||
|
||
export function sanitize(name: string) { | ||
return name | ||
.toLowerCase() | ||
.replaceAll(' ', '-') | ||
.replaceAll('"', '') | ||
.replaceAll('/', '_'); | ||
} | ||
|
||
export function outputDirectory(options: IOptions, targetPaths: string[]) { | ||
if (options.splitRequests) { | ||
return join(...targetPaths); | ||
} | ||
|
||
return join(...targetPaths.slice(0, -1)); | ||
} | ||
|
||
export function outputPathFor(item: Item, options: IOptions, targetPaths: string[]) { | ||
const directory = join(...targetPaths); | ||
|
||
if (options.splitRequests) { | ||
const filename = `${sanitize(item.name)}.http`; | ||
return join(directory, filename); | ||
} | ||
|
||
return `${directory}.http`; | ||
} |
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,18 @@ | ||
import { Logger, ILogObj } from 'tslog'; | ||
|
||
export const rootLogger = new Logger<ILogObj>({ | ||
prettyLogTemplate: "{{logLevelName}}\t", | ||
prettyLogStyles: { | ||
logLevelName: { | ||
"*": ["bold", "black", "bgWhiteBright", "dim"], | ||
SILLY: ["bold", "white"], | ||
TRACE: ["bold", "whiteBright"], | ||
DEBUG: ["bold", "green"], | ||
INFO: ["bold", "blue"], | ||
WARN: ["bold", "yellow"], | ||
ERROR: ["bold", "red"], | ||
FATAL: ["bold", "redBright"], | ||
} | ||
} | ||
}); | ||
|
Oops, something went wrong.