Add license banner to generated files

This commit is contained in:
coletdjnz
2025-09-26 20:00:56 +12:00
parent 3655915fc1
commit 66782588fa
2 changed files with 51 additions and 3 deletions

View File

@@ -11,6 +11,7 @@
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-sucrase": "5.0.2",
"@rollup/plugin-terser": "0.4.4",
"rollup-plugin-license": "^3.6.0",
"@types/bun": "1.2.21",
"@types/deno": "2.3.0",
"@types/node": "24.3.0",

View File

@@ -3,11 +3,30 @@ import nodeResolve from "@rollup/plugin-node-resolve";
import sucrase from "@rollup/plugin-sucrase";
import terser from "@rollup/plugin-terser";
import { createHash } from "node:crypto";
import { Buffer } from "node:buffer";
import license from 'rollup-plugin-license';
const LICENSE_BANNER =
"SPDX-License-Identifier: Unlicense\n" +
"This file was automatically generated by https://github.com/yt-dlp/ejs on <%= moment().toISOString() %>" +
"<% if (dependencies && dependencies.length) { %>" +
"\n\nBundled Dependencies:" +
"<% _.forEach(dependencies, function (dependency) { if (!dependency.private) { %>" +
"\n\n---\nName: <%= dependency.name %>" +
"<% if (dependency.version) { %>\nVersion: <%= dependency.version %><% } %>" +
"\nLicense: <%= dependency.license %>" +
"<% if (dependency.repository && dependency.repository.url) { %>\nRepository: <%= dependency.repository.url %><% } %>" +
"<% if (dependency.homepage && dependency.homepage.url) { %>\nHomepage: <%= dependency.homepage.url %><% } %>" +
"<% if (dependency.author) { %>\nAuthor: <%= dependency.author.text() %><% } %>" +
"<% if (dependency.licenseText) { %>\n\n<%= dependency.licenseText %><% } %>" +
"\n---<% } }) %>\n<% } %>"
const ALLOWED_COMMENTS_RE = /SPDX-License-Identifier:/
function printHash() {
return {
name: "hash-output-plugin",
async writeBundle(options, bundle) {
writeBundle(_options, bundle) {
for (const [fileName, assetInfo] of Object.entries(bundle)) {
if (assetInfo.code) {
try {
@@ -43,6 +62,11 @@ export default defineConfig([
exclude: ["node_modules/**"],
transforms: ["typescript"],
}),
license({
banner: {
content: LICENSE_BANNER
},
}),
printHash(),
],
},
@@ -67,7 +91,16 @@ export default defineConfig([
exclude: ["node_modules/**"],
transforms: ["typescript"],
}),
terser(),
terser({
format: {
comments: ALLOWED_COMMENTS_RE
}
}),
license({
banner: {
content: LICENSE_BANNER
},
}),
printHash(),
],
},
@@ -85,6 +118,11 @@ export default defineConfig([
exclude: ["node_modules/**"],
transforms: ["typescript"],
}),
license({
banner: {
content: LICENSE_BANNER
},
}),
printHash(),
],
},
@@ -103,7 +141,16 @@ export default defineConfig([
exclude: ["node_modules/**"],
transforms: ["typescript"],
}),
terser(),
terser({
format: {
comments: ALLOWED_COMMENTS_RE
}
}),
license({
banner: {
content: LICENSE_BANNER
},
}),
printHash(),
],
},