Philipp Kief e153f99d10
[Feature] Custom domain support (#1)
* made each provider a function so it always gives a new object instead of a reference, added name property, added domains property, removed domain property, added canSelfHost property

* getGitProvider now tests only the host of the url instead of the whole string. Removed switch statement for thesting domains in favor of a for loop which will allow custom domains. added new function addGitProvider which adds a copy of the config for given provider and new custom domain

* added custom providers library

* added loading of custom providers

* change async/await calls with with promise.then

* added detect property to provider.selectors object

* added flag isCustom to all custom provider objects for use in filtering

* added mozilla webextension polyfill so storage works across browsers

* wip: custom domains

* added wildcard for content scripts, so that popup can talk to current page

* added eslint exception for parameter reassignment in custom-providers.js

* added isCustom property to each provider, so it is consistent in all provider objects

* Closes #82

* Closes #76

* Added previous selectors as fallback for older instances

* Added ability to opt in to custom websites instead of the extension running on all of them by default. Only chromium browsers supported. Firefox does not allow requesting permissions from background scripts

---------

Co-authored-by: Michael Goodman <bulgedition@gmail.com>
2024-07-04 09:51:51 +02:00

99 lines
3.1 KiB
JavaScript

const path = require('path');
const fs = require('fs-extra');
const Parcel = require('parcel-bundler');
const destSVGPath = path.resolve(__dirname, '..', 'svg');
const distBasePath = path.resolve(__dirname, '..', 'dist');
const srcPath = path.resolve(__dirname, '..', 'src');
/** Create icons cache. */
async function consolidateSVGFiles() {
console.log('[1/2] Generate icon cache for extension.');
await 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));
}
function bundleJS(outDir, entryFile) {
const parcelOptions = {
watch: false,
minify: true,
sourceMaps: false,
outDir,
};
const bundler = new Parcel(entryFile, parcelOptions);
return bundler.bundle();
}
function src(distPath) {
console.log('[2/2] Bundle extension manifest, images and main script.');
const copyIcons = fs.copy(destSVGPath, distPath);
const bundleMainScript = () => bundleJS(distPath, path.resolve(srcPath, 'main.js'));
const bundlePopupScript = () =>
bundleJS(distPath, path.resolve(srcPath, 'ui', 'popup', 'settings-popup.js'));
const bundleOptionsScript = () =>
bundleJS(distPath, path.resolve(srcPath, 'ui', 'options', 'options.js'));
const bundleBackgroundScript = () =>
bundleJS(distPath, path.resolve(srcPath, 'background', 'background.js'));
const bundleAll = bundleMainScript()
.then(bundlePopupScript)
.then(bundleOptionsScript)
.then(bundleBackgroundScript);
const copyPopup = Promise.all(
['settings-popup.html', 'settings-popup.css', 'settings-popup.github-logo.svg'].map((file) =>
fs.copy(path.resolve(srcPath, 'ui', 'popup', file), path.resolve(distPath, file))
)
);
const copyOptions = Promise.all(
['options.html', 'options.css'].map((file) =>
fs.copy(path.resolve(srcPath, 'ui', 'options', file), path.resolve(distPath, file))
)
);
const copyStyles = fs.copy(
path.resolve(srcPath, 'injected-styles.css'),
path.resolve(distPath, 'injected-styles.css')
);
const copyExtensionLogos = fs.copy(path.resolve(srcPath, 'extensionIcons'), distPath);
return Promise.all([
copyExtensionLogos,
copyOptions,
copyPopup,
copyStyles,
copyIcons,
bundleAll,
]);
}
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 })
);
}
function buildDist(name, manifestName) {
const distPath = path.resolve(distBasePath, name);
return fs
.ensureDir(distPath)
.then(consolidateSVGFiles)
.then(() => src(distPath))
.then(() => buildManifest(distPath, manifestName))
.catch(console.error);
}
buildDist('firefox', 'firefox.json').then(() => buildDist('chrome-edge', 'chrome-edge.json'));