-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
feat: add possibility to override default path to config file #667
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ export const setup = async (autoSetup: boolean) => { | |
|
||
const config = await getConfigDiff(options) | ||
|
||
await writeConfigToFile(config) | ||
await writeConfigToFile(config, '.typesafe-i18n.json') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't you need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I wrote this, I think that this We can add path here too if needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be more consistent if someone is able to pass the -p flag also to the setup function. |
||
logger.info(`generated config file: '.typesafe-i18n.json'`) | ||
|
||
const installed = await installDependencies() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,19 @@ import { applyDefaultValues } from './core.mjs' | |
import type { GeneratorConfig, GeneratorConfigWithDefaultValues } from './types.mjs' | ||
import { validateConfig } from './validation.mjs' | ||
|
||
export const writeConfigToFile = async (config: GeneratorConfig) => | ||
writeConfigFile({ ...config, $schema: `https://unpkg.com/typesafe-i18n@${version}/schema/typesafe-i18n.json` }) | ||
export const writeConfigToFile = async (config: GeneratorConfig, configPath: string) => | ||
writeConfigFile( | ||
{ ...config, $schema: `https://unpkg.com/typesafe-i18n@${version}/schema/typesafe-i18n.json` }, | ||
configPath, | ||
) | ||
|
||
export const doesConfigFileExist = async () => doesPathExist(resolve('.typesafe-i18n.json')) | ||
|
||
export const readRawConfig = async () => | ||
(await importFile<GeneratorConfig & { $schema?: string }>(resolve('.typesafe-i18n.json'), false)) || {} | ||
export const readRawConfig = async (configPath: string) => | ||
(await importFile<GeneratorConfig & { $schema?: string }>(resolve(configPath), false)) || {} | ||
|
||
export const readConfig = async (): Promise<GeneratorConfig> => { | ||
const generatorConfig = await readRawConfig() | ||
export const readConfig = async (configPath = '.typesafe-i18n.json'): Promise<GeneratorConfig> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not use default values anywhere. This makes it easy to miss a spot where we forgot to pass it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you have some ideas, how we can save backward compatibility with previous codebase that have hardcoded path to file, without default values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally it get's passed from the CLI and |
||
const generatorConfig = await readRawConfig(configPath) | ||
|
||
// remove "$schema" property | ||
const configWithoutSchemaAttribute = Object.fromEntries( | ||
|
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.
can we add a validation here?
The string should end with
.json
and we should check if the file exists (except if it is asetup
call).