Skip to content

Commit d92c7fc

Browse files
committed
fix(cli): init new project new dir
1 parent 0c6d1bb commit d92c7fc

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

apps/cli/src/commands/init.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ export const init = new Command()
7171
});
7272

7373
async function validateProjectDirectory(cwd: string) {
74-
if (!existsSync(cwd)) {
75-
logger.error(`The path ${cwd} does not exist. Please try again.`);
76-
process.exit(1);
77-
}
78-
79-
if (!existsSync(path.join(cwd, 'package.json'))) {
74+
if (!existsSync(cwd) || !existsSync(path.join(cwd, 'package.json'))) {
8075
const { proceed } = await prompts({
8176
type: 'confirm',
8277
name: 'proceed',
@@ -99,13 +94,16 @@ async function validateProjectDirectory(cwd: string) {
9994
const spinner = ora(`Initializing ${projectName}...`).start();
10095

10196
const projectPath = path.join(cwd, projectName);
97+
if (!existsSync(projectPath)) {
98+
await fs.mkdir(projectPath, { recursive: true });
99+
}
102100

103101
await copyFolder(path.join(fileDir, '../__generated/starter-base'), projectPath);
104102

105103
await Promise.all([
106-
replaceAllInJsonFile(path.join(cwd, projectName, 'app.json'), 'starter-base', projectName),
104+
replaceAllInJsonFile(path.join(projectPath, 'app.json'), 'starter-base', projectName),
107105
replaceAllInJsonFile(
108-
path.join(cwd, projectName, 'package.json'),
106+
path.join(projectPath, 'package.json'),
109107
'@rnr/starter-base',
110108
projectName
111109
),
@@ -134,7 +132,7 @@ async function validateProjectDirectory(cwd: string) {
134132
});
135133

136134
spinner.succeed('New project initialized successfully!');
137-
process.exit(1);
135+
process.exit(0);
138136
}
139137
}
140138

0 commit comments

Comments
 (0)