Commit ba21ca7e authored by Philip Paetz's avatar Philip Paetz

feat(options): renamed options.types.filePath to options.types.fileName to...

feat(options): renamed options.types.filePath to options.types.fileName to clarify that you should not pass a full path here (because the path always defaults to options.configRoot to keep the options simple)

BREAKING CHANGE
Option name changed which would break apps using the options.types.filePath option
parent ef0e084a
export interface TypeOptions {
rootTypeName: string
filePath: string
fileName: string
}
export interface Options {
......@@ -17,13 +17,13 @@ export enum ConfigFileExtensions {
}
export const defaultOptions: Options = {
configRoot: 'config',
runtimeEnvName: 'NODE_ENV',
types: {
rootTypeName: 'Config',
filePath: 'strong-config.d.ts',
fileName: 'types.d.ts',
},
substitutionPattern: '\\$\\{(\\w+)\\}',
configRoot: 'config',
}
export default defaultOptions
export const optionsSchema = {
type: 'object',
title: 'Schema for strong-config options',
required: ['runtimeEnvName', 'types', 'substitutionPattern', 'configRoot'],
required: ['configRoot', 'runtimeEnvName', 'types', 'substitutionPattern'],
additionalProperties: false,
properties: {
configRoot: {
title: 'Config root path',
description: 'A path to a directory that contains all config files',
examples: ['config', '../config', 'app/config/'],
type: 'string',
},
runtimeEnvName: {
title: 'Runtime environment variable name',
description:
......@@ -26,10 +32,11 @@ export const optionsSchema = {
type: 'string',
pattern: '^[A-Z]\\w*$',
},
filePath: {
title: 'Path to types file',
description: 'The file that the generated types should be stored in',
examples: ['strong-config.d.ts', './types/config.ts'],
fileName: {
title: 'File name for auto-generated TypeScript types',
description:
'Name for the types file containing auto-generated TypeScript types for your config',
examples: ['types.d.ts', 'config.d.ts'],
type: 'string',
},
},
......@@ -42,11 +49,5 @@ export const optionsSchema = {
type: 'string',
format: 'regex',
},
configRoot: {
title: 'Config root path',
description: 'A path to a directory that contains all config files',
examples: ['config', '../config', '/app/config/'],
type: 'string',
},
},
}
......@@ -31,13 +31,11 @@ export const generateTypeFromSchema = async (
)
}
const configInterfaceAsString = `export interface ${
types.rootTypeName
} extends ${pascalCase(title)} {
runtimeEnv: string;
}
`
const configInterfaceAsString = `
export interface ${types.rootTypeName} extends ${pascalCase(title)} {
runtimeEnv: string
}`
const exportedTypes = baseTypes.concat(configInterfaceAsString)
fs.writeFileSync(types.filePath, exportedTypes)
fs.writeFileSync(`${configRoot}/${types.fileName}`, exportedTypes)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment