Skip to content

feat: upgrade to commander.js v8 #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@api-platform/api-doc-parser": "^0.12.0",
"@babel/runtime": "^7.0.0",
"chalk": "^4.1.0",
"commander": "^6.2.1",
"commander": "^8.2.0",
"handlebars": "^4.0.12",
"handlebars-helpers": "^0.10.0",
"isomorphic-fetch": "^3.0.0",
Expand Down
24 changes: 13 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ if (
program.help();
}

const options = program.opts();

const entrypoint =
program.args[0] || process.env.API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT;
const outputDirectory =
Expand All @@ -64,29 +66,29 @@ const entrypointWithSlash = entrypoint.endsWith("/")
? entrypoint
: entrypoint + "/";

const generator = generators(program.generator)({
hydraPrefix: program.hydraPrefix,
templateDirectory: program.templateDirectory,
const generator = generators(options.generator)({
hydraPrefix: options.hydraPrefix,
templateDirectory: options.templateDirectory,
});
const resourceToGenerate = program.resource
? program.resource.toLowerCase()
const resourceToGenerate = options.resource
? options.resource.toLowerCase()
: null;
const serverPath = program.serverPath ? program.serverPath.toLowerCase() : null;
const serverPath = options.serverPath ? options.serverPath.toLowerCase() : null;

const parser = (entrypointWithSlash) => {
const options = {};
if (program.username && program.password) {
if (options.username && options.password) {
const encoded = Buffer.from(
`${program.username}:${program.password}`
`${options.username}:${options.password}`
).toString("base64");
options.headers = new Headers();
options.headers.set("Authorization", `Basic ${encoded}`);
}
if (program.bearer) {
if (options.bearer) {
options.headers = new Headers();
options.headers.set("Authorization", `Bearer ${program.bearer}`);
options.headers.set("Authorization", `Bearer ${options.bearer}`);
}
switch (program.format) {
switch (options.format) {
case "swagger": // deprecated
case "openapi2":
return parseSwaggerDocumentation(entrypointWithSlash);
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2102,11 +2102,16 @@ commander@^4.0.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==

commander@^6.2.0, commander@^6.2.1:
commander@^6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c"
integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==

commander@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.2.0.tgz#37fe2bde301d87d47a53adeff8b5915db1381ca8"
integrity sha512-LLKxDvHeL91/8MIyTAD5BFMNtoIwztGPMiM/7Bl8rIPmHCZXRxmSWr91h57dpOpnQ6jIUqEWdXE/uBYMfiVZDA==

compare-versions@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62"
Expand Down