From 128d311b6c0eb3f03e625d03a0b26d5fa3cc1459 Mon Sep 17 00:00:00 2001 From: Maddison Hellstrom Date: Sun, 26 Apr 2020 01:42:39 -0700 Subject: [PATCH] [docs:feat] auto-generate copyright/license info --- README.tmpl.md | 6 +++--- gulpfile.js | 32 ++++++++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.tmpl.md b/README.tmpl.md index 0da67c7..b2b0ae7 100644 --- a/README.tmpl.md +++ b/README.tmpl.md @@ -157,6 +157,6 @@ Todo - [x] Simplify installation process - [x] Feed the kittens -License -------- -©2017-2019 Maddison Hellstrom - MIT License +Copyright +--------- + diff --git a/gulpfile.js b/gulpfile.js index 87d3f22..464f314 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -19,6 +19,10 @@ const gulpIf = require("gulp-if") const { COPYFILE_EXCL } = require("fs").constants const { URL } = require("url") +const pkg = require("./package.json") + +const copyrightYearOne = 2017 + const paths = { scripts: ["conf.priv.js", "completions.js", "conf.js", "actions.js", "help.js", "keys.js", "util.js"], entry: "conf.js", @@ -105,6 +109,23 @@ task("check-priv", async () => { return Promise.resolve() }) +const parseContributor = (contributor) => { + let c = contributor + if (typeof contributor === "string") { + const m = contributor.match(/^(?.*?)\s*(<(?.*?)>)?\s*(\((?.*?)\))?$/) + if (!m) { + throw new Error(`couldn't parse contributor '${contributor}'`) + } + c = m.groups + } else if (typeof contributor !== "object") { + throw new Error(`expected contributor to be of type 'string' or 'object', got '${typeof contributor}'`) + } + if (!c.name) { + return null + } + return `${c.url ? `` : ""}${c.name}${c.url ? "" : ""}` +} + task("docs", parallel(async () => { requireSrcFiles() await loadFaviconsManifest() @@ -188,6 +209,16 @@ task("docs", parallel(async () => { return `${acc1}${domainStr}${header}\n${maps}` }, Promise.resolve("")) + const year = (new Date()).getFullYear() + const copyrightYears = `${copyrightYearOne !== year ? `${copyrightYearOne}-${year}` : copyrightYearOne}` + let copyright = `

Author

© ${copyrightYears} ${parseContributor(pkg.author)}

` + if (Array.isArray(pkg.contributors) && pkg.contributors.length > 0) { + copyright += "

Contributors

    " + copyright += pkg.contributors.reduce((acc, c) => `${acc}
  • ${parseContributor(c)}
  • `, "") + copyright += "

" + } + copyright += `

License

Released under the ${pkg.license} License

` + return src([paths.readme]) .pipe(replace("", disclaimer)) .pipe(replace("", Object.keys(compl).length)) @@ -196,6 +227,7 @@ task("docs", parallel(async () => { .pipe(replace("", Object.keys(keys.maps).length)) .pipe(replace("", keysTable)) .pipe(replace("", screenshotList)) + .pipe(replace("", copyright)) .pipe(rename(paths.readmeOut)) .pipe(dest(".")) })) diff --git a/package.json b/package.json index 464cc55..821e91b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "chrome-extension", "configuration" ], - "author": "Maddison Hellstrom", + "author": "Maddison Hellstrom (https://github.com/b0o)", + "contributors": [], "license": "MIT", "dependencies": { "github-reserved-names": "^1.1.5"