-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
@@ -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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes 👍
site-configs/site-configs.ts
Outdated
|
||
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))); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
93dda00
to
3f0abbd
Compare
There was a problem hiding this 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.
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.