Skip to content
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

feat(WIP): rebuild #491

Closed
wants to merge 7 commits into from
Closed

feat(WIP): rebuild #491

wants to merge 7 commits into from

Conversation

climba03003
Copy link
Member

@climba03003 climba03003 commented May 27, 2022

Fixes #194
This rebuild the CLI functionality from scratch using @oclif/core.
Currently, I need some helps on the Github Actions. Which stale forever when I run the test.

  1. For generate command, plugin still pending to do.
  2. For start command, I removed some of the option since it is duplicated from export option.

Notable Change

  1. It is using TypeScript currently, as I am more familiar with the assist of typings.
  2. help and readme is auto generated.
  3. options now autoload.

How to Test

  1. Clone the Repo
  2. Install dependency
  3. Build the source using npm run build.
  4. node bin/run <command>

Checklist

@climba03003 climba03003 changed the title feat: rebuild feat(WIP): rebuild May 27, 2022
dependabot bot added 2 commits May 30, 2022 07:43
Bumps [yargs-parser](https://github.com/yargs/yargs-parser) from 20.2.9 to 21.0.1.
- [Release notes](https://github.com/yargs/yargs-parser/releases)
- [Changelog](https://github.com/yargs/yargs-parser/blob/main/CHANGELOG.md)
- [Commits](yargs/yargs-parser@yargs-parser-v20.2.9...yargs-parser-v21.0.1)

---
updated-dependencies:
- dependency-name: yargs-parser
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [del-cli](https://github.com/sindresorhus/del-cli) from 3.0.1 to 4.0.1.
- [Release notes](https://github.com/sindresorhus/del-cli/releases)
- [Commits](sindresorhus/del-cli@v3.0.1...v4.0.1)

---
updated-dependencies:
- dependency-name: del-cli
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
"pack": "oclif manifest && oclif readme",
"postpack": "shx rm -f oclif.manifest.json",
"preunit": "npm run pack",
"unit": "tap \"test/**/*.test.ts\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to go for tap here? E. g. mocha has way wider mainstream usage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tap is used through out the whole organization. So, it would be the first priority one.
mocha and jest can be added, but it needs somebody effort.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a difference between internal and external use, no? CLI is not intended to be used primarily internally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using united test framework inside the organization (fastify) have some advantages. Developer inside the organization do not need to learn multiple test framework.

There is a difference between internal and external use, no?

I think it would be a long discussion on test framework topic.

"shx": "^0.3.4",
"tap": "^16.2.0",
"ts-node": "^10.7.0",
"typescript": "~4.4.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty old

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ~4.4.0 just because of eslint and ts-standard.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts-standard seems to be barely maintained, are we sure we don't want to rely on something more actively supported? being locked into old TS is really not great

Copy link
Member Author

@climba03003 climba03003 Jun 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts-standard seems to be barely maintained, are we sure we don't want to rely on something more actively supported?

In here, I would like to share the same style with other packages. I am aware of ts-standard is leak of maintaince, but it does the job right now.
Currently, I am just waiting for https://github.com/standard/eslint-config-standard-with-typescript publish.

In my projects, I bumped the typescript version without problem. It only gives me warning of unsupported typescript.
As a tools that will be widely used, I don't think this warning is acceptable and I will wait for the update in standard first.

Object.assign(answer, await prompt([
{ type: 'list', name: 'language', message: 'Which language will you use?', default: 'JavaScript', choices: ['JavaScript', 'TypeScript'] },
{ type: 'list', name: 'lint', message: 'Which linter would you like to use?', default: this.questionLintDefault, choices: this.questionLintChoices },
{ type: 'list', name: 'test', message: 'Which test framework would you like to use?', default: 'tap', choices: ['tap'] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would default to Mocha here


if (this.shouldOverwrite) this.questionOverwriteValidate(answer.overwrite)

Object.assign(answer, await prompt([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having prettier somewhere might be helpful too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard or eslint already does it's job.

}
if (answer.language === 'TypeScript') {
scripts.test = 'tap "test/**/*.test.ts" --ts'
scripts.start = 'fastify start -r ts-node/register -l info app.js'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be prod-ready start? should it be using ts-node then? no command to build & run?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it needs build command.
It is doubt-able the needs for running in node directly because some of the detail for starting server is hide inside the CLI.


export function computeDependencies (_answer: any, pkg: any): { [key: string]: string } {
const dependencies: any = {}
dependencies['@fastify/autoload'] = pkg.dependencies['@fastify/autoload']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to include autoload by default? It makes following structure of the application harder. And I wonder what are the performance implications for large projects.

Copy link
Member Author

@climba03003 climba03003 Jun 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to include autoload by default?

For this question, I don't know. I added it just because the previous version use @fastify/autoload.
I am the one against using @fastify/auteload for beginner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcollina Thoughts? Should we drop autoload from default CLI?

"compilerOptions": {
"lib": ["ESNext"],
"module": "CommonJS",
"target": "ES2018",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing ES-version based target with Node-version based template import from TypeScript lib might be more convenient for backend

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version before, it using fastify-tsconfig and it hide all the options from user.
Using the official template face the same problem.

}

export function computeDependencies (_answer: any, pkg: any): { [key: string]: string } {
const dependencies: any = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add some optional, commonly used libs as well, such as fastify-dotenv, fastify-helmet, fastify-healthcheck, fastify-awilix (for DI).


await fastify.register(entryPlugin, { prefix: options.prefix })

await fastify.listen({ port: options.port, host: options.address })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coupling server startup to app definition is not ideal. what if I need app instance for my tests (using app.inject), but I don't want the overhead of starting/stopping server?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can look at the current test which provide the function to create fastify instance.

dependabot bot and others added 4 commits June 6, 2022 07:35
Bumps [help-me](https://github.com/mcollina/help-me) from 3.0.0 to 4.0.0.
- [Release notes](https://github.com/mcollina/help-me/releases)
- [Commits](https://github.com/mcollina/help-me/commits/v4.0.0)

---
updated-dependencies:
- dependency-name: help-me
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@simoneb
Copy link
Contributor

simoneb commented Sep 6, 2022

is this PR going anywhere?

@climba03003
Copy link
Member Author

climba03003 commented Sep 6, 2022

is this PR going anywhere?

Yes, I need some GitHub experts to help me on the GitHub Actions.
The test stale on GitHub Actions but works on local machine.

Moreover, I need more feedback on how the template should look like.

@simoneb
Copy link
Contributor

simoneb commented Sep 6, 2022

as far as I can see there are no checks being run in gh actions in the PR. see the checks tab, it says 0. as for the structure, my wild guess is that landing a PR with 150 changes files will be challenging

@climba03003
Copy link
Member Author

climba03003 commented Sep 6, 2022

as far as I can see there are no checks being run in gh actions in the PR. see the checks tab, it says 0.

I run it before and I see it stale forever. Then, I removed the ci files.

as for the structure, my wild guess is that landing a PR with 150 changes files will be challenging

It is a complete rewrite. So, it will be large different anyway.

@simoneb
Copy link
Contributor

simoneb commented Sep 6, 2022

ok. well without seeing the output of ci hard to say what might be the cause

@climba03003
Copy link
Member Author

climba03003 commented Sep 6, 2022

ok. well without seeing the output of ci hard to say what might be the cause

Here is the clean repo.
https://github.com/kaka-repo/fastify-cli

You can check the CI in here. I have push the CI file again for testing.
https://github.com/kaka-repo/fastify-cli/runs/8204969713

I may need some update before you can see the actual error.

@simoneb
Copy link
Contributor

simoneb commented Sep 6, 2022

that's not a hang. the operation was canceled because another job failed https://github.com/kaka-repo/fastify-cli/runs/8204970017?check_suite_focus=true

@climba03003
Copy link
Member Author

that's not a hang. the operation was canceled because another job failed https://github.com/kaka-repo/fastify-cli/runs/8204970017?check_suite_focus=true

Here is the hanging one https://github.com/kaka-repo/fastify-cli/runs/8205522639?check_suite_focus=true

@sinedied
Copy link
Contributor

I know it's a bit late for this given the work already done, but I'm a bit sad to see this change as the CLI was previously quite fast to install and lightweight: not trying to start a debate regarding features here, but oclif is quite heavy and brings in 92 (!) dependencies just on its core: https://npmgraph.js.org/?q=%40oclif%2Fcore
For the sake of comparison, commander brings similar benefits than oclif, with no added dependencies: https://npmgraph.js.org/?q=commander

Just sharing my maintainer experience here, but besides the bloat, added dependencies (even transitive ones) adds burden to the maintainers because of frequent updates and potential security issues.

@arthurfiorette
Copy link

Hey @climba03003, @sinedied. Any updates here?

Oclif would be an amazing feature! We know that oclif can be "bloated", however, the DX features it brings make it so valuable. Autocompletion of commands, ability to add plugins, cli validation and many other things that previously would have to be done manually will now be generated by oclif for us.

This will drastically reduce the amount of bugs to fix and code we would have to write.

@climba03003 climba03003 mentioned this pull request Jul 5, 2024
2 tasks
@jean-michelet
Copy link
Contributor

jean-michelet commented Jul 6, 2024

I think we should give it another try, maybe starting a new clean PR.

These utilities have proved their worth and will be well received by people migrating from other languages frameworks who use them a lot.

The main problem is CI, right?

@climba03003
Copy link
Member Author

The main problem is CI, right?

Yes, at least from last try. It never been able to works on Github Actions.
But works properly on local machines.

If anyone want a try or another PR.
He / She should use https://nodejs.org/docs/latest/api/util.html#utilparseargsconfig instead.
Then, in combine with inquirer

@jean-michelet
Copy link
Contributor

Should we start by increasing code coverage or focus on this feature first?
Seems like it would break some stuff, we could focus on coverage later?

@climba03003
Copy link
Member Author

Focus on implementation first, before caring on the test coverage.

@climba03003
Copy link
Member Author

Replaced by #743

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use oclif as cli framework
7 participants