Skip to content

Commit 18052b3

Browse files
authored
Merge pull request #26 from vitwit/rewrite
cli now takes one more param `--output` to specify path of output folder, default is root of current directory
2 parents 44dd5f5 + 9e3ca0e commit 18052b3

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ Below are the list of parameters available for node cli config while generating
3131
| `--base-url` | `-b` | base url of your application (API endpoint), will be passed axios instance | required |
3232
| `--name` | `-n` | it will be name of generated sdk class | optional |
3333
| `--version` | `-v` | version of sdk | optional |
34-
| `--required-headers` | `-r` | requirdHeaders params will berequired to pass when initiate the sdk class on frontend |
35-
| `--optional-headers` | `-o` | |
36-
37-
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.
38-
34+
| `--requiredHeaders` | `-r` | requirdHeaders params will berequired to pass when initiate the sdk class on frontend |
35+
| `--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.|
36+
|`--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 | |
3937
```js //usage
4038
const mySDK = new MySDK({
4139
MandatoryHeader1: "Header1Value",

src/cli.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function parseArgumentsIntoOptions(rawArgs) {
2222
"--base-url": String,
2323
"--required-headers": [String],
2424
"--optional-headers": [String],
25+
"--output": String,
2526
"--help": Boolean,
2627
// Aliases
2728
"-f": "--json-file",
@@ -60,7 +61,8 @@ export function parseArgumentsIntoOptions(rawArgs) {
6061
baseUrl: args["--base-url"],
6162
version: args["--version"],
6263
jsonFile: args["--json-file"],
63-
jsFile: args["--js-file"]
64+
jsFile: args["--js-file"],
65+
output: args["--output"]
6466
};
6567
}
6668

src/code-strings/sdk-strings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ ${
1818
1919
export default class ${toTitleCase(sdkName)} {
2020
constructor( headersObj ={}) {${
21-
version ? "\n this.version =" : ""
22-
}'${version}'
21+
version ? "\n this.version =" + "'" + version + "'" : ""
22+
}
2323
this.requiredHeaders = '${requiredHeaders}';
2424
this.optionalHeaders = '${optionalHeaders}';
2525
this.name = "${sdkName}";
@@ -123,7 +123,7 @@ export default class ${toTitleCase(sdkName)} {
123123
}
124124
// intercept response
125125
interceptResponse(cb) {
126-
// just want to make user provide one callback,so mergin to callbacks
126+
// just want to make user provide only one callback,so merging two callbacks
127127
const cb1 = r => cb(r);
128128
const cb2 = e => cb(undefined, e);
129129
this.axiosInstance.interceptors.response.use(cb1, cb2);

src/codgen.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class CodeGen {
2424
requiredHeaders = [],
2525
optionalHeaders = [],
2626
rawCliArgs,
27+
output,
2728
//
2829
apiMethodSignatureString = functionSignature,
2930
sdkClassStartString = stringOne,
@@ -86,7 +87,7 @@ export class CodeGen {
8687
};
8788

8889
//
89-
this.dirPathForGeneratedSdk = "src/sdk";
90+
this.dirPathForGeneratedSdk = output ? output + '/sdk' : "sdk"
9091
}
9192

9293
justBeforeLoopingOverJson() {
@@ -107,6 +108,8 @@ export class CodeGen {
107108

108109
boomBoomGenerateTheFiles() {
109110
if (!fs.existsSync(this.dirPathForGeneratedSdk)) {
111+
console.log('directory not exist')
112+
110113
fs.mkdirSync(this.dirPathForGeneratedSdk);
111114
}
112115

src/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ export const printManPage = () => {
8383
8484
--baseUrl: String
8585
86-
--requiredHeaders: [String] --requiredHeaders token,key,account or --requiredHeaders=token,key,account
86+
--requiredHeaders: [String] required headers token,key,account or --requiredHeaders=token,key,account
8787
88+
--output: String output dir path
89+
8890
--optionalHeaders: [String]
8991
9092
--help: Boolean

0 commit comments

Comments
 (0)