@anth0nycodes/license-generator 0.3.5 → 0.4.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
@@ -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,9 +1,11 @@
1
- export declare function getGitUsername(): string;
1
+ import type { Config, LicenseShape } from "./types.js";
2
+ export declare function getGitUsername(options?: {
3
+ fallback?: string;
4
+ }): string;
5
+ export declare function isValidLicense(licenses: LicenseShape[], licenseKey: string): boolean;
6
+ export declare function getErrorMessage(error: unknown): string;
2
7
  export declare function fileExists(path: string): Promise<boolean>;
3
- export interface Config {
4
- defaultLicense?: string;
5
- defaultAuthor?: string;
6
- }
8
+ export declare const CONFIG_FILE: string;
7
9
  export declare function getConfig(): Promise<Config>;
8
10
  export declare function setConfig(config: Config): Promise<void>;
9
11
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAOA,wBAAgB,cAAc,WAe7B;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,oBAO5C;AAKD,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,iBAc7C"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGvD,wBAAgB,cAAc,CAAC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,UAoBjE;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,MAAM,WAE1E;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,UAE7C;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,oBAO5C;AAGD,eAAO,MAAM,WAAW,QAAkC,CAAC;AAE3D,wBAAsB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAQjD;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,iBAS7C"}
package/dist/helpers.js CHANGED
@@ -1,25 +1,35 @@
1
1
  import { execSync } from "node:child_process";
2
2
  import { constants } from "node:fs";
3
- import { access } from "node:fs/promises";
4
- import { readFile, writeFile, mkdir } from "node:fs/promises";
3
+ import { readFile, writeFile, mkdir, access } from "node:fs/promises";
5
4
  import { join } from "node:path";
6
5
  import { homedir } from "node:os";
