Chris Sandvik 05f9f8c057
Fix ESLint config (#38)
* Add support for Azure DevOps and BitBucket

* Remove `console.log`

* Fix ESLint config

- Fix the ESLint config
- Fix all lint errors that cropped up as a result
- Add scripts to lint
- Add prettier format script
- Add `husky` / `lint-staged` to lint/format files when they're pushed

* Move provider configs to new file as requested

* Fixes to meet maintainers specs

* Fix remaining lint warns/errs

* eslint fix

* Update eslint/prettier packges

Remove unused `@types/node-fetch` package

* Add `eslint-plugin-jsdoc`

* Add eslint rule for allowing providers to reassign params in their `replaceIcon` functions

* Add sensible defaults for prettier to override any local editor settings

* Some final cleanup

* Loosen the required engines to allow for easier installing

Co-authored-by: Claudio Santos <Claudiohbsantos@users.noreply.github.com>
2022-06-30 22:25:48 -04:00

62 lines
2.0 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 src(distPath) {
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,
outDir: distPath,
};
const bundler = new Parcel(entryFile, parcelOptions);
const bundleMainScript = bundler.bundle();
const copyIcons = fs.copy(destSVGPath, distPath);
const copyExtensionLogos = fs.copy(path.resolve(srcPath, 'icons'), distPath);
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 })
);
}
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'));