@gesslar/licensed 1.3.0 → 2.0.1

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 CHANGED
@@ -53,7 +53,7 @@ The returned object has the following shape:
53
53
  name: "my-package", // package name, or null
54
54
  license: "MIT", // SPDX license identifier, or null
55
55
  licenseFile: "LICENSE.txt", // detected license filename, or null
56
- publicDomain: false, // true for Unlicense, 0BSD, CC0-1.0, MIT-0
56
+ publicDomain: false, // true for Unlicense, CC0-1.0
57
57
  dependencies: [
58
58
  { name: "lodash", license: "MIT", repo: "https://github.com/lodash/lodash" },
59
59
  { name: "private-pkg", license: "Unknown", repo: null },
@@ -93,7 +93,7 @@ const markdown = buildLicenseSection({
93
93
 
94
94
  ## License
95
95
 
96
- `@gesslar/licensed` is released into the public domain under the [0BSD](LICENSE.txt).
96
+ `@gesslar/licensed` is released under the [0BSD](LICENSE.txt).
97
97
 
98
98
  This package includes or depends on third-party components under their own
99
99
  licenses:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gesslar/licensed",
3
- "version": "1.3.0",
3
+ "version": "2.0.1",
4
4
  "description": "CLI and library for generating license sections in README.md",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,8 +17,8 @@
17
17
  "scripts": {
18
18
  "clean": "rm -rfv ./dist",
19
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 && sed -i '1{/^#!.*/d}' types/index.d.ts",
21
- "exec": "node ./src/index.js",
20
+ "types": "node -e \"require('fs').rmSync('types',{recursive:true,force:true});\" && tsc -p tsconfig.types.json",
21
+ "exec": "node ./src/cli.js",
22
22
  "test": "node --test tests/**/*.test.js",
23
23
  "lint": "eslint src/",
24
24
  "submit": "npm publish --access public --//registry.npmjs.org/:_authToken=\"${NPM_ACCESS_TOKEN}\"",
@@ -47,9 +47,9 @@
47
47
  ],
48
48
  "exports": {
49
49
  ".": {
50
- "types": "./types/index.d.ts",
51
- "default": "./src/index.js"
50
+ "types": "./types/lib.d.ts",
51
+ "default": "./src/lib.js"
52
52
  }
53
53
  },
54
- "bin": "./src/index.js"
54
+ "bin": "./src/cli.js"
55
55
  }
package/src/cli.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ import * as TK from "@gesslar/toolkit"
4
+ import {buildLicenseSection, licensed} from "./lib.js"
5
+
6
+ const cwd = new TK.DirectoryObject(TK.FileSystem.cwd)
7
+ const jsonFile = cwd.getFile("package.json")
8
+ const data = await licensed(jsonFile)
9
+
10
+ const output = buildLicenseSection({
11
+ name: data.name,
12
+ license: data.license,
13
+ licenseFile: data.licenseFile,
14
+ depResults: data.dependencies,
15
+ })
16
+
17
+ TK.Glog(output)
package/src/lib.js CHANGED
@@ -1,9 +1,10 @@
1
+ import * as TK from "@gesslar/toolkit"
1
2
  import {execFile} from "node:child_process"
2
3
  import {promisify} from "node:util"
3
4
 
4
5
  const exec = promisify(execFile)
5
6
 
6
- export const PUBLIC_DOMAIN = ["Unlicense", "0BSD", "CC0-1.0", "MIT-0"]
7
+ const PUBLIC_DOMAIN = ["Unlicense", "CC0-1.0"]
7
8
 
8
9
  /**
9
10
  * Cleans a repository URL to a normalized HTTPS form.
@@ -89,3 +90,34 @@ export function buildLicenseSection({name, license, licenseFile, depResults}) {
89
90
 
90
91
  return lines.join("\n")
91
92
  }
93
+
94
+ /**
95
+ * Generates structured license data for a project.
96
+ *
97
+ * @param {TK.FileObject} jsonFile - A FileObject pointing to the project's
98
+ * package.json.
99
+ * @returns {Promise<{name: string|null, license: string|null,
100
+ * licenseFile: string|null, publicDomain: boolean,
101
+ * dependencies: Array<{name: string, license: string,
102
+ * repo: string|null}>}>} Structured license data.
103
+ */
104
+ export async function licensed(jsonFile) {
105
+ const pkg = await jsonFile.loadData()
106
+ const cwd = jsonFile.parent
107
+
108
+ const licenseFileObj =
109
+ (await cwd.glob("{LICEN[CS]E,UNLICEN[CS]E}{,.txt,.md}"))?.files[0]
110
+
111
+ const deps = Object.keys(pkg.dependencies ?? {}).sort()
112
+ const depResults = deps.length
113
+ ? await Promise.all(deps.map(dep => npmView(dep)))
114
+ : []
115
+
116
+ return {
117
+ name: pkg.name ?? null,
118
+ license: pkg.license ?? null,
119
+ licenseFile: licenseFileObj?.name ?? null,
120
+ publicDomain: PUBLIC_DOMAIN.includes(pkg.license),
121
+ dependencies: depResults,
122
+ }
123
+ }
package/types/lib.d.ts CHANGED
@@ -38,5 +38,26 @@ export function buildLicenseSection({ name, license, licenseFile, depResults }:
38
38
  repo: string | null;
39
39
  }>;
40
40
  }): string;
