mirror of
https://gh.wpcy.net/https://github.com/WeblateOrg/weblate.git
synced 2026-04-26 07:59:21 +08:00
- Removed tribute from the old workflow to the new one in client/ - Built the libarary into static/js/vendor/tribute.js then - Used by the base.html template - Added license files and info using webpack during build - Improved the mainLicenseTransform function for better multiple library liceses exclusion handling.
83 lines
2.1 KiB
JavaScript
83 lines
2.1 KiB
JavaScript
// Copyright © Michal Čihař <michal@weblate.org>
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
const path = require("node:path");
|
|
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
|
const LicensePlugin = require("webpack-license-plugin");
|
|
const copyrightRegex = /Copyright.*\n/;
|
|
|
|
// REUSE-IgnoreStart
|
|
function extractCopyright(pkg) {
|
|
if (pkg.licenseText !== null) {
|
|
const copyrights = pkg.licenseText.match(copyrightRegex);
|
|
if (copyrights !== null) {
|
|
return copyrights.join("");
|
|
}
|
|
}
|
|
return `Copyright ${pkg.author}\n`;
|
|
}
|
|
|
|
function genericTransform(packages, filter) {
|
|
const mainPackages = packages.filter(filter);
|
|
const licenses = [...new Set(mainPackages.map((pkg) => pkg.license))]
|
|
.sort()
|
|
.join(" AND ");
|
|
|
|
const copyrights = [...new Set(mainPackages.map(extractCopyright))]
|
|
.sort()
|
|
.join("");
|
|
return `${copyrights}
|
|
SPDX-License-Identifier: ${licenses}
|
|
`;
|
|
}
|
|
// REUSE-IgnoreEnd
|
|
function mainLicenseTransform(packages) {
|
|
const excludePrefixes = ["@sentry", "tributejs"];
|
|
return genericTransform(
|
|
packages,
|
|
(pkg) => !excludePrefixes.some((prefix) => pkg.name.startsWith(prefix)),
|
|
);
|
|
}
|
|
function sentryLicenseTransform(packages) {
|
|
return genericTransform(packages, (pkg) => pkg.name.startsWith("@sentry"));
|
|
}
|
|
function tributeLicenseTransform(packages) {
|
|
return genericTransform(packages, (pkg) => pkg.name.startsWith("tributejs"));
|
|
}
|
|
|
|
module.exports = {
|
|
entry: {
|
|
main: "./src/main.js",
|
|
sentry: "./src/sentry.js",
|
|
tribute: "./src/tribute.js",
|
|
},
|
|
mode: "production",
|
|
optimization: {
|
|
minimize: true,
|
|
minimizer: [
|
|
new TerserPlugin({
|
|
extractComments: false,
|
|
terserOptions: {
|
|
format: {
|
|
comments: false,
|
|
},
|
|
},
|
|
}),
|
|
],
|
|
},
|
|
plugins: [
|
|
new LicensePlugin({
|
|
additionalFiles: {
|
|
"main.js.license": mainLicenseTransform,
|
|
"sentry.js.license": sentryLicenseTransform,
|
|
"tribute.js.license": tributeLicenseTransform,
|
|
},
|
|
}),
|
|
],
|
|
output: {
|
|
filename: "[name].js",
|
|
path: path.resolve(__dirname, "../weblate/static/js/vendor"),
|
|
},
|
|
};
|