Skip to content

Commit

Permalink
serverChannel updates preview.tsx - main.ts update currently not working
Browse files Browse the repository at this point in the history
  • Loading branch information
weeksling committed Jul 11, 2023
1 parent 5690a40 commit 84e978f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 84e978f

Please sign in to comment.