Skip to content

Commit

Permalink
Merge pull request #26 from vitwit/rewrite
Browse files Browse the repository at this point in the history
cli now takes one more param `--output` to specify path of output folder, default is root of current directory
  • Loading branch information
anilcse authored Oct 1, 2019
2 parents 44dd5f5 + 9e3ca0e commit 18052b3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ Below are the list of parameters available for node cli config while generating
| `--base-url` | `-b` | base url of your application (API endpoint), will be passed axios instance | required |
| `--name` | `-n` | it will be name of generated sdk class | optional |
| `--version` | `-v` | version of sdk | optional |
| `--required-headers` | `-r` | requirdHeaders params will berequired to pass when initiate the sdk class on frontend |
| `--optional-headers` | `-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.

| `--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.|
|`--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",
Expand Down
4 changes: 3 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"]
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/code-strings/sdk-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/codgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class CodeGen {
requiredHeaders = [],
optionalHeaders = [],
rawCliArgs,
output,
//
apiMethodSignatureString = functionSignature,
sdkClassStartString = stringOne,
Expand Down Expand Up @@ -86,7 +87,7 @@ export class CodeGen {
};

//
this.dirPathForGeneratedSdk = "src/sdk";
this.dirPathForGeneratedSdk = output ? output + '/sdk' : "sdk"
}

justBeforeLoopingOverJson() {
Expand All @@ -107,6 +108,8 @@ export class CodeGen {

boomBoomGenerateTheFiles() {
if (!fs.existsSync(this.dirPathForGeneratedSdk)) {
console.log('directory not exist')

fs.mkdirSync(this.dirPathForGeneratedSdk);
}

Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18052b3

Please sign in to comment.