| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var Rc = module.exports; | 
					
						
							|  |  |  | var fs = require('fs'); | 
					
						
							|  |  |  | var path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This is only called if packageRoot is specified
 | 
					
						
							|  |  |  | // (which it should be most of the time)
 | 
					
						
							|  |  |  | Rc._initSync = function(dirname, manager, configDir) { | 
					
						
							|  |  |  |     if (!dirname) { | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // dirname / opts.packageRoot
 | 
					
						
							|  |  |  |     var rcpath = path.resolve(dirname, '.greenlockrc'); | 
					
						
							|  |  |  |     var rc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |         rc = JSON.parse(fs.readFileSync(rcpath)); | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |         if ('ENOENT' !== e.code) { | 
					
						
							|  |  |  |             throw e; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         rc = {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 01:39:05 -07:00
										 |  |  |     var changed = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  |     // In the general case the manager should be specified in the
 | 
					
						
							|  |  |  |     // config file, which is in the config dir, but for the specific
 | 
					
						
							|  |  |  |     // case in which all custom plugins are being used and no config
 | 
					
						
							|  |  |  |     // dir is needed, we allow the manager to be read from the rc.
 | 
					
						
							|  |  |  |     // ex: manager: { module: 'name', xxxx: 'xxxx' }
 | 
					
						
							|  |  |  |     if (manager) { | 
					
						
							|  |  |  |         if (rc.manager) { | 
					
						
							|  |  |  |             if ( | 
					
						
							| 
									
										
										
										
											2019-11-19 02:24:09 -07:00
										 |  |  |                 ('string' === typeof rc.manager && rc.manager !== manager) || | 
					
						
							|  |  |  |                 ('string' !== typeof rc.manager && | 
					
						
							|  |  |  |                     rc.manager.module !== manager.module) | 
					
						
							| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  |             ) { | 
					
						
							| 
									
										
										
										
											2019-11-19 01:39:05 -07:00
										 |  |  |                 changed = true; | 
					
						
							| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  |                 console.info( | 
					
						
							|  |  |  |                     "changing `manager` from '%s' to '%s'", | 
					
						
							| 
									
										
										
										
											2019-11-19 01:39:05 -07:00
										 |  |  |                     rc.manager.module || rc.manager, | 
					
						
							|  |  |  |                     manager.module || manager | 
					
						
							| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  |                 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         rc.manager = manager; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!configDir) { | 
					
						
							|  |  |  |         configDir = rc.configDir; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (configDir && configDir !== rc.configDir) { | 
					
						
							|  |  |  |         if (rc.configDir) { | 
					
						
							|  |  |  |             console.info( | 
					
						
							|  |  |  |                 "changing `configDir` from '%s' to '%s'", | 
					
						
							|  |  |  |                 rc.configDir, | 
					
						
							|  |  |  |                 configDir | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-11-19 01:39:05 -07:00
										 |  |  |         changed = true; | 
					
						
							| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  |         rc.configDir = configDir; | 
					
						
							|  |  |  |     } else if (!rc.configDir) { | 
					
						
							| 
									
										
										
										
											2019-11-19 01:39:05 -07:00
										 |  |  |         changed = true; | 
					
						
							|  |  |  |         configDir = './greenlock.d'; | 
					
						
							| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  |         rc.configDir = configDir; | 
					
						
							| 
									
										
										
										
											2019-11-19 01:39:05 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (changed) { | 
					
						
							| 
									
										
										
										
											2019-11-18 01:21:31 -07:00
										 |  |  |         fs.writeFileSync(rcpath, JSON.stringify(rc)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return rc; | 
					
						
							|  |  |  | }; |