Skip to content

Commit d2d8376

Browse files
authored
P3) VSCode Extension: Add a Refresh Button to Tree View #4107 (#5)
* # Feature (4107): P3) VSCode Extension: Add a Refresh Button to Tree View - load config now can return value - Add or Update config function added * # Feature (4107): P3) VSCode Extension: Add a Refresh Button to Tree View - load config now can return value - Add or Update config function added - Version updated
1 parent d616772 commit d2d8376

File tree

5 files changed

+4050
-6
lines changed

5 files changed

+4050
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polyapi",
3-
"version": "0.23.15",
3+
"version": "0.23.16",
44
"description": "Poly is a CLI tool to help create and manage your Poly definitions.",
55
"license": "MIT",
66
"repository": {

src/commands/generate/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
WebhookHandleSpecification,
1515
} from '../../types';
1616
import { getSpecs } from '../../api';
17-
import { loadConfig } from '../../config';
17+
import { loadConfig, addOrUpdateConfig } from '../../config';
1818
import {
1919
generateContextDataFile,
2020
getContextDataFileContent,
@@ -393,6 +393,9 @@ const generate = async ({
393393

394394
try {
395395
specs = await getSpecs(contexts, names, functionIds, noTypes);
396+
if (contexts) {
397+
addOrUpdateConfig(polyPath, 'LAST_GENERATE_CONTEXTS_USED', contexts?.join(','));
398+
}
396399
} catch (error) {
397400
showErrGettingSpecs(error);
398401
return;

src/config.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ const getPolyConfigDirPath = (polyPath: string) =>
88
const getPolyConfigFilePath = (polyPath: string) =>
99
`${getPolyConfigDirPath(polyPath)}/.config.env`;
1010

11-
export const loadConfig = (polyPath: string) => {
11+
export const loadConfig = (polyPath: string): Record<string, string> | undefined => {
1212
const configFilePath = getPolyConfigFilePath(polyPath);
1313
if (fs.existsSync(configFilePath)) {
14-
dotenv.config({ path: configFilePath, override: process.env.CONFIG_ENV_PATH_PRIORITY === 'true' });
14+
const result = dotenv.config({
15+
path: configFilePath,
16+
override: process.env.CONFIG_ENV_PATH_PRIORITY === 'true',
17+
});
18+
19+
return result.parsed;
1520
}
21+
return undefined;
1622
};
1723

1824
export const saveConfig = (polyPath: string, config: Record<string, string>) => {
@@ -24,3 +30,11 @@ export const saveConfig = (polyPath: string, config: Record<string, string>) =>
2430
.join('\n'),
2531
);
2632
};
33+
34+
export const addOrUpdateConfig = (polyPath: string, key: string, value: string) => {
35+
const existingConfig = loadConfig(polyPath) ?? {};
36+
37+
existingConfig[key] = value;
38+
39+
saveConfig(polyPath, existingConfig);
40+
};

0 commit comments

Comments
 (0)