2020-12-19 15:11:24 -05:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs-extra');
|
2021-07-13 11:31:09 +05:45
|
|
|
const mkdirp = require('make-dir');
|
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');
|
|
|
|
const destSVGPath = path.resolve(__dirname, '..', 'svg');
|
2021-06-21 20:31:03 +05:45
|
|
|
const distPath = 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-06-22 05:54:24 +05:45
|
|
|
// Copy src files to dist.
|
|
|
|
mkdirp(distPath).then(createIconsCache).then(src);
|
2021-06-21 20:31:03 +05:45
|
|
|
|
2021-07-13 11:16:18 +05:45
|
|
|
/**
|
|
|
|
* Create icons cache.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2021-07-12 23:20:42 -04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-13 11:16:18 +05:45
|
|
|
/**
|
|
|
|
* Copy the src files.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @returns {Promise} a newly generated promise object.
|
|
|
|
*/
|
2021-06-22 05:54:24 +05:45
|
|
|
function src() {
|
2021-07-12 23:20:42 -04:00
|
|
|
console.log('[2/2] Bundle extension manifest, images and main script.');
|
|
|
|
|
2021-06-22 05:54:24 +05:45
|
|
|
const entryFile = path.resolve(srcPath, 'main.js');
|
|
|
|
const parcelOptions = {
|
|
|
|
watch: false,
|
|
|
|
minify: true,
|
2021-07-04 04:26:13 +05:45
|
|
|
sourceMaps: false,
|
2021-06-22 05:54:24 +05:45
|
|
|
};
|
|
|
|
const bundler = new Parcel(entryFile, parcelOptions);
|
|
|
|
const bundleMainScript = bundler.bundle();
|
|
|
|
|
2021-06-22 04:19:05 +05:45
|
|
|
const copyManifest = fs.copy(
|
|
|
|
path.resolve(srcPath, 'manifest.json'),
|
|
|
|
path.resolve(distPath, 'manifest.json')
|
|
|
|
);
|
2021-06-21 20:31:03 +05:45
|
|
|
|
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
|
|
|
|
2021-06-22 04:19:05 +05:45
|
|
|
return Promise.all([copyManifest, copyExtensionLogos, bundleMainScript]);
|
2021-01-02 15:14:31 -05:00
|
|
|
}
|