@gesslar/licensed 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
File without changes
package/UNLICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@gesslar/licensed",
3
+ "version": "1.0.0",
4
+ "description": "Simple CLI to produce license copy for README.md",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/gesslar/licensed.git"
8
+ },
9
+ "keywords": [],
10
+ "author": {
11
+ "name": "gesslar",
12
+ "url": "https://gesslar.dev"
13
+ },
14
+ "license": "Unlicense",
15
+ "type": "module",
16
+ "homepage": "https://github.com/gesslar/licensed#readme",
17
+ "scripts": {
18
+ "clean": "rm -rfv ./dist",
19
+ "build": "mkdir -pv ./dist && npm pack --pack-destination ./dist/",
20
+ "types": "node -e \"require('fs').rmSync('types',{recursive:true,force:true});\" && tsc -p tsconfig.types.json",
21
+ "exec": "node ./src/cli.js",
22
+ "lint": "eslint src/",
23
+ "submit": "npm publish --access public --//registry.npmjs.org/:_authToken=\"${NPM_ACCESS_TOKEN}\"",
24
+ "update": "npx npm-check-updates -u && npm install",
25
+ "pr": "gt submit -p --ai",
26
+ "patch": "npm version patch",
27
+ "minor": "npm version minor",
28
+ "major": "npm version major"
29
+ },
30
+ "dependencies": {
31
+ "@gesslar/toolkit": "^3.42.0"
32
+ },
33
+ "devDependencies": {
34
+ "@gesslar/uglier": "^2.0.0",
35
+ "eslint": "^10.0.2"
36
+ },
37
+ "engines": {
38
+ "node": ">=v24.13.0"
39
+ },
40
+ "files": [
41
+ "UNLICENSE.txt",
42
+ "src/**/*.js"
43
+ ]
44
+ }
package/src/cli.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ import * as TK from "@gesslar/toolkit"
4
+
5
+ import {execFile} from "node:child_process"
6
+ import {promisify} from "node:util"
7
+
8
+ ;(async() => {
9
+ const exec = promisify(execFile)
10
+
11
+ const cwd = new TK.DirectoryObject()
12
+ const jsonFile = cwd.getFile("package.json")
13
+ const pkg = await jsonFile.loadData()
14
+
15
+ // Detect license file in project root
16
+ const licenseFile = (await cwd.glob("{LICEN[CS]E,UNLICEN[CS]E}{,.txt,.md}"))?.files[0]
17
+
18
+ // Project name without scope
19
+ const name = pkg.name?.replace(/^@[^/]+\//, "") ?? "this project"
20
+ const license = pkg.license ?? "Unknown"
21
+
22
+ const publicDomain = ["Unlicense", "0BSD", "CC0-1.0"]
23
+ const phrase = publicDomain.includes(license)
24
+ ? `${name} is released into the public domain under the`
25
+ : `${name} is released under the`
26
+
27
+ const lines = [
28
+ "## License",
29
+ "",
30
+ phrase,
31
+ `[${license}](${licenseFile?.name ?? "LICENSE"}).`,
32
+ ]
33
+
34
+ const deps = Object.keys(pkg.dependencies ?? {}).sort()
35
+
36
+ if(deps.length) {
37
+ lines.push(
38
+ "",
39
+ "This package includes or depends on third-party components under their own",
40
+ "licenses:",
41
+ "",
42
+ "| Dependency | License |",
43
+ "| --- | --- |",
44
+ )
45
+
46
+ const results = await Promise.all(deps.map(dep => npmView(dep)))
47
+
48
+ for(const {name: dep, license: depLicense, repo} of results) {
49
+ const link = repo ? `[${dep}](${repo})` : dep
50
+ lines.push(`| ${link} | ${depLicense} |`)
51
+ }
52
+ }
53
+
54
+ TK.Glog(lines.join("\n"))
55
+
56
+ async function npmView(dep) {
57
+ try {
58
+ const {stdout} = await exec(
59
+ "npm", ["view", dep, "repository.url", "license", "--json"]
60
+ )
61
+ const data = JSON.parse(stdout)
62
+
63
+ return {
64
+ name: dep,
65
+ license: data.license ?? "Unknown",
66
+ repo: cleanUrl(data["repository.url"]),
67
+ }
68
+ } catch {
69
+ return {name: dep, license: "Unknown", repo: null}
70
+ }
71
+ }
72
+
73
+ function cleanUrl(raw) {
74
+ if(!raw)
75
+ return null
76
+
77
+ return raw
78
+ .replace(/^git\+/, "")
79
+ .replace(/\.git$/, "")
80
+ .replace(/^ssh:\/\/git@github\.com/, "https://github.com")
81
+ .replace(/^git:\/\//, "https://")
82
+ }
83
+ })()