-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcreate-next-stack.ts
More file actions
150 lines (128 loc) · 4.2 KB
/
create-next-stack.ts
File metadata and controls
150 lines (128 loc) · 4.2 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
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
139
140
141
142
143
144
145
146
147
148
149
150
import { Args, Command, Flags } from "@oclif/core"
import { commandInstance } from "../command-instance.ts"
import {
validateArgs,
validateFlags,
writablePackageManagerOptions,
writableRouterOptions,
writableStylingOptions,
} from "../create-next-stack-types.ts"
import { exitWithError } from "../helpers/exit-with-error.ts"
import { performSetupSteps } from "../setup/setup.ts"
export default class CreateNextStack extends Command {
static usage = "[APP_NAME] [FLAGS]" // Without "create-next-stack" as OCLIF adds this, even though this is a single command CLI.
static args = {
app_name: Args.string({
description: `The name of your app, optionally including a path prefix. Eg.: "my-app" or "path/to/my-app"`,
required: true,
}),
}
static flags = {
// General flags
help: Flags.help({
char: "h",
description: "Shows the CLI help information.",
}),
version: Flags.version({
char: "v",
description: "Shows the CLI version information.",
}),
debug: Flags.boolean({
description: "Show verbose error messages for debugging purposes.",
}),
// Router:
router: Flags.string({
options: writableRouterOptions,
default: "app",
description:
"Sets the React framework router to use. App Router is the default and recommended option.",
}),
// Package manager:
"package-manager": Flags.string({
required: true,
options: writablePackageManagerOptions,
description: "Sets the preferred package manager. (Required)",
}),
// Formatting:
prettier: Flags.boolean({
description: "Adds Prettier. (Code formatting)",
}),
// Styling:
styling: Flags.string({
required: true,
options: writableStylingOptions,
description: `Sets the preferred styling method. (Required) <styling-method> = ${writableStylingOptions.join(
"|",
)}`,
helpValue: "<styling-method>",
}),
// Component libraries:
chakra: Flags.boolean({
description: "Adds Chakra UI. (Component library) (Requires Emotion)",
}),
"material-ui": Flags.boolean({
description: "Adds Material UI. (Component library) (Requires Emotion)",
}),
mantine: Flags.boolean({
description: "Adds Mantine. (Component library)",
}),
// Form libraries:
"react-hook-form": Flags.boolean({
description: "Adds React Hook Form. (Form library)",
}),
formik: Flags.boolean({
description: "Adds Formik. (Form library)",
}),
// Animation
"framer-motion": Flags.boolean({
description: "Adds Framer Motion. (Animation library)",
}),
// Continuous integration
"github-actions": Flags.boolean({
description: "Adds a GitHub Actions continuous integration workflow.",
}),
// Formatting pre-commit hook
"formatting-pre-commit-hook": Flags.boolean({
description: "Adds a formatting pre-commit hook. (Requires Prettier)",
}),
// Icons
"react-icons": Flags.boolean({
description: "Adds React Icons. (Icon library)",
}),
// Server state management libraries
"react-query": Flags.boolean({
description: "Adds React Query. (Server state management library)",
}),
// Analytics
plausible: Flags.boolean({
description: "Adds Plausible. (Analytics)",
}),
// Hosting
netlify: Flags.boolean({
description: "Adds Netlify. (Hosting)",
}),
vercel: Flags.boolean({
description: "Adds Vercel. (Hosting)",
}),
// ORMs
prisma: Flags.boolean({
description: "Adds Prisma. (ORM)",
}),
}
async run(): Promise<void> {
commandInstance.set(this)
try {
const { args, flags } = await this.parse(CreateNextStack)
if (flags.debug) process.env["DEBUG"] = "true"
if (!validateArgs(args)) {
process.exit(1) // This tells TypeScript that this block is unreachable. validateArgs(args) either throws or returns true.
}
if (!validateFlags(flags)) {
process.exit(1) // This tells TypeScript that this block is unreachable. validateFlags(flags) either throws or returns true.
}
await performSetupSteps({ args, flags })
} catch (error) {
exitWithError(error)
}
}
}