-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathcreateWithOptions.ts
68 lines (60 loc) · 2.12 KB
/
createWithOptions.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
import * as prompts from "@clack/prompts";
import { $ } from "execa";
import { withSpinner, withSpinners } from "../shared/cli/spinners.js";
import { doesRepositoryExist } from "../shared/doesRepositoryExist.js";
import { GitHubAndOptions } from "../shared/options/readOptions.js";
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
import { runCommands } from "../steps/runCommands.js";
import { writeReadme } from "../steps/writeReadme/index.js";
import { writeStructure } from "../steps/writing/writeStructure.js";
export async function createWithOptions({ github, options }: GitHubAndOptions) {
await withSpinners("Creating repository structure", [
[
"Writing structure",
async () => {
await writeStructure(options);
},
],
[
"Writing README.md",
async () => {
await writeReadme(options);
},
],
]);
if (!options.excludeAllContributors && !options.skipAllContributorsApi) {
await withSpinner("Adding contributors to table", async () => {
await addToolAllContributors(options.owner);
});
}
if (!options.skipInstall) {
await withSpinner("Installing packages", async () =>
finalizeDependencies(options),
);
}
await runCommands("Cleaning up files", [
"pnpm dedupe",
"pnpm lint --fix",
"pnpm format --write",
]);
const sendToGitHub =
github &&
(await doesRepositoryExist(github.octokit, options)) &&
(options.createRepository ??
(await prompts.confirm({
message:
"Would you like to push the template's tooling up to the repository on GitHub?",
})) === true);
if (sendToGitHub) {
await withSpinner("Initializing GitHub repository", async () => {
await $`git remote add origin https://github.com/${options.owner}/${options.repository}`;
await $`git add -A`;
await $`git commit --message ${"feat: initialized repo ✨"}`;
await $`git push -u origin main --force`;
await initializeGitHubRepository(github.octokit, options);
});
}
return { sentToGitHub: sendToGitHub };
}