49 lines
1.5 KiB
JavaScript
Raw Normal View History

const path = require('path');
const fs = require('fs-extra');
2021-07-15 23:42:56 -04:00
const Parcel = require('parcel-bundler');
2021-07-12 23:20:42 -04:00
const destSVGPath = path.resolve(__dirname, '..', 'svg');
const distPath = path.resolve(__dirname, '..', 'dist');
2021-07-12 23:20:42 -04:00
const srcPath = path.resolve(__dirname, '..', 'src');
// Copy src files to dist.
2021-11-30 23:38:46 -05:00
fs.ensureDir(distPath).then(consolidateSVGFiles).then(src).catch(console.error);
2021-11-30 23:38:46 -05:00
/** Create icons cache. */
function consolidateSVGFiles() {
2021-07-12 23:20:42 -04:00
console.log('[1/2] Generate icon cache for extension.');
2021-11-30 23:38:46 -05:00
return fs
.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
}
/**
* Copy the src files.
*
* @returns {Promise} a newly generated promise object.
*/
function src() {
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');
const parcelOptions = {
2021-07-15 23:42:56 -04:00
watch: false,
minify: true,
sourceMaps: false,
};
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
const copyManifest = fs.copy(
path.resolve(srcPath, 'manifest.json'),
path.resolve(distPath, 'manifest.json')
);
const copyExtensionLogos = fs.copy(path.resolve(srcPath, 'icons'), distPath);
2021-11-30 23:38:46 -05:00
return Promise.all([copyManifest, copyExtensionLogos, bundleMainScript, copyIcons]);
}