2020-12-19 15:11:24 -05:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs-extra');
|
2021-07-15 23:42:56 -04:00
|
|
|
const Parcel = require('parcel-bundler');
|
2022-06-30 22:25:48 -04:00
|
|
|
|
2021-07-12 23:20:42 -04:00
|
|
|
const destSVGPath = path.resolve(__dirname, '..', 'svg');
|
2022-06-30 00:17:25 -04:00
|
|
|
const distBasePath = path.resolve(__dirname, '..', 'dist');
|
2021-07-12 23:20:42 -04:00
|
|
|
const srcPath = path.resolve(__dirname, '..', 'src');
|
2020-12-19 15:11:24 -05:00
|
|
|
|
2021-11-30 23:38:46 -05:00
|
|
|
/** Create icons cache. */
|
2022-06-30 22:25:48 -04:00
|
|
|
async function consolidateSVGFiles() {
|
2021-07-12 23:20:42 -04:00
|
|
|
console.log('[1/2] Generate icon cache for extension.');
|
2022-06-30 22:25:48 -04:00
|
|
|
await fs
|
2021-11-30 23:38:46 -05:00
|
|
|
.copy(path.resolve(srcPath, 'custom'), destSVGPath)
|
|
|
|
.then(() => fs.readdir(destSVGPath))
|
|
|
|
.then((files) => Object.fromEntries(files.map((filename) => [filename, filename])))
|
|
|
|
.then((iconsDict) => fs.writeJSON(path.resolve(srcPath, 'icon-list.json'), iconsDict));
|
2021-07-12 23:20:42 -04:00
|
|
|
}
|
|
|
|
|
2022-06-30 00:17:25 -04:00
|
|
|
function src(distPath) {
|
2021-07-12 23:20:42 -04:00
|
|
|
console.log('[2/2] Bundle extension manifest, images and main script.');
|
|
|
|
|
2021-07-15 23:42:56 -04:00
|
|
|
const entryFile = path.resolve(srcPath, 'main.js');
|
2021-06-22 05:54:24 +05:45
|
|
|
const parcelOptions = {
|
2021-07-15 23:42:56 -04:00
|
|
|
watch: false,
|
|
|
|
minify: true,
|
|
|
|
sourceMaps: false,
|
2022-06-30 00:17:25 -04:00
|
|
|
outDir: distPath,
|
2021-06-22 05:54:24 +05:45
|
|
|
};
|
2021-07-15 23:42:56 -04:00
|
|
|
const bundler = new Parcel(entryFile, parcelOptions);
|
|
|
|
const bundleMainScript = bundler.bundle();
|
2021-07-13 09:23:06 +01:00
|
|
|
|
2021-12-01 00:38:14 -05:00
|
|
|
const copyIcons = fs.copy(destSVGPath, distPath);
|
2021-11-30 23:38:46 -05:00
|
|
|
|
2021-06-28 17:55:39 +01:00
|
|
|
const copyExtensionLogos = fs.copy(path.resolve(srcPath, 'icons'), distPath);
|
2021-06-21 20:31:03 +05:45
|
|
|
|
2022-06-30 00:17:25 -04:00
|
|
|
return Promise.all([copyExtensionLogos, bundleMainScript, copyIcons]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildManifest(distPath, manifestName) {
|
|
|
|
return Promise.all([
|
|
|
|
fs.readJson(path.resolve(srcPath, 'manifests', 'base.json')),
|
|
|
|
fs.readJson(path.resolve(srcPath, 'manifests', manifestName)),
|
|
|
|
])
|
|
|
|
.then(([base, custom]) => ({ ...base, ...custom }))
|
|
|
|
.then((manifest) =>
|
|
|
|
fs.writeJson(path.resolve(distPath, 'manifest.json'), manifest, { spaces: 2 })
|
|
|
|
);
|
2021-01-02 15:14:31 -05:00
|
|
|
}
|
2022-06-30 00:17:25 -04:00
|
|
|
|
|
|
|
function buildDist(name, manifestName) {
|
|
|
|
const distPath = path.resolve(distBasePath, name);
|
|
|
|
|
2022-06-30 22:25:48 -04:00
|
|
|
return fs
|
|
|
|
.ensureDir(distPath)
|
2022-06-30 00:17:25 -04:00
|
|
|
.then(consolidateSVGFiles)
|
|
|
|
.then(() => src(distPath))
|
|
|
|
.then(() => buildManifest(distPath, manifestName))
|
|
|
|
.catch(console.error);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildDist('firefox', 'firefox.json').then(() => buildDist('chrome-edge', 'chrome-edge.json'));
|