1.0.2 • Published 7 years ago

config-tea v1.0.2

Weekly downloads
3
License
LGPL-3.0
Repository
github
Last release
7 years ago

#Configuration Tea

This is a server-side configuration plugin which is similar to the NET project application configuration. it is aimed at providing a convenient configuration management based on XML file. Of course, we have provided the extend interface for you to support other configuration based on other media like JSON file.

Git Repository

##Installation npm install config-tea

##Usage

  1. ###Basic

    • create a xml-based configuration file.

      		<?xml version="1.0" encoding="utf-8"?>
      		<Configuration>
      			    <Sections>
      			        <Section name='AppSettings' provider='./lib/appSettingSectionHandler'/>
      			    </Sections>
      			    <Databases>
      			        <Database name='local' connectionString='Data Source=.;Initial Catalog=Test;Integrated Security=true;'/>
      			    </Databases>
      			    <AppSettings>
      			        <add key="NODE_ENV" value="uat"/>
      			    </AppSettings>
      		</Configuration>
    • add package reference in your application main class.

      		var manager=require('config-tea').ConfigurationManager;
    • load and init configuration with the below code.

      		manager.init();
  2. ###Custom

    The custom usage is about custom configuration for some special application like log4js. you can define the custom section handler to load the configuration information and then initialize the anything based on the configuration information.

    • Add the custom XML nodes in the configuration file.

      		<Custom>
      	        	<add key="test" value="world"/>
      	     </Custom>
    • Define your custom section handler.

      		var util=require('util');
      		var configuration=require('../../index');
      	
      		var sectionHandler=configuration.SectionHandler;
      	
      		function customHandler(){
      	
      		}
      	
      		util.inherits(customHandler, sectionHandler);
      	
      		customHandler.prototype.getSectionName=function(){
      		    return 'Custom';
      		};
      	
      		customHandler.prototype.parseSection=function(parser,ctx){
      		    var result={
      	
      		    };
      		    if(parser){
      		        //to parser the XML data.
      		    }
      		    return result;
      		};
      	
      		customHandler.prototype.process=function(entity, ctx){
      		    var appConfig=ctx.getAppConfiguration();
      		    appConfig.custom=entity;
      		};
      	
      		module.exports=new customHandler();
    • Register your custom section handler in the configuration file.

      		<Sections>
      	         <Section name='Custom' provider='./customHandler'/>
      	     </Sections>
    • Load and init the configuration like the basic usage.

    ####examples:

    1. custom handler
    2. log handler
  3. ###Runtime

    The runtime configuration is the built-in configuration. it will change and update the process.env by your configuration in file.

    for example:

    <Runtime>
         <add key="NODE_ENV" value="production"/>
    </Runtime>			

##Reference

  1. ConfigurationManager

    ConfigurationManager is the manager class for configuration operation. it will provide the basic operation options for configuration.

    • init() - load and init configuration based on configuration file.
    • initFromFile(filePath) - load and init configuration based on a pointed configuration file.
    • initFromReader(reader) - load and init configuration based on configuration reader.
    • getAppConfig() - get the initialized configuration information.
    • getDatabases() - get the database relative configuration information. The database is the built-in configuration.
    • getAppSettings() - get the application settings configuration information. The appSettings is the built-in configuration.
  2. ConfigurationReader

    ConfigurationReader is the interface which is used to provide the basic template for custom media data reader like JSON.

  3. SectionHandler

    SectionHandler is the interface which is used to provide the basic template for custom configuration handler.

##Author

Iven Yin

email: yinchao77@126.com

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago