forked from mozilla-b2g/gaia
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
287 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dir": "../../build_stage/communications" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.