| 
									
										
										
										
											2018-05-31 14:29:00 -05:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * An asynchronous bootstrap function that runs before | 
					
						
							|  |  |  |  * your application gets started. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This gives you an opportunity to set up your data model, | 
					
						
							|  |  |  |  * run jobs, or perform some special logic. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const _ = require('lodash'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 15:35:40 +02:00
										 |  |  | module.exports = async () => { | 
					
						
							| 
									
										
										
										
											2018-05-31 14:29:00 -05:00
										 |  |  |   // set plugin store
 | 
					
						
							|  |  |  |   const pluginStore = strapi.store({ | 
					
						
							|  |  |  |     environment: strapi.config.environment, | 
					
						
							|  |  |  |     type: 'plugin', | 
					
						
							| 
									
										
										
										
											2019-04-05 16:11:09 +02:00
										 |  |  |     name: 'email', | 
					
						
							| 
									
										
										
										
											2018-05-31 14:29:00 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   strapi.plugins.email.config.providers = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 16:01:18 +02:00
										 |  |  |   const installedProviders = Object.keys(strapi.config.info.dependencies) | 
					
						
							|  |  |  |     .filter(d => d.startsWith('strapi-provider-email-')) | 
					
						
							|  |  |  |     .concat('strapi-provider-email-sendmail'); | 
					
						
							| 
									
										
										
										
											2018-05-31 14:29:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 16:01:18 +02:00
										 |  |  |   for (let installedProvider of _.uniq(installedProviders)) { | 
					
						
							| 
									
										
										
										
											2019-04-05 16:11:09 +02:00
										 |  |  |     strapi.plugins.email.config.providers.push(require(installedProvider)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-01 17:09:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 15:35:40 +02:00
										 |  |  |   // if provider config does not exist set one by default
 | 
					
						
							|  |  |  |   const config = await pluginStore.get({ key: 'provider' }); | 
					
						
							| 
									
										
										
										
											2019-03-01 17:09:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 15:35:40 +02:00
										 |  |  |   if (!config) { | 
					
						
							|  |  |  |     const provider = _.find(strapi.plugins.email.config.providers, { | 
					
						
							|  |  |  |       provider: 'sendmail', | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-05-31 14:29:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 15:35:40 +02:00
										 |  |  |     const value = _.assign({}, provider, { | 
					
						
							|  |  |  |       // TODO: set other default settings here
 | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-05-31 14:29:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 15:35:40 +02:00
										 |  |  |     await pluginStore.set({ key: 'provider', value }); | 
					
						
							| 
									
										
										
										
											2019-04-05 16:11:09 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-05-31 14:29:00 -05:00
										 |  |  | }; |