WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c3c4b2c

Browse files
Fix init UX issues
1 parent 67d5fef commit c3c4b2c

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "discraft",
3-
"version": "1.6.2-beta.8",
3+
"version": "1.6.2-beta.9",
44
"description": "Ultimate Discord bot framework",
55
"type": "module",
66
"packageManager": "[email protected]",

package/src/cli.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22

3+
import { CancelPromptError } from "@inquirer/core";
34
import { program } from "commander";
45
import consola from "consola";
56
import { version } from "../../package.json";
@@ -42,11 +43,18 @@ program
4243
program
4344
.command("init")
4445
.description("Initialize a new Discraft project")
45-
.action(() => {
46-
init().catch((error) => {
47-
consola.error("An error occurred during initialization:", error);
48-
process.exit(1);
49-
});
46+
.action(async () => {
47+
try {
48+
await init();
49+
} catch (error) {
50+
if (error instanceof CancelPromptError) {
51+
consola.info("Initialization cancelled by user.");
52+
process.exit(0);
53+
} else {
54+
consola.error("An error occurred during initialization:", error);
55+
process.exit(1);
56+
}
57+
}
5058
});
5159

5260
program.parse(process.argv);

package/src/cli/init/index.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async function init() {
6868
]);
6969

7070
let projectDir = currentWorkingDirectory;
71+
let projectName = path.basename(currentWorkingDirectory);
7172

7273
if (!useCurrentDir.useCurrent) {
7374
const projectDirResponse = await inquirer.prompt([
@@ -78,6 +79,7 @@ async function init() {
7879
default: "my-project",
7980
},
8081
]);
82+
projectName = projectDirResponse.projectName;
8183
projectDir = path.join(
8284
currentWorkingDirectory,
8385
projectDirResponse.projectName,
@@ -120,9 +122,43 @@ async function init() {
120122
}
121123

122124
consola.success("Project initialized successfully!");
123-
consola.info(
124-
`Go to ${path.relative(currentWorkingDirectory, projectDir)} and run "${packageManagerResponse.packageManager} run build" and "${packageManagerResponse.packageManager} run start" to get started.`,
125-
);
125+
126+
const pmNpmDefault =
127+
packageManagerResponse.packageManager === "none"
128+
? "npm"
129+
: packageManagerResponse.packageManager;
130+
// Enhanced instructions
131+
if (projectDir === currentWorkingDirectory) {
132+
consola.info(`
133+
Next Steps:
134+
1. Copy the .env.example file to .env:
135+
136+
cp .env.example .env
137+
138+
2. Open the .env file and fill in your bot's token and any other necessary environment variables.
139+
3. Run "${pmNpmDefault} run build" to compile your TypeScript code.
140+
4. Run "${pmNpmDefault} run start" to start your bot.
141+
142+
You are all set! Happy bot building!
143+
`);
144+
} else {
145+
consola.info(`
146+
Next Steps:
147+
1. Go to your project directory:
148+
149+
cd ${path.relative(currentWorkingDirectory, projectDir)}
150+
151+
2. Copy the .env.example file to .env:
152+
153+
cp .env.example .env
154+
155+
3. Open the .env file and fill in your bot's token and any other necessary environment variables.
156+
4. Run "${pmNpmDefault} run build" to compile your TypeScript code.
157+
5. Run "${pmNpmDefault} run start" to start your bot.
158+
159+
You are all set! Happy bot building!
160+
`);
161+
}
126162
} catch (error: any) {
127163
consola.error(`Failed to initialize project: ${error.message}`);
128164
}

0 commit comments

Comments
 (0)