Files
threshold-ui/addons/api/broccoli-plugins/build-workers.js
T
55e1e68f30 [COMPLIANCE] Update Copyright and License Headers (#3099)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Dharini <dharini@hashicorp.com>
2026-01-20 11:35:10 -05:00

57 lines
1.2 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
const Plugin = require('broccoli-plugin');
const path = require('path');
const fs = require('fs');
const esbuild = require('esbuild');
module.exports = class BuildWorkers extends Plugin {
build() {
this.inputPaths.forEach((inputPath) => {
this.#buildWorkers(inputPath);
});
}
#buildWorkers(inputPath) {
const workers = this.#getWorkers(inputPath);
const workerBuilder = this.#configureWorkerBuilder({
isProduction: this.isProduction,
buildDir: this.outputPath,
});
Object.entries(workers).map(workerBuilder);
}
#getWorkers(inputPath) {
let workers = {};
let dir = fs.readdirSync(inputPath);
dir
.filter((name) => name.endsWith('-worker.js'))
.forEach((name) => {
workers[name] = path.join(inputPath, name);
});
return workers;
}
#configureWorkerBuilder({ isProduction, buildDir }) {
return ([name, entryPath]) => {
esbuild.buildSync({
loader: { '.js': 'js' },
entryPoints: [entryPath],
bundle: true,
outfile: path.join(buildDir, name),
format: 'esm',
minify: isProduction,
sourcemap: !isProduction,
});
};
}
};