-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathindex.ts
69 lines (64 loc) · 1.99 KB
/
index.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
import * as prompts from "@clack/prompts";
import chalk from "chalk";
import { ModeResult } from "../bin/mode.js";
import { outro } from "../shared/cli/outro.js";
import { StatusCodes } from "../shared/codes.js";
import { generateNextSteps } from "../shared/generateNextSteps.js";
import { readOptions } from "../shared/options/readOptions.js";
import { runOrRestore } from "../shared/runOrRestore.js";
import { createAndEnterRepository } from "./createAndEnterRepository.js";
import { createRerunSuggestion } from "./createRerunSuggestion.js";
import { createWithOptions } from "./createWithOptions.js";
export async function create(args: string[]): Promise<ModeResult> {
const inputs = await readOptions(args, "create");
if (inputs.cancelled) {
return {
code: StatusCodes.Cancelled,
error: inputs.error,
options: inputs.options,
};
}
const wat = await createAndEnterRepository(inputs.options.repository);
if (!wat) {
prompts.outro(
chalk.red(
`The ${inputs.options.repository} directory already exists. Please remove the directory or try a different name.`,
),
);
return { code: StatusCodes.Failure, options: inputs.options };
}
return {
code: await runOrRestore({
run: async () => {
const { sentToGitHub } = await createWithOptions(inputs);
const nextSteps = generateNextSteps(inputs.options);
outro(
sentToGitHub
? nextSteps
: [
{
label:
"Consider creating a GitHub repository from the new directory:",
lines: [
`cd ${inputs.options.repository}`,
createRerunSuggestion({
...inputs.options,
mode: "initialize",
skipGitHubApi: false,
skipInstall: false,
}),
`git add -A`,
`git commit -m "feat: initial commit ✨"`,
`git push -u origin main`,
],
variant: "code",
},
...nextSteps,
],
);
},
skipRestore: inputs.options.skipRestore,
}),
options: inputs.options,
};
}