commit
AAAAAAAAAA
diff --git a/derivative-licence-permissions/generate-permission.js b/derivative-licence-permissions/generate-permission.js
index 6b4ab3b..aa92162 100644
--- a/derivative-licence-permissions/generate-permission.js
+++ b/derivative-licence-permissions/generate-permission.js
@@ -1,4 +1,3 @@
-// Run with node generate-permission.js
const readline = require("readline");
const fs = require("fs");
@@ -7,23 +6,148 @@ const rl = readline.createInterface({
output: process.stdout
});
-function ask(question) {
- return new Promise(resolve => rl.question(question, resolve));
+function ask(q) {
+ return new Promise(res => rl.question(q, res));
+}
+
+function validateVersion(v) {
+ return /^\d+\.\d+$/.test(v);
+}
+
+function validateUUID(uuid) {
+ return /^\d+$/.test(uuid) && uuid.length >= 17;
+}
+
+function validateDiscordIdentifier(name) {
+ return name.length >= 3;
+}
+
+function validateGithub(name) {
+ return /^[a-zA-Z0-9-]+$/.test(name);
+}
+
+function validateLicenceType(type) {
+ return ["locked", "free"].includes(type.toLowerCase());
+}
+
+function normalizeDiscordIdentifier(name) {
+ name = name.trim().replace(/\s+/g, "");
+ if (!name.startsWith("@")) {
+ name = "@" + name;
+ }
+ return name;
+}
+
+async function askValidated(question, validator, errorMsg) {
+ while (true) {
+ const raw = await ask(question);
+ const answer = raw.replace(/[\r\n]/g, "").trim();
+ if (answer.length === 0 || answer === "0") {
+ console.log("You need to give this value.");
+ continue;
+ }
+ if (validator(answer)) return answer;
+ console.log(errorMsg);
+ }
+}
+
+function getNextPermissionId() {
+
+ const year = new Date().getFullYear();
+ const files = fs.readdirSync(".");
+
+ let highest = 0;
+
+ for (const file of files) {
+
+ if (!file.endsWith(".md")) continue;
+
+ const content = fs.readFileSync(file, "utf8");
+
+ const match = content.match(/ESAL-DP-(\d{4})-(\d{3})/);
+
+ if (match && parseInt(match[1]) === year) {
+
+ const num = parseInt(match[2]);
+
+ if (num > highest) highest = num;
+ }
+ }
+
+ const next = highest + 1;
+
+ if (next > 999) {
+ throw new Error("Maximum permission count (999) reached for this year.");
+ }
+
+ const padded = String(next).padStart(3, "0");
+
+ return {
+ short: `${year}-${padded}`,
+ full: `ESAL-DP-${year}-${padded}`
+ };
}
(async () => {
- const id = await ask("Permission ID (e.g. ESAL-DP-2026-003): ");
- const name = await ask("Representative Name: ");
- const discord = await ask("Discord Identifier: ");
- const uuid = await ask("Discord UUID: ");
- const github = await ask("GitHub Username: ");
- const date = await ask("Date Granted (e.g. 28 March 2026): ");
- const licenceType = await ask("Licence Type (locked/free): ");
+ const idInfo = getNextPermissionId();
+
+ console.log(`Next Permission ID: ${idInfo.short}`);
+
+ const id = idInfo.full;
+
+ const name = await askValidated(
+ "Representative Name: ",
+ v => v.trim().length > 0,
+ "Name cannot be empty."
+ );
+
+ let discord = await askValidated(
+ "Discord Identifier: ",
+ validateDiscordIdentifier,
+ "Discord identifier must be at least 3 characters."
+ );
+
+ discord = normalizeDiscordIdentifier(discord);
+
+ const uuid = await askValidated(
+ "Discord UUID: ",
+ validateUUID,
+ "Discord UUID must be digits only and at least 17 characters."
+ );
+
+ const github = await askValidated(
+ "GitHub Username: ",
+ validateGithub,
+ "Invalid GitHub username. Letters, numbers, and hyphens only."
+ );
+
+ const esalVersion = await askValidated(
+ "ESAL Version Granted At (e.g. 1.4): ",
+ validateVersion,
+ "Invalid version format. Example: 1.4"
+ );
+
+ const licenceType = (await askValidated(
+ "Licence Type (locked/free): ",
+ validateLicenceType,
+ "Licence type must be 'locked' or 'free'."
+ )).toLowerCase();
+
+ const today = new Date();
+
+ const isoDate = today.toISOString().split("T")[0];
+
+ const readableDate = today.toLocaleDateString("en-GB", {
+ day: "numeric",
+ month: "long",
+ year: "numeric"
+ });
let conditionBlock;
if (licenceType === "free") {
+
conditionBlock = `1. The authorised party may create a licence derived from or based upon
the Estrogen Source-Available Licence (ESAL).
@@ -42,6 +166,7 @@ function ask(question) {
and may not be transferred, sublicensed, or assigned to another party.`;
} else {
+
conditionBlock = `1. The authorised party may create a licence derived from or based upon
the Estrogen Source-Available Licence (ESAL).
@@ -56,6 +181,7 @@ function ask(question) {
5. This permission applies only to the authorised party identified above
and may not be transferred, sublicensed, or assigned to another party.`;
+
}
const content = `Derivative Licence Permission
@@ -77,7 +203,7 @@ Discord Identifier: ${discord}
Discord UUID: ${uuid}
-GitHub Account: https://github.com/${github}
+GitHub Account: [${github}](https://github.com/${github})
Permission Granted
------------------
@@ -95,6 +221,9 @@ Scope
This permission applies solely to the creation and use of a derivative
licence for projects controlled or operated by the authorised party.
+This permission is applied to version ${esalVersion} of ESAL, or later,
+unless explicitly updated at a later date.
+
Revocation
----------
Clove Nytrix Doughmination Twilight reserves the right to revoke this
@@ -103,24 +232,27 @@ permission at any time.
Modification
------------
Clove Nytrix Doughmination Twilight reserves the right to modify this
-permission at any time, provided the authorised party is made aware of
-any modifications.
+permission at any time, provided the Authorised Party is made aware of
+any and all modifications.
Date Granted
------------
-${date}
+${readableDate}
Dates Modified
--------------
None as thus far
`;
- const filename = `${date.replace(/ /g, "-")}-${name.replace(/ /g, "")}-ESAL-DP.md`;
+ const safeName = name.replace(/\s+/g, "");
+
+ const filename = `${isoDate}-${safeName}-ESAL-DP.md`;
fs.writeFileSync(filename, content);
console.log(`\nPermission file created: ${filename}`);
+ console.log(`Permission ID: ${id}`);
rl.close();
-})();
+})();
\ No newline at end of file