Skip to content

Commit 416132c

Browse files
committed
engine loader now finds the mustache engine module from the edition!
1 parent faa09d6 commit 416132c

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

core/lib/pattern_engines/pattern_engines.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,49 @@
1212

1313
var path = require('path');
1414
var diveSync = require('diveSync');
15-
var engineMatcher = /^engine_(.*)\.js/;
16-
var enginesDirectory = __dirname;
17-
15+
var engineMatcher = /^patternengine-node-(.*)$/;
16+
var enginesDirectory = path.join(process.cwd(), 'node_modules');
1817
var PatternEngines; // the main export object
1918
var engineNameForExtension; // generated mapping of extension to engine name
2019

2120

2221
// free "private" functions, for internal setup only
2322

23+
// given a path: return the engine name is the path points to a valid engine
24+
// module directory, or false if it doesn't
25+
function isEngineModule(filePath) {
26+
var baseName = path.basename(filePath);
27+
var engineMatch = baseName.match(engineMatcher);
28+
29+
if (engineMatch) { return engineMatch[1]; }
30+
return false;
31+
}
32+
33+
function getEngineModulePath(engineName) {
34+
return path.resolve(enginesDirectory, "patternengine-node-" + engineName);
35+
}
36+
37+
// go find the names of all found engines
2438
function findSupportedPatternEngineNames() {
2539
var foundPatternEngineNames = [];
2640

27-
// find
41+
// iterate over module directory and build a list of available pattern engine
42+
// names
2843
diveSync(enginesDirectory, {
2944
recursive: false,
30-
filter: function (filePath, dir) {
31-
var baseName = path.basename(filePath),
32-
engineMatch = baseName.match(engineMatcher);
33-
34-
if (dir || engineMatch !== null) { return true; }
35-
return false;
36-
}
45+
directories: true
3746
}, function (err, filePath) {
3847
if (err) { throw err; }
39-
var baseName = path.basename(filePath),
40-
engineMatch = baseName.match(engineMatcher),
41-
foundEngineName = engineMatch[1];
42-
43-
foundPatternEngineNames.push(foundEngineName);
48+
var foundEngineName = isEngineModule(filePath);
49+
if (foundEngineName) {
50+
foundPatternEngineNames.push(foundEngineName);
51+
}
4452
});
4553

4654
return foundPatternEngineNames;
4755
}
4856

57+
4958
// try to load all supported engines
5059
function loadAllEngines(enginesObject) {
5160
console.log('\nLoading engines...');
@@ -54,7 +63,7 @@ function loadAllEngines(enginesObject) {
5463
var notLoaded = false;
5564

5665
try {
57-
enginesObject[engineName] = require('./engine_' + engineName);
66+
enginesObject[engineName] = require(getEngineModulePath(engineName));
5867
} catch (err) {
5968
// Handle errors loading each pattern engine. This will usually be
6069
// because the engine's renderer hasn't been installed by the end user

0 commit comments

Comments
 (0)