1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/development/build/manifest.js
Mark Stacey 3a5538bd50
Migrate beta version to the main version field (#12246)
The main `version` field in `package.json` will now include the beta
version (if present) rather than it being passed in via the CLI when
building. The `version` field is now a fully SemVer-compatible version,
with the added restriction that any prerelease portion of the version
must match the format `<build type>.<build version>`.

This brings the build in-line with the future release process we will
be using for the beta version. The plan is for each future release to
enter a "beta phase" where the version would get updated to reflect
that it's a beta, and we would increment this beta version over time as
we update the beta. The manifest gives us a place to store this beta
version. It was also important to replace the automatic minor bump
logic that was being used previously, because the version in beta might
not be a minor bump.

Additionally, the filename logic used for beta builds was updated to
be generic across all build types rather than beta-specific. This will
be useful for Flask builds in the future.
2021-10-06 15:14:48 -02:30

122 lines
3.3 KiB
JavaScript

const { promises: fs } = require('fs');
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 { createTask, composeSeries } = require('./task');
const { BuildTypes } = require('./utils');
module.exports = createManifestTasks;
function createManifestTasks({
browserPlatforms,
browserVersionMap,
buildType,
}) {
// merge base manifest with per-platform manifests
const prepPlatforms = async () => {
return Promise.all(
browserPlatforms.map(async (platform) => {
const platformModifications = await readJson(
path.join(
__dirname,
'..',
'..',
'app',
'manifest',
`${platform}.json`,
),
);
const result = merge(
cloneDeep(baseManifest),
platformModifications,
browserVersionMap[platform],
getBuildModifications(buildType),
);
const dir = path.join('.', 'dist', platform);
await fs.mkdir(dir, { recursive: true });
await writeJson(result, path.join(dir, 'manifest.json'));
}),
);
};
// dev: add perms
const envDev = createTaskForModifyManifestForEnvironment((manifest) => {
manifest.permissions = [...manifest.permissions, 'webRequestBlocking'];
});
// testDev: add perms
const envTestDev = createTaskForModifyManifestForEnvironment((manifest) => {
manifest.permissions = [
...manifest.permissions,
'webRequestBlocking',
'http://localhost/*',
];
});
// test: add permissions
const envTest = createTaskForModifyManifestForEnvironment((manifest) => {
manifest.permissions = [
...manifest.permissions,
'webRequestBlocking',
'http://localhost/*',
];
});
// high level manifest tasks
const dev = createTask('manifest:dev', composeSeries(prepPlatforms, envDev));
const testDev = createTask(
'manifest:testDev',
composeSeries(prepPlatforms, envTestDev),
);
const test = createTask(
'manifest:test',
composeSeries(prepPlatforms, envTest),
);
const prod = createTask('manifest:prod', prepPlatforms);
return { prod, dev, testDev, test };
// helper for modifying each platform's manifest.json in place
function createTaskForModifyManifestForEnvironment(transformFn) {
return () => {
return Promise.all(
browserPlatforms.map(async (platform) => {
const manifestPath = path.join(
'.',
'dist',
platform,
'manifest.json',
);
const manifest = await readJson(manifestPath);
transformFn(manifest);
await writeJson(manifest, manifestPath);
}),
);
};
}
}
// helper for reading and deserializing json from fs
async function readJson(file) {
return JSON.parse(await fs.readFile(file, 'utf8'));
}
// helper for serializing and writing json to fs
async function writeJson(obj, file) {
return fs.writeFile(file, JSON.stringify(obj, null, 2));
}
function getBuildModifications(buildType) {
const buildModifications = {};
if (buildType === BuildTypes.beta) {
Object.assign(buildModifications, betaManifestModifications);
}
return buildModifications;
}