Skip to content

Commit a7e0d7f

Browse files
authored
fix: --no-dir-check v2! (#791)
1 parent 6ce2b8a commit a7e0d7f

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

packages/cli/commands/create.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ async function createProject(cwd: ProjectPath, options: Options) {
144144
force: async ({ results: { directory } }) => {
145145
if (!options.dirCheck) return;
146146

147+
if (!fs.existsSync(directory!)) return;
148+
147149
const files = fs.readdirSync(directory!);
148150
const hasNonIgnoredFiles = files.some((file) => !file.startsWith('.git'));
149151
if (!hasNonIgnoredFiles) return;

packages/cli/tests/cli.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { beforeAll, describe, expect, it } from 'vitest';
2+
3+
import { exec } from 'tinyexec';
4+
import path from 'node:path';
5+
import fs from 'node:fs';
6+
import { parseJson } from '../../core/tooling/index.ts';
7+
8+
const monoRepoPath = path.resolve(__dirname, '..', '..', '..');
9+
10+
beforeAll(() => {
11+
const testOutputCliPath = path.resolve(monoRepoPath, '.test-output', 'cli');
12+
13+
if (fs.existsSync(testOutputCliPath)) {
14+
fs.rmSync(testOutputCliPath, { force: true, recursive: true });
15+
}
16+
});
17+
18+
describe('cli', () => {
19+
it('should be able to create a new project with cli command', async () => {
20+
const svBinPath = path.resolve(monoRepoPath, 'packages', 'cli', 'dist', 'bin.js');
21+
const testOutputPath = path.resolve(monoRepoPath, '.test-output', 'cli', 'test-project');
22+
23+
const result = await exec(
24+
'node',
25+
[
26+
svBinPath,
27+
'create',
28+
testOutputPath,
29+
'--template',
30+
'minimal',
31+
'--types',
32+
'ts',
33+
'--no-install',
34+
'--no-add-ons'
35+
],
36+
{ nodeOptions: { stdio: 'ignore' } }
37+
);
38+
39+
// cli finished well
40+
expect(result.exitCode).toBe(0);
41+
42+
// test output path exists
43+
expect(fs.existsSync(testOutputPath)).toBe(true);
44+
45+
// package.json has a name
46+
const packageJsonPath = path.resolve(testOutputPath, 'package.json');
47+
const packageJson = parseJson(fs.readFileSync(packageJsonPath, 'utf-8'));
48+
expect(packageJson.name).toBe('test-project');
49+
});
50+
});

0 commit comments

Comments
 (0)