Skip to content

Commit

Permalink
Enable run from command line (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner authored Sep 8, 2024
1 parent 5bf413f commit 4c1c2fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
dist
node_modules
solaris
output
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "httpyac-import",
"version": "0.3.3",
"version": "0.3.4",
"description": "CLI to convert Postman collection to httpyac files",
"homepage": "https://github.com/matthewturner/httpyac-import",
"repository": {
Expand All @@ -12,7 +12,7 @@
},
"main": "./src/app.ts",
"bin": {
"httpyac-import": "./bin/httpyac-import.js"
"httpyac-import": "./dist/app.js"
},
"scripts": {
"build": "npx tsc",
Expand Down
20 changes: 11 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /usr/bin/env node

import { writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';
import { Collection, ItemGroup, Item, PropertyList } from 'postman-collection';
import { parse } from 'ts-command-line-args';
Expand All @@ -7,7 +9,7 @@ import { sanitize } from './helpers';
import { RequestDefinitionBuilder } from './RequestDefinitionBuilder';

const args = parse<IOptions>({
sourcePath: {
sourcePath: {
type: String, alias: 's', optional: true as const, description: 'Path to the exported postman_collection.json'
},
targetPath: {
Expand All @@ -21,23 +23,23 @@ const args = parse<IOptions>({
description: 'List of headers to ignore, useful when using default headers. Supports regex patterns',
defaultValue: []
},
help: {
help: {
type: Boolean, optional: true, alias: 'h', description: 'Prints this usage guide'
},
},
{
helpArg: 'help',
headerContentSections: [{ header: 'Postman 2 HttpYac', content: 'Converts Postman collections to HttpYac format' }]
});
{
helpArg: 'help',
headerContentSections: [{ header: 'HttpYac Import', content: 'Converts Postman collections to HttpYac format' }]
});

const sourcePostmanCollectionPath = args.sourcePath.toString();
const sourcePostmanCollection = JSON.parse(readFileSync(sourcePostmanCollectionPath).toString());

const targetPaths = [ args.targetPath ];
const targetPaths = [args.targetPath];

const sourceCollection = new Collection(sourcePostmanCollection);

function processItems(items : PropertyList<Item | ItemGroup<Item>>) {
function processItems(items: PropertyList<Item | ItemGroup<Item>>) {
for (const item of items.all()) {
if (item instanceof Item) {
processItem(item);
Expand All @@ -51,7 +53,7 @@ function processItems(items : PropertyList<Item | ItemGroup<Item>>) {
}
}

function processItem(item : Item) {
function processItem(item: Item) {
const directory = join(...targetPaths);

if (!existsSync(directory)) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"experimentalDecorators": true,
"module": "commonjs",
"target": "ES5",
"outDir": "bin",
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"lib": [
Expand Down

0 comments on commit 4c1c2fc

Please sign in to comment.