Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move site-configs.ts to site-configs directory #401

Merged
merged 3 commits into from
Oct 28, 2024
Merged

Conversation

dkarnutsch
Copy link
Contributor

@dkarnutsch dkarnutsch commented Oct 17, 2024

Description

As a prerequisite for #388, I need to move site-configs.ts to a directory in order to mount it during build. Additionally, I think this improves readability.

@@ -2,7 +2,7 @@
"name": "starter",
"private": true,
"scripts": {
"create-site-configs-env": "npx @comet/cli inject-site-configs -i .env.site-configs.tpl -o .env.site-configs",
"create-site-configs-env": "npx @comet/cli inject-site-configs -f ../../../../../site-configs/site-configs.ts -i .env.site-configs.tpl -o .env.site-configs",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to https://github.com/vivid-planet/comet/blob/e2eb8265316f76980c0f47cb2ccdce2106ea7847/packages/cli/src/commands/site-configs.ts#L16.

It should always prepend process.cwd(). This should be fixed in Comet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkarnutsch do you want to merge it like this and change it once the fix is released in core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 👍


const files = (await fs.readdir(path)).filter((file) => !file.startsWith("_"));
const files = (await fs.readdir(path)).filter((file) => (!file.startsWith("_") && !["site-configs.d.ts", "site-configs.ts"].includes(file)));
Copy link
Contributor Author

@dkarnutsch dkarnutsch Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this solution. I think we should use a more declarative solution instead of relying on some magic.

I would propose to introduce a variable containing all sites. This was briefly discussed in one JFX.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use a standard, non-dynamic import, that would also improve typing (as you don't need as ... GetSiteConfig)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a brief test and I also suggest to go with @nsams basic solution:

import { SiteConfig } from "./site-configs.d";
import main from "./main";
import secondary from "./secondary";

// Types for files in site-configs/
export type Environment = "local" | "dev" | "test" | "staging" | "prod";
export type GetSiteConfig = (env: Environment) => SiteConfig;

const isValidEnvironment = (env: string): env is Environment => {
    return ["local", "dev", "test", "staging", "prod"].includes(env);
};

// Called by `npx @comet/cli inject-site-configs`
const getSiteConfigs = async (env: string): Promise<SiteConfig[]> => {
    if (!isValidEnvironment(env)) {
        throw new Error(`Invalid environment: ${env}`);
    }

    const imports = [main, secondary];
    return imports.map((getSiteConfig) => getSiteConfig(env));
};
export default getSiteConfigs;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@johnnyomair johnnyomair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should implement both your suggestions before merging this.

@dkarnutsch dkarnutsch merged commit 28864c4 into main Oct 28, 2024
3 checks passed
@dkarnutsch dkarnutsch deleted the move-site-configs branch October 28, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants