Skip to content

Commit

Permalink
feat(#1460): use new interpolation lib in app, electron, cli
Browse files Browse the repository at this point in the history
  • Loading branch information
helloanoop committed Jan 29, 2024
1 parent c598689 commit 7ba9b83
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 239 deletions.
77 changes: 11 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/bruno-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@reduxjs/toolkit": "^1.8.0",
"@tabler/icons": "^1.46.0",
"@tippyjs/react": "^4.2.6",
"@usebruno/common": "0.1.0",
"@usebruno/graphql-docs": "0.1.0",
"@usebruno/schema": "0.6.0",
"axios": "^1.5.1",
Expand All @@ -34,7 +35,6 @@
"graphiql": "^1.5.9",
"graphql": "^16.6.0",
"graphql-request": "^3.7.0",
"handlebars": "^4.7.8",
"httpsnippet": "^3.0.1",
"idb": "^7.0.0",
"immer": "^9.0.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import CodeView from './CodeView';
import StyledWrapper from './StyledWrapper';
import { isValidUrl } from 'utils/url/index';
import get from 'lodash/get';
import handlebars from 'handlebars';
import { findEnvironmentInCollection } from 'utils/collections';

// Todo: Fix this
// import { interpolate } from '@usebruno/common';
const brunoCommon = require('@usebruno/common');
const { interpolate } = brunoCommon.default;

const interpolateUrl = ({ url, envVars, collectionVariables, processEnvVars }) => {
if (!url || !url.length || typeof url !== 'string') {
return;
}

const template = handlebars.compile(url, { noEscape: true });

return template({
return interpolate(url, {
...envVars,
...collectionVariables,
process: {
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"package.json"
],
"dependencies": {
"@usebruno/common": "0.1.0",
"@usebruno/js": "0.9.4",
"@usebruno/lang": "0.9.0",
"axios": "^1.5.1",
Expand All @@ -32,7 +33,6 @@
"decomment": "^0.9.5",
"form-data": "^4.0.0",
"fs-extra": "^10.1.0",
"handlebars": "^4.7.8",
"http-proxy-agent": "^7.0.0",
"https-proxy-agent": "^7.0.2",
"inquirer": "^9.1.4",
Expand Down
30 changes: 9 additions & 21 deletions packages/bruno-cli/src/runner/interpolate-string.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
const Handlebars = require('handlebars');
const { forOwn, cloneDeep } = require('lodash');

const interpolateEnvVars = (str, processEnvVars) => {
if (!str || !str.length || typeof str !== 'string') {
return str;
}

const template = Handlebars.compile(str, { noEscape: true });

return template({
process: {
env: {
...processEnvVars
}
}
});
};
const { interpolate } = require('@usebruno/common');

const interpolateString = (str, { envVars, collectionVariables, processEnvVars }) => {
if (!str || !str.length || typeof str !== 'string') {
Expand All @@ -31,11 +15,15 @@ const interpolateString = (str, { envVars, collectionVariables, processEnvVars }
// envVars can inturn have values as {{process.env.VAR_NAME}}
// so we need to interpolate envVars first with processEnvVars
forOwn(envVars, (value, key) => {
envVars[key] = interpolateEnvVars(value, processEnvVars);
envVars[key] = interpolate(value, {
process: {
env: {
...processEnvVars
}
}
});
});

const template = Handlebars.compile(str, { noEscape: true });

// collectionVariables take precedence over envVars
const combinedVars = {
...envVars,
Expand All @@ -47,7 +35,7 @@ const interpolateString = (str, { envVars, collectionVariables, processEnvVars }
}
};

return template(combinedVars);
return interpolate(str, combinedVars);
};

module.exports = {
Expand Down
Loading

0 comments on commit 7ba9b83

Please sign in to comment.