-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathinputs.ts
138 lines (125 loc) · 3.55 KB
/
inputs.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { parseArgs } from "node:util";
import { Octokit } from "octokit";
import { titleCase } from "title-case";
import { PrefillPrompter } from "./PrefillPrompter.js";
import { ensureRepositoryExists } from "./ensureRepositoryExists.js";
import { getDefaultSettings } from "./getDefaultSettings.js";
import { getOctokit } from "./getOctokit.js";
import { optionalDefault } from "./optionalDefault.js";
export type GetterDefaultInputValues = {
[K in keyof DefaultInputValues]:
| (() => Promise<DefaultInputValues[K]>)
| DefaultInputValues[K];
};
export interface DefaultInputValues {
author: string | undefined;
description: string;
email: string | undefined;
funding: string | undefined;
owner: string | undefined;
releases: boolean | undefined;
repository: string;
skipApi: boolean;
skipRemoval: boolean;
skipRestore: boolean;
skipUninstalls: boolean;
title: string;
unitTests: boolean | undefined;
}
export interface InputValues extends DefaultInputValues {
owner: string;
}
export interface InputValuesAndOctokit {
octokit: Octokit | undefined;
values: InputValues;
}
export async function getInputValuesAndOctokit(
args: string[],
defaults: Partial<GetterDefaultInputValues> = {}
): Promise<InputValuesAndOctokit> {
const { defaultOwner, defaultRepository } = await getDefaultSettings();
const { values } = parseArgs({
args,
options: {
author: { type: "string" },
description: { type: "string" },
email: { type: "string" },
funding: { type: "string" },
owner: { type: "string" },
releases: { type: "boolean" },
repository: { type: "string" },
"skip-api": { type: "boolean" },
"skip-removal": { type: "boolean" },
"skip-restore": { type: "boolean" },
"skip-uninstall": { type: "boolean" },
title: { type: "string" },
unitTests: { type: "boolean" },
},
strict: false,
tokens: true,
});
const prompter = new PrefillPrompter();
const owner = await prompter.getPrefillOrPromptedValue(
"owner",
values.owner as string | undefined,
"What owner or user will the repository be under?",
defaultOwner
);
const octokit = await getOctokit(!!values["skip-api"]);
prompter.reset();
const repository = await ensureRepositoryExists(
octokit,
owner,
await prompter.getPrefillOrPromptedValue(
"repository",
values.repository as string | undefined,
"What will the kebab-case name of the repository be?",
defaultRepository
)
);
const title = await prompter.getPrefillOrPromptedValue(
"title",
values.title as string | undefined,
"What will the Title Case title of the repository be?",
titleCase(repository).replaceAll("-", " ")
);
const description = await prompter.getPrefillOrPromptedValue(
"description",
values.description as string | undefined,
"How would you describe the new package?",
"A very lovely package. Hooray!"
);
return {
octokit,
values: {
author: await optionalDefault(
values.author as string | undefined,
defaults.author
),
description,
email: await optionalDefault(
values.email as string | undefined,
defaults.email
),
funding: await optionalDefault(
values.funding as string | undefined,
defaults.funding
),
owner,
releases: await optionalDefault(
values.releases as boolean | undefined,
defaults.releases
),
repository,
skipApi: !!values["skip-api"],
skipRemoval: !!values["skip-removal"],
skipRestore: !!values["skip-restore"],
skipUninstalls: !!values["skip-uninstalls"],
title,
unitTests: await optionalDefault(
values.unitTests as boolean | undefined,
defaults.unitTests
),
},
};
}