Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1022767 - Fix relative path building in webapp-optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbigniew Braniecki committed Sep 19, 2014
1 parent 5dd229d commit b8065b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
6 changes: 5 additions & 1 deletion build/test/unit/mock_utils.js
Expand Up @@ -99,5 +99,9 @@ exports.scriptLoader = {
};

exports.dirname = function(path) {
return path.substr(0, path.lastIndexOf('.'));
return path.substr(0, path.lastIndexOf('/'));
};

exports.basename = function(path) {
return path.substr(path.lastIndexOf('/')+1);
};
9 changes: 6 additions & 3 deletions build/test/unit/webapp-optimize.test.js
Expand Up @@ -61,6 +61,9 @@ suite('webapp-optimize.js', function() {
clone: function() {
return getFile(filePath);
},
get parent() {
return getFile(filePath.substr(0, filePath.lastIndexOf('/')));
},
append: function(subPath) {
filePath += '/' + subPath;
},
Expand Down Expand Up @@ -353,7 +356,6 @@ suite('webapp-optimize.js', function() {
var writeAggregatedConfig;
setup(function() {
var htmlFile = mockUtils.getFile('test-index.html');
htmlFile.parent = mockUtils.getFile('test-parent-index.html');
htmlOptimizer = new app.HTMLOptimizer({
htmlFile: htmlFile,
webapp: {
Expand Down Expand Up @@ -525,9 +527,10 @@ suite('webapp-optimize.js', function() {

test('getFileByRelativePath', function() {
isSubjectToBranding = true;
var path = '/test';
var path = '/test/foo.html';
var result = htmlOptimizer.getFileByRelativePath(path);
assert.equal(result.file.getCurrentPath(), 'build_stage/test/official');
assert.equal(result.file.getCurrentPath(),
'build_stage/test/official/foo.html');
});
});
});
7 changes: 4 additions & 3 deletions build/test/unit/webapp-shared.test.js
Expand Up @@ -158,9 +158,10 @@ suite('webapp-shared.js', function() {
assert.equal(webappShared.used.unstable_styles[0], unstable_styles,
'push unstable_styles');

var locales = 'testlocales';
webappShared.pushFileByType('locales', locales + '.obj');
assert.equal(webappShared.used.locales[0], locales,
var localeName = 'date';
webappShared.pushFileByType('locales',
localeName + '/date.{locale}.properties');
assert.equal(webappShared.used.locales[0], localeName,
'push locales');
});

Expand Down
20 changes: 14 additions & 6 deletions build/webapp-optimize.js
Expand Up @@ -548,14 +548,22 @@ HTMLOptimizer.prototype.getFileByRelativePath = function(relativePath) {
return;
}
file.append(name);
if (utils.isSubjectToBranding(file.path)) {
file.append((this.config.OFFICIAL === '1') ? 'official' : 'unofficial');
}
if (utils.isSubjectToDeviceType(file.path)) {
file.append(this.config.GAIA_DEVICE_TYPE);
}
}, this);

var dirName = utils.dirname(relativePath);
var fileName = utils.basename(relativePath);

if (utils.isSubjectToBranding(dirName)) {
file = file.parent;
file.append((this.config.OFFICIAL === '1') ? 'official' : 'unofficial');
file.append(fileName);
}
if (utils.isSubjectToDeviceType(file.path)) {
file = file.parent;
file.append(this.config.GAIA_DEVICE_TYPE);
file.append(fileName);
}

try {
return {
file: file,
Expand Down

0 comments on commit b8065b6

Please sign in to comment.