50 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* External depedencies
*/
const path = require('path');
const fs = require('fs-extra');
const mkdirp = require('mkdirp');
2020-12-28 22:42:58 -05:00
const Parcel = require('parcel-bundler');
2021-07-12 23:20:42 -04:00
const extractSvgHtml = require('./extract-svg-html');
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.
mkdirp(distPath).then(createIconsCache).then(src);
2021-07-12 23:20:42 -04:00
// copy src files
function createIconsCache() {
console.log('[1/2] Generate icon cache for extension.');
return new Promise((resolve, reject) => {
fs.copy(path.resolve(srcPath, 'custom'), destSVGPath)
.then(() => extractSvgHtml({ task: '1' }))
.then(resolve)
.catch(reject);
});
}
function src() {
2021-07-12 23:20:42 -04:00
console.log('[2/2] Bundle extension manifest, images and main script.');
const entryFile = path.resolve(srcPath, 'main.js');
const parcelOptions = {
watch: false,
minify: true,
sourceMaps: false,
};
const bundler = new Parcel(entryFile, parcelOptions);
const bundleMainScript = bundler.bundle();
const copyManifest = fs.copy(
path.resolve(srcPath, 'manifest.json'),
path.resolve(distPath, 'manifest.json')
);
const copyExtensionLogos = fs.copy(path.resolve(srcPath, 'extensionIcons'), distPath);
return Promise.all([copyManifest, copyExtensionLogos, bundleMainScript]);
}