1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

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.
This commit is contained in:
Mark Stacey 2021-11-10 19:33:59 -03:30 committed by GitHub
parent 3f9ec40107
commit faebdd0ccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 66 additions and 13 deletions

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 847 B

After

Width:  |  Height:  |  Size: 847 B

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 172 KiB

After

Width:  |  Height:  |  Size: 172 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,7 @@
{
"applications": {
"gecko": {
"id": "webextension-beta@metamask.io"
}
}
}

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 902 B

After

Width:  |  Height:  |  Size: 902 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 211 KiB

After

Width:  |  Height:  |  Size: 211 KiB

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,7 @@
{
"applications": {
"gecko": {
"id": "webextension-flask@metamask.io"
}
}
}

View File

@ -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;
}

View File

@ -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`,
},
],

View File

@ -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 = {