diff --git a/tools/copyright.js b/tools/copyright.js index afeeada4..74952250 100644 --- a/tools/copyright.js +++ b/tools/copyright.js @@ -1,6 +1,6 @@ -/* AUTOGENERATED COPYRIGHT HEADER START - * Copyright (C) 2023 Michael Fabian 'Xaymar' Dirks - * AUTOGENERATED COPYRIGHT HEADER END */ +// AUTOGENERATED COPYRIGHT HEADER START +// Copyright (C) 2023 Michael Fabian 'Xaymar' Dirks +// AUTOGENERATED COPYRIGHT HEADER END const CHILD_PROCESS = require("node:child_process"); const PROCESS = require("node:process"); const PATH = require("node:path"); @@ -8,6 +8,9 @@ const FS = require("node:fs"); const FSPROMISES = require("node:fs/promises"); const OS = require("os"); +const SECTION_START = "AUTOGENERATED COPYRIGHT HEADER START"; +const SECTION_END = "AUTOGENERATED COPYRIGHT HEADER END"; + async function git_isIgnored(path) { await new Promise((resolve, reject) => { try { @@ -148,10 +151,10 @@ function makeHeader(file, copyright) { ".yml", ], prepend: [ - "#\u0020AUTOGENERATED COPYRIGHT HEADER START", + `# ${SECTION_START}`, ], append: [ - "#\u0020AUTOGENERATED COPYRIGHT HEADER END", + `# ${SECTION_END}`, ], prefix: "# ", suffix: "", @@ -164,15 +167,15 @@ function makeHeader(file, copyright) { ".iss.in", ], prepend: [ - ";\u0020AUTOGENERATED COPYRIGHT HEADER START", + `; ${SECTION_START}`, ], append: [ - ";\u0020AUTOGENERATED COPYRIGHT HEADER END", + `; ${SECTION_END}`, ], prefix: "; ", suffix: "", }, - "/**/": { + "//": { files: [ ], exts: [ ".c", @@ -189,12 +192,12 @@ function makeHeader(file, copyright) { ".effect" ], prepend: [ - "/*\u0020AUTOGENERATED COPYRIGHT HEADER START", + `// ${SECTION_START}`, ], append: [ - " *\u0020AUTOGENERATED COPYRIGHT HEADER END */", + `// ${SECTION_END}`, ], - prefix: " * ", + prefix: "// ", suffix: "", }, "": { @@ -212,13 +215,13 @@ function makeHeader(file, copyright) { ".pkgproj.in", ], prepend: [ - "`, ], append: [ - " --\u0020AUTOGENERATED COPYRIGHT HEADER END -->", + ``, ], - prefix: " --", - suffix: "", + prefix: "", } }; @@ -251,9 +254,15 @@ async function addCopyright(file) { let header = makeHeader(file, copyright); let insert = Buffer.from(header.join(eol) + eol); - let startHeader = content.indexOf(header[0]); - let endHeader = content.indexOf(header[header.length - 1], startHeader + 1); - endHeader += header[header.length - 1].length + eol.length; + // Find the starting point. + let startHeader = content.indexOf(SECTION_START); + startHeader = content.lastIndexOf(eol, startHeader); + startHeader += Buffer.from(eol).byteLength; + + // Find the ending point. + let endHeader = content.indexOf(SECTION_END); + endHeader = content.indexOf(eol, endHeader); + endHeader += Buffer.from(eol).byteLength; let fd = await FSPROMISES.open(file, "w+"); let fp = [];