Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions packages/wxt/src/cli/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,7 @@ describe('CLI', () => {
mockArgv('init');
await importCli();

expect(initializeMock).toBeCalledWith(
expect.objectContaining({ requireGit: true }),
);
expect(initializeMock).toBeCalledWith(expect.objectContaining({}));
});

it('should respect the provided folder', async () => {
Expand All @@ -503,7 +501,6 @@ describe('CLI', () => {
expect(initializeMock).toBeCalledWith(
expect.objectContaining({
directory: 'path/to/folder',
requireGit: true,
}),
);
});
Expand All @@ -515,7 +512,6 @@ describe('CLI', () => {
expect(initializeMock).toBeCalledWith(
expect.objectContaining({
template: 'vue',
requireGit: true,
}),
);
});
Expand All @@ -527,18 +523,17 @@ describe('CLI', () => {
expect(initializeMock).toBeCalledWith(
expect.objectContaining({
packageManager: 'pnpm',
requireGit: true,
}),
);
});

it('should respect passing --no-git', async () => {
mockArgv('init', '--no-git');
it('should respect passing --git', async () => {
mockArgv('init', '--git');
await importCli();

expect(initializeMock).toBeCalledWith(
expect.objectContaining({
requireGit: false,
requireGit: true,
}),
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/wxt/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ cli
.command('init [directory]', 'initialize a new project')
.option('-t, --template <template>', 'template to use')
.option('--pm <packageManager>', 'which package manager to use')
.option('--no-git', 'skip initialize git repo')
.option('--git', 'skip initialize git repo')
.action(
wrapAction(
async (directory, flags) => {
Expand Down
23 changes: 12 additions & 11 deletions packages/wxt/src/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ export async function initialize(options: {
(await question('Project Directory', { defaultValue: '.' }));
if (!directory) throw Error('Directory is required');

const isExists = await pathExists(directory);
if (isExists) {
const isEmpty =
(await readdir(directory)).filter((dir) => dir !== '.git').length === 0;
if (!isEmpty) {
consola.error(
`The directory ${path.resolve(directory)} is not empty. Aborted.`,
);
process.exit(1);
}
}

const templateName =
inputTemplateName ??
(await select('Choose a template', {
Expand Down Expand Up @@ -59,17 +71,6 @@ export async function initialize(options: {
options.requireGit ??
(await confirm('Initialize a new git repository?', { initial: true }));

const isExists = await pathExists(directory);
if (isExists) {
const isEmpty =
(await readdir(directory)).filter((dir) => dir !== '.git').length === 0;
if (!isEmpty) {
consola.error(
`The directory ${path.resolve(directory)} is not empty. Aborted.`,
);
process.exit(1);
}
}
await cloneProject({ directory, template, requireGitInitialized });

const cdPath = path.relative(process.cwd(), path.resolve(directory));
Expand Down
Loading