This is a utility for projects that relay heavily on classes and dependency injection. If a class constructor uses an 'inject'
directive, the list of parameter names will be copied as strings and placed on an inject
static property, so your DI tool can read them.
class MyService {
constructor(depOne, depTwo) {
'inject';
...
}
}
class MyService {
constructor(depOne, depTwo) {
'inject';
...
}
}
MyService.inject = ['depOne', 'depTwo']
.babelrc
{
"plugins": ["transform-class-inject-directive"]
}
babel --plugins transform-class-inject-directive script.js
require('@babel/core').transform('code', {
plugins: ['transform-class-inject-directive'],
});
string
, defaults to inject
.
Tells the plugin which is the name of the directive it should find in order to apply the transformation.
string
, defaults to inject
.
This is the name of the property the plugin will create in order to define the list of dependencies.
This only works on classes and regular functions (no arrow). The idea was for it to only work on classes, and the only reason it also works with functions is in order to add support in case you are transforming classes.
Task | Description |
---|---|
yarn test |
Run the project unit tests. |
yarn run lint |
Lint the modified files. |
yarn run lint:full |
Lint the project code. |
yarn run docs |
Generate the project documentation. |
yarn run todo |
List all the pending to-do's. |
I use Jest with Jest-Ex to test the project. The configuration file is on ./.jestrc
, the tests and mocks are on ./tests
and the script that runs it is on ./utils/scripts/test
.
I use ESlint to validate all our JS code. The configuration file for the project code is on ./.eslintrc
and for the tests on ./tests/.eslintrc
(which inherits from the one on the root), there's also an ./.eslintignore
to ignore some files on the process, and the script that runs it is on ./utils/scripts/lint
.
I use ESDoc to generate HTML documentation for the project. The configuration file is on ./.esdocrc
and the script that runs it is on ./utils/scripts/docs
.
I use @todo
comments to write all the pending improvements and fixes, and Leasot to generate a report. The script that runs it is on ./utils/scripts/todo
.