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
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ jobs:
- name: Create release body
run: |
if [[ "${{ inputs.npm_tag }}" == "latest" ]]; then
INSTALL_BASH="curl -fsSL https://viteplus.dev/install.sh | bash"
INSTALL_PS1="irm https://viteplus.dev/install.ps1 | iex"
INSTALL_BASH="curl -fsSL https://vite.plus | bash"
INSTALL_PS1="irm https://vite.plus/ps1 | iex"
else
INSTALL_BASH="curl -fsSL https://viteplus.dev/install.sh | VITE_PLUS_VERSION=${{ env.VERSION }} bash"
INSTALL_PS1="\\\$env:VITE_PLUS_VERSION=\\\"${{ env.VERSION }}\\\"; irm https://viteplus.dev/install.ps1 | iex"
INSTALL_BASH="curl -fsSL https://vite.plus | VITE_PLUS_VERSION=${{ env.VERSION }} bash"
INSTALL_PS1="\\\$env:VITE_PLUS_VERSION=\\\"${{ env.VERSION }}\\\"; irm https://vite.plus/ps1 | iex"
fi
cat > ./RELEASE_BODY.md <<EOF
## vite-plus v${{ env.VERSION }}
Expand Down Expand Up @@ -307,6 +307,6 @@ jobs:
• vite-plus@${{ env.VERSION }}

**Install:**
• macOS/Linux: `curl -fsSL https://viteplus.dev/install.sh | bash`
• Windows: `irm https://viteplus.dev/install.ps1 | iex`
• macOS/Linux: `curl -fsSL https://vite.plus | bash`
• Windows: `irm https://vite.plus/ps1 | iex`
embed-url: https://github.com/${{ github.repository }}/releases/tag/v${{ env.VERSION }}
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
"recommendations": ["VoidZero.vite-plus-extension-pack"]
}
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
"typescript.preferences.importModuleSpecifierEnding": "js",
"typescript.reportStyleChecksAsWarnings": false,
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.experimental.useTsgo": true
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Install Vite+ globally as `vp`:
For Linux or macOS:

```bash
curl -fsSL https://viteplus.dev/install.sh | bash
curl -fsSL https://vite.plus | bash
```

