@anth0nycodes/license-generator 0.3.4 → 0.4.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 +28 -1
- package/dist/helpers.d.ts +3 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +10 -3
- package/dist/helpers.js.map +1 -1
- package/dist/index.js +60 -7
- package/dist/index.js.map +1 -1
- package/dist/license.d.ts +1 -1
- package/dist/license.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/helpers.ts +12 -3
- package/src/index.ts +88 -7
- package/src/license.ts +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Interactive CLI tool to quickly generate open-source licenses for your projects.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
6
|
|
|
7
7
|
<p align="center"><img alt="NPM Downloads" src="https://img.shields.io/npm/d18m/%40anth0nycodes%2Flicense-generator?style=plastic"></p>
|
|
8
8
|
|
|
@@ -62,6 +62,33 @@ generate-license --sa "anth0nycodes"
|
|
|
62
62
|
generate-license --ls
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
#### Show License Information
|
|
66
|
+
|
|
67
|
+
View detailed information about a specific license:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
generate-license -i <license-key>
|
|
71
|
+
|
|
72
|
+
# Example:
|
|
73
|
+
generate-license -i mit
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Show Config
|
|
77
|
+
|
|
78
|
+
Display your current configuration settings:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
generate-license --sc
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Reset Config
|
|
85
|
+
|
|
86
|
+
Reset your configuration to default (clears saved license and author):
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
generate-license --rc
|
|
90
|
+
```
|
|
91
|
+
|
|
65
92
|
## Supported Licenses
|
|
66
93
|
|
|
67
94
|
This tool uses the GitHub Licenses API, which includes:
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { LicenseShape } from "./license.js";
|
|
1
2
|
export declare function getGitUsername(): string;
|
|
3
|
+
export declare function isValid(licenses: LicenseShape[], licenseKey: string): boolean;
|
|
2
4
|
export declare function fileExists(path: string): Promise<boolean>;
|
|
5
|
+
export declare const CONFIG_FILE: string;
|
|
3
6
|
export interface Config {
|
|
4
7
|
defaultLicense?: string;
|
|
5
8
|
defaultAuthor?: string;
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,wBAAgB,cAAc,WAe7B;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,MAAM,WAEnE;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,oBAO5C;AAGD,eAAO,MAAM,WAAW,QAAkC,CAAC;AAE3D,MAAM,WAAW,MAAM;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAQjD;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,iBAiB7C"}
|
package/dist/helpers.js
CHANGED
|
@@ -4,6 +4,7 @@ import { access } from "node:fs/promises";
|
|
|
4
4
|
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
|
+
import color from "picocolors";
|
|
7
8
|
export function getGitUsername() {
|
|
8
9
|
try {
|
|
9
10
|
const uncleanName = String(execSync("git config user.name"));
|
|
@@ -12,7 +13,7 @@ export function getGitUsername() {
|
|
|
12
13
|
catch (error) {
|
|
13
14
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
14
15
|
if (errorMessage.includes("git config user.name")) {
|
|
15
|
-
console.error(
|
|
16
|
+
console.error(`Error: Git username not configured. Set it with: ${color.cyan('git config --global user.name "Your Name"')}`);
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
19
|
console.error(`Error occurred in getGitUsername: ${errorMessage}`);
|
|
@@ -20,6 +21,9 @@ export function getGitUsername() {
|
|
|
20
21
|
throw error;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
24
|
+
export function isValid(licenses, licenseKey) {
|
|
25
|
+
return licenses.some((l) => l.key === licenseKey);
|
|
26
|
+
}
|
|
23
27
|
export async function fileExists(path) {
|
|
24
28
|
try {
|
|
25
29
|
await access(path, constants.F_OK);
|
|
@@ -30,7 +34,7 @@ export async function fileExists(path) {
|
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
const CONFIG_DIR = join(homedir(), ".license-generator");
|
|
33
|
-
const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
37
|
+
export const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
34
38
|
export async function getConfig() {
|
|
35
39
|
try {
|
|
36
40
|
const content = await readFile(CONFIG_FILE, "utf8");
|
|
@@ -45,7 +49,10 @@ export async function setConfig(config) {
|
|
|
45
49
|
try {
|
|
46
50
|
await mkdir(CONFIG_DIR, { recursive: true });
|
|
47
51
|
const existingConfig = await getConfig();
|
|
48
|
-
|
|
52
|
+
// If config has any keys, merge with existing; otherwise use config as-is (for reset)
|
|
53
|
+
const updatedConfig = Object.keys(config).length > 0
|
|
54
|
+
? { ...existingConfig, ...config }
|
|
55
|
+
: config;
|
|
49
56
|
await writeFile(CONFIG_FILE, JSON.stringify(updatedConfig, null, 2), "utf8");
|
|
50
57
|
}
|
|
51
58
|
catch (error) {
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC7D,OAAO,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,IAAI,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC;YAClD,OAAO,CAAC,KAAK,CACX,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EA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AoB,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAO3D,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,gDAAgD;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc;IAC5C,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7C,MAAM,cAAc,GAAG,MAAM,SAAS,EAAE,CAAC;QACzC,sFAAsF;QACtF,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC;YAClD,CAAC,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE;YAClC,CAAC,CAAC,MAAM,CAAC;QACX,MAAM,SAAS,CACb,WAAW,EACX,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,EACtC,MAAM,CACP,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,KAAK,EAAE,CAAC,CAAC;QACvD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { intro, select, isCancel, cancel } from "@clack/prompts";
|
|
|
4
4
|
import inquirer from "inquirer";
|
|
5
5
|
import { createLicense, getLicenseContent, getLicenses } from "./license.js";
|
|
6
6
|
import color from "picocolors";
|
|
7
|
-
import { getGitUsername } from "./helpers.js";
|
|
7
|
+
import { CONFIG_FILE, fileExists, getGitUsername, isValid } from "./helpers.js";
|
|
8
8
|
import { getConfig, setConfig } from "./helpers.js";
|
|
9
9
|
import { BASE_URL } from "./constants.js";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
@@ -12,7 +12,7 @@ import { dirname, join } from "node:path";
|
|
|
12
12
|
import { readFileSync } from "node:fs";
|
|
13
13
|
const __filename = fileURLToPath(import.meta.url);
|
|
14
14
|
const __dirname = dirname(__filename);
|
|
15
|
-
const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"), "
|
|
15
|
+
const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf8"));
|
|
16
16
|
const main = async () => {
|
|
17
17
|
const licenses = await getLicenses();
|
|
18
18
|
program
|
|
@@ -21,9 +21,12 @@ const main = async () => {
|
|
|
21
21
|
.version(packageJson.version);
|
|
22
22
|
program
|
|
23
23
|
.option("--ls, --list", "list all available license keys")
|
|
24
|
+
.option("-i, --info <license-key>", "show detailed license information")
|
|
24
25
|
.option("-q, --quick", "alternative to interactive mode, generate a license using the saved default license")
|
|
25
|
-
.option("--sl, --set-license <license-key>",
|
|
26
|
-
.option("--sa, --set-author <author>",
|
|
26
|
+
.option("--sl, --set-license <license-key>", `set a default license for ${color.cyan("-q")} / ${color.cyan("--quick")} option`)
|
|
27
|
+
.option("--sa, --set-author <author>", `set a default author for ${color.cyan("-q")} / ${color.cyan("--quick")} option`)
|
|
28
|
+
.option("--sc, --show-config", `displays your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`)
|
|
29
|
+
.option("--rc, --reset-config", `resets your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`);
|
|
27
30
|
program.parse();
|
|
28
31
|
const opts = program.opts();
|
|
29
32
|
// Lists all available license keys
|
|
@@ -34,12 +37,23 @@ const main = async () => {
|
|
|
34
37
|
console.log(`Available license keys:\n${availableLicenseKeys}`);
|
|
35
38
|
process.exit(0);
|
|
36
39
|
}
|
|
40
|
+
// Show license description
|
|
41
|
+
if (opts.info) {
|
|
42
|
+
const licenseKey = opts.info.toLowerCase();
|
|
43
|
+
if (!isValid(licenses, licenseKey)) {
|
|
44
|
+
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
45
|
+
console.error("Available licenses:", licenses.map((l) => l.key).join(", "));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const licenseContent = await getLicenseContent(`${BASE_URL}/${licenseKey}`);
|
|
49
|
+
console.log(`${color.yellow("Description:")} ${licenseContent.description}`);
|
|
50
|
+
process.exit(0);
|
|
51
|
+
}
|
|
37
52
|
let configUpdated = false;
|
|
38
53
|
// Sets a default license
|
|
39
54
|
if (opts.setLicense) {
|
|
40
55
|
const licenseKey = opts.setLicense.toLowerCase();
|
|
41
|
-
|
|
42
|
-
if (!isValid) {
|
|
56
|
+
if (!isValid(licenses, licenseKey)) {
|
|
43
57
|
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
44
58
|
console.error("Available licenses:", licenses.map((l) => l.key).join(", "));
|
|
45
59
|
process.exit(1);
|
|
@@ -55,6 +69,45 @@ const main = async () => {
|
|
|
55
69
|
console.log(`Default author set to: ${color.blueBright(author)}`);
|
|
56
70
|
configUpdated = true;
|
|
57
71
|
}
|
|
72
|
+
// Shows current config
|
|
73
|
+
if (opts.showConfig) {
|
|
74
|
+
if (!(await fileExists(CONFIG_FILE))) {
|
|
75
|
+
console.log(`${color.yellow("No config file found.")} No config to display. You can create a config by setting a default author with ${color.cyan("--sa <author>")} / ${color.cyan("--set-author <author>")} or a default license with ${color.cyan("--sl <license-key>")} / ${color.cyan("--set-license <license-key>")}.`);
|
|
76
|
+
process.exit(0);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const config = await getConfig();
|
|
80
|
+
const configString = JSON.stringify(config, null, 2);
|
|
81
|
+
const isConfigEmpty = Object.keys(config).length === 0;
|
|
82
|
+
console.log(`${color.yellow("Your current config:\n")}${configString}`);
|
|
83
|
+
if (isConfigEmpty) {
|
|
84
|
+
console.log(`\n${color.yellow("Note:")} Your config file is empty. You can set a default author with ${color.cyan("--sa <author>")} / ${color.cyan("--set-author <author>")} and a default license with ${color.cyan("--sl <license-key>")} / ${color.cyan("--set-license <license-key>")}.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
89
|
+
console.error(`Error reading config: ${errorMessage}`);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
process.exit(0);
|
|
93
|
+
}
|
|
94
|
+
// Resets config
|
|
95
|
+
if (opts.resetConfig) {
|
|
96
|
+
if (!(await fileExists(CONFIG_FILE))) {
|
|
97
|
+
console.log(`${color.yellow("No config file found.")} Nothing to reset. You can create a config by setting a default author with ${color.cyan("--sa <author>")} / ${color.cyan("--set-author <author>")} or a default license with ${color.cyan("--sl <license-key>")} / ${color.cyan("--set-license <license-key>")}.`);
|
|
98
|
+
process.exit(0);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
await setConfig({});
|
|
102
|
+
console.log(color.greenBright("Config reset successfully!"));
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
106
|
+
console.error(`Error resetting config: ${errorMessage}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
58
111
|
// Skips interactive mode and generates a license with the saved default license
|
|
59
112
|
if (opts.quick) {
|
|
60
113
|
const config = await getConfig();
|
|
@@ -72,7 +125,7 @@ const main = async () => {
|
|
|
72
125
|
}
|
|
73
126
|
}
|
|
74
127
|
if (configUpdated) {
|
|
75
|
-
console.log(
|
|
128
|
+
console.log(`\n${color.yellow("Note:")} Use ${color.cyan("-q")} / ${color.cyan("--quick")} to generate with this license.`);
|
|
76
129
|
return;
|
|
77
130
|
}
|
|
78
131
|
// Interactive mode
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,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ts
CHANGED
package/dist/license.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAOA,
|
|
1
|
+
{"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,mBAAmB;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,WAAW,4BAQhC;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC,CAgB9B;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,iBA2Bb"}
|
package/package.json
CHANGED
package/src/helpers.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { access } from "node:fs/promises";
|
|
|
4
4
|
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
|
+
import type { LicenseShape } from "./license.js";
|
|
8
|
+
import color from "picocolors";
|
|
7
9
|
|
|
8
10
|
export function getGitUsername() {
|
|
9
11
|
try {
|
|
@@ -13,7 +15,7 @@ export function getGitUsername() {
|
|
|
13
15
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
14
16
|
if (errorMessage.includes("git config user.name")) {
|
|
15
17
|
console.error(
|
|
16
|
-
|
|
18
|
+
`Error: Git username not configured. Set it with: ${color.cyan('git config --global user.name "Your Name"')}`,
|
|
17
19
|
);
|
|
18
20
|
} else {
|
|
19
21
|
console.error(`Error occurred in getGitUsername: ${errorMessage}`);
|
|
@@ -22,6 +24,10 @@ export function getGitUsername() {
|
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
export function isValid(licenses: LicenseShape[], licenseKey: string) {
|
|
28
|
+
return licenses.some((l) => l.key === licenseKey);
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
export async function fileExists(path: string) {
|
|
26
32
|
try {
|
|
27
33
|
await access(path, constants.F_OK);
|
|
@@ -32,7 +38,7 @@ export async function fileExists(path: string) {
|
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
const CONFIG_DIR = join(homedir(), ".license-generator");
|
|
35
|
-
const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
41
|
+
export const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
36
42
|
|
|
37
43
|
export interface Config {
|
|
38
44
|
defaultLicense?: string;
|
|
@@ -53,7 +59,10 @@ export async function setConfig(config: Config) {
|
|
|
53
59
|
try {
|
|
54
60
|
await mkdir(CONFIG_DIR, { recursive: true });
|
|
55
61
|
const existingConfig = await getConfig();
|
|
56
|
-
|
|
62
|
+
// If config has any keys, merge with existing; otherwise use config as-is (for reset)
|
|
63
|
+
const updatedConfig = Object.keys(config).length > 0
|
|
64
|
+
? { ...existingConfig, ...config }
|
|
65
|
+
: config;
|
|
57
66
|
await writeFile(
|
|
58
67
|
CONFIG_FILE,
|
|
59
68
|
JSON.stringify(updatedConfig, null, 2),
|
package/src/index.ts
CHANGED
|
@@ -5,17 +5,18 @@ import { intro, select, isCancel, cancel } from "@clack/prompts";
|
|
|
5
5
|
import inquirer from "inquirer";
|
|
6
6
|
import { createLicense, getLicenseContent, getLicenses } from "./license.js";
|
|
7
7
|
import color from "picocolors";
|
|
8
|
-
import { getGitUsername } from "./helpers.js";
|
|
8
|
+
import { CONFIG_FILE, fileExists, getGitUsername, isValid } from "./helpers.js";
|
|
9
9
|
import { getConfig, setConfig } from "./helpers.js";
|
|
10
10
|
import { BASE_URL } from "./constants.js";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import { dirname, join } from "node:path";
|
|
13
13
|
import { readFileSync } from "node:fs";
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
14
15
|
|
|
15
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
16
17
|
const __dirname = dirname(__filename);
|
|
17
18
|
const packageJson = JSON.parse(
|
|
18
|
-
readFileSync(join(__dirname, "../package.json"), "
|
|
19
|
+
readFileSync(join(__dirname, "../package.json"), "utf8"),
|
|
19
20
|
);
|
|
20
21
|
|
|
21
22
|
const main = async () => {
|
|
@@ -30,17 +31,26 @@ const main = async () => {
|
|
|
30
31
|
|
|
31
32
|
program
|
|
32
33
|
.option("--ls, --list", "list all available license keys")
|
|
34
|
+
.option("-i, --info <license-key>", "show detailed license information")
|
|
33
35
|
.option(
|
|
34
36
|
"-q, --quick",
|
|
35
37
|
"alternative to interactive mode, generate a license using the saved default license",
|
|
36
38
|
)
|
|
37
39
|
.option(
|
|
38
40
|
"--sl, --set-license <license-key>",
|
|
39
|
-
|
|
41
|
+
`set a default license for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
|
|
40
42
|
)
|
|
41
43
|
.option(
|
|
42
44
|
"--sa, --set-author <author>",
|
|
43
|
-
|
|
45
|
+
`set a default author for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
|
|
46
|
+
)
|
|
47
|
+
.option(
|
|
48
|
+
"--sc, --show-config",
|
|
49
|
+
`displays your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
|
|
50
|
+
)
|
|
51
|
+
.option(
|
|
52
|
+
"--rc, --reset-config",
|
|
53
|
+
`resets your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
|
|
44
54
|
);
|
|
45
55
|
|
|
46
56
|
program.parse();
|
|
@@ -56,14 +66,33 @@ const main = async () => {
|
|
|
56
66
|
process.exit(0);
|
|
57
67
|
}
|
|
58
68
|
|
|
69
|
+
// Show license description
|
|
70
|
+
if (opts.info) {
|
|
71
|
+
const licenseKey = opts.info.toLowerCase();
|
|
72
|
+
|
|
73
|
+
if (!isValid(licenses, licenseKey)) {
|
|
74
|
+
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
75
|
+
console.error(
|
|
76
|
+
"Available licenses:",
|
|
77
|
+
licenses.map((l) => l.key).join(", "),
|
|
78
|
+
);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const licenseContent = await getLicenseContent(`${BASE_URL}/${licenseKey}`);
|
|
83
|
+
console.log(
|
|
84
|
+
`${color.yellow("Description:")} ${licenseContent.description}`,
|
|
85
|
+
);
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|
|
88
|
+
|
|
59
89
|
let configUpdated = false;
|
|
60
90
|
|
|
61
91
|
// Sets a default license
|
|
62
92
|
if (opts.setLicense) {
|
|
63
93
|
const licenseKey = opts.setLicense.toLowerCase();
|
|
64
|
-
const isValid = licenses.some((l) => l.key === licenseKey);
|
|
65
94
|
|
|
66
|
-
if (!isValid) {
|
|
95
|
+
if (!isValid(licenses, licenseKey)) {
|
|
67
96
|
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
68
97
|
console.error(
|
|
69
98
|
"Available licenses:",
|
|
@@ -85,6 +114,56 @@ const main = async () => {
|
|
|
85
114
|
configUpdated = true;
|
|
86
115
|
}
|
|
87
116
|
|
|
117
|
+
// Shows current config
|
|
118
|
+
if (opts.showConfig) {
|
|
119
|
+
if (!(await fileExists(CONFIG_FILE))) {
|
|
120
|
+
console.log(
|
|
121
|
+
`${color.yellow("No config file found.")} No config to display. You can create a config by setting a default author with ${color.cyan("--sa <author>")} / ${color.cyan("--set-author <author>")} or a default license with ${color.cyan("--sl <license-key>")} / ${color.cyan("--set-license <license-key>")}.`,
|
|
122
|
+
);
|
|
123
|
+
process.exit(0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const config = await getConfig();
|
|
128
|
+
const configString = JSON.stringify(config, null, 2);
|
|
129
|
+
const isConfigEmpty = Object.keys(config).length === 0;
|
|
130
|
+
console.log(`${color.yellow("Your current config:\n")}${configString}`);
|
|
131
|
+
|
|
132
|
+
if (isConfigEmpty) {
|
|
133
|
+
console.log(
|
|
134
|
+
`\n${color.yellow("Note:")} Your config file is empty. You can set a default author with ${color.cyan("--sa <author>")} / ${color.cyan("--set-author <author>")} and a default license with ${color.cyan("--sl <license-key>")} / ${color.cyan("--set-license <license-key>")}.`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const errorMessage =
|
|
139
|
+
error instanceof Error ? error.message : String(error);
|
|
140
|
+
console.error(`Error reading config: ${errorMessage}`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
process.exit(0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Resets config
|
|
147
|
+
if (opts.resetConfig) {
|
|
148
|
+
if (!(await fileExists(CONFIG_FILE))) {
|
|
149
|
+
console.log(
|
|
150
|
+
`${color.yellow("No config file found.")} Nothing to reset. You can create a config by setting a default author with ${color.cyan("--sa <author>")} / ${color.cyan("--set-author <author>")} or a default license with ${color.cyan("--sl <license-key>")} / ${color.cyan("--set-license <license-key>")}.`,
|
|
151
|
+
);
|
|
152
|
+
process.exit(0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
await setConfig({});
|
|
157
|
+
console.log(color.greenBright("Config reset successfully!"));
|
|
158
|
+
} catch (error) {
|
|
159
|
+
const errorMessage =
|
|
160
|
+
error instanceof Error ? error.message : String(error);
|
|
161
|
+
console.error(`Error resetting config: ${errorMessage}`);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
process.exit(0);
|
|
165
|
+
}
|
|
166
|
+
|
|
88
167
|
// Skips interactive mode and generates a license with the saved default license
|
|
89
168
|
if (opts.quick) {
|
|
90
169
|
const config = await getConfig();
|
|
@@ -106,7 +185,9 @@ const main = async () => {
|
|
|
106
185
|
}
|
|
107
186
|
|
|
108
187
|
if (configUpdated) {
|
|
109
|
-
console.log(
|
|
188
|
+
console.log(
|
|
189
|
+
`\n${color.yellow("Note:")} Use ${color.cyan("-q")} / ${color.cyan("--quick")} to generate with this license.`,
|
|
190
|
+
);
|
|
110
191
|
return;
|
|
111
192
|
}
|
|
112
193
|
|
package/src/license.ts
CHANGED