1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

83 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-04-26 00:31:51 -07:00
/**
* ParcelJS Bundle Configuration.
*
* @see https://parceljs.org/api.html
*/
2021-04-25 20:11:46 -07:00
const Bundler = require('parcel-bundler');
2021-04-26 00:31:51 -07:00
// Bundler options common to all bundle jobs.
2021-04-25 20:11:46 -07:00
const options = {
2021-04-26 00:31:51 -07:00
logLevel: 2,
cache: true,
2021-04-25 20:11:46 -07:00
watch: false,
minify: true,
outDir: './dist',
publicUrl: '/static',
};
2021-04-26 00:31:51 -07:00
// Get CLI arguments for optional overrides.
2021-04-25 20:11:46 -07:00
const args = process.argv.slice(2);
2021-04-26 00:31:51 -07:00
// Allow cache disabling.
2021-04-25 20:11:46 -07:00
if (args.includes('--no-cache')) {
options.cache = false;
}
2021-04-26 00:31:51 -07:00
// Style (SCSS) bundle jobs. Generally, everything should be bundled into netbox.css from main.scss
// unless there is a specific reason to do otherwise.
2021-04-25 20:11:46 -07:00
const styles = [
['styles/_external.scss', 'netbox-external.css'],
['styles/_light.scss', 'netbox-light.css'],
['styles/_dark.scss', 'netbox-dark.css'],
['styles/_elevations.scss', 'rack_elevation.css'],
['styles/_cable_trace.scss', 'cable_trace.css'],
2021-04-25 20:11:46 -07:00
];
2021-04-26 00:31:51 -07:00
// Script (JavaScript) bundle jobs. Generally, everything should be bundled into netbox.js from
// index.ts unless there is a specific reason to do otherwise.
2021-04-25 20:11:46 -07:00
const scripts = [
['src/index.ts', 'netbox.js'],
['src/jobs.ts', 'jobs.js'],
['src/device/lldp.ts', 'lldp.js'],
['src/device/config.ts', 'config.js'],
['src/device/status.ts', 'status.js'],
];
2021-04-26 00:31:51 -07:00
/**
* Run style bundle jobs.
*/
2021-04-25 20:11:46 -07:00
async function bundleStyles() {
for (const [input, outFile] of styles) {
const instance = new Bundler(input, { outFile, ...options });
await instance.bundle();
}
}
2021-04-26 00:31:51 -07:00
/**
* Run script bundle jobs.
*/
2021-04-25 20:11:46 -07:00
async function bundleScripts() {
for (const [input, outFile] of scripts) {
const instance = new Bundler(input, { outFile, ...options });
await instance.bundle();
}
}
2021-04-26 00:31:51 -07:00
/**
* Run all bundle jobs.
*/
2021-04-25 20:11:46 -07:00
async function bundleAll() {
if (args.includes('--styles')) {
2021-04-26 00:31:51 -07:00
// Only run style jobs.
2021-04-25 20:11:46 -07:00
return await bundleStyles();
} else if (args.includes('--scripts')) {
2021-04-26 00:31:51 -07:00
// Only run script jobs.
2021-04-25 20:11:46 -07:00
return await bundleScripts();
}
await bundleStyles();
await bundleScripts();
}
bundleAll();