1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/development/build/static.js
kumavis 9f4820ee98
Build - refactor for bundle factoring and swappable runtime (#11080)
* wip

* build - breakout sentry-install bundle

* deps - move new build sys deps to published versions

* chore: lint fix

* clean - remove unused file

* clean - remove unsused package script

* lavamoat - update build system policy

* build - render html to all platforms

* development - improve sourcemap debugger output

* deps - update lavapack

* lint - fix

* deps - update lavapack for bugfix

* deps - update lavapack for bugfix

* deps - bump lavapack for line ending normalization

* sourcemap explorer - disable boundary validation

* ci - reset normal ci flow

* build - re-enable minification on prod

* build - remove noisy log about html dest

* build - update terser and remove gulp wrapper for sourcemap fix

* Revert "sourcemap explorer - disable boundary validation"

This reverts commit 94112209ed880a6ebf4ee2ded411e59db6908162.

* build - reenable react-devtools in dev mode

* wip

* build - breakout sentry-install bundle

* deps - move new build sys deps to published versions

* chore: lint fix

* clean - remove unused file

* clean - remove unsused package script

* lavamoat - update build system policy

* build - render html to all platforms

* development - improve sourcemap debugger output

* deps - update lavapack

* lint - fix

* deps - update lavapack for bugfix

* deps - update lavapack for bugfix

* deps - bump lavapack for line ending normalization

* sourcemap explorer - disable boundary validation

* ci - reset normal ci flow

* build - re-enable minification on prod

* build - remove noisy log about html dest

* build - update terser and remove gulp wrapper for sourcemap fix

* Revert "sourcemap explorer - disable boundary validation"

This reverts commit 94112209ed880a6ebf4ee2ded411e59db6908162.

* build - reenable react-devtools in dev mode

* Updating lockfile

* lint fix

* build/dev - patch watchifys incompatible binary stats output

* ui - add comment about conditional import

* build - improve comment

* Update development/stream-flat-map.js

Co-authored-by: Brad Decker <git@braddecker.dev>

* Outputting all bundle file links (metamaskbot)

Co-authored-by: ryanml <ryanlanese@gmail.com>
Co-authored-by: Brad Decker <git@braddecker.dev>
2021-07-15 10:59:34 -07:00

169 lines
3.7 KiB
JavaScript

const path = require('path');
const fs = require('fs-extra');
const watch = require('gulp-watch');
const glob = require('fast-glob');
const locales = require('../../app/_locales/index.json');
const { createTask, composeSeries } = require('./task');
module.exports = createStaticAssetTasks;
const copyTargets = [
{
src: `./app/_locales/`,
dest: `_locales`,
},
{
src: `./app/images/`,
dest: `images`,
},
{
src: `./node_modules/@metamask/contract-metadata/images/`,
dest: `images/contract`,
},
{
src: `./app/fonts/`,
dest: `fonts`,
},
{
src: `./app/vendor/`,
dest: `vendor`,
},
{
src: `./node_modules/@fortawesome/fontawesome-free/webfonts/`,
dest: `fonts/fontawesome`,
},
{
src: `./ui/css/output/`,
pattern: `*.css`,
dest: ``,
},
{
src: `./app/loading.html`,
dest: `loading.html`,
},
{
src: `./node_modules/globalthis/dist/browser.js`,
dest: `globalthis.js`,
},
{
src: `./node_modules/ses/dist/lockdown.cjs`,
dest: `lockdown-install.js`,
},
{
src: `./app/scripts/lockdown-run.js`,
dest: `lockdown-run.js`,
},
{
// eslint-disable-next-line node/no-extraneous-require
src: require.resolve('@lavamoat/lavapack/src/runtime-cjs.js'),
dest: `runtime-cjs.js`,
},
];
const languageTags = new Set();
for (const locale of locales) {
const { code } = locale;
const tag = code.split('_')[0];
languageTags.add(tag);
}
for (const tag of languageTags) {
copyTargets.push({
src: `./node_modules/@formatjs/intl-relativetimeformat/dist/locale-data/${tag}.json`,
dest: `intl/${tag}/relative-time-format-data.json`,
});
}
const copyTargetsDev = [
...copyTargets,
{
src: './development',
pattern: '/chromereload.js',
dest: ``,
},
// empty files to suppress missing file errors
{
src: './development/empty.js',
dest: `bg-libs.js`,
},
{
src: './development/empty.js',
dest: `ui-libs.js`,
},
];
const copyTargetsProd = [
...copyTargets,
// empty files to suppress missing file errors
{
src: './development/empty.js',
dest: `chromereload.js`,
},
];
function createStaticAssetTasks({ livereload, browserPlatforms }) {
const prod = createTask(
'static:prod',
composeSeries(
...copyTargetsProd.map((target) => {
return async function copyStaticAssets() {
await performCopy(target);
};
}),
),
);
const dev = createTask(
'static:dev',
composeSeries(
...copyTargetsDev.map((target) => {
return async function copyStaticAssets() {
await setupLiveCopy(target);
};
}),
),
);
return { dev, prod };
async function setupLiveCopy(target) {
const pattern = target.pattern || '/**/*';
watch(target.src + pattern, (event) => {
livereload.changed(event.path);
performCopy(target);
});
await performCopy(target);
}
async function performCopy(target) {
await Promise.all(
browserPlatforms.map(async (platform) => {
if (target.pattern) {
await copyGlob(
target.src,
`${target.src}${target.pattern}`,
`./dist/${platform}/${target.dest}`,
);
} else {
await copyGlob(
target.src,
`${target.src}`,
`./dist/${platform}/${target.dest}`,
);
}
}),
);
}
async function copyGlob(baseDir, srcGlob, dest) {
const sources = await glob(srcGlob, { onlyFiles: false });
await Promise.all(
sources.map(async (src) => {
const relativePath = path.relative(baseDir, src);
await fs.copy(src, `${dest}${relativePath}`);
}),
);
}
}