-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicense.ts
More file actions
52 lines (45 loc) · 1.09 KB
/
license.ts
File metadata and controls
52 lines (45 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { getLicense } from "license";
import { resolve } from "node:path";
import { readFile, writeFile } from "./file.js";
import type { AVAILABLE_LICENSES } from "./repo.js";
const LICENSE_FILENAME = "LICENSE";
export async function readLicense({ directory }: { directory: string }) {
return readFile({ path: resolve(directory, LICENSE_FILENAME) });
}
export async function writeLicense({
directory,
contents,
}: {
directory: string;
contents: string;
}) {
const path = resolve(directory, LICENSE_FILENAME);
return writeFile({
path,
contents,
});
}
export async function generateLicense({
directory,
license,
author,
}: {
directory: string;
license: (typeof AVAILABLE_LICENSES)[number];
author: string;
}) {
const path = resolve(directory, LICENSE_FILENAME);
const contents = getLicense(license, {
author,
year: String(new Date().getFullYear()),
});
/**
* @todo Contents is not perfect yet, e.g.:
* - On one line: "MIT License Copyright [...]"
* - Lines should be wrapped at 80 characters
*/
return writeFile({
path,
contents,
});
}