diff --git a/.changeset/tasty-maps-draw.md b/.changeset/tasty-maps-draw.md new file mode 100644 index 0000000..12cb217 --- /dev/null +++ b/.changeset/tasty-maps-draw.md @@ -0,0 +1,5 @@ +--- +"css-var-extract": minor +--- + +Support `CVE_CONFIG` environment variable diff --git a/README.md b/README.md index 021da9b..e510583 100644 --- a/README.md +++ b/README.md @@ -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 { diff --git a/packages/css-var-extract/src/config.ts b/packages/css-var-extract/src/config.ts index da8003c..6249e60 100644 --- a/packages/css-var-extract/src/config.ts +++ b/packages/css-var-extract/src/config.ts @@ -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,