| 
									
										
										
										
											2016-03-18 11:12:50 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Module dependencies | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Node.js core.
 | 
					
						
							| 
									
										
										
										
											2016-08-09 12:38:05 +02:00
										 |  |  | const fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2016-03-18 11:12:50 +01:00
										 |  |  | const path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Local dependencies.
 | 
					
						
							|  |  |  | const routesJSON = require('../json/routes.json.js'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * 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-18 11:12:50 +01:00
										 |  |  |   before: require('./before'), | 
					
						
							|  |  |  |   targets: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Use the default `controller` file as a template for
 | 
					
						
							|  |  |  |     // every generated controller.
 | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |     ':folderPrefix/:folderName/controllers/:filename': { | 
					
						
							| 
									
										
										
										
											2016-03-18 11:12:50 +01:00
										 |  |  |       template: 'controller.template' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // every generated controller.
 | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |     ':folderPrefix/:folderName/services/:filename': { | 
					
						
							| 
									
										
										
										
											2016-03-18 11:12:50 +01:00
										 |  |  |       template: 'service.template' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Copy an empty JavaScript model where every functions will be.
 | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |     ':folderPrefix/:folderName/models/:filename': { | 
					
						
							| 
									
										
										
										
											2016-03-18 11:12:50 +01:00
										 |  |  |       template: 'model.template' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Copy the generated JSON model for the connection,
 | 
					
						
							|  |  |  |     // schema and attributes.
 | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |     ':folderPrefix/:folderName/models/:filenameSettings': { | 
					
						
							| 
									
										
										
										
											2016-03-18 11:12:50 +01:00
										 |  |  |       template: 'model.settings.template' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Generate routes.
 | 
					
						
							| 
									
										
										
										
											2017-02-14 01:10:37 +01:00
										 |  |  |     ':folderPrefix/:folderName/config/routes.json': { | 
					
						
							| 
									
										
										
										
											2016-03-18 11:12:50 +01:00
										 |  |  |       jsonfile: routesJSON | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; |