Use js file for configuration instead of json
extrem7 opened this issue · comments
It could also be helpful to support JS configuration because scopes could be generated automatically based on folders structure using node path utils.
I may be misunderstanding. But, because the config is a language like json, you can achieve this in any language AFAIK.
Using a basic example / pseudo code in javascript/nodejs, you could generate a config based on the file structure of a project and write it to your json config.
import { readdirSync, writeFileSync } from 'fs'
const YOUR_SRC_DIR = '...'
const options = readdirSync(YOUR_SRC_DIR , { withFileTypes: true })
.filter(dir=> dir.isDirectory())
.map(dir => ({value: dir.name, label: dir.name}))
const config = {
commit_scope: {
options: options
}
// Whatever else you want in your config...
}
const config_as_json = JSON.stringify(config, null, 2);
const DIR_WITH_YOUR_CONFIG = '...'
writeFileSync(`${DIR_WITH_YOUR_CONFIG}/.better-commits.json`, config_as_json );
I see. But in this case, I need to regenerate it on each new module created. I use cz-customizable now and just generate scoped on fly.
I believe I see what you're saying. You're using node utils here (https://github.com/leoforfree/cz-customizable/blob/master/cz-config-EXAMPLE.js#L27) to generate scopes whenever you run npm run commit
, correct?
You can do the same with better-commits
using your package.json
commands, a bash script, etc...
Adapt the js you're currently using to generate scopes to save JSON to your .better-commits.json
(as mentioned aboved). Then update your better-commits
command/alias to update your config before running better commits.
As an example with something like bun.js, the command might be bun run scopes.js && better-commits
.
I have a few issues that when I get to (I just had a baby 😅) I plan to reduce the size of better-commits significantly. better-commits is already small & simple compared to alternatives like commitizen. Adding the ability to write a js config adds a lot of complexity to the project. In other words, it's better to combine existing tools with better-commits than to bolt on to it.
Hope that clarifies / helps!