Removes foreign for Firefox CSS prefixes

This commit is contained in:
Yury Delendik 2013-07-09 17:14:21 -05:00
parent d71948038f
commit 2ab481a1da
2 changed files with 77 additions and 2 deletions

View File

@ -101,6 +101,66 @@ function preprocess(inFilename, outFilename, defines) {
}
exports.preprocess = preprocess;
function preprocessCSS(mode, source, destination) {
function hasPrefixed(line) {
return (/(^|\W)-(ms|o|webkit)-\w/.test(line));
}
function removePrefixed(content) {
var lines = content.split(/\r?\n/g);
var i = 0;
while (i < lines.length) {
var line = lines[i];
if (!hasPrefixed(line)) {
i++;
continue;
}
if (/\{\s*$/.test(line)) {
var bracketLevel = 1;
var j = i + 1;
while (j < lines.length && bracketLevel > 0) {
var checkBracket = /([{}])\s*$/.exec(lines[j]);
if (checkBracket) {
if (checkBracket[1] === '{') {
bracketLevel++;
} else if (lines[j].indexOf('{') < 0) {
bracketLevel--;
}
}
j++;
}
lines.splice(i, j - i);
} else if (/[};]\s*$/.test(line)) {
lines.splice(i, 1);
} else {
// multiline? skipping until next directive or bracket
do {
lines.splice(i, 1);
} while (i < lines.length &&
!/\}\s*$/.test(lines[i]) &&
lines[i].indexOf(':') < 0);
if (i < lines.length && /\S\s*}\s*$/.test(lines[i])) {
lines[i] = lines[i].substr(lines[i].indexOf('}'));
}
}
// collapse whitespaces
while (lines[i] === '' && lines[i - 1] === '') {
lines.splice(i, 1);
}
}
return lines.join('\n');
}
if (mode !== 'firefox') {
throw new Error('Invalid CSS preprocessor mode');
}
var content = fs.readFileSync(source, 'utf8');
var out = removePrefixed(content);
fs.writeFileSync(destination, out);
}
exports.preprocessCSS = preprocessCSS;
/**
* Simplifies common build steps.
* @param {object} setup
@ -131,6 +191,13 @@ function build(setup) {
preprocess(source, destWithFolder, defines);
});
});
(setup.preprocessCSS || []).forEach(function(option) {
var mode = option[0];
var source = option[1];
var destination = option[2];
preprocessCSS(mode, source, destination);
});
}
exports.build = build;

12
make.js
View File

@ -70,8 +70,7 @@ target.all = function() {
// Files that need to be included in every build.
var COMMON_WEB_FILES =
['web/viewer.css',
'web/images',
['web/images',
'web/debugger.js'],
COMMON_WEB_FILES_PREPROCESS =
['web/viewer.js',
@ -102,6 +101,7 @@ target.generic = function() {
copy: [
[COMMON_WEB_FILES, GENERIC_DIR + '/web'],
['external/webL10n/l10n.js', GENERIC_DIR + '/web'],
['web/viewer.css', GENERIC_DIR + '/web'],
['web/compatibility.js', GENERIC_DIR + '/web'],
['web/compressed.tracemonkey-pldi-09.pdf', GENERIC_DIR + '/web'],
['web/locale', GENERIC_DIR + '/web']
@ -410,6 +410,10 @@ target.firefox = function() {
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
[BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR + BUILD_TARGET],
[SRC_DIR + 'network.js', FIREFOX_BUILD_CONTENT_DIR]
],
preprocessCSS: [
['firefox', 'web/viewer.css',
FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.css']
]
};
builder.build(setup);
@ -520,6 +524,9 @@ target.mozcentral = function() {
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
[BUILD_TARGET, MOZCENTRAL_CONTENT_DIR + BUILD_TARGET],
[SRC_DIR + 'network.js', MOZCENTRAL_CONTENT_DIR]
],
preprocessCSS: [
['firefox', 'web/viewer.css', MOZCENTRAL_CONTENT_DIR + '/web/viewer.css']
]
};
builder.build(setup);
@ -629,6 +636,7 @@ target.chrome = function() {
'extensions/chrome/icon*.png',],
CHROME_BUILD_DIR],
['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web'],
['web/viewer.css', CHROME_BUILD_CONTENT_DIR + '/web'],
['web/locale', CHROME_BUILD_CONTENT_DIR + '/web']
],
preprocess: [