From 84e978f0deaf792a91c243eedee2c17745ed5fb1 Mon Sep 17 00:00:00 2001 From: Matthew Weeks Date: Wed, 5 Jul 2023 12:46:33 -0400 Subject: [PATCH] serverChannel updates preview.tsx - main.ts update currently not working --- src/index.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index f1a166b7..f06631a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { readConfig, writeConfig } from "@storybook/csf-tools"; // eslint-disable-next-line import/no-unresolved import { run } from "chromatic/node"; -import { BUILD_STARTED, START_BUILD, UPDATE_PROJECT_ID } from "./constants"; +import { BUILD_STARTED, START_BUILD, UPDATE_PROJECT } from "./constants"; import { findConfig } from "./utils/storybook.config.utils"; /** @@ -35,17 +35,33 @@ async function serverChannel(channel: Channel, { projectToken }: { projectToken: }); }); - channel.on(UPDATE_PROJECT_ID, async (id) => { + channel.on(UPDATE_PROJECT, async (id, token) => { + + // update project id // find config file path const previewPath = await findConfig("preview"); // Find config file const PreviewConfig = await readConfig(previewPath); // Add parameters to config file - PreviewConfig.setFieldValue(["projectId"], id); + const previousProjectId = PreviewConfig.getFieldNode(["parameters", "projectId"]); + console.log("updating project id", previousProjectId, id); + PreviewConfig.setFieldValue(["parameters", "projectId"], id); // Write to config file await writeConfig(PreviewConfig); + + + + // update project token in main.ts - this is not currently working, does not select the main.ts section correctly + const mainPath = await findConfig("main"); + const MainConfig = await readConfig(mainPath); + + // TODO: Get the correct field node + const addonsConfig = MainConfig.getFieldNode(["addons"]); + console.log(addonsConfig); + + MainConfig.setFieldValue(["addons", "projectToken"], token); }); return channel;