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

feat: Create types and js for nested configs #36

Closed

Conversation

yugal-dream11
Copy link

@yugal-dream11 yugal-dream11 commented Jul 8, 2019

Solves #37

@yugal-dream11 yugal-dream11 force-pushed the feat/nested-config-search branch from 5903a5f to 39821eb Compare July 17, 2019 08:47
bin/cli Outdated Show resolved Hide resolved
export const getAllConfigPath: <T extends NonConfigEnv>(
process: T
) => Array<string> = process =>
glob.sync(`**/${baseConfigPathName}`, {
Copy link
Owner

Choose a reason for hiding this comment

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

take the glob param as a parameter to the cli.

Copy link
Owner

Choose a reason for hiding this comment

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

move this function to its own file.

process: T
) => Array<string> = process =>
glob.sync(`**/${baseConfigPathName}`, {
ignore: ['node_modules/**'],
Copy link
Owner

Choose a reason for hiding this comment

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

ignored paths should be configurable.

webpack.ts Outdated
@@ -20,4 +20,4 @@ export const NodeConfigTSPlugin: {
} = R.compose(
setConfigResolver,
setGlobalConfigPlugin
)
) as {(config: Configuration): Configuration}
Copy link
Owner

Choose a reason for hiding this comment

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

why do we need type-casting here?

@@ -25,24 +25,30 @@ export type NonConfigEnv = {
}

export const configPaths = <T extends NonConfigEnv>(
Copy link
Owner

Choose a reason for hiding this comment

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

Add a JSDoc explaining what this function is doing.
Add information about each argument that is being passed.

Copy link
Owner

Choose a reason for hiding this comment

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

/**
 * Returns the paths for all the config files — {default, env, deployment, user} etc.
 * @param process - Used to know which file to load. For eg. if env=production, the env config will be env/production.json.
 * @param root - // TODO
 */

@@ -25,24 +25,30 @@ export type NonConfigEnv = {
}

export const configPaths = <T extends NonConfigEnv>(
process: T
process: T,
subPath?: string
): ConfigTypes => {
const baseDIR = baseConfigPath(process)
Copy link
Owner

Choose a reason for hiding this comment

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

baseConfigPath should not be dynamic any more because its being passed as an argument to this function.

/**
* Write typedef and js for each path in nested config
*/
export const writeConfigFilesToSystem = () => {
Copy link
Owner

Choose a reason for hiding this comment

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

split this into two separate functions/files.

const getJsFileBuffer = (p: string) =>
defaultJsFileContent.concat(` mainConfig['${p}']`)

const getTsFileBuffer = (config: Config) =>
Copy link
Owner

Choose a reason for hiding this comment

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

This seems like a pure function. We can write unit tests easily for it.

Copy link
Owner

Choose a reason for hiding this comment

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

config should be object

)
return itar(configPaths(process))
}
): Configurations<ConfigTypes> => readConfigFiles(configPaths(process))
Copy link
Owner

Choose a reason for hiding this comment

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

this change seems unnecessary. Can you confirm?
If not needed can you revert this file.

index.ts Outdated

import {mergeAllConfigs} from './src/mergeAllConfigs'
export const config: Config = mergeAllConfigs(process)
export const config: Config = createMergedConfig(process)
Copy link
Owner

Choose a reason for hiding this comment

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

This rename is not needed.

@yugal-dream11 yugal-dream11 force-pushed the feat/nested-config-search branch from 68cdfee to b8a61ea Compare July 29, 2019 09:56
import {generateJsFiles} from './generateJsFiles'
import {generateTypeDefFiles} from './generateTypeDefFiles'

process.env['BOOTSTRAP'] = 'true'
Copy link
Owner

Choose a reason for hiding this comment

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

Never change env variables.

process.env['BOOTSTRAP'] = 'true'

generateTypeDefFiles()
generateJsFiles()
Copy link
Owner

Choose a reason for hiding this comment

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

generateTypeDefFiles & generateTypeDefFiles should only use the default.json to create files.


export const checkIfBootstrap: <T extends NonConfigEnv>(
process: T
) => boolean = process => process.env['BOOTSTRAP'] === 'true'
Copy link
Owner

Choose a reason for hiding this comment

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

this file can be removed.

return glob.sync(`**/${includePattern}`, {
ignore: getIgnorePatterns(process).map((x: string) => x + '/**'),
cwd: process.cwd()
})
Copy link
Owner

Choose a reason for hiding this comment

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

filter out file paths that don't have default.json in them.

process: T
) => Array<string> = process => {
const includePattern = getIncludePattern(process)
return glob.sync(`**/${includePattern}`, {
Copy link
Owner

Choose a reason for hiding this comment

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

don't change the passed user pattern.


export const getIncludePattern: <T extends ProcessArgv>(
process: T
) => string = process => minimist(process.argv)['pattern'] || DEFAULT_BASE_DIR
Copy link
Owner

Choose a reason for hiding this comment

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

all exported functions should be in their files.

export const checkIfDefaultJson = <T extends NonConfigEnv>(
process: T,
p: string
) => fs.existsSync(path.resolve(process.cwd(), `${p}/default.json`))
Copy link
Owner

Choose a reason for hiding this comment

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

you might not need this function any more since the paths will only contain config/default.json

"import {config as mainConfig} from 'node-config-ts' \n export const config ="

export const getJsFileBuffer = (p: string) =>
defaultJsFileContent.concat(` mainConfig['${p}']`)
Copy link
Owner

Choose a reason for hiding this comment

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

this will become a problem when u change the config directory's path.

import {loadCLIConfigs} from './loadCliConfigs'
import {checkIfBootstrap} from './checkIfBootstrap'

export const mergeFileConfigsForPath: <T extends NonConfigEnv>(
Copy link
Owner

Choose a reason for hiding this comment

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

add JSDoc

@yugal-dream11 yugal-dream11 force-pushed the feat/nested-config-search branch from 357d87a to 0dbe671 Compare August 12, 2019 12:31
@tusharmath tusharmath closed this Jan 14, 2023
@tusharmath
Copy link
Owner

Outdated. Closing for now.

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.

2 participants