From 467636fb1c5b845b7b77a4b8c41ae57ac9bc858b Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 5 Jan 2023 11:20:49 +0000 Subject: [PATCH] Add license selector --- scripts/package-lock.json | 81 ++++++ scripts/package.json | 1 + scripts/src/lib/Template.svelte | 20 ++ scripts/src/lib/template/git.ts | 2 - scripts/src/lib/template/license.ts | 80 ++++++ .../src/lib/template/licenses/apache-2.0.txt | 237 ++++++++++++++++++ scripts/src/lib/template/licenses/arr.txt | 6 + .../git/LICENSE => licenses/cc0-1.0.txt} | 35 ++- .../template/licenses/headers/apache-2.0.txt | 17 ++ .../lib/template/licenses/headers/cc0-1.0.txt | 14 ++ .../src/lib/template/licenses/lgpl-3.0.txt | 198 +++++++++++++++ scripts/src/lib/template/licenses/mit.txt | 51 ++++ scripts/src/lib/template/licenses/readme.md | 3 + scripts/src/lib/template/mixin.ts | 21 +- scripts/src/lib/template/modentrypoint.ts | 21 +- scripts/src/lib/template/template.ts | 3 + 16 files changed, 776 insertions(+), 14 deletions(-) create mode 100644 scripts/src/lib/template/license.ts create mode 100644 scripts/src/lib/template/licenses/apache-2.0.txt create mode 100644 scripts/src/lib/template/licenses/arr.txt rename scripts/src/lib/template/{templates/git/LICENSE => licenses/cc0-1.0.txt} (83%) create mode 100644 scripts/src/lib/template/licenses/headers/apache-2.0.txt create mode 100644 scripts/src/lib/template/licenses/headers/cc0-1.0.txt create mode 100644 scripts/src/lib/template/licenses/lgpl-3.0.txt create mode 100644 scripts/src/lib/template/licenses/mit.txt create mode 100644 scripts/src/lib/template/licenses/readme.md diff --git a/scripts/package-lock.json b/scripts/package-lock.json index 986aef42..4c11286e 100644 --- a/scripts/package-lock.json +++ b/scripts/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "eta": "^1.12.3", "file-saver": "^2.0.5", + "front-matter": "^4.0.2", "jszip": "^3.10.1" }, "devDependencies": { @@ -503,6 +504,14 @@ "node": ">= 8" } }, + "node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -674,6 +683,18 @@ "@esbuild/win32-x64": "0.16.9" } }, + "node_modules/esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/eta": { "version": "1.12.3", "resolved": "https://registry.npmjs.org/eta/-/eta-1.12.3.tgz", @@ -727,6 +748,14 @@ "node": ">=8" } }, + "node_modules/front-matter": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/front-matter/-/front-matter-4.0.2.tgz", + "integrity": "sha512-I8ZuJ/qG92NWX8i5x1Y8qyj3vizhXS31OxjKDu3LKP+7/qBgfIKValiZIEwoVoJKUHlhWtYrktkxV1XsX+pPlg==", + "dependencies": { + "js-yaml": "^3.13.1" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -904,6 +933,18 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, + "node_modules/js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dependencies": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/jszip": { "version": "3.10.1", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", @@ -1347,6 +1388,11 @@ "deprecated": "Please use @jridgewell/sourcemap-codec instead", "dev": true }, + "node_modules/sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" + }, "node_modules/string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", @@ -1920,6 +1966,14 @@ "picomatch": "^2.0.4" } }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "requires": { + "sprintf-js": "~1.0.2" + } + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2047,6 +2101,11 @@ "@esbuild/win32-x64": "0.16.9" } }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, "eta": { "version": "1.12.3", "resolved": "https://registry.npmjs.org/eta/-/eta-1.12.3.tgz", @@ -2088,6 +2147,14 @@ "to-regex-range": "^5.0.1" } }, + "front-matter": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/front-matter/-/front-matter-4.0.2.tgz", + "integrity": "sha512-I8ZuJ/qG92NWX8i5x1Y8qyj3vizhXS31OxjKDu3LKP+7/qBgfIKValiZIEwoVoJKUHlhWtYrktkxV1XsX+pPlg==", + "requires": { + "js-yaml": "^3.13.1" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2225,6 +2292,15 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, + "js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, "jszip": { "version": "3.10.1", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", @@ -2537,6 +2613,11 @@ "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", "dev": true }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" + }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", diff --git a/scripts/package.json b/scripts/package.json index 8dd0e4a5..58bb76f9 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -21,6 +21,7 @@ "dependencies": { "eta": "^1.12.3", "file-saver": "^2.0.5", + "front-matter": "^4.0.2", "jszip": "^3.10.1" } } diff --git a/scripts/src/lib/Template.svelte b/scripts/src/lib/Template.svelte index 55c17be8..b35de742 100644 --- a/scripts/src/lib/Template.svelte +++ b/scripts/src/lib/Template.svelte @@ -5,6 +5,7 @@ import DownloadIcon from "./DownloadIcon.svelte"; import { nameToModId } from "./template/template"; import { getMinorMinecraftVersion } from "./template/java"; + import { licenses, licensesMap } from "./template/license"; let minecraftVersion: string; let projectName = "Template Mod"; @@ -12,6 +13,7 @@ let useKotlin = false; let dataGeneration = false; let splitSources = true; + let license = "MIT License"; let customModId: string | undefined; let loading = false; @@ -107,6 +109,7 @@ useKotlin, dataGeneration: dataGeneration && supportsDataGen, splitSources: splitSources && supportsSplitSources, + license: licensesMap.get(license)!, }; const zip = new JSZip(); @@ -202,6 +205,23 @@ +
+

