Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
76
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/createprofile.js
Executable file
76
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/createprofile.js
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
'use strict';
|
||||
var fs = require('fs'),
|
||||
tmpdir = require('./tmpdir');
|
||||
|
||||
var Profiles = {
|
||||
/**
|
||||
* Attempts to find a gaia profile from a directory and then copies it to a
|
||||
* new directory.
|
||||
*
|
||||
* @param {String} path to runtime (/Applications/B2G.App).
|
||||
* @param {Function} callback [Error err, String path].
|
||||
*/
|
||||
gaia: function(path, callback) {
|
||||
var gaiaProfile = require('./gaiaprofile');
|
||||
gaiaProfile(path, function(err, basePath) {
|
||||
if (err) return callback(err);
|
||||
this.baseProfile(basePath, callback);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new profile by copying an existing one.
|
||||
*
|
||||
* @param {String} path to copy profile from.
|
||||
* @param {Function} callback [Error err, String path].
|
||||
*/
|
||||
baseProfile: function(path, callback) {
|
||||
var traverseDir = require('traverse-directory');
|
||||
this.tmp(function(err, target) {
|
||||
var traverse = traverseDir(path, target);
|
||||
|
||||
traverse.file(function(source, target, next) {
|
||||
next(traverseDir.copyfile, source, target);
|
||||
});
|
||||
|
||||
traverse.directory(function(source, target, next) {
|
||||
var leaf = source.replace(path, '');
|
||||
|
||||
// the / here is really important otherwise we will end up symlinking
|
||||
// the entire webapps directory is not what we want.
|
||||
if (leaf.indexOf('webapps/') !== -1) {
|
||||
next(traverseDir.symlinkdir, source, target);
|
||||
return;
|
||||
}
|
||||
next(traverseDir.copydir, source, target);
|
||||
});
|
||||
|
||||
traverse.run(function() {
|
||||
if (err) return callback(err);
|
||||
callback(null, target);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Verifies profile exists and returns it or an error.
|
||||
*
|
||||
* @param {Function} callback [Error err, String path].
|
||||
*/
|
||||
profile: function(path, callback) {
|
||||
fs.exists(path, function(pathExists) {
|
||||
if (pathExists) return callback(null, path);
|
||||
|
||||
callback(new Error('invalid profile path: "' + path + '" is not found.'));
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a tmpdir for profile to reside in.
|
||||
*
|
||||
* @param {Function} callback [Error err, dir].
|
||||
*/
|
||||
tmp: tmpdir
|
||||
};
|
||||
|
||||
module.exports = Profiles;
|
||||
32
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/gaiaprofile.js
Executable file
32
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/gaiaprofile.js
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
var fsPath = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
/**
|
||||
* Detects the gaia profile inside of a runtime directory.
|
||||
*
|
||||
* @param {String} path of runtime.
|
||||
* @return {String} location of base profile.
|
||||
*/
|
||||
function gaiaProfile (basePath, callback) {
|
||||
var foundPath = false;
|
||||
var pending = 2;
|
||||
|
||||
function next(path, exists) {
|
||||
if (exists) {
|
||||
foundPath = true;
|
||||
callback(null, path);
|
||||
}
|
||||
|
||||
if (--pending === 0 && !foundPath) {
|
||||
callback(new Error('could not find path to gaia profile'));
|
||||
}
|
||||
}
|
||||
|
||||
var linux = fsPath.join(basePath, 'gaia', 'profile');
|
||||
fs.exists(linux, next.bind(null, linux));
|
||||
var macos = fsPath.join(basePath, 'Contents', 'Resources', 'gaia', 'profile');
|
||||
fs.exists(macos, next.bind(null, macos));
|
||||
}
|
||||
|
||||
module.exports = gaiaProfile;
|
||||
25
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/options/apps.js
Executable file
25
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/options/apps.js
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
var installApps = require('packaged-webapp').installApps;
|
||||
|
||||
function apps(profile, options, callback) {
|
||||
// abort if no apps are given
|
||||
if (
|
||||
// no options
|
||||
!options ||
|
||||
// no apps
|
||||
!options.apps ||
|
||||
// empty app object
|
||||
(Object.keys(options.apps).length === 0)
|
||||
) {
|
||||
return process.nextTick(callback.bind(null, null, profile));
|
||||
}
|
||||
|
||||
var list = [];
|
||||
for (var origin in options.apps) {
|
||||
list.push({ origin: origin, source: options.apps[origin] });
|
||||
}
|
||||
|
||||
installApps(profile, list, callback);
|
||||
}
|
||||
|
||||
module.exports = apps;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
var fse = require('fs-extra');
|
||||
|
||||
/**
|
||||
* Recursively copy a directory of prebuilt files into a profile. Used for
|
||||
* overwriting files in a clean profile for tests.
|
||||
*
|
||||
* Options:
|
||||
* - (Object) extract: Directory to copy into profile.
|
||||
*
|
||||
* @param {String} profile path to profile.
|
||||
* @param {Object} options for directory.
|
||||
* @param {Function} callback fires after successfully copying.
|
||||
*/
|
||||
function copyExtract(profile, options, callback) {
|
||||
// we userPrefs was used in the past
|
||||
var extractsDir = options.extracts;
|
||||
// don't do anything unless there is a directory to copy
|
||||
if (!extractsDir) {
|
||||
return process.nextTick(callback.bind(null, null, profile));
|
||||
}
|
||||
|
||||
fse.copy(extractsDir, profile, function(err) {
|
||||
if (err) return callback(err);
|
||||
return callback(null, profile);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = copyExtract;
|
||||
32
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/options/prefs.js
Executable file
32
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/options/prefs.js
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
var fs = require('fs'),
|
||||
fsPath = require('path'),
|
||||
pref = require('../pref');
|
||||
|
||||
var USER_PREF = 'user.js';
|
||||
/**
|
||||
* Appends prefs to the given profile.
|
||||
*
|
||||
* Options:
|
||||
* - (Object) prefs: key/value pairs.
|
||||
*
|
||||
* @param {String} profile path to profile.
|
||||
* @param {Object} options for prefs.
|
||||
* @param {Function} callback fires after successfully saving.
|
||||
*/
|
||||
function appendPrefs(profile, options, callback) {
|
||||
// we userPrefs was used in the past
|
||||
var prefsConfig = options.prefs || options.userPrefs;
|
||||
// don't do anything unless there are some new prefs
|
||||
if (!prefsConfig || Object.keys(prefsConfig).length === 0) {
|
||||
return process.nextTick(callback.bind(null, null, profile));
|
||||
}
|
||||
|
||||
var filename = fsPath.join(profile, USER_PREF);
|
||||
fs.appendFile(filename, '\n' + pref(prefsConfig), function(err) {
|
||||
if (err) return callback(err);
|
||||
callback(null, profile);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = appendPrefs;
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
'use strict';
|
||||
/** handles mutation of settings.json */
|
||||
var SETTINGS = 'settings.json';
|
||||
var PERMISSIONS_DB = 'permissions.sqlite';
|
||||
|
||||
var fs = require('fs'),
|
||||
fsPath = require('path');
|
||||
|
||||
/**
|
||||
* Updates the settings.json file of a given profile
|
||||
*
|
||||
* @param {String} profile path.
|
||||
* @param {Options} options with .settings.
|
||||
* @param {Function} callback [Error err, profile].
|
||||
*/
|
||||
function settings(profile, options, callback) {
|
||||
if (!options || !options.settings) {
|
||||
return process.nextTick(callback.bind(null, null, profile));
|
||||
}
|
||||
|
||||
// location of settings.json
|
||||
var settingsPath = fsPath.join(profile, SETTINGS);
|
||||
// location of permissions
|
||||
var permissionsPath = fsPath.join(profile, PERMISSIONS_DB);
|
||||
|
||||
function readSettings() {
|
||||
fs.readFile(settingsPath, 'utf8', function(err, content) {
|
||||
var json;
|
||||
try {
|
||||
json = JSON.parse(content);
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
writeSettings(json);
|
||||
});
|
||||
}
|
||||
|
||||
function writeSettings(original) {
|
||||
// copy new settings over
|
||||
var newSettings = options.settings;
|
||||
for (var name in newSettings) {
|
||||
original[name] = newSettings[name];
|
||||
}
|
||||
|
||||
var pending = 2;
|
||||
function next(err) {
|
||||
if (err) {
|
||||
callback && callback(err);
|
||||
callback = null;
|
||||
}
|
||||
|
||||
if (--pending === 0)
|
||||
callback(null, profile);
|
||||
}
|
||||
|
||||
fs.exists(permissionsPath, function(itDoes) {
|
||||
if (!itDoes)
|
||||
return next();
|
||||
|
||||
fs.unlink(permissionsPath, next);
|
||||
});
|
||||
|
||||
// and finally write the file back out
|
||||
fs.writeFile(
|
||||
settingsPath,
|
||||
// slows it down a but but makes it readable!
|
||||
JSON.stringify(original, null, 2),
|
||||
next
|
||||
);
|
||||
}
|
||||
|
||||
// check if file exists
|
||||
fs.exists(settingsPath, function(fileExists) {
|
||||
if (fileExists) {
|
||||
// when file exists read it then write
|
||||
readSettings();
|
||||
} else {
|
||||
// otherwise simply write
|
||||
writeSettings({});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = settings;
|
||||
60
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/pref.js
Executable file
60
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/pref.js
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
'use strict';
|
||||
var PREF = 'pref';
|
||||
|
||||
/**
|
||||
* Builds a multi line string of prefs.
|
||||
*
|
||||
* @param {Object} prefs key/value pairs.
|
||||
* @return {String} lines
|
||||
*/
|
||||
function prefs(object) {
|
||||
var result = [];
|
||||
Object.keys(object).forEach(function(key) {
|
||||
result.push(pref(key, object[key]));
|
||||
});
|
||||
|
||||
return result.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pref string based on a name/value pair.
|
||||
*
|
||||
* pref('browser.dom.window.dump.enabled', true);
|
||||
* // => 'pref("browser.dom.window.dump.enabled", true);'
|
||||
*
|
||||
* // can also be given a single object
|
||||
*
|
||||
* pref({
|
||||
* 'key': value
|
||||
* });
|
||||
* // => multiple lines
|
||||
*
|
||||
* @param {String} name of pref;
|
||||
* @param {Object|Number|String} value of pref.
|
||||
* @return {String} version of pref.
|
||||
*/
|
||||
function pref(name, value) {
|
||||
if (!value && typeof name === 'object')
|
||||
return prefs(name);
|
||||
|
||||
var type = typeof value;
|
||||
var out = PREF + '("' + name + '", ';
|
||||
|
||||
switch (type) {
|
||||
case 'string':
|
||||
out += '"' + value + '"';
|
||||
break;
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
out += value;
|
||||
break;
|
||||
default:
|
||||
out += '"' + JSON.stringify(value) + '"';
|
||||
break;
|
||||
}
|
||||
|
||||
out += ');';
|
||||
return out;
|
||||
}
|
||||
|
||||
module.exports = pref;
|
||||
37
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/tmpdir.js
Executable file
37
gaia/tests/jsmarionette/runner/mozilla-profile-builder/lib/tmpdir.js
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
var tmp = require('tmp');
|
||||
|
||||
// https://github.com/mozilla-b2g/mozilla-profile-builder/issues/2
|
||||
process.on('SIGINT', function() {});
|
||||
|
||||
/**
|
||||
* Wrapper around common tmp dir creation functionality.
|
||||
*
|
||||
* Options:
|
||||
* - (Boolean) keep: when true profile will not be removed on process close.
|
||||
*
|
||||
* @param {Object} options for tmp dir creation.
|
||||
* @param {Function} callback for tmp dir creation.
|
||||
*/
|
||||
function tmpdir(options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = null;
|
||||
}
|
||||
|
||||
// configuration for temp directory
|
||||
// https://github.com/raszi/node-tmp#options
|
||||
var tmpConfig = {};
|
||||
if (options && options.keep) {
|
||||
// keep directory for later
|
||||
tmpConfig.keep = true;
|
||||
} else {
|
||||
// discard directory when process closes.
|
||||
tmpConfig.unsafeCleanup = true;
|
||||
tmpConfig.keep = false;
|
||||
}
|
||||
|
||||
tmp.dir(tmpConfig, callback);
|
||||
}
|
||||
|
||||
module.exports = tmpdir;
|
||||
Loading…
Reference in a new issue