Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yurenju committed Feb 10, 2014
1 parent 7a317b0 commit 308a51f
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 148 deletions.
13 changes: 13 additions & 0 deletions apps/communications/Makefile
@@ -0,0 +1,13 @@
-include $(PWD)/build/common.mk

BUILD_DIR=$(PWD)/build_stage/communications

.PHONY: all clean
all: clean
@echo Building communications app to build_stage...
@mkdir -p $(BUILD_DIR)
@cp -r * $(BUILD_DIR)
@rm -rf $(BUILD_DIR)/Makefile $(BUILD_DIR)/build $(BUILD_DIR)/test
@$(call run-app-js-command, build)
clean:
@rm -rf $(BUILD_DIR)
205 changes: 205 additions & 0 deletions apps/communications/build/build.js
@@ -0,0 +1,205 @@
'use strict';

/* global require, exports */
var utils = require('utils');

const APP_NAME = 'communications';
const DEBUG = false;

var CommAppBuilder = function() {
};

CommAppBuilder.prototype.APP_DIR = 'apps/' + APP_NAME;
CommAppBuilder.prototype.DIST_DIR = 'build_stage/' + APP_NAME;

// set destination directory and application directory
CommAppBuilder.prototype.setOptions = function(options) {
var distDirPath = [options.GAIA_DIR].concat(this.DIST_DIR.split('/'));
this.distDir = utils.getFile.apply(utils, distDirPath);

var appDirPath = [options.GAIA_DIR].concat(this.APP_DIR.split('/'));
this.appDir = utils.getFile.apply(utils, appDirPath);

this.webapp = utils.getWebapp(this.appDir.path, options.GAIA_DOMAIN,
options.GAIA_SCHEME, options.GAIA_PORT);
this.gaia = utils.getGaia(options);

var content = JSON.parse(utils.getFileContent(utils.getFile(this.appDir.path,
'build', 'communications_services.json')));
var custom = utils.getDistributionFileContent('communications_services',
content);
this.commsServices = JSON.parse(custom);
this.official = options.OFFICIAL;
};

CommAppBuilder.prototype.generateManifest = function() {
var manifestObject;
if (this.gaia.l10nManager) {
manifestObject = this.gaia.l10nManager.localizeManifest(this.webapp);
} else {
var manifestContent = utils.getFileContent(this.webapp.manifestFile);
manifestObject = JSON.parse(manifestContent);
}

var redirects = manifestObject.redirects;

var indexedRedirects = {};
redirects.forEach(function(aRedirect) {
indexedRedirects[aRedirect.from] = aRedirect.to;
});

var mappingParameters = {
'facebook': 'redirectURI',
'live': 'redirectURI',
'gmail': 'redirectURI',
'facebook_dialogs': 'redirectMsg',
'facebook_logout': 'redirectLogout'
};

var newRedirects = [];
redirects.forEach(function(aRedirect) {
var from = aRedirect.from;
var service = this.commsServices[from.split('_')[0] || from] ||
this.commsServices;
newRedirects.push({
from: service[mappingParameters[from]],
to: indexedRedirects[from]
});
}, this);

manifestObject.redirects = newRedirects;

var file = utils.getFile(this.distDir.path, 'manifest.webapp');
var args = DEBUG ? [manifestObject, undefined, 2] : [manifestObject];
utils.writeContent(file, JSON.stringify.apply(JSON, args));
};

CommAppBuilder.prototype.copyDistributionConfig = function() {
if (!this.gaia.distributionDir) {
return;
}

// Communications config
var init = utils.getFile(this.distDir.path, 'contacts', 'config.json');
var content = {
'defaultContactsOrder': 'givenName',
'facebookEnabled': true,
'operationsTimeout': 25000,
'logLevel': 'DEBUG',
'facebookSyncPeriod': 24,
'testToken': ''
};
utils.writeContent(init,
utils.getDistributionFileContent('communications', content,
this.gaia.distributionDir));

// Communications External Services
init = utils.getFile(this.appDir.path, 'contacts', 'oauth2', 'js',
'parameters.js');

// Bug 883344 Only use default facebook app id if is mozilla partner build
if (this.official === '1') {
this.commsServices.facebook.applicationId = '395559767228801';
this.commsServices.live.applicationId = '00000000440F8B08';
}

var commsServices =
utils.getDistributionFileContent('communications_services',
this.commsServices, this.gaia.distributionDir);

utils.writeContent(init,
'var oauthflow = this.oauthflow || {}; oauthflow.params = ' +
commsServices + ';');

/////////
let variantFile = utils.getFile(gaia.distributionDir, 'variant.json');
if (variantFile.exists()) {
let resources = this.getSingleVariantResources(variantFile);

var customizationFile = utils.getFile(this.appDir.path,
'resources', 'customization.json');
utils.writeContent(customization, JSON.stringify(resources.conf));

resources.files.forEach(function(file) {
var resourceFile;
if (file instanceof Ci.nsILocalFile) {
resourceFile = utils.getFile()
let filename = 'resources/' + file.leafName;
if (zip.hasEntry(filename)) {
zip.removeEntry(filename, false);
}
var compression = getCompression(filename, webapp);
addEntryFileWithTime(zip, filename, file, DEFAULT_TIME,
compression);
} else {
let filename = 'resources/' + file.filename;
if (zip.hasEntry(filename)) {
zip.removeEntry(filename, false);
}
addEntryStringWithTime(zip, filename, JSON.stringify(file.content),
DEFAULT_TIME);
}
});
} else {
utils.log(variantFile.path + ' not found. Single variant resources will not' +
' be added.\n');
}
};

