2021-02-04 19:15:23 +01:00
|
|
|
const { promises: fs } = require('fs');
|
|
|
|
const gulp = require('gulp');
|
2022-05-05 16:28:24 +02:00
|
|
|
const sort = require('gulp-sort');
|
2021-02-04 19:15:23 +01:00
|
|
|
const gulpZip = require('gulp-zip');
|
|
|
|
const del = require('del');
|
|
|
|
const pify = require('pify');
|
|
|
|
const pump = pify(require('pump'));
|
2022-03-10 17:01:50 +01:00
|
|
|
|
|
|
|
const { BuildType } = require('../lib/build-type');
|
2022-06-21 22:07:05 +02:00
|
|
|
const { TASKS } = require('./constants');
|
2021-02-04 19:15:23 +01:00
|
|
|
const { createTask, composeParallel } = require('./task');
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
module.exports = createEtcTasks;
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2022-03-10 17:01:50 +01:00
|
|
|
function createEtcTasks({ browserPlatforms, buildType, livereload, version }) {
|
2022-06-21 22:07:05 +02:00
|
|
|
const clean = createTask(TASKS.CLEAN, async function clean() {
|
2021-02-04 19:15:23 +01:00
|
|
|
await del(['./dist/*']);
|
2020-11-03 00:41:28 +01:00
|
|
|
await Promise.all(
|
|
|
|
browserPlatforms.map(async (platform) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
await fs.mkdir(`./dist/${platform}`, { recursive: true });
|
2020-11-03 00:41:28 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2022-06-21 22:07:05 +02:00
|
|
|
const reload = createTask(TASKS.RELOAD, function devReload() {
|
2021-02-04 19:15:23 +01:00
|
|
|
livereload.listen({ port: 35729 });
|
|
|
|
});
|
2020-03-09 01:55:02 +01:00
|
|
|
|
|
|
|
// zip tasks for distribution
|
2020-11-03 00:41:28 +01:00
|
|
|
const zip = createTask(
|
2022-06-21 22:07:05 +02:00
|
|
|
TASKS.ZIP,
|
2020-11-03 00:41:28 +01:00
|
|
|
composeParallel(
|
2022-03-10 17:01:50 +01:00
|
|
|
...browserPlatforms.map((platform) =>
|
|
|
|
createZipTask(platform, buildType, version),
|
|
|
|
),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return { clean, reload, zip };
|
2020-03-09 01:55:02 +01:00
|
|
|
}
|
|
|
|
|
2022-03-10 17:01:50 +01:00
|
|
|
function createZipTask(platform, buildType, version) {
|
2020-03-09 01:55:02 +01:00
|
|
|
return async () => {
|
2021-10-06 19:44:48 +02:00
|
|
|
const path =
|
2021-10-25 18:57:30 +02:00
|
|
|
buildType === BuildType.main
|
2021-10-06 19:44:48 +02:00
|
|
|
? `metamask-${platform}-${version}`
|
|
|
|
: `metamask-${buildType}-${platform}-${version}`;
|
2020-03-09 01:55:02 +01:00
|
|
|
await pump(
|
2021-09-08 22:08:23 +02:00
|
|
|
gulp.src(`dist/${platform}/**`),
|
2022-05-05 16:28:24 +02:00
|
|
|
// sort files and set `mtime` to epoch to ensure zip build is deterministic
|
|
|
|
sort(),
|
2022-07-18 19:33:58 +02:00
|
|
|
// Modified time set to an arbitrary static date to ensure build the is reproducible.
|
|
|
|
// The date chosen is MetaMask's birthday. Originally we chose the Unix epoch, but this
|
|
|
|
// resulted in invalid dates on certain timezones/operating systems.
|
|
|
|
gulpZip(`${path}.zip`, { modifiedTime: new Date('2016-07-14T00:00:00') }),
|
2020-03-09 01:55:02 +01:00
|
|
|
gulp.dest('builds'),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-03-09 01:55:02 +01:00
|
|
|
}
|