Add platform-specific build type manifest modifications (#12638)
The build system now supports platform-specific modifications to the manifest for each build type. The need to customize the `id` on Firefox motivated this change. To support this, a new directory was made in each build type directory for manifest changes. The images currently in this directory were moved into an `images` subdirectory. This new `manifest` directory can include each manifest file currently in `app/manifest`. The `_base.json` file is assumed to exist, but the platform manifest modifications are optional.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 847 B After Width: | Height: | Size: 847 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
7
app/build-types/beta/manifest/firefox.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "webextension-beta@metamask.io"
|
||||
}
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 902 B After Width: | Height: | Size: 902 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 211 KiB After Width: | Height: | Size: 211 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
7
app/build-types/flask/manifest/firefox.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "webextension-flask@metamask.io"
|
||||
}
|
||||
}
|
||||
}
|
@ -3,8 +3,6 @@ const path = require('path');
|
||||
const { merge, cloneDeep } = require('lodash');
|
||||
|
||||
const baseManifest = require('../../app/manifest/_base.json');
|
||||
const betaManifestModifications = require('../../app/manifest/_beta_modifications.json');
|
||||
const flaskManifestModifications = require('../../app/manifest/_flask_modifications.json');
|
||||
|
||||
const { createTask, composeSeries } = require('./task');
|
||||
const { BuildType } = require('./utils');
|
||||
@ -34,7 +32,7 @@ function createManifestTasks({
|
||||
cloneDeep(baseManifest),
|
||||
platformModifications,
|
||||
browserVersionMap[platform],
|
||||
getBuildModifications(buildType),
|
||||
await getBuildModifications(buildType, platform),
|
||||
);
|
||||
const dir = path.join('.', 'dist', platform);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
@ -113,12 +111,53 @@ async function writeJson(obj, file) {
|
||||
return fs.writeFile(file, JSON.stringify(obj, null, 2));
|
||||
}
|
||||
|
||||
function getBuildModifications(buildType) {
|
||||
const buildModifications = {};
|
||||
if (buildType === BuildType.beta) {
|
||||
Object.assign(buildModifications, betaManifestModifications);
|
||||
} else if (buildType === BuildType.flask) {
|
||||
Object.assign(buildModifications, flaskManifestModifications);
|
||||
/**
|
||||
* Get manifest modifications for the given build type, including modifications specific to the
|
||||
* given platform.
|
||||
*
|
||||
* @param {BuildType} buildType - The build type.
|
||||
* @param {string} platform - The platform (i.e. the browser).
|
||||
* @returns {Object} The build modificantions for the given build type and platform.
|
||||
*/
|
||||
async function getBuildModifications(buildType, platform) {
|
||||
if (!Object.values(BuildType).includes(buildType)) {
|
||||
throw new Error(`Invalid build type: ${buildType}`);
|
||||
} else if (buildType === BuildType.main) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const builtTypeManifestDirectoryPath = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'app',
|
||||
'build-types',
|
||||
buildType,
|
||||
'manifest',
|
||||
);
|
||||
|
||||
const baseBuildTypeModificationsPath = path.join(
|
||||
builtTypeManifestDirectoryPath,
|
||||
'_base.json',
|
||||
);
|
||||
const buildModifications = await readJson(baseBuildTypeModificationsPath);
|
||||
|
||||
const platformBuildTypeModificationsPath = path.join(
|
||||
builtTypeManifestDirectoryPath,
|
||||
`${platform}.json`,
|
||||
);
|
||||
try {
|
||||
const platformBuildTypeModifications = await readJson(
|
||||
platformBuildTypeModificationsPath,
|
||||
);
|
||||
Object.assign(buildModifications, platformBuildTypeModifications);
|
||||
} catch (error) {
|
||||
// Suppress 'ENOENT' error because it indicates there are no platform-specific manifest
|
||||
// modifications for this build type.
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return buildModifications;
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ module.exports = function createStaticAssetTasks({
|
||||
const additionalBuildTargets = {
|
||||
[BuildType.beta]: [
|
||||
{
|
||||
src: './app/build-types/beta/',
|
||||
src: './app/build-types/beta/images/',
|
||||
dest: `images`,
|
||||
},
|
||||
],
|
||||
[BuildType.flask]: [
|
||||
{
|
||||
src: './app/build-types/flask/',
|
||||
src: './app/build-types/flask/images/',
|
||||
dest: `images`,
|
||||
},
|
||||
],
|
||||
|
@ -1,8 +1,8 @@
|
||||
///: BEGIN:ONLY_INCLUDE_IN(beta)
|
||||
import betaJson from '../../../app/build-types/beta/beta-mascot.json';
|
||||
import betaJson from '../../../app/build-types/beta/images/beta-mascot.json';
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
||||
import flaskJson from '../../../app/build-types/flask/flask-mascot.json';
|
||||
import flaskJson from '../../../app/build-types/flask/images/flask-mascot.json';
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
|
||||
const assetList = {
|
||||
|