Mod License:

+
+

+ Select the license you wish to use for your mod. For help with choosing a license please visit GitHub's https://choosealicense.com/ website. +

+ +
+

diff --git a/scripts/src/lib/template/git.ts b/scripts/src/lib/template/git.ts index ab6afbb3..3bd2f3b5 100644 --- a/scripts/src/lib/template/git.ts +++ b/scripts/src/lib/template/git.ts @@ -2,10 +2,8 @@ import type { ComputedConfiguration, TemplateWriter } from "./template"; import gitignore from './templates/git/gitignore?raw'; import workflow from './templates/git/workflow.yml?raw'; -import license from './templates/git/LICENSE?raw'; export async function addGitFiles(writer: TemplateWriter, config: ComputedConfiguration) { await writer.write('.gitignore', gitignore); await writer.write('.github/workflows/build.yml', workflow); - await writer.write('LICENSE', license); } \ No newline at end of file diff --git a/scripts/src/lib/template/license.ts b/scripts/src/lib/template/license.ts new file mode 100644 index 00000000..6737362f --- /dev/null +++ b/scripts/src/lib/template/license.ts @@ -0,0 +1,80 @@ +import frontMatter from 'front-matter' +import type { ComputedConfiguration, TemplateWriter } from './template'; + +const licensesRaw = import.meta.glob("./licenses/*.txt", { as: "raw", eager: true }); +const headersRaw = import.meta.glob("./licenses/headers/*.txt", { as: "raw", eager: true }); + +const currentYear = new Date().getFullYear().toString(); + +// https://github.com/desktop/desktop/blob/af7b8ae7d1f88ba93e01731cdd7d070ee7ca4a7e/script/build.ts#L16 +interface ChooseALicense { + readonly title: string + readonly nickname?: string + readonly "spdx-id": string +} + +interface Header { + readonly "spdx-id": string +} + +export type License = { + readonly name: string + readonly id: string + readonly body: string +}; + +export const licenses = Object.values(licensesRaw) + .map(parseLicense) + .sort((a, b) => a.name.localeCompare(b.name)); +export const licensesMap = new Map(licenses.map(l => [l.name, l])); +export const licenseHeaders = new Map(Object.values(headersRaw).map(parseHeader)); + +function parseLicense(content: string): License { + const result = frontMatter(content); + + return { + name: result.attributes.nickname || result.attributes.title, + id: result.attributes['spdx-id'], + body: result.body, + }; +} + +function parseHeader(content: string): [string, string] { + const result = frontMatter
(content); + const headerText = result.body.trim() + return [result.attributes['spdx-id'], headerText] +} + +export function fillLicensePlaceholders(text: string): string { + // TODO [fullname]? + // TODO [modname] + return text.replaceAll("[yyyy]", currentYear); +} + +export function applyHeader(text: string, license: License): string { + const header = licenseHeaders.get(license.id); + + if (header == undefined) { + return text; + } + + return commentBlock(fillLicensePlaceholders(header)) + "\n\n" + text; +} + +export async function addLicense(writer: TemplateWriter, options: ComputedConfiguration): Promise { + writer.write("LICENSE", fillLicensePlaceholders(options.license.body)); +} + +/* + * Blah + */ +function commentBlock(header: string): string { + var lines = ["/*"]; + + for (var line of header.split("\n")) { + lines.push(" * " + line); + } + + lines.push(" */") + return lines.join("\n"); +} \ No newline at end of file diff --git a/scripts/src/lib/template/licenses/apache-2.0.txt b/scripts/src/lib/template/licenses/apache-2.0.txt new file mode 100644 index 00000000..09bcecc3 --- /dev/null +++ b/scripts/src/lib/template/licenses/apache-2.0.txt @@ -0,0 +1,237 @@ +--- +title: Apache License 2.0 +spdx-id: Apache-2.0 +redirect_from: /licenses/apache/ +featured: true +hidden: false + +description: A permissive license whose main conditions require preservation of copyright and license notices. Contributors provide an express grant of patent rights. Licensed works, modifications, and larger works may be distributed under different terms and without source code. + +how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. + +note: The Apache Software Foundation recommends taking the additional step of adding a boilerplate notice to the header of each source file. You can find the notice in the appendix at the very end of the license text. + +using: + Kubernetes: https://github.com/kubernetes/kubernetes/blob/master/LICENSE + PDF.js: https://github.com/mozilla/pdf.js/blob/master/LICENSE + Swift: https://github.com/apple/swift/blob/main/LICENSE.txt + +permissions: + - commercial-use + - modifications + - distribution + - patent-use + - private-use + +conditions: + - include-copyright + - document-changes + +limitations: + - trademark-use + - liability + - warranty + +--- + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [fullname] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/scripts/src/lib/template/licenses/arr.txt b/scripts/src/lib/template/licenses/arr.txt new file mode 100644 index 00000000..53e8afef --- /dev/null +++ b/scripts/src/lib/template/licenses/arr.txt @@ -0,0 +1,6 @@ +--- +title: All Rights Reserved / None +spdx-id: ARR +--- + +All Rights Reserved \ No newline at end of file diff --git a/scripts/src/lib/template/templates/git/LICENSE b/scripts/src/lib/template/licenses/cc0-1.0.txt similarity index 83% rename from scripts/src/lib/template/templates/git/LICENSE rename to scripts/src/lib/template/licenses/cc0-1.0.txt index 1625c179..a40cf103 100644 --- a/scripts/src/lib/template/templates/git/LICENSE +++ b/scripts/src/lib/template/licenses/cc0-1.0.txt @@ -1,3 +1,36 @@ +--- +title: Creative Commons Zero v1.0 Universal +spdx-id: CC0-1.0 +redirect_from: /licenses/cc0/ +hidden: false + +description: The Creative Commons CC0 Public Domain Dedication waives copyright interest in a work you've created and dedicates it to the world-wide public domain. Use CC0 to opt out of copyright entirely and ensure your work has the widest reach. As with the Unlicense and typical software licenses, CC0 disclaims warranties. CC0 is very similar to the Unlicense. + +how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. + +note: Creative Commons recommends taking the additional step of adding a boilerplate notice to the top of each file. The boilerplate can be found on their website. + +using: + Awesome: https://github.com/sindresorhus/awesome/blob/main/license + Shields.io: https://github.com/badges/shields/blob/master/LICENSE + psdash: https://github.com/Jahaja/psdash/blob/master/LICENSE + +permissions: + - commercial-use + - modifications + - distribution + - private-use + +conditions: [] + +limitations: + - liability + - trademark-use + - patent-use + - warranty + +--- + Creative Commons Legal Code CC0 1.0 Universal @@ -118,4 +151,4 @@ express Statement of Purpose. Work. d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to - this CC0 or use of the Work. \ No newline at end of file + this CC0 or use of the Work. diff --git a/scripts/src/lib/template/licenses/headers/apache-2.0.txt b/scripts/src/lib/template/licenses/headers/apache-2.0.txt new file mode 100644 index 00000000..d18f9818 --- /dev/null +++ b/scripts/src/lib/template/licenses/headers/apache-2.0.txt @@ -0,0 +1,17 @@ +--- +spdx-id: Apache-2.0 +--- + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/scripts/src/lib/template/licenses/headers/cc0-1.0.txt b/scripts/src/lib/template/licenses/headers/cc0-1.0.txt new file mode 100644 index 00000000..f26a3946 --- /dev/null +++ b/scripts/src/lib/template/licenses/headers/cc0-1.0.txt @@ -0,0 +1,14 @@ +--- +spdx-id: CC0-1.0 +--- + +[modname] + +Written in [yyyy] by [fullname] + +To the extent possible under law, the author(s) have dedicated all copyright +and related and neighboring rights to this software to the public domain +worldwide. This software is distributed without any warranty. + +You should have received a copy of the CC0 Public Domain Dedication along with +this software. If not, see . \ No newline at end of file diff --git a/scripts/src/lib/template/licenses/lgpl-3.0.txt b/scripts/src/lib/template/licenses/lgpl-3.0.txt new file mode 100644 index 00000000..407ae1f5 --- /dev/null +++ b/scripts/src/lib/template/licenses/lgpl-3.0.txt @@ -0,0 +1,198 @@ +--- +title: GNU Lesser General Public License v3.0 +spdx-id: LGPL-3.0 +nickname: GNU LGPLv3 +redirect_from: /licenses/lgpl-v3/ + +description: Permissions of this copyleft license are conditioned on making available complete source code of licensed works and modifications under the same license or the GNU GPLv3. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work through interfaces provided by the licensed work may be distributed under different terms and without source code for the larger work. + +how: This license is an additional set of permissions to the GNU GPLv3 license. Follow the instructions to apply the GNU GPLv3, in the root of your source code. Then add another file named COPYING.LESSER and copy the text. + +note: The Free Software Foundation recommends taking the additional step of adding a boilerplate notice to the top of each file. The boilerplate can be found at the end of the GNU GPLv3 license. Insert the word “Lesser” before “General” in all three places in the boilerplate notice to make sure that you refer to the GNU LGPLv3 and not the GNU GPLv3. + +using: + +permissions: + - commercial-use + - modifications + - distribution + - patent-use + - private-use + +conditions: + - include-copyright + - disclose-source + - document-changes + - same-license--library + +limitations: + - liability + - warranty + +--- + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/scripts/src/lib/template/licenses/mit.txt b/scripts/src/lib/template/licenses/mit.txt new file mode 100644 index 00000000..9ce215e9 --- /dev/null +++ b/scripts/src/lib/template/licenses/mit.txt @@ -0,0 +1,51 @@ +--- +title: MIT License +spdx-id: MIT +featured: true +hidden: false + +description: A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code. + +how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders. + +using: + Babel: https://github.com/babel/babel/blob/master/LICENSE + .NET: https://github.com/dotnet/runtime/blob/main/LICENSE.TXT + Rails: https://github.com/rails/rails/blob/master/MIT-LICENSE + +permissions: + - commercial-use + - modifications + - distribution + - private-use + +conditions: + - include-copyright + +limitations: + - liability + - warranty + +--- + +MIT License + +Copyright (c) [yyyy] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/scripts/src/lib/template/licenses/readme.md b/scripts/src/lib/template/licenses/readme.md new file mode 100644 index 00000000..5c0ecd51 --- /dev/null +++ b/scripts/src/lib/template/licenses/readme.md @@ -0,0 +1,3 @@ +# About the licenses + +These license files are from: https://github.com/github/choosealicense.com/tree/gh-pages/_licenses \ No newline at end of file diff --git a/scripts/src/lib/template/mixin.ts b/scripts/src/lib/template/mixin.ts index 6b6cfaa7..7107865b 100644 --- a/scripts/src/lib/template/mixin.ts +++ b/scripts/src/lib/template/mixin.ts @@ -4,6 +4,13 @@ import type { ComputedConfiguration, TemplateWriter } from "./template"; import mixinTemplate from './templates/mixin/Mixin.java.eta?raw'; import mixinClientTemplate from './templates/mixin/ClientMixin.java.eta?raw'; import { getJavaVersion } from "./java"; +import { applyHeader, type License } from './license'; + +type MixinOptions = { + className: string, + packageName: string, + license: License +} export async function generateMixin(writer: TemplateWriter, options: ComputedConfiguration) : Promise { const packageName = options.packageName + ".mixin"; @@ -23,9 +30,10 @@ export async function generateMixin(writer: TemplateWriter, options: ComputedCon const mixinJsonName = `${options.modid}.mixins.json`; await writer.write(`src/main/resources/${mixinJsonName}`, JSON.stringify(mixinJson, null, "\t")); - await writer.write(`src/main/java/${packageName.replaceAll("\.", "/")}/${className}.java`, renderTemplate(mixinTemplate, { + await writer.write(`src/main/java/${packageName.replaceAll("\.", "/")}/${className}.java`, renderSource(mixinTemplate, { className, - packageName + packageName, + license: options.license })); return [mixinJsonName]; @@ -49,9 +57,10 @@ export async function generateClientMixin(writer: TemplateWriter, options: Compu const mixinJsonName = `${options.modid}.client.mixins.json`; await writer.write(`src/client/resources/${mixinJsonName}`, JSON.stringify(mixinJson, null, "\t")); - await writer.write(`src/client/java/${packageName.replaceAll("\.", "/")}/${className}.java`, renderTemplate(mixinClientTemplate, { + await writer.write(`src/client/java/${packageName.replaceAll("\.", "/")}/${className}.java`, renderSource(mixinClientTemplate, { className, - packageName + packageName, + license: options.license })); return [ @@ -60,4 +69,8 @@ export async function generateClientMixin(writer: TemplateWriter, options: Compu "environment": "client" } ]; +} + +function renderSource(template: string, options: MixinOptions): string { + return applyHeader(renderTemplate(template, options), options.license); } \ No newline at end of file diff --git a/scripts/src/lib/template/modentrypoint.ts b/scripts/src/lib/template/modentrypoint.ts index add3cc85..676c4849 100644 --- a/scripts/src/lib/template/modentrypoint.ts +++ b/scripts/src/lib/template/modentrypoint.ts @@ -8,6 +8,7 @@ import kotlinEntrypointClientTemplate from './templates/entrypoint/ClientEntrypo import javaEntrypointDataGeneratorTemplate from './templates/entrypoint/DataGeneratorEntrypoint.java.eta?raw'; import kotlinEntrypointDataGeneratorTemplate from './templates/entrypoint/DataGeneratorEntrypoint.kt.eta?raw'; import { getMinorMinecraftVersion } from "./java"; +import { applyHeader, type License } from './license'; interface ClassOptions { package: string, // com.example @@ -18,6 +19,7 @@ interface ClassOptions { slf4j: boolean, clientEntrypoint: boolean, dataEntrypoint: boolean, + license: License, } export async function generateEntrypoint(writer: TemplateWriter, options: ComputedConfiguration): Promise { @@ -31,7 +33,8 @@ export async function generateEntrypoint(writer: TemplateWriter, options: Comput modid: options.modid, slf4j: getMinorMinecraftVersion(options.minecraftVersion) >= 18, clientEntrypoint: options.splitSources, - dataEntrypoint: options.dataGeneration + dataEntrypoint: options.dataGeneration, + license: options.license } if (options.kotlin) { @@ -48,10 +51,10 @@ async function generateJavaEntrypoint(writer: TemplateWriter, options: ClassOpti ] }; - await writer.write(`src/main/java/${options.path}.java`, renderTemplate(javaEntrypointTemplate, options)) + await writer.write(`src/main/java/${options.path}.java`, renderSource(javaEntrypointTemplate, options)) if (options.clientEntrypoint) { - await writer.write(`src/client/java/${options.path}Client.java`, renderTemplate(javaEntrypointClientTemplate, {...options, className: options.className + "Client"})); + await writer.write(`src/client/java/${options.path}Client.java`, renderSource(javaEntrypointClientTemplate, {...options, className: options.className + "Client"})); entrypoints = { ...entrypoints, @@ -62,7 +65,7 @@ async function generateJavaEntrypoint(writer: TemplateWriter, options: ClassOpti } if (options.dataEntrypoint) { - await writer.write(`src/main/java/${options.path}DataGenerator.java`, renderTemplate(javaEntrypointDataGeneratorTemplate, {...options, className: options.className + "DataGenerator"})); + await writer.write(`src/main/java/${options.path}DataGenerator.java`, renderSource(javaEntrypointDataGeneratorTemplate, {...options, className: options.className + "DataGenerator"})); entrypoints = { ...entrypoints, @@ -85,10 +88,10 @@ async function generateKotlinEntrypoint(writer: TemplateWriter, options: ClassOp ] }; - await writer.write(`src/main/kotlin/${options.path}.kt`, renderTemplate(kotlinEntrypointTemplate, options)) + await writer.write(`src/main/kotlin/${options.path}.kt`, renderSource(kotlinEntrypointTemplate, options)) if (options.clientEntrypoint) { - await writer.write(`src/client/kotlin/${options.path}Client.kt`, renderTemplate(kotlinEntrypointClientTemplate, {...options, className: options.className + "Client"})) + await writer.write(`src/client/kotlin/${options.path}Client.kt`, renderSource(kotlinEntrypointClientTemplate, {...options, className: options.className + "Client"})) entrypoints = { ...entrypoints, @@ -102,7 +105,7 @@ async function generateKotlinEntrypoint(writer: TemplateWriter, options: ClassOp } if (options.dataEntrypoint) { - await writer.write(`src/main/kotlin/${options.path}DataGenerator.kt`, renderTemplate(kotlinEntrypointDataGeneratorTemplate, {...options, className: options.className + "DataGenerator"})) + await writer.write(`src/main/kotlin/${options.path}DataGenerator.kt`, renderSource(kotlinEntrypointDataGeneratorTemplate, {...options, className: options.className + "DataGenerator"})) entrypoints = { ...entrypoints, @@ -116,4 +119,8 @@ async function generateKotlinEntrypoint(writer: TemplateWriter, options: ClassOp } return entrypoints; +} + +function renderSource(template: string, options: ClassOptions): string { + return applyHeader(renderTemplate(template, options), options.license); } \ No newline at end of file diff --git a/scripts/src/lib/template/template.ts b/scripts/src/lib/template/template.ts index 0106b269..ece6b7c5 100644 --- a/scripts/src/lib/template/template.ts +++ b/scripts/src/lib/template/template.ts @@ -3,6 +3,7 @@ import { addGroovyGradle } from './gradlegroovy'; import { getApiVersionForMinecraft, getKotlinAdapterVersions, getLoaderVersions, getMinecraftYarnVersions } from '../Api'; import { addModJson } from './modjson'; import { addGitFiles } from './git'; +import { addLicense, type License } from './license'; export interface Options { /** @@ -24,6 +25,7 @@ export interface Configuration { useKotlin: boolean, dataGeneration: boolean, splitSources: boolean, + license: License } export interface KotlinConfiguration { @@ -55,6 +57,7 @@ export async function generateTemplate(options: Options) { await addGroovyGradle(options.writer, computedConfig); await addModJson(options.writer, computedConfig); await addGitFiles(options.writer, computedConfig); + await addLicense(options.writer, computedConfig); } export function nameToModId(name: string) {