@anth0nycodes/license-generator 0.4.0 → 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/dist/helpers.d.ts +6 -7
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +17 -19
- package/dist/helpers.js.map +1 -1
- package/dist/index.js +55 -30
- package/dist/index.js.map +1 -1
- package/dist/license.d.ts +1 -17
- package/dist/license.d.ts.map +1 -1
- package/dist/license.js +14 -19
- package/dist/license.js.map +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +2 -1
- package/src/helpers.ts +23 -28
- package/src/index.ts +75 -41
- package/src/license.ts +15 -36
- package/src/types.ts +24 -0
package/dist/helpers.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { LicenseShape } from "./
|
|
2
|
-
export declare function getGitUsername(
|
|
3
|
-
|
|
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;
|
|
4
7
|
export declare function fileExists(path: string): Promise<boolean>;
|
|
5
8
|
export declare const CONFIG_FILE: string;
|
|
6
|
-
export interface Config {
|
|
7
|
-
defaultLicense?: string;
|
|
8
|
-
defaultAuthor?: string;
|
|
9
|
-
}
|
|
10
9
|
export declare function getConfig(): Promise<Config>;
|
|
11
10
|
export declare function setConfig(config: Config): Promise<void>;
|
|
12
11
|
//# sourceMappingURL=helpers.d.ts.map
|
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":"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,29 +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
6
|
import color from "picocolors";
|
|
8
|
-
export function getGitUsername() {
|
|
7
|
+
export function getGitUsername(options = {}) {
|
|
9
8
|
try {
|
|
10
9
|
const uncleanName = String(execSync("git config user.name"));
|
|
11
10
|
return uncleanName.replace(/\r?\n/g, "");
|
|
12
11
|
}
|
|
13
12
|
catch (error) {
|
|
14
|
-
|
|
13
|
+
if (options.fallback !== undefined) {
|
|
14
|
+
return options.fallback;
|
|
15
|
+
}
|
|
16
|
+
const errorMessage = getErrorMessage(error);
|
|
15
17
|
if (errorMessage.includes("git config user.name")) {
|
|
16
18
|
console.error(`Error: Git username not configured. Set it with: ${color.cyan('git config --global user.name "Your Name"')}`);
|
|
19
|
+
process.exit(1);
|
|
17
20
|
}
|
|
18
21
|
else {
|
|
19
22
|
console.error(`Error occurred in getGitUsername: ${errorMessage}`);
|
|
23
|
+
process.exit(1);
|
|
20
24
|
}
|
|
21
|
-
throw error;
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
|
-
export function
|
|
27
|
+
export function isValidLicense(licenses, licenseKey) {
|
|
25
28
|
return licenses.some((l) => l.key === licenseKey);
|
|
26
29
|
}
|
|
30
|
+
export function getErrorMessage(error) {
|
|
31
|
+
return error instanceof Error ? error.message : String(error);
|
|
32
|
+
}
|
|
27
33
|
export async function fileExists(path) {
|
|
28
34
|
try {
|
|
29
35
|
await access(path, constants.F_OK);
|
|
@@ -46,18 +52,10 @@ export async function getConfig() {
|
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
export async function setConfig(config) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
? { ...existingConfig, ...config }
|
|
55
|
-
: config;
|
|
56
|
-
await writeFile(CONFIG_FILE, JSON.stringify(updatedConfig, null, 2), "utf8");
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.error(`Error occurred in setConfig: ${error}`);
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
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");
|
|
62
60
|
}
|
|
63
61
|
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],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C;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,8 +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 { CONFIG_FILE, fileExists, getGitUsername,
|
|
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";
|
|
@@ -40,34 +39,55 @@ const main = async () => {
|
|
|
40
39
|
// Show license description
|
|
41
40
|
if (opts.info) {
|
|
42
41
|
const licenseKey = opts.info.toLowerCase();
|
|
43
|
-
if (!
|
|
42
|
+
if (!isValidLicense(licenses, licenseKey)) {
|
|
44
43
|
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
45
44
|
console.error("Available licenses:", licenses.map((l) => l.key).join(", "));
|
|
46
45
|
process.exit(1);
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
}
|
|
51
57
|
}
|
|
52
58
|
let configUpdated = false;
|
|
53
59
|
// Sets a default license
|
|
54
60
|
if (opts.setLicense) {
|
|
55
61
|
const licenseKey = opts.setLicense.toLowerCase();
|
|
56
|
-
if (!
|
|
62
|
+
if (!isValidLicense(licenses, licenseKey)) {
|
|
57
63
|
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
58
64
|
console.error("Available licenses:", licenses.map((l) => l.key).join(", "));
|
|
59
65
|
process.exit(1);
|
|
60
66
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
}
|
|
64
77
|
}
|
|
65
78
|
// Sets a default author
|
|
66
79
|
if (opts.setAuthor) {
|
|
67
80
|
const author = opts.setAuthor;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
}
|
|
71
91
|
}
|
|
72
92
|
// Shows current config
|
|
73
93
|
if (opts.showConfig) {
|
|
@@ -83,13 +103,13 @@ const main = async () => {
|
|
|
83
103
|
if (isConfigEmpty) {
|
|
84
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>")}.`);
|
|
85
105
|
}
|
|
106
|
+
process.exit(0);
|
|
86
107
|
}
|
|
87
108
|
catch (error) {
|
|
88
|
-
const errorMessage =
|
|
109
|
+
const errorMessage = getErrorMessage(error);
|
|
89
110
|
console.error(`Error reading config: ${errorMessage}`);
|
|
90
111
|
process.exit(1);
|
|
91
112
|
}
|
|
92
|
-
process.exit(0);
|
|
93
113
|
}
|
|
94
114
|
// Resets config
|
|
95
115
|
if (opts.resetConfig) {
|
|
@@ -100,28 +120,30 @@ const main = async () => {
|
|
|
100
120
|
try {
|
|
101
121
|
await setConfig({});
|
|
102
122
|
console.log(color.greenBright("Config reset successfully!"));
|
|
123
|
+
process.exit(0);
|
|
103
124
|
}
|
|
104
125
|
catch (error) {
|
|
105
|
-
const errorMessage =
|
|
126
|
+
const errorMessage = getErrorMessage(error);
|
|
106
127
|
console.error(`Error resetting config: ${errorMessage}`);
|
|
107
128
|
process.exit(1);
|
|
108
129
|
}
|
|
109
|
-
process.exit(0);
|
|
110
130
|
}
|
|
111
131
|
// Skips interactive mode and generates a license with the saved default license
|
|
112
132
|
if (opts.quick) {
|
|
113
|
-
const config = await getConfig();
|
|
114
|
-
let name = config.defaultAuthor || getGitUsername();
|
|
115
133
|
let year = String(new Date().getFullYear());
|
|
116
|
-
let licenseKey = config.defaultLicense || "mit";
|
|
117
|
-
const licenseOptionContent = await getLicenseContent(`${BASE_URL}/${licenseKey}`);
|
|
118
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}`);
|
|
119
140
|
await createLicense(licenseOptionContent, year, name);
|
|
120
141
|
process.exit(0);
|
|
121
142
|
}
|
|
122
143
|
catch (error) {
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
const errorMessage = getErrorMessage(error);
|
|
145
|
+
console.error(`Error occurred trying to create license: ${errorMessage}`);
|
|
146
|
+
process.exit(1);
|
|
125
147
|
}
|
|
126
148
|
}
|
|
127
149
|
if (configUpdated) {
|
|
@@ -150,7 +172,7 @@ const main = async () => {
|
|
|
150
172
|
type: "input",
|
|
151
173
|
name: "name",
|
|
152
174
|
message: "Enter name:",
|
|
153
|
-
default: getGitUsername(),
|
|
175
|
+
default: getGitUsername({ fallback: "placeholder" }),
|
|
154
176
|
validate(value) {
|
|
155
177
|
if (value.length === 0)
|
|
156
178
|
return "Name is required";
|
|
@@ -176,21 +198,24 @@ const main = async () => {
|
|
|
176
198
|
cancel("Operation cancelled.");
|
|
177
199
|
process.exit(0);
|
|
178
200
|
}
|
|
179
|
-
// Grab the content of the selected license
|
|
180
|
-
const licenseOptionContent = await getLicenseContent(`${BASE_URL}/${String(licenseOption)}`);
|
|
181
201
|
// Write LICENSE file
|
|
182
202
|
try {
|
|
203
|
+
// Grab the content of the selected license
|
|
204
|
+
const licenseOptionContent = await getLicenseContent(`${BASE_URL}/${String(licenseOption)}`);
|
|
183
205
|
await createLicense(licenseOptionContent, answers.year, answers.name);
|
|
184
206
|
}
|
|
185
207
|
catch (error) {
|
|
186
|
-
|
|
187
|
-
|
|
208
|
+
const errorMessage = getErrorMessage(error);
|
|
209
|
+
console.error(`Error occurred trying to create license: ${errorMessage}`);
|
|
210
|
+
process.exit(1);
|
|
188
211
|
}
|
|
189
212
|
};
|
|
190
213
|
try {
|
|
191
|
-
main();
|
|
214
|
+
await main();
|
|
192
215
|
}
|
|
193
216
|
catch (error) {
|
|
194
|
-
|
|
217
|
+
const errorMessage = getErrorMessage(error);
|
|
218
|
+
console.error(`Error in main: ${errorMessage}`);
|
|
219
|
+
process.exit(1);
|
|
195
220
|
}
|
|
196
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,
|
|
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,EACL,WAAW,EACX,UAAU,EACV,eAAe,EACf,cAAc,EACd,SAAS,EACT,SAAS,EACT,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,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;AAEv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AK,CAAC;wBAAE,OAAO,4BAA4B,CAAC;oBAChE,OAAO,IAAI,CAAC;gBACd,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,qBAAqB;IACrB,IAAI,CAAC;QACH,2CAA2C;QAC3C,MAAM,oBAAoB,GAAG,MAAM,iBAAiB,CAClD,GAAG,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,EAAE,CACvC,CAAC;QACF,MAAM,aAAa,CAAC,oBAAoB,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAC5C,OAAO,CAAC,KAAK,CAAC,4CAA4C,YAAY,EAAE,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC;AAEF,IAAI,CAAC;IACH,MAAM,IAAI,EAAE,CAAC;AACf,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,kBAAkB,YAAY,EAAE,CAAC,CAAC;IAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/license.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
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
|
package/dist/license.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
package/dist/license.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CA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AAC;SAC9B,UAAU,CAAC,2BAA2B,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"}
|
package/dist/types.d.ts
ADDED
|
@@ -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 @@
|
|
|
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.4.
|
|
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,33 +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";
|
|
7
|
-
import type { LicenseShape } from "./
|
|
6
|
+
import type { Config, LicenseShape } from "./types.js";
|
|
8
7
|
import color from "picocolors";
|
|
9
8
|
|
|
10
|
-
export function getGitUsername() {
|
|
9
|
+
export function getGitUsername(options: { fallback?: string } = {}) {
|
|
11
10
|
try {
|
|
12
11
|
const uncleanName = String(execSync("git config user.name"));
|
|
13
12
|
return uncleanName.replace(/\r?\n/g, "");
|
|
14
13
|
} catch (error) {
|
|
15
|
-
|
|
14
|
+
if (options.fallback !== undefined) {
|
|
15
|
+
return options.fallback;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const errorMessage = getErrorMessage(error);
|
|
16
19
|
if (errorMessage.includes("git config user.name")) {
|
|
17
20
|
console.error(
|
|
18
21
|
`Error: Git username not configured. Set it with: ${color.cyan('git config --global user.name "Your Name"')}`,
|
|
19
22
|
);
|
|
23
|
+
process.exit(1);
|
|
20
24
|
} else {
|
|
21
25
|
console.error(`Error occurred in getGitUsername: ${errorMessage}`);
|
|
26
|
+
process.exit(1);
|
|
22
27
|
}
|
|
23
|
-
throw error;
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
export function
|
|
31
|
+
export function isValidLicense(licenses: LicenseShape[], licenseKey: string) {
|
|
28
32
|
return licenses.some((l) => l.key === licenseKey);
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
export function getErrorMessage(error: unknown) {
|
|
36
|
+
return error instanceof Error ? error.message : String(error);
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
export async function fileExists(path: string) {
|
|
32
40
|
try {
|
|
33
41
|
await access(path, constants.F_OK);
|
|
@@ -40,11 +48,6 @@ export async function fileExists(path: string) {
|
|
|
40
48
|
const CONFIG_DIR = join(homedir(), ".license-generator");
|
|
41
49
|
export const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
42
50
|
|
|
43
|
-
export interface Config {
|
|
44
|
-
defaultLicense?: string;
|
|
45
|
-
defaultAuthor?: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
51
|
export async function getConfig(): Promise<Config> {
|
|
49
52
|
try {
|
|
50
53
|
const content = await readFile(CONFIG_FILE, "utf8");
|
|
@@ -56,20 +59,12 @@ export async function getConfig(): Promise<Config> {
|
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
export async function setConfig(config: Config) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
CONFIG_FILE,
|
|
68
|
-
JSON.stringify(updatedConfig, null, 2),
|
|
69
|
-
"utf8",
|
|
70
|
-
);
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.error(`Error occurred in setConfig: ${error}`);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
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");
|
|
75
70
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,13 +5,19 @@ 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 {
|
|
9
|
-
|
|
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";
|
|
13
20
|
import { readFileSync } from "node:fs";
|
|
14
|
-
import { readFile } from "node:fs/promises";
|
|
15
21
|
|
|
16
22
|
const __filename = fileURLToPath(import.meta.url);
|
|
17
23
|
const __dirname = dirname(__filename);
|
|
@@ -70,7 +76,7 @@ const main = async () => {
|
|
|
70
76
|
if (opts.info) {
|
|
71
77
|
const licenseKey = opts.info.toLowerCase();
|
|
72
78
|
|
|
73
|
-
if (!
|
|
79
|
+
if (!isValidLicense(licenses, licenseKey)) {
|
|
74
80
|
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
75
81
|
console.error(
|
|
76
82
|
"Available licenses:",
|
|
@@ -79,11 +85,19 @@ const main = async () => {
|
|
|
79
85
|
process.exit(1);
|
|
80
86
|
}
|
|
81
87
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
}
|
|
87
101
|
}
|
|
88
102
|
|
|
89
103
|
let configUpdated = false;
|
|
@@ -92,7 +106,7 @@ const main = async () => {
|
|
|
92
106
|
if (opts.setLicense) {
|
|
93
107
|
const licenseKey = opts.setLicense.toLowerCase();
|
|
94
108
|
|
|
95
|
-
if (!
|
|
109
|
+
if (!isValidLicense(licenses, licenseKey)) {
|
|
96
110
|
console.error(`Error: "${licenseKey}" is not a valid license.`);
|
|
97
111
|
console.error(
|
|
98
112
|
"Available licenses:",
|
|
@@ -101,17 +115,34 @@ const main = async () => {
|
|
|
101
115
|
process.exit(1);
|
|
102
116
|
}
|
|
103
117
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
}
|
|
107
129
|
}
|
|
108
130
|
|
|
109
131
|
// Sets a default author
|
|
110
132
|
if (opts.setAuthor) {
|
|
111
133
|
const author = opts.setAuthor;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
}
|
|
115
146
|
}
|
|
116
147
|
|
|
117
148
|
// Shows current config
|
|
@@ -134,13 +165,13 @@ const main = async () => {
|
|
|
134
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>")}.`,
|
|
135
166
|
);
|
|
136
167
|
}
|
|
168
|
+
|
|
169
|
+
process.exit(0);
|
|
137
170
|
} catch (error) {
|
|
138
|
-
const errorMessage =
|
|
139
|
-
error instanceof Error ? error.message : String(error);
|
|
171
|
+
const errorMessage = getErrorMessage(error);
|
|
140
172
|
console.error(`Error reading config: ${errorMessage}`);
|
|
141
173
|
process.exit(1);
|
|
142
174
|
}
|
|
143
|
-
process.exit(0);
|
|
144
175
|
}
|
|
145
176
|
|
|
146
177
|
// Resets config
|
|
@@ -155,32 +186,33 @@ const main = async () => {
|
|
|
155
186
|
try {
|
|
156
187
|
await setConfig({});
|
|
157
188
|
console.log(color.greenBright("Config reset successfully!"));
|
|
189
|
+
process.exit(0);
|
|
158
190
|
} catch (error) {
|
|
159
|
-
const errorMessage =
|
|
160
|
-
error instanceof Error ? error.message : String(error);
|
|
191
|
+
const errorMessage = getErrorMessage(error);
|
|
161
192
|
console.error(`Error resetting config: ${errorMessage}`);
|
|
162
193
|
process.exit(1);
|
|
163
194
|
}
|
|
164
|
-
process.exit(0);
|
|
165
195
|
}
|
|
166
196
|
|
|
167
197
|
// Skips interactive mode and generates a license with the saved default license
|
|
168
198
|
if (opts.quick) {
|
|
169
|
-
const config = await getConfig();
|
|
170
|
-
let name = config.defaultAuthor || getGitUsername();
|
|
171
199
|
let year = String(new Date().getFullYear());
|
|
172
|
-
let licenseKey = config.defaultLicense || "mit";
|
|
173
|
-
|
|
174
|
-
const licenseOptionContent = await getLicenseContent(
|
|
175
|
-
`${BASE_URL}/${licenseKey}`,
|
|
176
|
-
);
|
|
177
200
|
|
|
178
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
|
+
|
|
179
210
|
await createLicense(licenseOptionContent, year, name);
|
|
180
211
|
process.exit(0);
|
|
181
212
|
} catch (error) {
|
|
182
|
-
|
|
183
|
-
|
|
213
|
+
const errorMessage = getErrorMessage(error);
|
|
214
|
+
console.error(`Error occurred trying to create license: ${errorMessage}`);
|
|
215
|
+
process.exit(1);
|
|
184
216
|
}
|
|
185
217
|
}
|
|
186
218
|
|
|
@@ -217,7 +249,7 @@ const main = async () => {
|
|
|
217
249
|
type: "input",
|
|
218
250
|
name: "name",
|
|
219
251
|
message: "Enter name:",
|
|
220
|
-
default: getGitUsername(),
|
|
252
|
+
default: getGitUsername({ fallback: "placeholder" }),
|
|
221
253
|
validate(value) {
|
|
222
254
|
if (value.length === 0) return "Name is required";
|
|
223
255
|
return true;
|
|
@@ -240,22 +272,24 @@ const main = async () => {
|
|
|
240
272
|
process.exit(0);
|
|
241
273
|
}
|
|
242
274
|
|
|
243
|
-
// Grab the content of the selected license
|
|
244
|
-
const licenseOptionContent = await getLicenseContent(
|
|
245
|
-
`${BASE_URL}/${String(licenseOption)}`,
|
|
246
|
-
);
|
|
247
|
-
|
|
248
275
|
// Write LICENSE file
|
|
249
276
|
try {
|
|
277
|
+
// Grab the content of the selected license
|
|
278
|
+
const licenseOptionContent = await getLicenseContent(
|
|
279
|
+
`${BASE_URL}/${String(licenseOption)}`,
|
|
280
|
+
);
|
|
250
281
|
await createLicense(licenseOptionContent, answers.year, answers.name);
|
|
251
282
|
} catch (error) {
|
|
252
|
-
|
|
253
|
-
|
|
283
|
+
const errorMessage = getErrorMessage(error);
|
|
284
|
+
console.error(`Error occurred trying to create license: ${errorMessage}`);
|
|
285
|
+
process.exit(1);
|
|
254
286
|
}
|
|
255
287
|
};
|
|
256
288
|
|
|
257
289
|
try {
|
|
258
|
-
main();
|
|
290
|
+
await main();
|
|
259
291
|
} catch (error) {
|
|
260
|
-
|
|
292
|
+
const errorMessage = getErrorMessage(error);
|
|
293
|
+
console.error(`Error in main: ${errorMessage}`);
|
|
294
|
+
process.exit(1);
|
|
261
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
|
-
export 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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
}
|