-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathcreateWithOptions.ts
61 lines (52 loc) · 2.09 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
import { $ } from "execa";
import { withSpinner, withSpinners } from "../shared/cli/spinners.js";
import { createCleanupCommands } from "../shared/createCleanupCommands.js";
import { doesRepositoryExist } from "../shared/doesRepositoryExist.js";
import { GitHubAndOptions } from "../shared/options/readOptions.js";
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
import { clearLocalGitTags } from "../steps/clearLocalGitTags.js";
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
import { runCleanup } from "../steps/runCleanup.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(github?.octokit, options);
});
}
if (!options.skipInstall) {
await withSpinner("Installing packages", async () =>
finalizeDependencies(options),
);
await runCleanup(createCleanupCommands(options.bin), options.mode);
}
await withSpinner("Clearing any local Git tags", clearLocalGitTags);
const sendToGitHub =
github && (await doesRepositoryExist(github.octokit, options));
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 ✨"} --no-gpg-sign`;
await $`git push -u origin main --force`;
await initializeGitHubRepository(github.octokit, options);
});
}
return { sentToGitHub: sendToGitHub };
}