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

Commit

Permalink
Merge pull request #33978 from rickychien/email-build-to-node
Browse files Browse the repository at this point in the history
Bug 1240678 - Running email build.js on node.js r=@scottwu
  • Loading branch information
rickychien committed Feb 4, 2016
2 parents 193f5bf + bc9561d commit 6c1a832
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 48 deletions.
57 changes: 16 additions & 41 deletions apps/email/build/build.js
Expand Up @@ -4,19 +4,12 @@

var utils = require('utils');
var esomin = require('esomin');
var { Cc, Ci } = require('chrome');
var converter =
Cc['@mozilla.org/intl/scriptableunicodeconverter'].
createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = 'UTF-8';
var secClass = Cc['@mozilla.org/security/hash;1'];
var nsICryptoHash = Ci.nsICryptoHash;
var digests = [];
var appName;

// FIXME: It will be replace with webapp-shared.js
// Taken from r.js css optimizing step.
var cssImportRegExp = /\@import\s+(url\()?\s*([^);]+)\s*(\))?([\w, ]*)(;)?/ig;
var digests = [];
var appName;

function stripCssComments(contents) {
var index,
Expand Down Expand Up @@ -162,31 +155,16 @@ function generateServicesConfig(options) {
}

function onFileRead(contents) {
digests.push(getDigest(contents));
}

function getDigest(contents) {
var result = {};

// data is an array of bytes
var data = converter.convertToByteArray(contents, result);
var ch = secClass.createInstance(nsICryptoHash);
ch.init(ch.SHA1);
ch.update(data, data.length);
var hash = ch.finish(false);
// convert the binary hash data to a hex string.
return hash.split('').map(function(char, i) {
return toHexString(hash.charCodeAt(i));
}).join('');
digests.push(utils.getHash(contents));
}

function writeCacheValue(options) {
// Update the cache value based on digest values of all files.
var finalDigest = getDigest(digests.join(',')),
cacheRegExp = /HTML_CACHE_VERSION\s*=\s*["'][^"']+["']/,
cacheFile = utils.getFile(options.STAGE_APP_DIR, 'js',
'html_cache_restore.js'),
contents = utils.getFileContent(cacheFile);
var finalDigest = utils.getHash(digests.join(','));
var cacheRegExp = /HTML_CACHE_VERSION\s*=\s*["'][^"']+["']/;
var cacheFile = utils.getFile(options.STAGE_APP_DIR, 'js',
'html_cache_restore.js');
var contents = utils.getFileContent(cacheFile);
contents = contents.replace(cacheRegExp,
'HTML_CACHE_VERSION = \'' + finalDigest + '\'');

Expand Down Expand Up @@ -334,19 +312,16 @@ exports.execute = function(options) {
requirejs = sandbox.requirejs;
}

var promises = [
optimize(options, requirejs),
getParse(requirejs)
];

return Promise.all(promises)
return optimize(options, requirejs)
.then(function() {
return getParse(requirejs);
})
.then(function(result) {
var [buildText, parse] = result;

shared.js = getSharedJs(parse, options.APP_DIR,
shared.js = getSharedJs(result, options.APP_DIR,
backendRegExp, onFileRead);
[shared.style, shared.style_unstable] =
getSharedStyles(options.APP_DIR, onFileRead);
var styles = getSharedStyles(options.APP_DIR, onFileRead);
shared.style = styles[0];
shared.style_unstable = styles[1];
utils.writeContent(sharedJsonFile, JSON.stringify(shared, null, 2));

writeCacheValue(options);
Expand Down
2 changes: 1 addition & 1 deletion build/build-app.js
Expand Up @@ -15,7 +15,7 @@ exports.execute = function(options) {
'clock',
'communications',
'costcontrol',
//'email',
'email',
'findmydevice',
'ftu',
'gallery',
Expand Down
8 changes: 4 additions & 4 deletions build/utils-node.js
Expand Up @@ -575,10 +575,6 @@ module.exports = {
this.copyDirTo(appDir, options.STAGE_DIR, appDir.leafName);
},

exit: function(code) {
process.exit(code);
},

scriptLoader: {

scripts: {},
Expand Down Expand Up @@ -622,5 +618,9 @@ module.exports = {

getHash: function(string) {
return crypto.createHash('sha1').update(string).digest('hex');
},

exit: function(code) {
process.exit(code);
}
};
2 changes: 1 addition & 1 deletion build/utils-xpc.js
Expand Up @@ -1428,5 +1428,5 @@ exports.getUUIDMapping = getUUIDMapping;
exports.getMD5hash = getMD5hash;
exports.createSandbox = createSandbox;
exports.runScriptInSandbox= runScriptInSandbox;
exports.exit = exit;
exports.getHash = getHash;
exports.exit = exit;
2 changes: 1 addition & 1 deletion build/utils.js
Expand Up @@ -371,5 +371,5 @@ exports.normalizePath = utils.normalizePath;
exports.getMD5hash = utils.getMD5hash;
exports.createSandbox = utils.createSandbox;
exports.runScriptInSandbox = utils.runScriptInSandbox;
exports.exit = utils.exit;
exports.getHash = utils.getHash;
exports.exit = utils.exit;

0 comments on commit 6c1a832

Please sign in to comment.