Comments (7)
@Junkern I'm a product manager at Heroku where we've been developing oclif. As we're just getting started with the project, I'd be really interested in your feedback and learning more about your use case. Feel free to respond here or drop us a note at [email protected]
from oclif.
by design we do not call any files so we only load the files we need. In a large project, it might take several seconds to create everything.
It sounds like you want an init hook. We should have some docs and a generator for that soon, but for now here is what you need to do:
First add a line like this to declare the hook: https://github.com/heroku/cli/blob/oclif/package.json#L56
(You will want init probably for your usage though, prerun happens later)
Then create a hook file like this: https://github.com/heroku/cli/blob/oclif/src/hooks/prerun/analytics.ts
You can also create your own hooks
from oclif.
reading your message again though, I would probably use a base class here. Init hooks are more for things you want to run on every command. It would work, but you'd likely have to involve some globals. Unfortunately I don't have a great example of setting this up, but I would do something like this:
class MyBaseClass extends Command {
myApiClient = new ApiClient()
}
then in the command:
class extends MyBaseClass {
async run() {
this.myApiClient.doSomething()
}
}
Which does not give you dependency injection though. Maybe https://github.com/thlorenz/proxyquire would be helpful?
from oclif.
A third idea:
class MyBaseClass extends Command {
static apiClient = ApiClient
myApiClient = new MyBaseClass.apiClient()
}
and in the test:
beforeEach(() => {
MyBaseClass.apiClient = MockApiClient
})
Hopefully one of these ideas is helpful. Let me know if you have any ideas how else this might be done!
from oclif.
Thanks for the quick feedback!
I indeed went for the base class scenario. But instead of doing that with static
, I simply but the initialization of the classes I need in all commands into the init()
function. It worked, but I don't know if there are any downsides^^ Just tested it out with static
and that works as well.
from oclif.
so long as you don't need to modify the static property in the test then doing it as an instance property should be fine. The advantage of static is you have access to it in the test if you want to modify it
from oclif.
That makes totally sense! Thanks a lot:)
from oclif.
Related Issues (20)
- how to build and run? HOT 7
- Dynamic flags? HOT 1
- Bug: eslint - typescript support for 4.9.5 HOT 3
- how to remove "See code" from readme? HOT 8
- Bug: `enableJsonFlag` flag not working with flags and/or args? HOT 1
- Bug: AccessDenied during oclif promote
- 安装报错 HOT 2
- Oclif's bin/dev is not able to expand tsconfig paths and fails HOT 3
- Allow to change oclif's hardcoded sections' words to another idiom
- can i create multi cli bin in a single package HOT 3
- With ESM, `this.configDir` returns `~/.config/ts-node` on static `.run()` HOT 2
- cryptic "command not found" returned on typercript transpile error HOT 1
- MODULE_NOT_FOUND] import() failed to load Library HOT 1
- Verifying shasum for Node.js dist causing `oclif pack` to fail nondeterministically on some Linux distros HOT 8
- How to generate documentation in a file other than README.md using oclif? HOT 4
- Conflict between the vscode formatting/prettier default configuration and the lint of oclif HOT 1
- Full stack trace displayed rather than pretty printed error
- vite-node incompatible with oclif
- Default `.gitignore` content generated using yarn 2+ is missing recommended lines by yarn
- Example using worker_thread
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oclif.