For Windows:
Expand Down Expand Up @@ -140,6 +140,7 @@ Vite+ automatically wraps your package manager (pnpm, npm, or Yarn) based on `pa
#### Maintain

- **upgrade** - Update `vp` itself to the latest version
- **implode** - Remove `vp` and all related data

### Scaffolding your first Vite+ project

Expand Down
110 changes: 92 additions & 18 deletions crates/vite_global_cli/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct HelpDoc {
pub usage: &'static str,
pub summary: Vec<&'static str>,
pub sections: Vec<HelpSection>,
pub documentation_url: Option<&'static str>,
}

#[derive(Clone, Debug)]
Expand All @@ -29,6 +30,7 @@ struct OwnedHelpDoc {
usage: String,
summary: Vec<String>,
sections: Vec<OwnedHelpSection>,
documentation_url: Option<String>,
}

#[derive(Clone, Debug)]
Expand All @@ -55,6 +57,33 @@ fn section_lines(title: &'static str, lines: Vec<&'static str>) -> HelpSection {
HelpSection::Lines { title, lines }
}

fn documentation_url_for_command_path(command_path: &[&str]) -> Option<&'static str> {
match command_path {
[] => Some("https://viteplus.dev/guide/"),
["create"] => Some("https://viteplus.dev/guide/create"),
["migrate"] => Some("https://viteplus.dev/guide/migrate"),
["config"] | ["staged"] => Some("https://viteplus.dev/guide/commit-hooks"),
[
"install" | "add" | "remove" | "update" | "dedupe" | "outdated" | "list" | "ls" | "why"
| "info" | "view" | "show" | "link" | "unlink" | "pm",
..,
] => Some("https://viteplus.dev/guide/install"),
["dev"] => Some("https://viteplus.dev/guide/dev"),
["check"] => Some("https://viteplus.dev/guide/check"),
["lint"] => Some("https://viteplus.dev/guide/lint"),
["fmt"] => Some("https://viteplus.dev/guide/fmt"),
["test"] => Some("https://viteplus.dev/guide/test"),
["run"] => Some("https://viteplus.dev/guide/run"),
["exec" | "dlx"] => Some("https://viteplus.dev/guide/vpx"),
["cache"] => Some("https://viteplus.dev/guide/cache"),
["build" | "preview"] => Some("https://viteplus.dev/guide/build"),
["pack"] => Some("https://viteplus.dev/guide/pack"),
["env", ..] => Some("https://viteplus.dev/guide/env"),
["upgrade"] => Some("https://viteplus.dev/guide/upgrade"),
_ => None,
}
}

pub fn render_heading(title: &str) -> String {
let heading = format!("{title}:");
if !should_style_help() {
Expand All @@ -73,21 +102,12 @@ fn render_usage_value(usage: &str) -> String {
}

fn should_accent_heading(title: &str) -> bool {
matches!(
title,
"Start"
| "Develop"
| "Execute"
| "Build"
| "Manage Dependencies"
| "Maintain"
| "Setup"
| "Manage"
| "Inspect"
| "Examples"
| "Options"
| "Related Commands"
)
title != "Usage"
}

fn write_documentation_footer(output: &mut String, documentation_url: &str) {
let _ = writeln!(output);
let _ = writeln!(output, "{} {documentation_url}", render_heading("Documentation"));
}

pub fn should_style_help() -> bool {
Expand Down Expand Up @@ -189,6 +209,10 @@ pub fn render_help_doc(doc: &HelpDoc) -> String {
}
}

if let Some(documentation_url) = doc.documentation_url {
write_documentation_footer(&mut output, documentation_url);
}

output
}

Expand Down Expand Up @@ -222,6 +246,10 @@ fn render_owned_help_doc(doc: &OwnedHelpDoc) -> String {
}
}

if let Some(documentation_url) = &doc.documentation_url {
write_documentation_footer(&mut output, documentation_url);
}

output
}

Expand Down Expand Up @@ -386,7 +414,7 @@ fn parse_clap_help_to_doc(raw_help: &str) -> Option<OwnedHelpDoc> {
}
}

Some(OwnedHelpDoc { usage, summary, sections })
Some(OwnedHelpDoc { usage, summary, sections, documentation_url: None })
}

pub fn top_level_help_doc() -> HelpDoc {
Expand Down Expand Up @@ -459,6 +487,7 @@ pub fn top_level_help_doc() -> HelpDoc {
],
),
],
documentation_url: documentation_url_for_command_path(&[]),
}
}

Expand Down Expand Up @@ -546,6 +575,7 @@ fn env_help_doc() -> HelpDoc {
],
),
],
documentation_url: documentation_url_for_command_path(&["env"]),
}
}

Expand Down Expand Up @@ -577,6 +607,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
vec![" vp dev", " vp dev --open", " vp dev --host localhost --port 5173"],
),
],
documentation_url: documentation_url_for_command_path(&["dev"]),
}),
"build" => Some(HelpDoc {
usage: "vp build [ROOT] [OPTIONS]",
Expand Down Expand Up @@ -604,6 +635,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
vec![" vp build", " vp build --watch", " vp build --sourcemap"],
),
],
documentation_url: documentation_url_for_command_path(&["build"]),
}),
"preview" => Some(HelpDoc {
usage: "vp preview [ROOT] [OPTIONS]",
Expand All @@ -628,6 +660,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
),
section_lines("Examples", vec![" vp preview", " vp preview --port 4173"]),
],
documentation_url: documentation_url_for_command_path(&["preview"]),
}),
"test" => Some(HelpDoc {
usage: "vp test [COMMAND] [FILTERS] [OPTIONS]",
Expand Down Expand Up @@ -666,6 +699,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
],
),
],
documentation_url: documentation_url_for_command_path(&["test"]),
}),
"lint" => Some(HelpDoc {
usage: "vp lint [PATH]... [OPTIONS]",
Expand All @@ -692,6 +726,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
],
),
],
documentation_url: documentation_url_for_command_path(&["lint"]),
}),
"fmt" => Some(HelpDoc {
usage: "vp fmt [PATH]... [OPTIONS]",
Expand All @@ -714,6 +749,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
vec![" vp fmt", " vp fmt src --check", " vp fmt . --write"],
),
],
documentation_url: documentation_url_for_command_path(&["fmt"]),
}),
"check" => Some(HelpDoc {
usage: "vp check [OPTIONS] [PATHS]...",
Expand All @@ -737,6 +773,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
],
),
],
documentation_url: documentation_url_for_command_path(&["check"]),
}),
"pack" => Some(HelpDoc {
usage: "vp pack [...FILES] [OPTIONS]",
Expand All @@ -759,6 +796,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
vec![" vp pack", " vp pack src/index.ts --dts", " vp pack --watch"],
),
],
documentation_url: documentation_url_for_command_path(&["pack"]),
}),
"run" => Some(HelpDoc {
usage: "vp run [OPTIONS] [TASK_SPECIFIER] [ADDITIONAL_ARGS]...",
Expand Down Expand Up @@ -809,6 +847,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
],
),
],
documentation_url: documentation_url_for_command_path(&["run"]),
}),
"exec" => Some(HelpDoc {
usage: "vp exec [OPTIONS] [COMMAND]...",
Expand Down Expand Up @@ -862,6 +901,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
],
),
],
documentation_url: documentation_url_for_command_path(&["exec"]),
}),
"cache" => Some(HelpDoc {
usage: "vp cache <COMMAND>",
Expand All @@ -870,6 +910,7 @@ fn delegated_help_doc(command: &str) -> Option<HelpDoc> {
section_rows("Commands", vec![row("clean", "Clean up all the cache")]),
section_rows("Options", vec![row("-h, --help", "Print help")]),
],
documentation_url: documentation_url_for_command_path(&["cache"]),
}),
_ => None,
}
Expand Down Expand Up @@ -1010,6 +1051,11 @@ pub fn print_unified_clap_help_for_path(command_path: &[&str]) -> bool {
let Some(doc) = parse_clap_help_to_doc(&raw_help) else {
return false;
};
let doc = OwnedHelpDoc {
documentation_url: documentation_url_for_command_path(command_path)
.map(ToString::to_string),
..doc
};

println!("{}", vite_shared::header::vite_plus_header());
println!();
Expand All @@ -1020,8 +1066,8 @@ pub fn print_unified_clap_help_for_path(command_path: &[&str]) -> bool {
#[cfg(test)]
mod tests {
use super::{
has_help_flag_before_terminator, parse_clap_help_to_doc, parse_rows, split_comment_suffix,
strip_ansi,
HelpDoc, documentation_url_for_command_path, has_help_flag_before_terminator,
parse_clap_help_to_doc, parse_rows, render_help_doc, split_comment_suffix, strip_ansi,
};

#[test]
Expand Down Expand Up @@ -1110,4 +1156,32 @@ Options:
fn split_comment_suffix_returns_none_without_comment() {
assert!(split_comment_suffix(" vp env list").is_none());
}

#[test]
fn docs_url_is_mapped_for_grouped_commands() {
assert_eq!(
documentation_url_for_command_path(&["add"]),
Some("https://viteplus.dev/guide/install")
);
assert_eq!(
documentation_url_for_command_path(&["env", "list"]),
Some("https://viteplus.dev/guide/env")
);
assert_eq!(
documentation_url_for_command_path(&["config"]),
Some("https://viteplus.dev/guide/commit-hooks")
);
}

#[test]
fn render_help_doc_appends_documentation_footer() {
let output = render_help_doc(&HelpDoc {
usage: "vp demo",
summary: vec![],
sections: vec![],
documentation_url: Some("https://viteplus.dev/guide/demo"),
});

assert!(output.contains("Documentation: https://viteplus.dev/guide/demo"));
}
}
Loading
Loading