From b3b27a4630dfd75c43f3e58239602505362877f0 Mon Sep 17 00:00:00 2001 From: Yash Rathore Date: Mon, 30 Sep 2019 13:22:24 +0530 Subject: [PATCH] output param added --- README.md | 6 ++---- src/cli.js | 4 +++- src/code-strings/sdk-strings.js | 6 +++--- src/codgen.js | 5 ++++- src/utils.js | 4 +++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b9829db..126b4e7 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,8 @@ Below are the list of parameters available for node cli config while generating | `--name` | `-n` | it will be name of generated sdk class | optional | | `--version` | `-v` | version of sdk | optional | | `--requiredHeaders` | `-r` | requirdHeaders params will berequired to pass when initiate the sdk class on frontend | -| `--optionalHeaders` | `-o` | | - -Any other parameters passed will be added to configs.headers which will be passed to axios instance. All the headers will be used as default headers for every request. - +| `--optionalHeaders` | `-o` | | Any other parameters passed will be added to configs.headers which will be passed to axios instance. All the headers will be used as default headers for every request.| +|`--output`| | path of directory you want to store generated sdk folder in. for example to store in src of current directory pass `--output src`,for current dir's sibling folder's src `--output ../siblingDir/src`, don't pass any trailing slash,wrap in quotes if path contains escape character | | ```js //usage const mySDK = new MySDK({ MandatoryHeader1: "Header1Value", diff --git a/src/cli.js b/src/cli.js index a729065..e6b8669 100644 --- a/src/cli.js +++ b/src/cli.js @@ -22,6 +22,7 @@ export function parseArgumentsIntoOptions(rawArgs) { "--base-url": String, "--required-headers": [String], "--optional-headers": [String], + "--output": String, "--help": Boolean, // Aliases "-f": "--json-file", @@ -60,7 +61,8 @@ export function parseArgumentsIntoOptions(rawArgs) { baseUrl: args["--base-url"], version: args["--version"], jsonFile: args["--json-file"], - jsFile: args["--js-file"] + jsFile: args["--js-file"], + output: args["--output"] }; } diff --git a/src/code-strings/sdk-strings.js b/src/code-strings/sdk-strings.js index ad05cf1..9859528 100644 --- a/src/code-strings/sdk-strings.js +++ b/src/code-strings/sdk-strings.js @@ -18,8 +18,8 @@ ${ export default class ${toTitleCase(sdkName)} { constructor( headersObj ={}) {${ - version ? "\n this.version =" : "" - }'${version}' + version ? "\n this.version =" + "'" + version + "'" : "" + } this.requiredHeaders = '${requiredHeaders}'; this.optionalHeaders = '${optionalHeaders}'; this.name = "${sdkName}"; @@ -123,7 +123,7 @@ export default class ${toTitleCase(sdkName)} { } // intercept response interceptResponse(cb) { - // just want to make user provide one callback,so mergin to callbacks + // just want to make user provide only one callback,so merging two callbacks const cb1 = r => cb(r); const cb2 = e => cb(undefined, e); this.axiosInstance.interceptors.response.use(cb1, cb2); diff --git a/src/codgen.js b/src/codgen.js index a0d75ae..fad6e76 100644 --- a/src/codgen.js +++ b/src/codgen.js @@ -24,6 +24,7 @@ export class CodeGen { requiredHeaders = [], optionalHeaders = [], rawCliArgs, + output, // apiMethodSignatureString = functionSignature, sdkClassStartString = stringOne, @@ -86,7 +87,7 @@ export class CodeGen { }; // - this.dirPathForGeneratedSdk = "src/sdk"; + this.dirPathForGeneratedSdk = output ? output + '/sdk' : "sdk" } justBeforeLoopingOverJson() { @@ -107,6 +108,8 @@ export class CodeGen { boomBoomGenerateTheFiles() { if (!fs.existsSync(this.dirPathForGeneratedSdk)) { + console.log('directory not exist') + fs.mkdirSync(this.dirPathForGeneratedSdk); } diff --git a/src/utils.js b/src/utils.js index 63310d4..daec1c9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -83,8 +83,10 @@ export const printManPage = () => { --baseUrl: String - --requiredHeaders: [String] --requiredHeaders token,key,account or --requiredHeaders=token,key,account + --requiredHeaders: [String] required headers token,key,account or --requiredHeaders=token,key,account + --output: String output dir path + --optionalHeaders: [String] --help: Boolean