| 
									
										
										
										
											2016-03-25 22:50:01 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Module dependencies | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Node.js core.
 | 
					
						
							| 
									
										
										
										
											2016-09-28 11:42:26 +02:00
										 |  |  | const fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2016-03-25 22:50:01 +01:00
										 |  |  | const path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Generate a core API | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							| 
									
										
										
										
											2016-08-09 12:38:05 +02:00
										 |  |  |   templatesDirectory: scope => { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       // Try to reach the path. If it fail, throw an error.
 | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |       fs.accessSync(path.resolve(__dirname, '..', 'templates', scope.args.tpl), fs.constants.R_OK | fs.constants.W_OK); | 
					
						
							| 
									
										
										
										
											2016-08-09 12:38:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |       return path.resolve(__dirname, '..', 'templates', scope.args.tpl); | 
					
						
							| 
									
										
										
										
											2016-08-09 12:38:05 +02:00
										 |  |  |     } catch (e) { | 
					
						
							|  |  |  |       // Default template is Mongoose
 | 
					
						
							|  |  |  |       return path.resolve(__dirname, '..', 'templates', 'mongoose'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-03-25 22:50:01 +01:00
										 |  |  |   before: require('./before'), | 
					
						
							|  |  |  |   targets: { | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |     'api/:api/services/:filename': { | 
					
						
							| 
									
										
										
										
											2016-03-25 22:50:01 +01:00
										 |  |  |       template: 'service.template' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; |