Merge pull request #104 from PradnyaBaviskar/lb-explorer-issue-65

Resolve relative paths in bootScripts using appRootDir
This commit is contained in:
Miroslav Bajtoš 2015-03-11 08:43:39 +01:00
commit cb7ca7d9ad
2 changed files with 34 additions and 0 deletions

View File

@ -62,8 +62,11 @@ module.exports = function compile(options) {
// require directories // require directories
var bootDirs = options.bootDirs || []; // precedence var bootDirs = options.bootDirs || []; // precedence
bootDirs = bootDirs.concat(path.join(appRootDir, 'boot')); bootDirs = bootDirs.concat(path.join(appRootDir, 'boot'));
resolveRelativePaths(bootDirs, appRootDir);
var bootScripts = options.bootScripts || []; var bootScripts = options.bootScripts || [];
resolveRelativePaths(bootScripts, appRootDir);
bootDirs.forEach(function(dir) { bootDirs.forEach(function(dir) {
bootScripts = bootScripts.concat(findScripts(dir)); bootScripts = bootScripts.concat(findScripts(dir));
}); });
@ -497,3 +500,12 @@ function buildComponentInstructions(rootDir, componentConfig) {
}; };
}); });
} }
function resolveRelativePaths(relativePaths, appRootDir) {
relativePaths.forEach(function(relativePath, k) {
var start = relativePath.substring(0, 2);
if (start === './' || start === '..') {
relativePaths[k] = path.resolve(appRootDir, relativePath);
}
});
}

View File

@ -417,6 +417,28 @@ describe('compiler', function() {
expect(instructions.files.boot).to.eql([initJs]); expect(instructions.files.boot).to.eql([initJs]);
}); });
it('should resolve relative path in `bootScripts`', function() {
appdir.createConfigFilesSync();
var initJs = appdir.writeFileSync('custom-boot/init.js',
'module.exports = function(app) { app.fnCalled = true; };');
var instructions = boot.compile({
appRootDir: appdir.PATH,
bootScripts: ['./custom-boot/init.js']
});
expect(instructions.files.boot).to.eql([initJs]);
});
it('should resolve relative path in `bootDirs`', function() {
appdir.createConfigFilesSync();
var initJs = appdir.writeFileSync('custom-boot/init.js',
'module.exports = function(app) { app.fnCalled = true; };');
var instructions = boot.compile({
appRootDir: appdir.PATH,
bootDirs:['./custom-boot']
});
expect(instructions.files.boot).to.eql([initJs]);
});
it('ignores models/ subdirectory', function() { it('ignores models/ subdirectory', function() {
appdir.createConfigFilesSync(); appdir.createConfigFilesSync();
appdir.writeFileSync('models/my-model.js', ''); appdir.writeFileSync('models/my-model.js', '');