7
- export function getGitUsername() {
6
+ import color from "picocolors";
7
+ export function getGitUsername(options = {}) {
8
8
  try {
9
9
  const uncleanName = String(execSync("git config user.name"));
10
10
  return uncleanName.replace(/\r?\n/g, "");
11
11
  }
12
12
  catch (error) {
13
- const errorMessage = error instanceof Error ? error.message : String(error);
13
+ if (options.fallback !== undefined) {
14
+ return options.fallback;
15
+ }
16
+ const errorMessage = getErrorMessage(error);
14
17
  if (errorMessage.includes("git config user.name")) {
15
- console.error('Error: Git username not configured. Set it with: git config --global user.name "Your Name"');
18
+ console.error(`Error: Git username not configured. Set it with: ${color.cyan('git config --global user.name "Your Name"')}`);
19
+ process.exit(1);
16
20
  }
17
21
  else {
18
22
  console.error(`Error occurred in getGitUsername: ${errorMessage}`);
23
+ process.exit(1);
19
24
  }
20
- throw error;
21
25
  }
22
26
  }
27
+ export function isValidLicense(licenses, licenseKey) {
28
+ return licenses.some((l) => l.key === licenseKey);
29
+ }
30
+ export function getErrorMessage(error) {
31
+ return error instanceof Error ? error.message : String(error);
32
+ }
23
33
  export async function fileExists(path) {
24
34
  try {
25
35
  await access(path, constants.F_OK);
@@ -30,7 +40,7 @@ export async function fileExists(path) {
30
40
  }
31
41
  }
32
42
  const CONFIG_DIR = join(homedir(), ".license-generator");
33
- const CONFIG_FILE = join(CONFIG_DIR, "config.json");
43
+ export const CONFIG_FILE = join(CONFIG_DIR, "config.json");
34
44
  export async function getConfig() {
35
45
  try {
36
46
  const content = await readFile(CONFIG_FILE, "utf8");
@@ -42,15 +52,10 @@ export async function getConfig() {
42
52
  }
43
53
  }
44
54
  export async function setConfig(config) {
45
- try {
46
- await mkdir(CONFIG_DIR, { recursive: true });
47
- const existingConfig = await getConfig();
48
- const updatedConfig = { ...existingConfig, ...config };
49
- await writeFile(CONFIG_FILE, JSON.stringify(updatedConfig, null, 2), "utf8");
50
- }
51
- catch (error) {
52
- console.error(`Error occurred in setConfig: ${error}`);
53
- throw error;
54
- }
55
+ await mkdir(CONFIG_DIR, { recursive: true });
56
+ const existingConfig = await getConfig();
57
+ // If config has any keys, merge with existing; otherwise use config as-is (for reset)
58
+ const updatedConfig = Object.keys(config).length > 0 ? { ...existingConfig, ...config } : config;
59
+ await writeFile(CONFIG_FILE, JSON.stringify(updatedConfig, null, 2), "utf8");
55
60
  }
56
61
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAA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C,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,oBAAoB,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAE3D,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,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,MAAM,cAAc,GAAG,MAAM,SAAS,EAAE,CAAC;IAEzC,sFAAsF;IACtF,MAAM,aAAa,GACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAE7E,MAAM,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC/E,CAAC"}
package/dist/index.js CHANGED
@@ -4,15 +4,14 @@ 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";
8
- import { getConfig, setConfig } from "./helpers.js";
7
+ import { CONFIG_FILE, fileExists, getErrorMessage, getGitUsername, getConfig, setConfig, isValidLicense, } from "./helpers.js";
9
8
  import { BASE_URL } from "./constants.js";
10
9
  import { fileURLToPath } from "node:url";
11
10
  import { dirname, join } from "node:path";
12
11
  import { readFileSync } from "node:fs";
13
12
  const __filename = fileURLToPath(import.meta.url);
14
13
  const __dirname = dirname(__filename);
15
- const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8"));
14
+ const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf8"));
16
15
  const main = async () => {
17
16
  const licenses = await getLicenses();
18
17
  program
@@ -21,9 +20,12 @@ const main = async () => {
21
20
  .version(packageJson.version);
22
21
  program
23
22
  .option("--ls, --list", "list all available license keys")
23
+ .option("-i, --info <license-key>", "show detailed license information")
24
24
  .option("-q, --quick", "alternative to interactive mode, generate a license using the saved default license")
25
- .option("--sl, --set-license <license-key>", "set a default license for -q / --quick option")
26
- .option("--sa, --set-author <author>", "set a default author for -q / --quick option");
25
+ .option("--sl, --set-license <license-key>", `set a default license for ${color.cyan("-q")} / ${color.cyan("--quick")} option`)
26
+ .option("--sa, --set-author <author>", `set a default author for ${color.cyan("-q")} / ${color.cyan("--quick")} option`)
27
+ .option("--sc, --show-config", `displays your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`)
28
+ .option("--rc, --reset-config", `resets your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`);
27
29
  program.parse();
28
30
  const opts = program.opts();
29
31
  // Lists all available license keys
@@ -34,45 +36,118 @@ const main = async () => {
34
36
  console.log(`Available license keys:\n${availableLicenseKeys}`);
35
37
  process.exit(0);
36
38
  }
39
+ // Show license description
40
+ if (opts.info) {
41
+ const licenseKey = opts.info.toLowerCase();
42
+ if (!isValidLicense(licenses, licenseKey)) {
43
+ console.error(`Error: "${licenseKey}" is not a valid license.`);
44
+ console.error("Available licenses:", licenses.map((l) => l.key).join(", "));
45
+ process.exit(1);
46
+ }
47
+ try {
48
+ const { description: licenseDescription } = await getLicenseContent(`${BASE_URL}/${licenseKey}`);
49
+ console.log(`${color.yellow("Description:")} ${licenseDescription}`);
50
+ process.exit(0);
51
+ }
52
+ catch (error) {
53
+ const errorMessage = getErrorMessage(error);
54
+ console.error(`Error grabbing information on ${licenseKey} license: ${errorMessage}`);
55
+ process.exit(1);
56
+ }
57
+ }
37
58
  let configUpdated = false;
38
59
  // Sets a default license
39
60
  if (opts.setLicense) {
40
61
  const licenseKey = opts.setLicense.toLowerCase();
41
- const isValid = licenses.some((l) => l.key === licenseKey);
42
- if (!isValid) {
62
+ if (!isValidLicense(licenses, licenseKey)) {
43
63
  console.error(`Error: "${licenseKey}" is not a valid license.`);
44
64
  console.error("Available licenses:", licenses.map((l) => l.key).join(", "));
45
65
  process.exit(1);
46
66
  }
47
- await setConfig({ defaultLicense: licenseKey });
48
- console.log(`Default license set to: ${color.blueBright(licenseKey)}`);
49
- configUpdated = true;
67
+ try {
68
+ await setConfig({ defaultLicense: licenseKey });
69
+ console.log(`Default license set to: ${color.blueBright(licenseKey)}`);
70
+ configUpdated = true;
71
+ }
72
+ catch (error) {
73
+ const errorMessage = getErrorMessage(error);
74
+ console.error(`Error trying to set ${licenseKey} as the default license: ${errorMessage}`);
75
+ process.exit(1);
76
+ }
50
77
  }
51
78
  // Sets a default author
52
79
  if (opts.setAuthor) {
53
80
  const author = opts.setAuthor;
54
- await setConfig({ defaultAuthor: author });
55
- console.log(`Default author set to: ${color.blueBright(author)}`);
56
- configUpdated = true;
81
+ try {
82
+ await setConfig({ defaultAuthor: author });
83
+ console.log(`Default author set to: ${color.blueBright(author)}`);
84
+ configUpdated = true;
85
+ }
86
+ catch (error) {
87
+ const errorMessage = getErrorMessage(error);
88
+ console.error(`Error trying to set ${author} as the default author: ${errorMessage}`);
89
+ process.exit(1);
90
+ }
91
+ }
92
+ // Shows current config
93
+ if (opts.showConfig) {
94
+ if (!(await fileExists(CONFIG_FILE))) {
95
+ 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>")}.`);
96
+ process.exit(0);
97
+ }
98
+ try {
99
+ const config = await getConfig();
100
+ const configString = JSON.stringify(config, null, 2);
101
+ const isConfigEmpty = Object.keys(config).length === 0;
102
+ console.log(`${color.yellow("Your current config:\n")}${configString}`);
103
+ if (isConfigEmpty) {
104
+ 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>")}.`);
105
+ }
106
+ process.exit(0);
107
+ }
108
+ catch (error) {
109
+ const errorMessage = getErrorMessage(error);
110
+ console.error(`Error reading config: ${errorMessage}`);
111
+ process.exit(1);
112
+ }
113
+ }
114
+ // Resets config
115
+ if (opts.resetConfig) {
116
+ if (!(await fileExists(CONFIG_FILE))) {
117
+ 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>")}.`);
118
+ process.exit(0);
119
+ }
120
+ try {
121
+ await setConfig({});
122
+ console.log(color.greenBright("Config reset successfully!"));
123
+ process.exit(0);
124
+ }
125
+ catch (error) {
126
+ const errorMessage = getErrorMessage(error);
127
+ console.error(`Error resetting config: ${errorMessage}`);
128
+ process.exit(1);
129
+ }
57
130
  }
58
131
  // Skips interactive mode and generates a license with the saved default license
59
132
  if (opts.quick) {
60
- const config = await getConfig();
61
- let name = config.defaultAuthor || getGitUsername();
62
133
  let year = String(new Date().getFullYear());
63
- let licenseKey = config.defaultLicense || "mit";
64
- const licenseOptionContent = await getLicenseContent(`${BASE_URL}/${licenseKey}`);
65
134
  try {
135
+ const config = await getConfig();
136
+ // In quick mode, we need git config if no default author is set
137
+ const name = config.defaultAuthor || getGitUsername();
138
+ const licenseKey = config.defaultLicense || "mit";
139
+ const licenseOptionContent = await getLicenseContent(`${BASE_URL}/${licenseKey}`);
66
140
  await createLicense(licenseOptionContent, year, name);
67
141
  process.exit(0);
68
142
  }
69
143
  catch (error) {
70
- console.error(`Error occurred in createLicense: ${error}`);
71
- throw error;
144
+ const errorMessage = getErrorMessage(error);
145
+ console.error(`Error occurred trying to create license: ${errorMessage}`);
146
+ process.exit(1);
72
147
  }
73
148
  }
74
149
  if (configUpdated) {
75
- console.log(`Use -q / --quick to generate with this license.`);
150
+ console.log(`\n${color.yellow("Note:")} Use ${color.cyan("-q")} / ${color.cyan("--quick")} to generate with this license.`);
76
151
  return;
77
152
  }
78
153
  // Interactive mode
@@ -97,7 +172,7 @@ const main = async () => {
97
172
  type: "input",
98
173
  name: "name",
99
174
  message: "Enter name:",
100
- default: getGitUsername(),
175
+ default: getGitUsername({ fallback: "placeholder" }),
101
176
  validate(value) {
102
177
  if (value.length === 0)
103
178
  return "Name is required";
@@ -123,21 +198,24 @@ const main = async () => {
123
198
  cancel("Operation cancelled.");
124
199
  process.exit(0);
125
200
  }
126
- // Grab the content of the selected license
127
- const licenseOptionContent = await getLicenseContent(`${BASE_URL}/${String(licenseOption)}`);
128
201
  // Write LICENSE file
129
202
  try {
203
+ // Grab the content of the selected license
204
+ const licenseOptionContent = await getLicenseContent(`${BASE_URL}/${String(licenseOption)}`);
130
205
  await createLicense(licenseOptionContent, answers.year, answers.name);
131
206
  }
132
207
  catch (error) {
133
- console.error(`Error occurred in createLicense: ${error}`);
134
- throw error;
208
+ const errorMessage = getErrorMessage(error);
209
+ console.error(`Error occurred trying to create license: ${errorMessage}`);
210
+ process.exit(1);
135
211
  }
136
212
  };
137
213
  try {
138
- main();
214
+ await main();
139
215
  }
140
216
  catch (error) {
141
- console.error(`Error in main: ${error}`);
217
+ const errorMessage = getErrorMessage(error);
218
+ console.error(`Error in main: ${errorMessage}`);
219
+ process.exit(1);
142
220
  }
143
221
  //# sourceMappingURL=index.js.map
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;AAC9C,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;AAEvC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAC5B,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,OAAO,CAAC,CAC1D,CAAC;AAEF,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;IACtB,MAAM,QAAQ,GAAG,MAAM,WAAW,EAAE,CAAC;IAErC,OAAO;SACJ,IAAI,CAAC,mBAAmB,CAAC;SACzB,WAAW,CACV,8EAA8E,CAC/E;SACA,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEhC,OAA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CAAC,CAAC;AAClB,CAAC"}
package/dist/license.d.ts CHANGED
@@ -1,21 +1,5 @@
1
- interface LicenseShape {
2
- key: string;
3
- name: string;
4
- spdx_id: string;
5
- url: string;
6
- node_id: string;
7
- }
8
- interface LicenseContentShape {
9
- key: string;
10
- name: string;
11
- description: string;
12
- permissions: string[];
13
- conditions: string[];
14
- limitations: string[];
15
- body: string;
16
- }
1
+ import { LicenseContentShape, LicenseShape } from "./types.js";
17
2
  export declare function getLicenses(): Promise<LicenseShape[]>;
18
3
  export declare function getLicenseContent(url: string): Promise<LicenseContentShape>;
19
4
  export declare function createLicense(content: LicenseContentShape, year: string, name: string): Promise<void>;
20
- export {};
21
5
  //# sourceMappingURL=license.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAOA,UAAU,YAAY;IACpB,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"}
1
+ {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/D,wBAAsB,WAAW,4BAShC;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC,CAW9B;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,iBA2Bb"}
package/dist/license.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import axios from "axios";
2
2
  import color from "picocolors";
3
3
  import { writeFile } from "node:fs/promises";
4
- import { fileExists } from "./helpers.js";
4
+ import { fileExists, getErrorMessage } from "./helpers.js";
5
5
  import { cancel, confirm, spinner } from "@clack/prompts";
6
6
  import { BASE_URL } from "./constants.js";
7
7
  export async function getLicenses() {
@@ -10,27 +10,22 @@ export async function getLicenses() {
10
10
  return data;
11
11
  }
12
12
  catch (error) {
13
- console.error(`Error in getLicenses: ${error}`);
14
- throw error;
13
+ const errorMessage = getErrorMessage(error);
14
+ console.error(`Error in getLicenses: ${errorMessage}`);
15
+ process.exit(1);
15
16
  }
16
17
  }
17
18
  export async function getLicenseContent(url) {
18
- try {
19
- const { data } = await axios.get(url);
20
- return {
21
- key: data.key,
22
- name: data.name,
23
- description: data.description,
24
- permissions: data.permissions,
25
- conditions: data.conditions,
26
- limitations: data.limitations,
27
- body: data.body,
28
- };
29
- }
30
- catch (error) {
31
- console.error(`Error in getLicenseContent: ${error}`);
32
- throw error;
33
- }
19
+ const { data } = await axios.get(url);
20
+ return {
21
+ key: data.key,
22
+ name: data.name,
23
+ description: data.description,
24
+ permissions: data.permissions,
25
+ conditions: data.conditions,
26
+ limitations: data.limitations,
27
+ body: data.body,
28
+ };
34
29
  }
35
30
  export async function createLicense(content, year, name) {
36
31
  let uncleanBody = content.body;
@@ -1 +1 @@
1
- {"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"A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BAA2B,EAAE,IAAI,CAAC;SAC7C,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC;SAC1B,UAAU,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAExC,IAAI,MAAM,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAChC,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC;YACnC,OAAO,EAAE,yCAAyC;SACnD,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,CAAC,sBAAsB,CAAC,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC;IAC/C,MAAM,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,21 @@
1
+ export interface LicenseShape {
2
+ key: string;
3
+ name: string;
4
+ spdx_id: string;
5
+ url: string;
6
+ node_id: string;
7
+ }
8
+ export interface LicenseContentShape {
9
+ key: string;
10
+ name: string;
11
+ description: string;
12
+ permissions: string[];
13
+ conditions: string[];
14
+ limitations: string[];
15
+ body: string;
16
+ }
17
+ export interface Config {
18
+ defaultLicense?: string;
19
+ defaultAuthor?: string;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,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,MAAM,WAAW,mBAAmB;IAClC,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;AAGD,MAAM,WAAW,MAAM;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anth0nycodes/license-generator",
3
- "version": "0.3.5",
3
+ "version": "0.4.1",
4
4
  "description": "An open-source CLI tool to generate licenses for your repository.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -56,6 +56,7 @@
56
56
  "dev": "tsx src/index.ts",
57
57
  "build": "tsc",
58
58
  "start": "node dist/index.js",
59
+ "check": "tsc --noEmit",
59
60
  "publish:npm": "pnpm publish --access public"
60
61
  }
61
62
  }
package/src/helpers.ts CHANGED
@@ -1,27 +1,41 @@
1
1
  import { execSync } from "node:child_process";
2
2
  import { constants } from "node:fs";
3
- import { access } from "node:fs/promises";
4
- import { readFile, writeFile, mkdir } from "node:fs/promises";
3
+ import { readFile, writeFile, mkdir, access } from "node:fs/promises";
5
4
  import { join } from "node:path";
6
5
  import { homedir } from "node:os";
6
+ import type { Config, LicenseShape } from "./types.js";
7
+ import color from "picocolors";
7
8
 
8
- export function getGitUsername() {
9
+ export function getGitUsername(options: { fallback?: string } = {}) {
9
10
  try {
10
11
  const uncleanName = String(execSync("git config user.name"));
11
12
  return uncleanName.replace(/\r?\n/g, "");
12
13
  } catch (error) {
13
- const errorMessage = error instanceof Error ? error.message : String(error);
14
+ if (options.fallback !== undefined) {
15
+ return options.fallback;
16
+ }
17
+
18
+ const errorMessage = getErrorMessage(error);
14
19
  if (errorMessage.includes("git config user.name")) {
15
20
  console.error(
16
- 'Error: Git username not configured. Set it with: git config --global user.name "Your Name"',
21
+ `Error: Git username not configured. Set it with: ${color.cyan('git config --global user.name "Your Name"')}`,
17
22
  );
23
+ process.exit(1);
18
24
  } else {
19
25
  console.error(`Error occurred in getGitUsername: ${errorMessage}`);
26
+ process.exit(1);
20
27
  }
21
- throw error;
22
28
  }
23
29
  }
24
30
 
31
+ export function isValidLicense(licenses: LicenseShape[], licenseKey: string) {
32
+ return licenses.some((l) => l.key === licenseKey);
33
+ }
34
+
35
+ export function getErrorMessage(error: unknown) {
36
+ return error instanceof Error ? error.message : String(error);
37
+ }
38
+
25
39
  export async function fileExists(path: string) {
26
40
  try {
27
41
  await access(path, constants.F_OK);
@@ -32,12 +46,7 @@ export async function fileExists(path: string) {
32
46
  }
33
47
 
34
48
  const CONFIG_DIR = join(homedir(), ".license-generator");
35
- const CONFIG_FILE = join(CONFIG_DIR, "config.json");
36
-
37
- export interface Config {
38
- defaultLicense?: string;
39
- defaultAuthor?: string;
40
- }
49
+ export const CONFIG_FILE = join(CONFIG_DIR, "config.json");
41
50
 
42
51
  export async function getConfig(): Promise<Config> {
43
52
  try {
@@ -50,17 +59,12 @@ export async function getConfig(): Promise<Config> {
50
59
  }
51
60
 
52
61
  export async function setConfig(config: Config) {
53
- try {
54
- await mkdir(CONFIG_DIR, { recursive: true });
55
- const existingConfig = await getConfig();
56
- const updatedConfig = { ...existingConfig, ...config };
57
- await writeFile(
58
- CONFIG_FILE,
59
- JSON.stringify(updatedConfig, null, 2),
60
- "utf8",
61
- );
62
- } catch (error) {
63
- console.error(`Error occurred in setConfig: ${error}`);
64
- throw error;
65
- }
62
+ await mkdir(CONFIG_DIR, { recursive: true });
63
+ const existingConfig = await getConfig();
64
+
65
+ // If config has any keys, merge with existing; otherwise use config as-is (for reset)
66
+ const updatedConfig =
67
+ Object.keys(config).length > 0 ? { ...existingConfig, ...config } : config;
68
+
69
+ await writeFile(CONFIG_FILE, JSON.stringify(updatedConfig, null, 2), "utf8");
66
70
  }
package/src/index.ts CHANGED
@@ -5,8 +5,15 @@ 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";
9
- import { getConfig, setConfig } from "./helpers.js";
8
+ import {
9
+ CONFIG_FILE,
10
+ fileExists,
11
+ getErrorMessage,
12
+ getGitUsername,
13
+ getConfig,
14
+ setConfig,
15
+ isValidLicense,
16
+ } from "./helpers.js";
10
17
  import { BASE_URL } from "./constants.js";
11
18
  import { fileURLToPath } from "node:url";
12
19
  import { dirname, join } from "node:path";
@@ -15,7 +22,7 @@ import { readFileSync } from "node:fs";
15
22
  const __filename = fileURLToPath(import.meta.url);
16
23
  const __dirname = dirname(__filename);
17
24
  const packageJson = JSON.parse(
18
- readFileSync(join(__dirname, "../package.json"), "utf-8"),
25
+ readFileSync(join(__dirname, "../package.json"), "utf8"),
19
26
  );
20
27
 
21
28
  const main = async () => {
@@ -30,17 +37,26 @@ const main = async () => {
30
37
 
31
38
  program
32
39
  .option("--ls, --list", "list all available license keys")
40
+ .option("-i, --info <license-key>", "show detailed license information")
33
41
  .option(
34
42
  "-q, --quick",
35
43
  "alternative to interactive mode, generate a license using the saved default license",
36
44
  )
37
45
  .option(
38
46
  "--sl, --set-license <license-key>",
39
- "set a default license for -q / --quick option",
47
+ `set a default license for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
40
48
  )
41
49
  .option(
42
50
  "--sa, --set-author <author>",
43
- "set a default author for -q / --quick option",
51
+ `set a default author for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
52
+ )
53
+ .option(
54
+ "--sc, --show-config",
55
+ `displays your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
56
+ )
57
+ .option(
58
+ "--rc, --reset-config",
59
+ `resets your config for ${color.cyan("-q")} / ${color.cyan("--quick")} option`,
44
60
  );
45
61
 
46
62
  program.parse();
@@ -56,14 +72,41 @@ const main = async () => {
56
72
  process.exit(0);
57
73
  }
58
74
 
75
+ // Show license description
76
+ if (opts.info) {
77
+ const licenseKey = opts.info.toLowerCase();
78
+
79
+ if (!isValidLicense(licenses, licenseKey)) {
80
+ console.error(`Error: "${licenseKey}" is not a valid license.`);
81
+ console.error(
82
+ "Available licenses:",
83
+ licenses.map((l) => l.key).join(", "),
84
+ );
85
+ process.exit(1);
86
+ }
87
+
88
+ try {
89
+ const { description: licenseDescription } = await getLicenseContent(
90
+ `${BASE_URL}/${licenseKey}`,
91
+ );
92
+ console.log(`${color.yellow("Description:")} ${licenseDescription}`);
93
+ process.exit(0);
94
+ } catch (error) {
95
+ const errorMessage = getErrorMessage(error);
96
+ console.error(
97
+ `Error grabbing information on ${licenseKey} license: ${errorMessage}`,
98
+ );
99
+ process.exit(1);
100
+ }
101
+ }
102
+
59
103
  let configUpdated = false;
60
104
 
61
105
  // Sets a default license
62
106
  if (opts.setLicense) {
63
107
  const licenseKey = opts.setLicense.toLowerCase();
64
- const isValid = licenses.some((l) => l.key === licenseKey);
65
108
 
66
- if (!isValid) {
109
+ if (!isValidLicense(licenses, licenseKey)) {
67
110
  console.error(`Error: "${licenseKey}" is not a valid license.`);
68
111
  console.error(
69
112
  "Available licenses:",
@@ -72,41 +115,111 @@ const main = async () => {
72
115
  process.exit(1);
73
116
  }
74
117
 
75
- await setConfig({ defaultLicense: licenseKey });
76
- console.log(`Default license set to: ${color.blueBright(licenseKey)}`);
77
- configUpdated = true;
118
+ try {
119
+ await setConfig({ defaultLicense: licenseKey });
120
+ console.log(`Default license set to: ${color.blueBright(licenseKey)}`);
121
+ configUpdated = true;
122
+ } catch (error) {
123
+ const errorMessage = getErrorMessage(error);
124
+ console.error(
125
+ `Error trying to set ${licenseKey} as the default license: ${errorMessage}`,
126
+ );
127
+ process.exit(1);
128
+ }
78
129
  }
79
130
 
80
131
  // Sets a default author
81
132
  if (opts.setAuthor) {
82
133
  const author = opts.setAuthor;
83
- await setConfig({ defaultAuthor: author });
84
- console.log(`Default author set to: ${color.blueBright(author)}`);
85
- configUpdated = true;
134
+
135
+ try {
136
+ await setConfig({ defaultAuthor: author });
137
+ console.log(`Default author set to: ${color.blueBright(author)}`);
138
+ configUpdated = true;
139
+ } catch (error) {
140
+ const errorMessage = getErrorMessage(error);
141
+ console.error(
142
+ `Error trying to set ${author} as the default author: ${errorMessage}`,
143
+ );
144
+ process.exit(1);
145
+ }
146
+ }
147
+
148
+ // Shows current config
149
+ if (opts.showConfig) {
150
+ if (!(await fileExists(CONFIG_FILE))) {
151
+ console.log(
152
+ `${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>")}.`,
153
+ );
154
+ process.exit(0);
155
+ }
156
+
157
+ try {
158
+ const config = await getConfig();
159
+ const configString = JSON.stringify(config, null, 2);
160
+ const isConfigEmpty = Object.keys(config).length === 0;
161
+ console.log(`${color.yellow("Your current config:\n")}${configString}`);
162
+
163
+ if (isConfigEmpty) {
164
+ console.log(
165
+ `\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>")}.`,
166
+ );
167
+ }
168
+
169
+ process.exit(0);
170
+ } catch (error) {
171
+ const errorMessage = getErrorMessage(error);
172
+ console.error(`Error reading config: ${errorMessage}`);
173
+ process.exit(1);
174
+ }
175
+ }
176
+
177
+ // Resets config
178
+ if (opts.resetConfig) {
179
+ if (!(await fileExists(CONFIG_FILE))) {
180
+ console.log(
181
+ `${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>")}.`,
182
+ );
183
+ process.exit(0);
184
+ }
185
+
186
+ try {
187
+ await setConfig({});
188
+ console.log(color.greenBright("Config reset successfully!"));
189
+ process.exit(0);
190
+ } catch (error) {
191
+ const errorMessage = getErrorMessage(error);
192
+ console.error(`Error resetting config: ${errorMessage}`);
193
+ process.exit(1);
194
+ }
86
195
  }
87
196
 
88
197
  // Skips interactive mode and generates a license with the saved default license
89
198
  if (opts.quick) {
90
- const config = await getConfig();
91
- let name = config.defaultAuthor || getGitUsername();
92
199
  let year = String(new Date().getFullYear());
93
- let licenseKey = config.defaultLicense || "mit";
94
-
95
- const licenseOptionContent = await getLicenseContent(
96
- `${BASE_URL}/${licenseKey}`,
97
- );
98
200
 
99
201
  try {
202
+ const config = await getConfig();
203
+ // In quick mode, we need git config if no default author is set
204
+ const name = config.defaultAuthor || getGitUsername();
205
+ const licenseKey = config.defaultLicense || "mit";
206
+ const licenseOptionContent = await getLicenseContent(
207
+ `${BASE_URL}/${licenseKey}`,
208
+ );
209
+
100
210
  await createLicense(licenseOptionContent, year, name);
101
211
  process.exit(0);
102
212
  } catch (error) {
103
- console.error(`Error occurred in createLicense: ${error}`);
104
- throw error;
213
+ const errorMessage = getErrorMessage(error);
214
+ console.error(`Error occurred trying to create license: ${errorMessage}`);
215
+ process.exit(1);
105
216
  }
106
217
  }
107
218
 
108
219
  if (configUpdated) {
109
- console.log(`Use -q / --quick to generate with this license.`);
220
+ console.log(
221
+ `\n${color.yellow("Note:")} Use ${color.cyan("-q")} / ${color.cyan("--quick")} to generate with this license.`,
222
+ );
110
223
  return;
111
224
  }
112
225
 
@@ -136,7 +249,7 @@ const main = async () => {
136
249
  type: "input",
137
250
  name: "name",
138
251
  message: "Enter name:",
139
- default: getGitUsername(),
252
+ default: getGitUsername({ fallback: "placeholder" }),
140
253
  validate(value) {
141
254
  if (value.length === 0) return "Name is required";
142
255
  return true;
@@ -159,22 +272,24 @@ const main = async () => {
159
272
  process.exit(0);
160
273
  }
161
274
 
162
- // Grab the content of the selected license
163
- const licenseOptionContent = await getLicenseContent(
164
- `${BASE_URL}/${String(licenseOption)}`,
165
- );
166
-
167
275
  // Write LICENSE file
168
276
  try {
277
+ // Grab the content of the selected license
278
+ const licenseOptionContent = await getLicenseContent(
279
+ `${BASE_URL}/${String(licenseOption)}`,
280
+ );
169
281
  await createLicense(licenseOptionContent, answers.year, answers.name);
170
282
  } catch (error) {
171
- console.error(`Error occurred in createLicense: ${error}`);
172
- throw error;
283
+ const errorMessage = getErrorMessage(error);
284
+ console.error(`Error occurred trying to create license: ${errorMessage}`);
285
+ process.exit(1);
173
286
  }
174
287
  };
175
288
 
176
289
  try {
177
- main();
290
+ await main();
178
291
  } catch (error) {
179
- console.error(`Error in main: ${error}`);
292
+ const errorMessage = getErrorMessage(error);
293
+ console.error(`Error in main: ${errorMessage}`);
294
+ process.exit(1);
180
295
  }
package/src/license.ts CHANGED
@@ -1,56 +1,35 @@
1
1
  import axios from "axios";
2
2
  import color from "picocolors";
3
3
  import { writeFile } from "node:fs/promises";
4
- import { fileExists } from "./helpers.js";
4
+ import { fileExists, getErrorMessage } from "./helpers.js";
5
5
  import { cancel, confirm, spinner } from "@clack/prompts";
6
6
  import { BASE_URL } from "./constants.js";
7
-
8
- interface LicenseShape {
9
- key: string;
10
- name: string;
11
- spdx_id: string;
12
- url: string;
13
- node_id: string;
14
- }
15
-
16
- interface LicenseContentShape {
17
- key: string;
18
- name: string;
19
- description: string;
20
- permissions: string[];
21
- conditions: string[];
22
- limitations: string[];
23
- body: string;
24
- }
7
+ import { LicenseContentShape, LicenseShape } from "./types.js";
25
8
 
26
9
  export async function getLicenses() {
27
10
  try {
28
11
  const { data }: { data: LicenseShape[] } = await axios.get(BASE_URL);
29
12
  return data;
30
13
  } catch (error) {
31
- console.error(`Error in getLicenses: ${error}`);
32
- throw error;
14
+ const errorMessage = getErrorMessage(error);
15
+ console.error(`Error in getLicenses: ${errorMessage}`);
16
+ process.exit(1);
33
17
  }
34
18
  }
35
19
 
36
20
  export async function getLicenseContent(
37
21
  url: string,
38
22
  ): Promise<LicenseContentShape> {
39
- try {
40
- const { data }: { data: LicenseContentShape } = await axios.get(url);
41
- return {
42
- key: data.key,
43
- name: data.name,
44
- description: data.description,
45
- permissions: data.permissions,
46
- conditions: data.conditions,
47
- limitations: data.limitations,
48
- body: data.body,
49
- };
50
- } catch (error) {
51
- console.error(`Error in getLicenseContent: ${error}`);
52
- throw error;
53
- }
23
+ const { data }: { data: LicenseContentShape } = await axios.get(url);
24
+ return {
25
+ key: data.key,
26
+ name: data.name,
27
+ description: data.description,
28
+ permissions: data.permissions,
29
+ conditions: data.conditions,
30
+ limitations: data.limitations,
31
+ body: data.body,
32
+ };
54
33
  }
55
34
 
56
35
  export async function createLicense(
package/src/types.ts ADDED
@@ -0,0 +1,24 @@
1
+ // Licenses
2
+ export interface LicenseShape {
3
+ key: string;
4
+ name: string;
5
+ spdx_id: string;
6
+ url: string;
7
+ node_id: string;
8
+ }
9
+
10
+ export interface LicenseContentShape {
11
+ key: string;
12
+ name: string;
13
+ description: string;
14
+ permissions: string[];
15
+ conditions: string[];
16
+ limitations: string[];
17
+ body: string;
18
+ }
19
+
20
+ // Config
21
+ export interface Config {
22
+ defaultLicense?: string;
23
+ defaultAuthor?: string;
24
+ }