Skip to content

Commit c9e79a3

Browse files
fix: Set configuration during wizard
1 parent eb5d8ae commit c9e79a3

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/configuration.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ async function readConfig() {
3838
});
3939

4040
const debuggerId = await generateDebuggerId(!!configFromWizard.observable);
41-
config = {
41+
setConfig({
4242
...configFromWizard,
4343
debuggerId,
4444
start: false, // don't start the debugger after the wizard
45-
};
45+
});
4646
} else {
4747
const configMerged = { ...configFromCliArgs, ...configFromConfigFile };
4848
const debuggerId = await generateDebuggerId(!!configMerged.observable);
49-
config = {
49+
setConfig({
5050
...configMerged,
5151
debuggerId,
5252
start: true,
53-
};
53+
});
5454
}
5555
}
5656

@@ -169,6 +169,14 @@ function saveDiscoveredLambdas(lambdasListNew: LambdaResource[]) {
169169
}
170170
}
171171

172+
/**
173+
* Set the configuration
174+
* @param newConfig
175+
*/
176+
function setConfig(newConfig: LldConfig) {
177+
config = newConfig;
178+
}
179+
172180
export const Configuration = {
173181
readConfig,
174182
get config() {
@@ -180,4 +188,5 @@ export const Configuration = {
180188
discoverLambdas,
181189
getLambda,
182190
getLambdas,
191+
setConfig,
183192
};

src/configuration/getConfigFromWizard.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ResourceDiscovery } from "../resourceDiscovery.js";
1616
import { GitIgnore } from "../gitignore.js";
1717
import { VsCode } from "../vsCode.js";
1818
import { Logger } from "../logger.js";
19+
import { Configuration } from "../configuration.js";
1920

2021
const configFileName = path.resolve(configFileDefaultName);
2122

@@ -205,6 +206,10 @@ export async function getConfigFromWizard({
205206
]);
206207

207208
if (answersFilter.function === "Pick one") {
209+
// I need to use congiration settings I accquired so far to get the list of lambdas
210+
const configTemp = getConfigFromAnswers(answers);
211+
Configuration.setConfig(configTemp as any); // not complete config
212+
208213
lambdasList = await ResourceDiscovery.getLambdas(
209214
getConfigFromAnswers(answers) as LldConfig
210215
);
@@ -295,10 +300,17 @@ export async function getConfigFromWizard({
295300
const config = getConfigFromAnswers(answers);
296301

297302
if (save) {
298-
// save to file that looks like this:
299-
Logger.log(`Saving to config file ${configFileName}`);
303+
await saveConfiguration(config);
304+
}
305+
306+
return config;
307+
}
300308

301-
const configContent = `
309+
async function saveConfiguration(config: LldConfigCliArgs) {
310+
Logger.log(`Saving to config file ${configFileName}`);
311+
312+
// save to file that looks like this:
313+
const configContent = `
302314
import { type LldConfigTs } from "lambda-live-debugger";
303315
304316
export default {
@@ -321,17 +333,14 @@ export default {
321333
} satisfies LldConfigTs;
322334
`;
323335

324-
// remove lines that contains undefined or ""
325-
const configContentCleaned = configContent
326-
.trim()
327-
.split("\n")
328-
.filter((l) => !l.includes("undefined") && !l.includes('""'))
329-
.join("\n");
330-
331-
await fs.writeFile(configFileName, configContentCleaned);
332-
}
336+
// remove lines that contains undefined or ""
337+
const configContentCleaned = configContent
338+
.trim()
339+
.split("\n")
340+
.filter((l) => !l.includes("undefined") && !l.includes('""'))
341+
.join("\n");
333342

334-
return config;
343+
await fs.writeFile(configFileName, configContentCleaned);
335344
}
336345

337346
function getConfigFromAnswers(answers: any): LldConfigCliArgs {

0 commit comments

Comments
 (0)