add start_watching({interval}) parameter
This commit is contained in:
		
							parent
							
								
									0092627935
								
							
						
					
					
						commit
						6939fed6e2
					
				@ -11,12 +11,12 @@ const assign_deep = require('assign-deep')
 | 
				
			|||||||
const my = { envar: {} }
 | 
					const my = { envar: {} }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
  start_watching ({ envarFiles = ['./envar-base-dynamic.js', './envar-base-dynamic.gitignore.js'], rawEnvar = {} } = {}) {
 | 
					  start_watching ({ envarFiles = ['./envar-base-dynamic.js', './envar-base-dynamic.gitignore.js'], rawEnvar = {}, interval = 1000 } = {}) {
 | 
				
			||||||
    chokidar.watch(envarFiles, { interval: 500 }).on('change', (onpath) => {
 | 
					    chokidar.watch(envarFiles, { interval }).on('change', (onpath) => {
 | 
				
			||||||
      // .on('all', (event, onpath)) 但这时,即使server刚启动,也会调用到这里一次
 | 
					      // .on('all', (event, onpath)) 但这时,即使server刚启动,也会调用到这里一次
 | 
				
			||||||
      console.log('envarTool.start_watching: envar file changed:', onpath)
 | 
					      console.log('envarTool.start_watching: envar file changed:', onpath)
 | 
				
			||||||
      delete require.cache[require.resolve(path.resolve(onpath))]
 | 
					 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
 | 
					        delete require.cache[require.resolve(path.resolve(onpath))]
 | 
				
			||||||
        assign_deep(rawEnvar, require(path.resolve(onpath)))
 | 
					        assign_deep(rawEnvar, require(path.resolve(onpath)))
 | 
				
			||||||
        console.log(`envarTool.start_watching: successfully reload ${onpath}`)
 | 
					        console.log(`envarTool.start_watching: successfully reload ${onpath}`)
 | 
				
			||||||
      } catch (expt) {
 | 
					      } catch (expt) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user