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 #23766 from azasypkin/bug-1050416-build-script
Browse files Browse the repository at this point in the history
Bug 1050416 - [Messages][Build] Add build script to ignore the desktop-only folder for production build. r=julien
  • Loading branch information
azasypkin committed Sep 30, 2014
2 parents ac369f2 + 936b243 commit 5937b83
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 120 deletions.
30 changes: 30 additions & 0 deletions apps/sms/build/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* global require, exports */

'use strict';

var utils = require('utils');

function removeDesktopOnlyFolder(appStageDir) {
var desktopOnlyDir = utils.getFile(appStageDir, 'js', 'desktop-only');

if (desktopOnlyDir.exists()) {
desktopOnlyDir.remove(true);
}
}

function removeDesktopOnlyScripts(appStageDir) {
var indexFile = utils.getFile(appStageDir, 'index.html');
var desktopOnlyScriptsRegex = /<script.+desktop\-only.+<\/script>/g;

utils.writeContent(
indexFile,
utils.getFileContent(indexFile).replace(desktopOnlyScriptsRegex, '')
);
}

exports.execute = function(options) {
utils.copyToStage(options);

removeDesktopOnlyFolder(options.STAGE_APP_DIR);
removeDesktopOnlyScripts(options.STAGE_APP_DIR);
};
6 changes: 6 additions & 0 deletions apps/sms/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<link rel="localization" href="locales/sms.{locale}.properties">
<link rel="localization" href="/shared/locales/date/date.{locale}.properties">
<link rel="localization" href="/shared/locales/sim_picker/sim_picker.{locale}.properties">
<!-- Firefox Desktop shims -->
<script defer src="js/desktop-only/navigator_moz_icc_manager.js"></script>
<script defer src="js/desktop-only/navigator_moz_settings.js"></script>
<script defer src="js/desktop-only/navigator_moz_mobilemessage.js"></script>
<script defer src="js/desktop-only/navigator_moz_contacts.js"></script>
<script defer src="js/desktop-only/async_storage.js"></script>
<!-- Web Components -->
<script defer src="/shared/elements/config.js"></script>
<script defer src="/shared/elements/gaia-header/dist/script.js"></script>
Expand Down
84 changes: 84 additions & 0 deletions apps/sms/js/desktop-only/async_storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
(function(exports) {
'use strict';

// Fake drafts stored in local store
const timestamp = Date.now(),
store = new Map();

const draftIndex = [
[11, [{
recipients: ['555', '666'],
subject: '',
content: ['This is a draft message'],
timestamp: timestamp - (3600000 * 24),
threadId: 11,
type: 'sms'
}]],
[null, [{
recipients: [],
subject: '',
content: ['This is a draft SMS, with no recipient'],
timestamp: timestamp,
threadId: null,
type: 'sms'
}, {
recipients: ['555-666-1234'],
subject: '',
content: ['This is a draft SMS, with a recipient, but no thread'],
timestamp: timestamp - 3600000,
threadId: null,
type: 'sms'
}]],
[8, [{
recipients: ['123456'],
subject: '',
content: [
'This is a draft MMS...',
{
blob: {
type: 'audio/ogg',
size: 12345
},
name: 'audio.oga'
},
'...with a recipient and a thread'
],
timestamp: timestamp - (3600000 * 2),
threadId: 8,
type: 'mms'
}]]
];

store.set('draft index', draftIndex);

function callCallback(value, callback) {
if (typeof callback === 'function') {
setTimeout(callback.bind(null, value), 0);
}
}

Object.defineProperty(exports, 'asyncStorage', {
// Marking as non-configurable to not be overridden by real asyncStorage
configurable: false,
value: {
getItem: function asm_getItem(key, callback) {
callCallback(store.get(key) || null, callback);
},
setItem: function asm_setItem(key, value, callback) {
callCallback(store.set(key, value), callback);
},
removeItem: function asm_removeItem(key, callback) {
callCallback(store.delete(key), callback);
},
clear: function asm_clear(callback) {
callCallback(store.clear(), callback);
},
length: function(callback) {
callCallback(store.size, callback);
},
key: function() {
throw new Error('Not Implemented');
}
}
});
})(window);
11 changes: 11 additions & 0 deletions apps/sms/js/desktop-only/navigator_moz_icc_manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function() {
'use strict';

if (navigator.mozIccManager) {
return;
}

navigator.mozIccManager = {
iccIds: []
};
})();
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global Drafts, asyncStorage */
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