41
- export const PUBLIC_DOMAIN: string[];
41
+ /**
42
+ * Generates structured license data for a project.
43
+ *
44
+ * @param {TK.FileObject} jsonFile - A FileObject pointing to the project's
45
+ * package.json.
46
+ * @returns {Promise<{name: string|null, license: string|null,
47
+ * licenseFile: string|null, publicDomain: boolean,
48
+ * dependencies: Array<{name: string, license: string,
49
+ * repo: string|null}>}>} Structured license data.
50
+ */
51
+ export function licensed(jsonFile: TK.FileObject): Promise<{
52
+ name: string | null;
53
+ license: string | null;
54
+ licenseFile: string | null;
55
+ publicDomain: boolean;
56
+ dependencies: Array<{
57
+ name: string;
58
+ license: string;
59
+ repo: string | null;
60
+ }>;
61
+ }>;
62
+ import * as TK from "@gesslar/toolkit";
42
63
  //# sourceMappingURL=lib.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.js"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,8BAHW,MAAM,GAAC,IAAI,GAAC,SAAS,GACnB,MAAM,GAAC,IAAI,CAWvB;AAED;;;;;;GAMG;AACH,6BAJW,MAAM,GACJ,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAC,IAAI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D,YAAY,EAAE,KAAK,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QACnD,IAAI,EAAE,MAAM,GAAC,IAAI,CAAA;KAAC,CAAC,CAAA;CAAC,CAAC,CAqBzB;oBA1HmB,kBAAkB"}
package/src/index.js DELETED
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import * as TK from "@gesslar/toolkit"
4
- import {buildLicenseSection, npmView, PUBLIC_DOMAIN} from "./lib.js"
5
- import {fileURLToPath} from "node:url"
6
-
7
- /**
8
- * Generates structured license data for a project.
9
- *
10
- * @param {import("@gesslar/toolkit").FileObject} jsonFile - A FileObject
11
- * pointing to the project's package.json.
12
- * @returns {Promise<{name: string|null, license: string|null,
13
- * licenseFile: string|null, publicDomain: boolean,
14
- * dependencies: Array<{name: string, license: string,
15
- * repo: string|null}>}>} Structured license data.
16
- */
17
- export async function licensed(jsonFile) {
18
- const pkg = await jsonFile.loadData()
19
- const cwd = jsonFile.parent
20
-
21
- const licenseFileObj =
22
- (await cwd.glob("{LICEN[CS]E,UNLICEN[CS]E}{,.txt,.md}"))?.files[0]
23
-
24
- const deps = Object.keys(pkg.dependencies ?? {}).sort()
25
- const depResults = deps.length
26
- ? await Promise.all(deps.map(dep => npmView(dep)))
27
- : []
28
-
29
- return {
30
- name: pkg.name ?? null,
31
- license: pkg.license ?? null,
32
- licenseFile: licenseFileObj?.name ?? null,
33
- publicDomain: PUBLIC_DOMAIN.includes(pkg.license),
34
- dependencies: depResults,
35
- }
36
- }
37
-
38
- export {buildLicenseSection, cleanUrl, npmView} from "./lib.js"
39
-
40
- // CLI mode
41
- if(process.argv[1] === fileURLToPath(import.meta.url)) {
42
- const cwd = new TK.DirectoryObject()
43
- const jsonFile = cwd.getFile("package.json")
44
- const data = await licensed(jsonFile)
45
-
46
- const output = buildLicenseSection({
47
- name: data.name,
48
- license: data.license,
49
- licenseFile: data.licenseFile,
50
- depResults: data.dependencies,
51
- })
52
-
53
- TK.Glog(output)
54
- }
package/types/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Generates structured license data for a project.
3
- *
4
- * @param {import("@gesslar/toolkit").FileObject} jsonFile - A FileObject
5
- * pointing to the project's package.json.
6
- * @returns {Promise<{name: string|null, license: string|null,
7
- * licenseFile: string|null, publicDomain: boolean,
8
- * dependencies: Array<{name: string, license: string,
9
- * repo: string|null}>}>} Structured license data.
10
- */
11
- export function licensed(jsonFile: import("@gesslar/toolkit").FileObject): Promise<{
12
- name: string | null;
13
- license: string | null;
14
- licenseFile: string | null;
15
- publicDomain: boolean;
16
- dependencies: Array<{
17
- name: string;
18
- license: string;
19
- repo: string | null;
20
- }>;
21
- }>;
22
- export { buildLicenseSection, cleanUrl, npmView } from "./lib.js";
23
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAMA;;;;;;;;;GASG;AACH,mCAPW,OAAO,kBAAkB,EAAE,UAAU,GAEnC,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,GAAC,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,GAAC,IAAI,CAAC;IACzD,WAAW,EAAE,MAAM,GAAC,IAAI,CAAC;IAAC,YAAY,EAAE,OAAO,CAAC;IAChD,YAAY,EAAE,KAAK,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QACnD,IAAI,EAAE,MAAM,GAAC,IAAI,CAAA;KAAC,CAAC,CAAA;CAAC,CAAC,CAqBzB"}