compiler: Simplify verifyModelDefinitions()
Refactor `verifyModelDefinitions()` to use the new function `fixFileExtension` instead of removed `filterValidSourceFiles()`.
This commit is contained in:
parent
0563840006
commit
43df90a4c8
|
@ -276,25 +276,6 @@ function sortByInheritance(instructions) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns matching files with a supported `sourceFile` extension like
|
|
||||||
* `.js` or `.coffee`
|
|
||||||
* @param {Array} allFiles
|
|
||||||
* @param {string} basename
|
|
||||||
* @returns {Array}
|
|
||||||
*/
|
|
||||||
function filterValidSourceFiles(allFiles, basename) {
|
|
||||||
var base, ext, validFileType;
|
|
||||||
return allFiles
|
|
||||||
.filter(function(f) {
|
|
||||||
ext = path.extname(f);
|
|
||||||
base = path.basename(f, ext);
|
|
||||||
validFileType = (ext !== '.node') && (ext !== '.json') &&
|
|
||||||
((typeof require.extensions[ext]) === 'function');
|
|
||||||
return validFileType && (base === basename);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function verifyModelDefinitions(rootDir, modelDefinitions) {
|
function verifyModelDefinitions(rootDir, modelDefinitions) {
|
||||||
if (!modelDefinitions || modelDefinitions.length < 1) {
|
if (!modelDefinitions || modelDefinitions.length < 1) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -303,22 +284,14 @@ function verifyModelDefinitions(rootDir, modelDefinitions) {
|
||||||
var registry = {};
|
var registry = {};
|
||||||
modelDefinitions.forEach(function(definition, idx) {
|
modelDefinitions.forEach(function(definition, idx) {
|
||||||
if (definition.sourceFile) {
|
if (definition.sourceFile) {
|
||||||
try {
|
|
||||||
var fullPath = path.resolve(rootDir, definition.sourceFile);
|
var fullPath = path.resolve(rootDir, definition.sourceFile);
|
||||||
var basename = path.basename(fullPath, path.extname(fullPath));
|
definition.sourceFile = fixFileExtension(
|
||||||
var files = tryReadDir(path.dirname(fullPath));
|
fullPath,
|
||||||
var sourceFile = filterValidSourceFiles(files, basename)[0];
|
tryReadDir(path.dirname(fullPath)),
|
||||||
|
true);
|
||||||
definition.sourceFile = path.join(path.dirname(fullPath), sourceFile);
|
if (!definition.sourceFile) {
|
||||||
definition.sourceFile = require.resolve(definition.sourceFile);
|
debug('Model source code not found: %s - %s', definition.sourceFile);
|
||||||
} catch (err) {
|
|
||||||
debug('Model source code not found: %s - %s',
|
|
||||||
definition.sourceFile,
|
|
||||||
err.code || err);
|
|
||||||
definition.sourceFile = undefined;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
definition.sourceFile = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('Found model "%s" - %s %s',
|
debug('Found model "%s" - %s %s',
|
||||||
|
|
Loading…
Reference in New Issue