Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"create-vp-test-generated-setup": {
"name": "create-vp-test-generated-setup",
"dist-tags": {
"latest": "1.0.0"
},
"versions": {
"1.0.0": {
"name": "create-vp-test-generated-setup",
"version": "1.0.0",
"bin": {
"create-vp-test-generated-setup": "index.cjs"
},
"dist": {
"tarball": "{REGISTRY}/create-vp-test-generated-setup/-/create-vp-test-generated-setup-1.0.0.tgz",
"integrity": "sha512-eg95ZfZTfRmqgWms3s+wI5sd8Jl9lMMYWcHsfWtdKKP2hEeIpWUlHAuELDWc/3vyUi8KZDB6edDGwZtIZ2w+Zw=="
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The fake `create-vp-test-generated-setup` CLI writes AGENTS.md and
# .vscode/settings.json and runs `git init`, so the setup prompts that follow
# it must react to those files.
[[case]]
name = "create_remote_generated_setup"
vp = "local"
steps = [
{ argv = ["vp", "create", "vp-test-generated-setup", "--package-manager", "pnpm", "--", "my-app"], comment = "after the create CLI: no git prompt, a hooks prompt, then append/skip for the generated AGENTS.md", snapshot = false, continue-on-failure = true, interactions = [
{ "expect-milestone" = "confirm:confirm:yes" },
{ "write-key" = "enter" },
{ "expect-milestone" = "select:select:1" },
{ "write-key" = "up" },
{ "expect-milestone" = "select:select:0" },
{ "write-key" = "enter" },
] },
{ argv = ["vpt", "grep-file", "my-app/AGENTS.md", "<!--VITE PLUS START-->"], comment = "Vite+ instructions are appended to the generated AGENTS.md", continue-on-failure = true },
{ argv = ["vpt", "print-file", "my-app/.vscode/settings.json"], comment = "generated editor config is merged without a prompt", continue-on-failure = true },
{ argv = ["vpt", "stat-file", "my-app/.vite-hooks/pre-commit", "--assert", "file"], comment = "hooks are set up in the repository the create CLI initialized", continue-on-failure = true },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# create_remote_generated_setup

## `vp create vp-test-generated-setup --package-manager pnpm -- my-app`

after the create CLI: no git prompt, a hooks prompt, then append/skip for the generated AGENTS.md


## `vpt grep-file my-app/AGENTS.md '<'\!'--VITE PLUS START-->'`

Vite+ instructions are appended to the generated AGENTS.md

```
my-app/AGENTS.md: found "<!--VITE PLUS START-->"
```

## `vpt print-file my-app/.vscode/settings.json`

generated editor config is merged without a prompt

```
{
"editor.tabSize": 2,
"npm.scriptRunner": "vp",
"editor.defaultFormatter": "oxc.oxc-vscode",
"[javascript]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"oxc.disableNestedConfig": true,
"oxc.fmt.disableNestedConfig": true,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"editor.codeActionsOnSave": {
"source.fixAll.oxc": "explicit"
}
}
```

## `vpt stat-file my-app/.vite-hooks/pre-commit --assert file`

hooks are set up in the repository the create CLI initialized

```
my-app/.vite-hooks/pre-commit: file
```
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"create-vp-test-vite-plus": {
"name": "create-vp-test-vite-plus",
"dist-tags": {
"latest": "1.0.0"
},
"versions": {
"1.0.0": {
"name": "create-vp-test-vite-plus",
"version": "1.0.0",
"bin": {
"create-vp-test-vite-plus": "index.cjs"
},
"dist": {
"tarball": "{REGISTRY}/create-vp-test-vite-plus/-/create-vp-test-vite-plus-1.0.0.tgz",
"integrity": "sha512-xvpZCYhS9b6ee0uUQC7FlICwKIR/W6nkIQfWZ1UAfd8b+gzgUjT5kR8JILcITLstgv0prAnOeAVmsgyQExbD7A=="
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The fake `create-vp-test-vite-plus` CLI writes a project that already uses
# Vite+, so `vp create` must leave its setup unchanged.
[[case]]
name = "create_remote_vite_plus_template"
vp = "local"
steps = [
{ argv = ["vp", "create", "vp-test-vite-plus", "--no-interactive", "--no-agent", "--no-editor", "--no-git", "--no-hooks", "--", "my-app"], comment = "create from a template that already generates a Vite+ project", snapshot = false, continue-on-failure = true },
{ argv = ["vpt", "print-file", "my-app/package.json"], comment = "dependencies and scripts are not rewritten", continue-on-failure = true },
{ argv = ["vpt", "stat-file", "my-app/pnpm-workspace.yaml", "--assert-not", "file"], comment = "no Vite+ overrides are added", continue-on-failure = true },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# create_remote_vite_plus_template

## `vp create vp-test-vite-plus --no-interactive --no-agent --no-editor --no-git --no-hooks -- my-app`

create from a template that already generates a Vite+ project


## `vpt print-file my-app/package.json`

dependencies and scripts are not rewritten

```
{
"name": "my-app",
"private": true,
"type": "module",
"scripts": {
"dev": "vp dev",
"lint": "eslint ."
},
"devDependencies": {
"eslint": "^9.0.0",
"vite-plus": "latest"
},
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "<version>",
"onFail": "download"
}
}
}
```

## `vpt stat-file my-app/pnpm-workspace.yaml --assert-not file`

no Vite+ overrides are added

```
my-app/pnpm-workspace.yaml: missing
```
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/guide/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Vite+ ships with these built-in templates:

Run `vp create --list` to see the built-in templates and the common shorthand templates Vite+ recognizes.

After a third-party template runs, `vp create` migrates the generated project to Vite+. When a standalone project already depends on `vite-plus`, `vp create` skips this migration and keeps the template's tooling choices.

## Options

- `--directory <dir>` writes the generated project into a specific target directory. Only built-in templates and bundled `@org` templates support this option.
Expand Down
122 changes: 81 additions & 41 deletions packages/cli/src/create/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ import {
resolveApproveBuildTargets,
} from '../utils/approve-builds.ts';
import { unwrapCliParseOutcome } from '../utils/cli-parse.ts';
import { isForceOverrideMode } from '../utils/constants.ts';
import { documentationUrl } from '../utils/documentation.ts';
import { detectExistingEditors, selectEditors, writeEditorConfigs } from '../utils/editor.ts';
import { findGitRoot, initGitRepository } from '../utils/git.ts';
import { renderCliDoc } from '../utils/help.ts';
import { readJsonFile } from '../utils/json.ts';
import { hasVitePlusDependency } from '../utils/package.ts';
import { displayRelative } from '../utils/path.ts';
import {
cancelAndExit,
Expand Down Expand Up @@ -730,45 +732,64 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
? formatLocalVpCommand(packageManager, 'vp run')
: 'vp run';

const existingAgentTargetPaths =
options.agent !== undefined || !options.interactive
? undefined
: detectExistingAgentTargetPaths(workspaceInfoOptional.rootDir);
if (existingAgentTargetPaths !== undefined) {
selectedAgentTargetPaths = existingAgentTargetPaths;
} else {
const agentSelection = await selectAgentTargets({
interactive: options.interactive,
agent: options.agent,
onCancel: () => cancelAndExit(),
});
selectedAgentTargetPaths = agentSelection.targetPaths;
shouldWriteCopilotSetupWorkflow = agentSelection.selectedAgents.some(
(agent) => agent.id === COPILOT_AGENT_ID,
);
}

const shouldConfigureEditors = shouldConfigureEditorsForCreate({
editor: options.editor,
isMonorepo,
});
if (shouldConfigureEditors) {
const existingEditors =
options.editor || !options.interactive

// Agent, editor, git and hook choices. Direct scaffolds ask up front. A
// `create-xxx` CLI asks after it ran (`generatedProjectPath`), so its own
// prompts come first and the answers reflect the files it generated.
let shouldSetupGit = false;
const resolveProjectSetup = async (generatedProjectPath?: string) => {
const agentInstructionsRoot =
generatedProjectPath && !isMonorepo ? generatedProjectPath : workspaceInfoOptional.rootDir;
const existingAgentTargetPaths =
options.agent !== undefined || !options.interactive
? undefined
: detectExistingEditors(workspaceInfoOptional.rootDir);
selectedEditors =
existingEditors ??
(await selectEditors({
: detectExistingAgentTargetPaths(agentInstructionsRoot);
if (existingAgentTargetPaths !== undefined) {
selectedAgentTargetPaths = existingAgentTargetPaths;
} else {
const agentSelection = await selectAgentTargets({
interactive: options.interactive,
editor: options.editor,
agent: options.agent,
onCancel: () => cancelAndExit(),
}));
}
});
selectedAgentTargetPaths = agentSelection.targetPaths;
shouldWriteCopilotSetupWorkflow = agentSelection.selectedAgents.some(
(agent) => agent.id === COPILOT_AGENT_ID,
);
}

if (shouldConfigureEditors) {
const existingEditors =
options.editor || !options.interactive
? undefined
: detectExistingEditors(generatedProjectPath ?? workspaceInfoOptional.rootDir);
selectedEditors =
existingEditors ??
(await selectEditors({
interactive: options.interactive,
editor: options.editor,
onCancel: () => cancelAndExit(),
}));
}

const shouldSetupGit = await resolveGitInit(options, isMonorepo);
if (!isMonorepo && (!options.interactive || shouldSetupGit || options.hooks === true)) {
shouldSetupHooks = await promptGitHooks(options);
// A `create-xxx` CLI may have initialized the repository itself.
const hasGitRepository =
generatedProjectPath !== undefined && fs.existsSync(path.join(generatedProjectPath, '.git'));
shouldSetupGit = !hasGitRepository && (await resolveGitInit(options, isMonorepo));
if (
!isMonorepo &&
(!options.interactive || hasGitRepository || shouldSetupGit || options.hooks === true)
) {
shouldSetupHooks = await promptGitHooks(options);
}
};

if (isDirectScaffoldTemplate) {
await resolveProjectSetup();
}

const createProgress =
Expand Down Expand Up @@ -1077,6 +1098,9 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
}

const fullPath = path.join(workspaceInfo.rootDir, projectDir);
if (!isDirectScaffoldTemplate) {
await resolveProjectSetup(fullPath);
}

// Register a scaffolded generator in `create.templates` so it appears in the
// `vp create` picker (and resolves by name) without a manual config edit.
Expand Down Expand Up @@ -1138,7 +1162,8 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
await writeEditorConfigs({
projectRoot: fullPath,
editorId: selectedEditors,
interactive: options.interactive,
// Editor configs a `create-xxx` CLI generated are merged without asking per file.
interactive: options.interactive && isDirectScaffoldTemplate,
silent: compactOutput,
extraVsCodeSettings: { 'npm.scriptRunner': 'vp' },
packageManager,
Expand All @@ -1149,16 +1174,29 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
resumeCreateProgress();
}

// A `create-xxx` CLI that already generates a Vite+ project made its own
// toolchain choices (e.g. keeping ESLint), so skip migration like `vp migrate`
// does for Vite+ projects. Monorepo packages still need the rewrite to align
// with the workspace catalog.
const packageJsonPath = path.join(fullPath, 'package.json');
const isVitePlusTemplate =
!isMonorepo &&
templateInfo.type === TemplateType.remote &&
!isForceOverrideMode() &&
fs.existsSync(packageJsonPath) &&
hasVitePlusDependency(readJsonFile(packageJsonPath));

// The migrate-before-rewrite reorder is only needed when the template
// actually ships ESLint or Prettier (e.g. `create-vite --template
// react-ts`). Builtin templates (vite:library, vite:application,
// vite:monorepo) don't — their package.json already references vite-plus
// and relies on `rewrite*Project` to add tarball overrides BEFORE the
// first install, so install-first would break CI's local-tarball resolve.
const shouldMigrateLintFmtTools =
detectEslintProject(fullPath).hasDependency ||
detectPrettierProject(fullPath).hasDependency ||
detectTsupProject(fullPath).hasDependency;
!isVitePlusTemplate &&
(detectEslintProject(fullPath).hasDependency ||
detectPrettierProject(fullPath).hasDependency ||
detectTsupProject(fullPath).hasDependency);

let installSummary: CommandRunSummary | undefined;

Expand Down Expand Up @@ -1338,12 +1376,14 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
await installAndMigrate(fullPath);
}
updateCreateProgress('Applying Vite+ project setup');
const skipStagedMigration = shouldSkipStagedMigrationForHooks(
fullPath,
shouldSetupHooks,
workspaceInfo.packageManager,
);
rewriteStandaloneProject(fullPath, workspaceInfo, skipStagedMigration, compactOutput);
if (!isVitePlusTemplate) {
const skipStagedMigration = shouldSkipStagedMigrationForHooks(
fullPath,
shouldSetupHooks,
workspaceInfo.packageManager,
);
rewriteStandaloneProject(fullPath, workspaceInfo, skipStagedMigration, compactOutput);
}
setPackageManager(fullPath, workspaceInfo.downloadPackageManager);
for (const framework of detectFramework(fullPath)) {
if (!hasFrameworkShim(fullPath, framework)) {
Expand Down
Loading