Expand All @@ -10,9 +9,11 @@
*********************************************************** */
(function(window) {
if (navigator.mozMobileMessage) {
return;
}

var MockNavigatormozMobileMessage =
window.DesktopMockNavigatormozMobileMessage = {};
var MockNavigatormozMobileMessage = {};

var outstandingRequests = 0;
var requests = {};
Expand Down Expand Up @@ -322,64 +323,6 @@
'101', '102', '103', '104', '105', '106', '107', '108', '109'
];

var timestamp = Date.now();
// Fake drafts stored in local store
(function() {
var drafts = [
{
recipients: ['555', '666'],
subject: '',
content: ['This is a draft message'],
timestamp: timestamp - (3600000 * 24),
threadId: 42,
type: 'sms'
},
{
recipients: [],
subject: '',
content: ['This is a draft SMS, with no recipient'],
timestamp: timestamp,
threadId: null,
type: 'sms'
},
{
recipients: ['555-666-1234'],
subject: '',
content: ['This is a draft SMS, with a recipient, but no thread'],
timestamp: timestamp - 3600000,
threadId: null,
type: 'sms'
},
{
recipients: ['123456'],
subject: '',
content: [
'This is a draft MMS...',
{
blob: {
type: 'audio/ogg',
size: 12345
},
name: 'audio.oga'
},
'...with a recipient and a thread'
],
timestamp: timestamp - (3600000 * 2),
threadId: 8,
type: 'mms'
}
];


asyncStorage.getItem('draft index', function(result) {
if (result === null || !result.length) {
drafts.forEach(Drafts.add, Drafts);
Drafts.store();
}
});
}());


// Fake in-memory message database
var messagesDb = {
id: 0,
Expand Down Expand Up @@ -1553,4 +1496,6 @@
return request;
};

navigator.mozMobileMessage = MockNavigatormozMobileMessage;

}(window));
37 changes: 37 additions & 0 deletions apps/sms/js/desktop-only/navigator_moz_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(function() {
'use strict';

if (navigator.mozSettings) {
return;
}

const KNOWN_SETTINGS = new Map();

KNOWN_SETTINGS.set('locale.hour12', true);

navigator.mozSettings = {
createLock: function() {
return {
get: function(key) {
var request = {
addEventListener: function(eventName, callback) {
request[eventName] = callback;
}
};

window.setTimeout(function() {
if (typeof request.onsuccess === 'function') {
request.result = {};
request.result[key] = KNOWN_SETTINGS.get(key);
request.onsuccess.call(request);
}
}, 0);

return request;
}
};
},

addObserver: function() {}
};
})();
6 changes: 2 additions & 4 deletions apps/sms/js/message_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ var MessageManager = {
return;
}
this.initialized = true;
// Allow for stubbing in environments that do not implement the
// `navigator.mozMobileMessage` API
this._mozMobileMessage = navigator.mozMobileMessage ||
window.DesktopMockNavigatormozMobileMessage;

this._mozMobileMessage = navigator.mozMobileMessage;

this._mozMobileMessage.addEventListener(
'received', this.onMessageReceived.bind(this)
Expand Down
11 changes: 0 additions & 11 deletions apps/sms/js/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,6 @@ var Startup = {
var initUIApp = this._initUIApp.bind(this);
window.addEventListener('DOMContentLoaded', function() {
window.dispatchEvent(new CustomEvent('moz-chrome-dom-loaded'));

if (!navigator.mozMobileMessage) {
var mocks = [
'js/desktop-only/mobilemessage.js',
'js/desktop-only/contacts.js'
];
LazyLoader.load(mocks, function() {
MessageManager.init(initUIApp);
});
return;
}
MessageManager.init(initUIApp);
});
}
Expand Down
21 changes: 0 additions & 21 deletions apps/sms/js/thread_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ var ThreadUI = {
this.mainWrapper = document.getElementById('main-wrapper');
this.threadMessages = document.getElementById('thread-messages');

// Allow for stubbing in environments that do not implement the
// `navigator.mozMobileMessage` API
this._mozMobileMessage = navigator.mozMobileMessage ||
window.DesktopMockNavigatormozMobileMessage;

window.addEventListener('resize', this.resizeHandler.bind(this));

// binding so that we can remove this listener later
Expand Down Expand Up @@ -1290,22 +1285,6 @@ var ThreadUI = {
number = thread.participants[0];
others = thread.participants.length - 1;

// For Desktop testing, there is a fake mozContacts but it's not working
// completely. So in the case of Desktop testing we are going to execute
// the callback directly in order to make it work!
// https://bugzilla.mozilla.org/show_bug.cgi?id=836733
if (!this._mozMobileMessage) {
navigator.mozL10n.setAttributes(
this.headerText,
'thread-header-text',
{
name: number,
n: others
}
);
return Promise.resolve();
}

// Add data to contact activity interaction
this.headerText.dataset.number = number;

Expand Down
2 changes: 1 addition & 1 deletion apps/sms/jsdoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sms": {
"src": ["apps/sms/js/**/*.js",
"!apps/sms/js/desktop-only/contacts.js"],
"!apps/sms/js/desktop-only/*"],
"options": {
"destination": "docs/sms"
}
Expand Down
7 changes: 1 addition & 6 deletions apps/sms/test/unit/sms_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*global MocksHelper, MockL10n, MockGestureDetector, MockDialog,
loadBodyHTML, ThreadUI, MessageManager, MockNavigatormozMobileMessage,
loadBodyHTML, ThreadUI, MessageManager,
ThreadListUI, Contacts, MockContact, MockThreadList,
MockThreadMessages, getMockupedDate, Utils */
/*
Expand All @@ -16,7 +16,6 @@ require('/shared/test/unit/mocks/mock_gesture_detector.js');
require('/shared/test/unit/mocks/mock_l10n.js');
requireApp('sms/test/unit/mock_contact.js');
requireApp('sms/test/unit/mock_time_headers.js');
requireApp('sms/test/unit/mock_navigatormoz_sms.js');
requireApp('sms/test/unit/mock_attachment_menu.js');
requireApp('sms/test/unit/mock_information.js');
requireApp('sms/test/unit/mock_dialog.js');
Expand Down Expand Up @@ -78,7 +77,6 @@ suite('SMS App Unit-Test', function() {
}

var nativeMozL10n = navigator.mozL10n;
var realMozMobileMessage;
var realGestureDetector;

suiteSetup(function() {
Expand Down Expand Up @@ -125,12 +123,9 @@ suite('SMS App Unit-Test', function() {
// ...And render
ThreadUI.init();
ThreadListUI.init();
realMozMobileMessage = ThreadUI._mozMobileMessage;
ThreadUI._mozMobileMessage = MockNavigatormozMobileMessage;
});

suiteTeardown(function() {
ThreadUI._mozMobileMessage = realMozMobileMessage;
// cleanup
window.document.body.innerHTML = '';
});
Expand Down
Loading

0 comments on commit 5937b83

Please sign in to comment.