Provide scriptExtensions option
Backport of https://github.com/strongloop/loopback-boot/pull/240 with some simplifications for this version
This commit is contained in:
parent
622c64ebde
commit
4300b82e24
lib
|
@ -40,9 +40,18 @@ module.exports = function compile(options) {
|
|||
ConfigLoader.loadDataSources(dsRootDir, env);
|
||||
assertIsValidConfig('data source', dataSourcesConfig);
|
||||
|
||||
// backport https://github.com/strongloop/loopback-boot/pull/240/
|
||||
var scriptExtensions = options.scriptExtensions ||
|
||||
Object.keys(require.extensions);
|
||||
if (!Array.isArray(scriptExtensions) || !scriptExtensions.length) {
|
||||
scriptExtensions = ['.js', '.json', '.node'];
|
||||
}
|
||||
|
||||
// require directories
|
||||
var modelsScripts = findScripts(path.join(modelsRootDir, 'models'));
|
||||
var bootScripts = findScripts(path.join(appRootDir, 'boot'));
|
||||
var modelsScripts = findScripts(path.join(modelsRootDir, 'models'),
|
||||
scriptExtensions);
|
||||
var bootScripts = findScripts(path.join(appRootDir, 'boot'),
|
||||
scriptExtensions);
|
||||
|
||||
// When executor passes the instruction to loopback methods,
|
||||
// loopback modifies the data. Since we are loading the data using `require`,
|
||||
|
@ -73,7 +82,7 @@ function assertIsValidConfig(name, config) {
|
|||
* @private
|
||||
*/
|
||||
|
||||
function findScripts(dir) {
|
||||
function findScripts(dir, scriptExtensions) {
|
||||
assert(dir, 'cannot require directory contents without directory name');
|
||||
|
||||
var files = tryReadDir(dir);
|
||||
|
@ -105,10 +114,11 @@ function findScripts(dir) {
|
|||
|
||||
// only require files supported by require.extensions (.txt .md etc.)
|
||||
if (stats.isFile()) {
|
||||
if (ext in require.extensions)
|
||||
if (scriptExtensions.indexOf(ext) !== -1) {
|
||||
results.push(filepath);
|
||||
else
|
||||
} else {
|
||||
debug('Skipping file %s - unknown extension', filepath);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
path.join(require.resolve(filepath));
|
||||
|
|
Loading…
Reference in New Issue