drop.chapril.org-firefoxsend/common/assets.js
Donovan Preston cab6f1bafb
Implement the mechanics of fxa login on android, but don't show ui fo… (#1000)
* Implement the mechanics of fxa login on android, but don't show ui for it yet. Also, scopedKeys are not yet implemented.

* Hopefully fix the package-lock conflict?

* WIP on android scoped keys

* Finish implementing login.

* created android/user.js to handle android logins
2018-11-08 16:35:19 -05:00

56 lines
1.2 KiB
JavaScript

const genmap = require('../build/generate_asset_map');
const isServer = typeof genmap === 'function';
let prefix = '';
let manifest = {};
try {
//eslint-disable-next-line node/no-missing-require
manifest = require('../dist/manifest.json');
} catch (e) {
// use middleware
}
const assets = isServer ? manifest : genmap;
function getAsset(name) {
return prefix + assets[name];
}
function setPrefix(name) {
prefix = name;
}
function getMatches(match) {
return Object.keys(assets)
.filter(k => match.test(k))
.map(getAsset);
}
const instance = {
setPrefix: setPrefix,
get: getAsset,
match: getMatches,
setMiddleware: function(middleware) {
function getManifest() {
return JSON.parse(
middleware.fileSystem.readFileSync(
middleware.getFilenameFromUrl('/manifest.json')
)
);
}
if (middleware) {
instance.get = function getAssetWithMiddleware(name) {
const m = getManifest();
return prefix + m[name];
};
instance.match = function matchAssetWithMiddleware(match) {
const m = getManifest();
return Object.keys(m)
.filter(k => match.test(k))
.map(k => prefix + m[k]);
};
}
}
};
module.exports = instance;