Skip to content

Commit

Permalink
feat: Support CVE_CONFIG environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sya-ri committed Sep 5, 2024
1 parent 57c0ed2 commit e811f32
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-maps-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"css-var-extract": minor
---

Support `CVE_CONFIG` environment variable
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,17 @@ cve watch
You can create `cve.config.json` and change settings.
If you are using a plugin, it also supports inline configuration.

### cve.config.json
You can also override the settings by the `CVE_CONFIG` environment variable.

### Priority

The lower the number, the higher the priority.

1. Environment variable: `CVE_CONFIG`
2. Inline config
3. File config `cve.config.json`

### JSON

```json
{
Expand Down
8 changes: 7 additions & 1 deletion packages/css-var-extract/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ export const getConfig = (
"cve.config.json",
);
const exists = fs.existsSync(configFilePathJson);
const env = process.env.CVE_CONFIG;
const envConfig = env ? JSON.parse(env) : {};

let config: Config;
if (exists) {
config = configSchema.parse({
...JSON.parse(fs.readFileSync(configFilePathJson, "utf-8")),
...inlineConfig,
...envConfig,
});
} else {
config = configSchema.parse(inlineConfig);
config = configSchema.parse({
...inlineConfig,
...envConfig,
});
if (!noCreate) {
fs.writeFileSync(
configFilePathJson,
Expand Down

0 comments on commit e811f32

Please # to comment.