1.1.6 • Published 6 years ago

opinionated-config-parser v1.1.6

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

opinionated-config-parser

Build Status codecov Maintainability License

Select configuration for specific build target. If no target, defaults to process.env.NODE_ENV.

  1. select an environment, mix (may overwrite) its data with the subfields of root;
  2. convert key name to format of __OUT_DIR__
  3. return another copy for webpack 'DefinePlugin', which set them for client use;

example:

parseCfg(source, 'mock')

source

{
	outDir:'dev'
	publicPath:'/',
	apiPath:'/api/'
	targets:{
		mock:{
			publicPath:'/root/',
			apiPath:'https://hna-app-test.hnair.com'
		},
		production:{
			outDir:'dist',
			publicPath:'/appname/',
			apiPath:'https://hna-app-test.hnair.com',
		}
	}
}

output

{
	__OUT_DIR__:'dev',
	__PUBLIC_PATH__:'/root/',
	__API_PATH__:'https://hna-app-test.hnair.com',
}

interface

parseCfg(cfgInput, targetSelected, postProcessor) ⇒ Object

Kind: global function Returns: Object - refer to @see See: returned object

  • cfg {Object} - merged config;
  • stringifiedCfg {Object} - with strings processed with JSON.stringify;
  • target {string} - calculated target;
ParamTypeDescription
cfgInputjsoncontent
targetSelectedstringselected target, subkey of 'targets';
postProcessorFunctionprocess after selected config is merged before converting key character cases

License

MIT.

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago