Skip to content

Commit

Permalink
Merge pull request #2889 from evidence-dev/fix/environment-variables-…
Browse files Browse the repository at this point in the history
…in-deployment-section

fix: environemnt variables appear in the deploy section again
  • Loading branch information
zachstence authored Dec 11, 2024
2 parents 2d5774e + 2efb8df commit fcc0e81
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-fans-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@evidence-dev/evidence': patch
'@evidence-dev/sdk': patch
---

fix environment variable display in settings page
1 change: 1 addition & 0 deletions packages/lib/sdk/src/plugins/datasources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './loadSources.js';
export * from './loadSourcePlugins.js';
export * from './writeSourceConfig.js';
export * from './cli/edit/Options.js';
export { getDatasourceConfigAsEnvironmentVariables } from './loadSourceConfig.js';
25 changes: 25 additions & 0 deletions packages/lib/sdk/src/plugins/datasources/loadSourceConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,28 @@ export const loadSourceConfig = async (sourceDir) => {
options
};
};

/**
* @param {import('./schemas/datasource.schema.js').DatasourceSpec} datasource
*/
export const getDatasourceConfigAsEnvironmentVariables = (datasource) => {
/** @type {Record<string,string>} */
const environmentVariables = {};
/**
* @param {any} obj
* @param {string} [currentKey]
*/
const generateNestedEnvVars = (obj, currentKey = '') => {
for (const [key, value] of Object.entries(obj)) {
const newKey = currentKey ? `${currentKey}__${key}` : key;
if (typeof value === 'object') {
generateNestedEnvVars(value, newKey);
} else {
environmentVariables[`EVIDENCE_SOURCE__${datasource.name}__${newKey}`] = value.toString();
}
}
};
generateNestedEnvVars(datasource.options);

return environmentVariables;
};
13 changes: 10 additions & 3 deletions sites/example-project/src/pages/settings/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
loadSourcePlugins,
DatasourceSpecFileSchema,
Options,
writeSourceConfig
writeSourceConfig,
getDatasourceConfigAsEnvironmentVariables
} from '@evidence-dev/sdk/plugins';

export const load = async () => {
Expand All @@ -15,12 +16,18 @@ export const load = async () => {
const datasources = await loadSourcePlugins();

const plugins = Object.entries(datasources.bySource).reduce((acc, [name, v]) => {
acc[name] = { package: { package: v[0] }, options: v[1].options };
acc[name] = {
package: { package: v[0] },
options: v[1].options
};
return acc;
}, {});

return {
sources,
sources: sources.map((source) => ({
...source,
environmentVariables: getDatasourceConfigAsEnvironmentVariables(source)
})),
plugins
};
}
Expand Down
2 changes: 0 additions & 2 deletions sites/example-project/src/pages/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
let { settings, customFormattingSettings, sources, plugins } = data;
$: ({ settings, customFormattingSettings, sources, plugins } = data);
console.log({ settings, sources, plugins });
import { dev } from '$app/environment';
import {
Expand Down

0 comments on commit fcc0e81

Please sign in to comment.