Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f603eb
fix: Initializing git repo on project creation
nishu-murmu Sep 12, 2026
d5302e4
added check for whether the project is already under git control.
nishu-murmu Sep 12, 2026
a271938
Merge branch 'main' into fix/git-init
nishu-murmu Sep 18, 2026
840bc1a
Merge branch 'main' into fix/git-init
nishu-murmu Oct 1, 2026
cf2e491
chore: fix type check errors
nishu-murmu Oct 2, 2026
bc009df
chore: fix validation workflow and background context getter
nishu-murmu Oct 2, 2026
8501ab3
chore: fixing the type check errors.
nishu-murmu Oct 2, 2026
ac5b458
Merge branch 'main' into fix/git-init
nishu-murmu Oct 2, 2026
0c3fd4c
Merge branch 'chore/build' of github-personal:wxt-dev/wxt into fix/gi…
nishu-murmu Oct 2, 2026
20ed392
Merge branch 'main' into fix/git-init
nishu-murmu Oct 3, 2026
420433b
Merge branch 'main' into fix/git-init
nishu-murmu Oct 3, 2026
9527000
Merge branch 'main' of github-personal:wxt-dev/wxt into fix/git-init
nishu-murmu Oct 7, 2026
559a0e8
Merge branch 'fix/git-init' of github-personal:wxt-dev/wxt into fix/g…
nishu-murmu Oct 7, 2026
1a929cd
feat: asking whether to initialize the git repo or not during project…
nishu-murmu Oct 7, 2026
b3bc105
chore: fixing build errors for the tests
nishu-murmu Oct 7, 2026
be0eb06
Update packages/wxt/src/initialize.ts
nishu-murmu Oct 9, 2026
89d7ad8
Merge branch 'main' into fix/git-init
nishu-murmu Oct 9, 2026
968c82d
Merge branch 'main' into fix/git-init
nishu-murmu Oct 10, 2026
899d586
Merge branch 'main' into fix/git-init
PatrykKuniczak Oct 10, 2026
66c0b69
Merge branch 'main' of github-personal:wxt-dev/wxt into fix/git-init
nishu-murmu Oct 10, 2026
a86727b
Merge branch 'fix/git-init' of github-personal:wxt-dev/wxt into fix/g…
nishu-murmu Oct 10, 2026
4df56d6
Merge branch 'main' into fix/git-init
nishu-murmu Oct 10, 2026
b8c757f
Merge branch 'main' into fix/git-init
nishu-murmu Oct 12, 2026
d22eb54
Merge branch 'main' into fix/git-init
nishu-murmu Oct 13, 2026
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
42 changes: 32 additions & 10 deletions packages/wxt/src/cli/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,34 +491,56 @@ describe('CLI', () => {
mockArgv('init');
await importCli();

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

it('should respect the provided folder', async () => {
mockArgv('init', 'path/to/folder');
await importCli();

expect(initializeMock).toBeCalledWith({
directory: 'path/to/folder',
});
expect(initializeMock).toBeCalledWith(
expect.objectContaining({
directory: 'path/to/folder',
requireGit: true,
}),
);
});

it('should respect passing --template', async () => {
mockArgv('init', '-t', 'vue');
await importCli();

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

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

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

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

expect(initializeMock).toBeCalledWith(
expect.objectContaining({
requireGit: false,
}),
);
});
});
});
2 changes: 2 additions & 0 deletions packages/wxt/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ 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')
.action(
wrapAction(
async (directory, flags) => {
await initialize({
directory,
template: flags.template,
packageManager: flags.pm,
requireGit: flags.git,
});
},
{ disableFinishedLog: true },
Expand Down
29 changes: 26 additions & 3 deletions packages/wxt/src/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { question, select } from '@topcli/prompts';
import { question, select, confirm } from '@topcli/prompts';
import { consola } from 'consola';
import { downloadTemplate } from 'giget';
import { readdir, rename } from 'node:fs/promises';
import { pathExists } from './internal-utils/fs-utils';
import { normalizePath } from './internal-utils/path-utils';
import path from 'node:path';
import { styleText } from 'node:util';
import { TextStyle } from './internal-utils/type-utils';
import { createSpinner } from './internal/spinner';
import { x as spawn } from 'tinyexec';

export async function initialize(options: {
directory?: string;
template?: string;
packageManager?: string;
requireGit?: boolean;
}) {
consola.info('Initializing new project');

Expand Down Expand Up @@ -51,6 +54,11 @@ export async function initialize(options: {
],
}));

// Asks whether require git initialized or not?
const requireGitInitialized =
options.requireGit ??
Comment thread
nishu-murmu marked this conversation as resolved.
(await confirm('Initialize a new git repository?', { initial: true }));

const isExists = await pathExists(directory);
if (isExists) {
const isEmpty =
Expand All @@ -62,7 +70,7 @@ export async function initialize(options: {
process.exit(1);
}
}
await cloneProject({ directory, template });
await cloneProject({ directory, template, requireGitInitialized });

const cdPath = path.relative(process.cwd(), path.resolve(directory));
console.log();
Expand Down Expand Up @@ -151,14 +159,16 @@ async function listTemplatesGithub(): Promise<Template[]> {
async function cloneProject({
directory,
template,
requireGitInitialized,
}: {
directory: string;
template: Template;
requireGitInitialized: boolean;
}) {
const spinner = createSpinner('Downloading template').start();
try {
// 1. Clone repo
await downloadTemplate(`gh:${REPO}/${template.path}`, {
const response = await downloadTemplate(`gh:${REPO}/${template.path}`, {
dir: directory,
force: true,
});
Expand All @@ -171,6 +181,19 @@ async function cloneProject({
consola.warn('Failed to move _gitignore to .gitignore:', err),
);

// 3. Initializing Git
if (requireGitInitialized) {
try {
const dirPath = normalizePath(response.dir);
await spawn('git', ['init'], {
throwOnError: true,
nodeOptions: { cwd: dirPath, shell: true },
});
} catch (error) {
console.error(error);
}
}

spinner.success();
} catch (err) {
spinner.error();
Expand Down
Loading