2016-04-21 14:52:00 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Node.js core.
|
2016-09-28 11:42:26 +02:00
|
|
|
const fs = require('fs');
|
2016-04-21 14:52:00 +02: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-04-21 14:52:00 +02:00
|
|
|
before: require('./before'),
|
|
|
|
targets: {
|
2017-02-14 01:10:37 +01:00
|
|
|
':filePath/:filename': {
|
2016-04-21 14:52:00 +02:00
|
|
|
template: 'controller.template'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|