-
Notifications
You must be signed in to change notification settings - Fork 167
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
Feature/support generate swagge for typescript (#608) #641
Feature/support generate swagge for typescript (#608) #641
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending a PR! I don't think we should add ts-node
as a dependency :(, as it's too opinionated and subjected to TypeScript semver rules.
Note that the generator does not use ts-node
either.
I would recommend you try a different approach:
- load
tsconfig.json
and check theoutDir
folder - load the application from there
- if
outDir
is not built, error telling the user to build the folder - adjust the typescript template to add a "swagger" script
There seems to be quite a few linting issues that are spurious. Did you enable prettier format-on-save for all files in VSCode?
util.js
Outdated
requireFastifyForModule, | ||
showHelpForCommand, | ||
requireServerPluginFromPath | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
util.js
Outdated
fs.existsSync('/run/secrets/kubernetes.io/serviceaccount/token') | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
@@ -94,14 +118,23 @@ function showHelpForCommand (commandName) { | |||
console.log(fs.readFileSync(helpFilePath, 'utf8')) | |||
exit() | |||
} catch (e) { | |||
exit(`unable to get help for command "${commandName}"`) | |||
exit(`unable to get help for command '${commandName}'`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
util.js
Outdated
throw new Error( | ||
'Async/Await plugin function should contain 2 arguments. ' + | ||
'Refer to documentation for more information.' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
util.js
Outdated
throw new Error(`fastify-cli cannot import plugin at '${resolvedModulePath}'. Your version of node does not support ES modules. To fix this error upgrade to Node 14 or use CommonJS syntax.`) | ||
throw new Error( | ||
`fastify-cli cannot import plugin at '${resolvedModulePath}'. Your version of node does not support ES modules. To fix this error upgrade to Node 14 or use CommonJS syntax.` | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
util.js
Outdated
throw new Error(`${resolvedModulePath} doesn't exist within ${process.cwd()}`) | ||
throw new Error( | ||
`${resolvedModulePath} doesn't exist within ${process.cwd()}` | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
util.js
Outdated
? 'module' | ||
: commonjsPattern.test(fname) | ||
? 'commonjs' | ||
: packageType) || 'commonjs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
util.js
Outdated
const moduleSupport = semver.satisfies( | ||
process.version, | ||
'>= 14 || >= 12.17.0 < 13.0.0' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
Thanks for the feedback! I appreciate your guidance, and I've already implemented the suggested, regarding the linting issues, I've taken care of them. |
Code LGTM, a test is missing. |
Hello, sorry for make you await, but you can tell me, how test it, i think test is about confirm if genereta ts incluede swagger script |
Yes. I think you should add the required logic in https://github.com/fastify/fastify-cli/blob/master/test/generate-typescript.test.js. I would recommend adding a test similar to fastify-cli/test/generate-typescript.test.js Line 103 in a444cd8
|
Done it, thanks for explain me! |
The test is still missing. You would want to add a new test that calls that new command that you added. |
Checklist
npm run test
andnpm run benchmark
and the Code of conduct