CommAppBuilder.prototype.getSingleVariantResources = function (conf) {
var distDir = utils.getGaia(config).distributionDir;
conf = utils.getJSON(conf);

let output = {};
let resources = [];
conf['operators'].forEach(function(operator) {
let object = {};

getResource(distDir, operator['wallpaper'], resources, object, 'wallpaper');
getResource(distDir, operator['default_contacts'],
resources, object, 'default_contacts');
getResource(distDir, operator['support_contacts'],
resources, object, 'support_contacts');

let ringtone = operator['ringtone'];
if (ringtone) {
let ringtoneName = ringtone['name'];
if (!ringtoneName) {
throw new Error('Missing name for ringtone in single variant conf.');
}

getResource(distDir, ringtone['path'], resources, object, 'ringtone');
if (!object.ringtone) {
throw new Error('Missing path for ringtone in single variant conf.');
}

// Generate ringtone JSON
let uuidGenerator = Cc['@mozilla.org/uuid-generator;1'].
createInstance(Ci.nsIUUIDGenerator);
let ringtoneObj = { filename: uuidGenerator.generateUUID().toString() +
'.json',
content: { uri: object['ringtone'],
name: ringtoneName }};

resources.push(ringtoneObj);
object['ringtone'] = '/resources/' + ringtoneObj.filename;
}

operator['mcc-mnc'].forEach(function(mcc) {
if (Object.keys(object).length !== 0) {
output[mcc] = object;
}
});
});

return {'conf': output, 'files': resources};
}

CommAppBuilder.prototype.execute = function(options) {
this.setOptions(options);
this.generateManifest();
};

exports.execute = function(options) {
(new CommAppBuilder()).execute(options);
};
File renamed without changes.
3 changes: 3 additions & 0 deletions apps/communications/gaia_build.json
@@ -0,0 +1,3 @@
{
"dir": "../../build_stage/communications"
}
32 changes: 0 additions & 32 deletions build/applications-data.js
Expand Up @@ -405,38 +405,6 @@ function execute(options) {
utils.writeContent(init,
utils.getDistributionFileContent('wapuaprof.json', content, distDir));

// Communications config
init = utils.getFile(config.GAIA_DIR,
'apps', 'communications', 'contacts', 'config.json');
content = {
'defaultContactsOrder': 'givenName',
'facebookEnabled': true,
'operationsTimeout': 25000,
'logLevel': 'DEBUG',
'facebookSyncPeriod': 24,
'testToken': ''
};
utils.writeContent(init,
utils.getDistributionFileContent('communications', content, distDir));

// Communications External Services
init = utils.getFile(config.GAIA_DIR,
'apps', 'communications', 'contacts', 'oauth2', 'js', 'parameters.js');
content = JSON.parse(utils.getFileContent(utils.getFile(config.GAIA_DIR,
'build', 'config',
'communications_services.json')));

// Bug 883344 Only use default facebook app id if is mozilla partner build
if (config.OFFICIAL === '1') {
content.facebook.applicationId = '395559767228801';
content.live.applicationId = '00000000440F8B08';
}

utils.writeContent(init,
'var oauthflow = this.oauthflow || {}; oauthflow.params = ' +
utils.getDistributionFileContent('communications_services', content,
distDir) + ';');

// Customize the maximum image size for Camera and Gallery
(function customizeMaximumImageSize() {
let defaultValue = {
Expand Down

0 comments on commit 308a51f

Please sign in to comment.