2021-02-04 19:15:23 +01:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const watch = require('gulp-watch');
|
|
|
|
const glob = require('fast-glob');
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const locales = require('../../app/_locales/index.json');
|
2020-07-03 02:34:48 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { createTask, composeSeries } = require('./task');
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
module.exports = createStaticAssetTasks;
|
2020-03-09 01:55:02 +01:00
|
|
|
|
|
|
|
const copyTargets = [
|
|
|
|
{
|
|
|
|
src: `./app/_locales/`,
|
|
|
|
dest: `_locales`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: `./app/images/`,
|
|
|
|
dest: `images`,
|
|
|
|
},
|
|
|
|
{
|
2020-12-01 23:55:01 +01:00
|
|
|
src: `./node_modules/@metamask/contract-metadata/images/`,
|
2020-03-09 01:55:02 +01:00
|
|
|
dest: `images/contract`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: `./app/fonts/`,
|
|
|
|
dest: `fonts`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: `./app/vendor/`,
|
|
|
|
dest: `vendor`,
|
|
|
|
},
|
2020-03-31 01:05:51 +02:00
|
|
|
{
|
|
|
|
src: `./node_modules/@fortawesome/fontawesome-free/webfonts/`,
|
|
|
|
dest: `fonts/fontawesome`,
|
|
|
|
},
|
2020-03-09 01:55:02 +01:00
|
|
|
{
|
2021-04-28 21:53:59 +02:00
|
|
|
src: `./ui/css/output/`,
|
2020-03-09 01:55:02 +01:00
|
|
|
pattern: `*.css`,
|
|
|
|
dest: ``,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: `./app/`,
|
|
|
|
pattern: `*.html`,
|
|
|
|
dest: ``,
|
|
|
|
},
|
2020-12-08 19:38:31 +01:00
|
|
|
{
|
|
|
|
src: `./node_modules/globalthis/dist/browser.js`,
|
|
|
|
dest: `globalthis.js`,
|
|
|
|
},
|
2020-11-24 04:26:43 +01:00
|
|
|
{
|
2020-12-09 16:34:11 +01:00
|
|
|
src: `./node_modules/ses/dist/lockdown.cjs`,
|
|
|
|
dest: `lockdown.js`,
|
2020-11-24 04:26:43 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
src: `./app/scripts/`,
|
|
|
|
pattern: `runLockdown.js`,
|
|
|
|
dest: ``,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const languageTags = new Set();
|
2020-07-03 02:34:48 +02:00
|
|
|
for (const locale of locales) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { code } = locale;
|
|
|
|
const tag = code.split('_')[0];
|
|
|
|
languageTags.add(tag);
|
2020-07-03 02:34:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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`,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-03 02:34:48 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 01:55:02 +01:00
|
|
|
const copyTargetsDev = [
|
|
|
|
...copyTargets,
|
|
|
|
{
|
2021-06-22 19:32:54 +02:00
|
|
|
src: './development',
|
2020-03-09 01:55:02 +01:00
|
|
|
pattern: '/chromereload.js',
|
|
|
|
dest: ``,
|
|
|
|
},
|
2021-03-31 05:12:28 +02:00
|
|
|
// empty files to suppress missing file errors
|
|
|
|
{
|
2021-03-31 10:13:37 +02:00
|
|
|
src: './development/empty.js',
|
2021-03-31 05:12:28 +02:00
|
|
|
dest: `bg-libs.js`,
|
|
|
|
},
|
|
|
|
{
|
2021-03-31 10:13:37 +02:00
|
|
|
src: './development/empty.js',
|
2021-03-31 05:12:28 +02:00
|
|
|
dest: `ui-libs.js`,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const copyTargetsProd = [
|
|
|
|
...copyTargets,
|
|
|
|
// empty files to suppress missing file errors
|
|
|
|
{
|
2021-03-31 10:13:37 +02:00
|
|
|
src: './development/empty.js',
|
2021-03-31 05:12:28 +02:00
|
|
|
dest: `chromereload.js`,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function createStaticAssetTasks({ livereload, browserPlatforms }) {
|
|
|
|
const prod = createTask(
|
|
|
|
'static:prod',
|
|
|
|
composeSeries(
|
2021-03-31 05:12:28 +02:00
|
|
|
...copyTargetsProd.map((target) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
return async function copyStaticAssets() {
|
2021-02-04 19:15:23 +01:00
|
|
|
await performCopy(target);
|
|
|
|
};
|
2020-11-03 00:41:28 +01:00
|
|
|
}),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const dev = createTask(
|
|
|
|
'static:dev',
|
|
|
|
composeSeries(
|
|
|
|
...copyTargetsDev.map((target) => {
|
|
|
|
return async function copyStaticAssets() {
|
2021-02-04 19:15:23 +01:00
|
|
|
await setupLiveCopy(target);
|
|
|
|
};
|
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 { dev, prod };
|
2020-03-09 01:55:02 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function setupLiveCopy(target) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pattern = target.pattern || '/**/*';
|
2020-03-09 01:55:02 +01:00
|
|
|
watch(target.src + pattern, (event) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
livereload.changed(event.path);
|
|
|
|
performCopy(target);
|
|
|
|
});
|
|
|
|
await performCopy(target);
|
2020-03-09 01:55:02 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
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}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
} else {
|
|
|
|
await copyGlob(
|
|
|
|
target.src,
|
|
|
|
`${target.src}`,
|
|
|
|
`./dist/${platform}/${target.dest}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-09 01:55:02 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function copyGlob(baseDir, srcGlob, dest) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const sources = await glob(srcGlob, { onlyFiles: false });
|
2020-11-03 00:41:28 +01:00
|
|
|
await Promise.all(
|
|
|
|
sources.map(async (src) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const relativePath = path.relative(baseDir, src);
|
|
|
|
await fs.copy(src, `${dest}${relativePath}`);
|
2020-11-03 00:41:28 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-09 01:55:02 +01:00
|
|
|
}
|
|
|
|
}
|