Skip to content
This repository was archived by the owner on Dec 17, 2023. It is now read-only.

Commit ec58475

Browse files
committed
ask for directory, fix more things
1 parent 7c8a820 commit ec58475

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
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": "create-djs-app",
3-
"version": "1.1.2-dev.4",
3+
"version": "1.1.2-dev.5",
44
"description": "Create a Discord.js project easily.",
55
"main": "index.js",
66
"bin": {

src/functions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
promptGit,
99
promptGuildId,
1010
promptInstall,
11+
promptLocation,
1112
promptName,
1213
promptTemplate,
1314
promptToken,
@@ -43,6 +44,7 @@ export function argsToOptions(rawArgs) {
4344

4445
export async function prompt(options) {
4546
const name = await promptName();
47+
const location = await promptLocation();
4648
const token = await promptToken();
4749
const guildId = await promptGuildId();
4850

@@ -68,6 +70,7 @@ export async function prompt(options) {
6870
name: name,
6971
token: token,
7072
guildId: guildId,
73+
targetDirectory: location,
7174
template: options.template || template,
7275
git: options.git || git,
7376
runInstall: options.runInstall || runInstall,

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function copyTemplateFiles(options) {
4444
export async function createProject(options) {
4545
options = {
4646
...options,
47-
targetDirectory: options.targetDirectory || process.cwd(),
47+
targetDirectory: options.targetDirectory || ".",
4848
};
4949

5050
const templateDir = path.resolve(
@@ -74,6 +74,7 @@ export async function createProject(options) {
7474
{
7575
title: `Install dependencies using ${getPkgManager()}`,
7676
task: () => installPkgs(options),
77+
enabled: () => options.runInstall,
7778
},
7879
]);
7980

src/utils/questions.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import inquirer from "inquirer";
22
import { getPkgManager, validateNpmName } from "../functions";
33
import path from "path";
4+
import { existsSync } from "fs";
45

56
export async function promptName() {
67
const { name } = await inquirer.prompt({
@@ -20,6 +21,24 @@ export async function promptName() {
2021
return name;
2122
}
2223

24+
export async function promptLocation() {
25+
const { dir } = await inquirer.prompt({
26+
type: "input",
27+
name: "dir",
28+
message: "Where would you like to create your project?",
29+
default: ".",
30+
validate: (dir) => {
31+
if (dir === ".") return true;
32+
33+
const validation = existsSync(dir);
34+
if (!validation) return true;
35+
return "That directory already exists.";
36+
},
37+
});
38+
39+
return dir;
40+
}
41+
2342
export async function promptToken() {
2443
const { confirmToken } = await inquirer.prompt({
2544
type: "confirm",

0 commit comments

Comments
 (0)