-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
298 lines (272 loc) · 9.3 KB
/
Copy pathindex.js
File metadata and controls
298 lines (272 loc) · 9.3 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env node
import path from "path";
import inquirer from "inquirer";
import chalk from "chalk";
import K from "./constants.js";
import createNextApp from "./scripts/create-next-app.js";
import ora from "ora";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
import installChakraUI from "./scripts/install-chakraui.js";
import installPWA from "./scripts/install-pwa.js";
import installLicense from "./scripts/install-license.js";
import installJest from "./scripts/install-jest.js";
import installCypress from "./scripts/install-cypress.js";
import installPlaywright from "./scripts/install-playwright.js";
import installReactMarkdown from "./scripts/install-reactmarkdown.js";
import installStylelint from "./scripts/install-stylelint.js";
import installPrettier from "./scripts/install-prettier.js";
import installHusky from "./scripts/install-husky.js";
import installReactIcons from "./scripts/install-react-icons.js";
import installNextAuth from "./scripts/install-next-auth.js";
import installMomentJS from "./scripts/install-momentjs.js";
import installLodash from "./scripts/install-lodash.js";
import installWithoutChakraUI from "./scripts/install-without-chakraui.js";
import installHuskyWithPrecommitHook from "./scripts/install-husky-with-precommit-hook.js";
import installMUI from "./scripts/install-mui.js";
import installRadixUI from "./scripts/install-radix.js";
const prompt = inquirer.createPromptModule();
const currentDir = process.cwd();
const logi = console.log;
const spinner = ora();
logi(
"=== Welcome to " +
chalk.bold.green("NextJS 13 Easy Template (TypeScript)") +
"! ==="
);
logi(
chalk.yellow(
`Note: This template will create a NextJS 13 project for you, using ${chalk.bold(
"'App Router'"
)} (to know more about 'app router', visit: ${chalk.blue(
"https://nextjs.org/docs"
)}), in TypeScript`
)
);
logi(
"👋 \tTo allow us to easily set up your project in no time,\n\tplease answer the following questions ↓ ↓ ↓\n"
);
let stdin = process.stdin;
stdin.on("data", (key) => {
if (key == "\u0003") {
logi(
chalk.bold.yellow(
"\nInstallation has been cancelled! Please run the program again if you would like to try to install again!"
)
);
}
});
process.on("SIGINT", () => {
logi(
chalk.bold.yellow(
"\nInstallation has been cancelled! Please run the program again if you would like to try to install again!"
)
);
});
try {
const { projectName } = await prompt([
{
name: "projectName",
message: "Enter your project name: ",
validate: (input) => {
if (input.trim().length <= 0) {
return "Project name cannot be empty!";
} else {
return true;
}
},
},
]);
const { uiLibrary } = await prompt([
{
name: "uiLibrary",
message: "Do you want to integrate with any UI Library?",
type: "list",
choices: [K.chakraui, K.mui, K.radix, K.nan],
},
]);
const { unitTest, e2eTest, linterAndFormatter, additionalFeatures } =
await prompt([
{
name: "unitTest",
message: "Choose unit-test framework to install: ",
type: "list",
choices: [K.jest, K.nan],
},
{
name: "e2eTest",
message: "Choose end-to-end (E2E) framework to install: ",
type: "list",
choices: [K.playwright, K.cypress, K.nan],
},
{
name: "linterAndFormatter",
message:
"Any additional linter(s) or formatter(s) you would like to install: ",
type: "checkbox",
choices: [K.stylelint, K.prettier],
},
{
name: "additionalFeatures",
message:
"Any additional convenient libraries you would like to install?",
type: "checkbox",
choices: [
K.reactIcons,
K.nextAuth,
K.lodash,
K.momentjs,
K.reactMarkdown,
],
},
]);
let husky;
if (unitTest.includes(K.jest)) {
const answer = await prompt([
{
name: "husky",
message:
"Since you have installed Jest testing framework, would you like to install Husky and set up a pre-commit hook?",
type: "list",
choices: [K.huskyInstallOnly, K.huskyPreCommit, K.nan],
},
]);
husky = answer.husky;
} else {
const answer = await prompt([
{
name: "husky",
message: "Would you like to install Husky?",
type: "list",
choices: [K.huskyInstallOnly, K.nan],
},
]);
husky = answer.husky;
}
const projectDir = path.resolve(currentDir, projectName);
const templateDir = path.resolve(__dirname, "template");
createNextApp(projectName, templateDir);
if (uiLibrary.includes(K.chakraui)) {
spinner.start(
"Setting up project layout for PWA & SEO + Installing Chakra UI..."
);
await installChakraUI(projectDir, templateDir);
spinner.succeed(
"Chakra UI successfully installed! PWA & SEO successfully configured!"
);
} else if (uiLibrary.includes(K.mui)) {
spinner.start(
"Setting up project layout for PWA & SEO + Installing Material UI..."
);
await installMUI(projectDir, templateDir);
spinner.succeed(
"Material UI successfully installed! PWA & SEO successfully configured!"
);
} else if (uiLibrary.includes(K.radix)) {
spinner.start(
"Setting up project layout for PWA & SEO + Installing Radix UI..."
);
await installRadixUI(projectDir, templateDir);
spinner.succeed(
"Radix UI successfully installed! PWA & SEO successfully configured!"
);
} else {
spinner.start("Setting up project layout for PWA & SEO...");
await installWithoutChakraUI(projectDir, templateDir);
spinner.succeed("PWA & SEO configured successfully!");
}
spinner.start(
"Installing next-pwa, copying manifest.json and icons for PWA ..."
);
await installPWA(projectDir, templateDir);
spinner.succeed("PWA successfully set up!");
spinner.start("Retrieving MIT License...");
await installLicense(projectDir, templateDir);
spinner.succeed("MIT License successfully copied!");
if (unitTest.includes(K.jest)) {
spinner.start("Installing Jest...");
await installJest(projectDir, templateDir);
spinner.succeed("Jest successfully installed!");
}
if (e2eTest.includes(K.cypress)) {
spinner.start("Installing Cypress...");
await installCypress(projectDir);
spinner.succeed("Cypress successfully installed!");
}
if (e2eTest.includes(K.playwright)) {
spinner.start("Installing Playwright...");
await installPlaywright(projectDir);
spinner.succeed("Playwright successfully installed");
}
if (linterAndFormatter.includes(K.stylelint)) {
spinner.start("Installing Stylelint...");
await installStylelint(projectDir, templateDir);
spinner.succeed("Stylelint successfully installed");
}
if (linterAndFormatter.includes(K.prettier)) {
spinner.start("Installing Prettier...");
await installPrettier(projectDir, templateDir);
spinner.succeed("Prettier successfully installed!");
}
if (husky.includes(K.huskyInstallOnly)) {
spinner.start("Initialize Git & Installing Husky...");
await installHusky(projectDir);
spinner.succeed("Git initialized! Husky successfully installed!");
} else if (husky.includes(K.huskyPreCommit)) {
spinner.start("Initialize Git & Installing Husky and pre-commit hook...");
await installHuskyWithPrecommitHook(projectDir);
spinner.succeed(
"Git initialized! Husky and pre-commit hook successfully installed!"
);
}
if (additionalFeatures.includes(K.reactIcons)) {
spinner.start("Installing React-Icons...");
await installReactIcons(projectDir);
spinner.succeed("React-Icons successfully installed!");
}
if (additionalFeatures.includes(K.nextAuth)) {
spinner.start("Installing NextAuth.js...");
await installNextAuth(projectDir, templateDir);
spinner.succeed("NextAuth.js successfully installed!");
}
if (additionalFeatures.includes(K.momentjs)) {
spinner.start("Installing Moment.js...");
await installMomentJS(projectDir);
spinner.succeed("Moment.js successfully installed!");
}
if (additionalFeatures.includes(K.lodash)) {
spinner.start("Installing Lodash...");
await installLodash(projectDir);
spinner.succeed("Lodash successfully installed!");
}
if (additionalFeatures.includes(K.reactMarkdown)) {
spinner.start("Installing React Markdown...");
await installReactMarkdown(projectDir, templateDir);
spinner.succeed("React Markdown successfully installed!");
}
logi(chalk.green("Installation completed"));
logi(
chalk.gray("Try ") +
chalk.bold.yellow(`cd ${projectName}`) +
chalk.gray(" and ") +
chalk.bold.yellow("npm run dev") +
chalk.gray(" to run the example Next13 TypeScript web application.")
);
logi(
chalk.gray("And see ") +
chalk.bold.yellow("PWA (Try in chrome and you can 'install' the app)") +
chalk.gray(" in actions!")
);
} catch (error) {
if (error.isTtyError) {
logi(
chalk.bold.red("Prompt couldn't be rendered in the current environment")
);
} else {
logi(chalk.bold.red(`\n${error}`));
logi(chalk.bold.red(`Something is wrong! Please try again!`));
}
process.exit(1);
}