mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-03 06:40:05 +01:00
Compare commits
4 Commits
yaak-cli-0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
851f12f149 | ||
|
|
cc0d31fdbb | ||
|
|
bab4fe899b | ||
|
|
0b250ff5b5 |
@@ -110,7 +110,7 @@ fn should_skip_check() -> bool {
|
||||
}
|
||||
|
||||
async fn fetch_version_check() -> Option<VersionCheckResponse> {
|
||||
let api_url = format!("{}/api/v1/cli/version-check", api_base_url());
|
||||
let api_url = format!("{}/cli/check", update_base_url());
|
||||
let current_version = version::cli_version();
|
||||
let payload = VersionCheckRequest {
|
||||
current_version,
|
||||
@@ -146,11 +146,10 @@ fn install_source() -> String {
|
||||
.unwrap_or_else(|| "source".to_string())
|
||||
}
|
||||
|
||||
fn api_base_url() -> &'static str {
|
||||
fn update_base_url() -> &'static str {
|
||||
match std::env::var("ENVIRONMENT").ok().as_deref() {
|
||||
Some("staging") => "https://todo.yaak.app",
|
||||
Some("development") => "http://localhost:9444",
|
||||
_ => "https://api.yaak.app",
|
||||
_ => "https://update.yaak.app",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::task::block_in_place;
|
||||
use tokio::time;
|
||||
use yaak_common::command::new_checked_command;
|
||||
use yaak_crypto::manager::EncryptionManager;
|
||||
use yaak_grpc::manager::{GrpcConfig, GrpcHandle};
|
||||
use yaak_grpc::{Code, ServiceDefinition, serialize_message};
|
||||
@@ -97,6 +98,7 @@ impl<R: Runtime> PluginContextExt<R> for WebviewWindow<R> {
|
||||
struct AppMetaData {
|
||||
is_dev: bool,
|
||||
version: String,
|
||||
cli_version: Option<String>,
|
||||
name: String,
|
||||
app_data_dir: String,
|
||||
app_log_dir: String,
|
||||
@@ -113,9 +115,11 @@ async fn cmd_metadata(app_handle: AppHandle) -> YaakResult<AppMetaData> {
|
||||
let vendored_plugin_dir =
|
||||
app_handle.path().resolve("vendored/plugins", BaseDirectory::Resource)?;
|
||||
let default_project_dir = app_handle.path().home_dir()?.join("YaakProjects");
|
||||
let cli_version = detect_cli_version().await;
|
||||
Ok(AppMetaData {
|
||||
is_dev: is_dev(),
|
||||
version: app_handle.package_info().version.to_string(),
|
||||
cli_version,
|
||||
name: app_handle.package_info().name.to_string(),
|
||||
app_data_dir: app_data_dir.to_string_lossy().to_string(),
|
||||
app_log_dir: app_log_dir.to_string_lossy().to_string(),
|
||||
@@ -126,6 +130,28 @@ async fn cmd_metadata(app_handle: AppHandle) -> YaakResult<AppMetaData> {
|
||||
})
|
||||
}
|
||||
|
||||
async fn detect_cli_version() -> Option<String> {
|
||||
// Prefer `yaak`, but support the legacy `yaakcli` alias if present.
|
||||
if let Some(version) = detect_cli_version_for_binary("yaak").await {
|
||||
return Some(version);
|
||||
}
|
||||
detect_cli_version_for_binary("yaakcli").await
|
||||
}
|
||||
|
||||
async fn detect_cli_version_for_binary(program: &str) -> Option<String> {
|
||||
let mut cmd = new_checked_command(program, "--version").await.ok()?;
|
||||
let out = cmd.arg("--version").output().await.ok()?;
|
||||
if !out.status.success() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let line = String::from_utf8(out.stdout).ok()?;
|
||||
let line = line.lines().find(|l| !l.trim().is_empty())?.trim();
|
||||
let mut parts = line.split_whitespace();
|
||||
let _name = parts.next();
|
||||
Some(parts.next().unwrap_or(line).to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn cmd_template_tokens_to_string<R: Runtime>(
|
||||
window: WebviewWindow<R>,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::ffi::OsStr;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::{self, ErrorKind};
|
||||
use std::process::Stdio;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
||||
@@ -14,3 +16,27 @@ pub fn new_xplatform_command<S: AsRef<OsStr>>(program: S) -> tokio::process::Com
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
/// Creates a command only if the binary exists and can be invoked with the given probe argument.
|
||||
pub async fn new_checked_command<S: AsRef<OsStr>>(
|
||||
program: S,
|
||||
probe_arg: &str,
|
||||
) -> io::Result<tokio::process::Command> {
|
||||
let program: OsString = program.as_ref().to_os_string();
|
||||
|
||||
let mut probe = new_xplatform_command(&program);
|
||||
probe.arg(probe_arg).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
|
||||
|
||||
let status = probe.status().await?;
|
||||
if !status.success() {
|
||||
return Err(io::Error::new(
|
||||
ErrorKind::NotFound,
|
||||
format!(
|
||||
"'{}' is not available on PATH or failed to execute",
|
||||
program.to_string_lossy()
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(new_xplatform_command(&program))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use crate::error::Error::GitNotFound;
|
||||
use crate::error::Result;
|
||||
use std::path::Path;
|
||||
use std::process::Stdio;
|
||||
use tokio::process::Command;
|
||||
use yaak_common::command::new_xplatform_command;
|
||||
use yaak_common::command::new_checked_command;
|
||||
|
||||
/// Create a git command that runs in the specified directory
|
||||
pub(crate) async fn new_binary_command(dir: &Path) -> Result<Command> {
|
||||
@@ -14,17 +13,5 @@ pub(crate) async fn new_binary_command(dir: &Path) -> Result<Command> {
|
||||
|
||||
/// Create a git command without a specific directory (for global operations)
|
||||
pub(crate) async fn new_binary_command_global() -> Result<Command> {
|
||||
// 1. Probe that `git` exists and is runnable
|
||||
let mut probe = new_xplatform_command("git");
|
||||
probe.arg("--version").stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
|
||||
|
||||
let status = probe.status().await.map_err(|_| GitNotFound)?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(GitNotFound);
|
||||
}
|
||||
|
||||
// 2. Build the reusable git command
|
||||
let cmd = new_xplatform_command("git");
|
||||
Ok(cmd)
|
||||
new_checked_command("git", "--version").await.map_err(|_| GitNotFound)
|
||||
}
|
||||
|
||||
56
package-lock.json
generated
56
package-lock.json
generated
@@ -73,7 +73,7 @@
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.13",
|
||||
"@tauri-apps/cli": "^2.9.6",
|
||||
"@yaakapp/cli": "^0.4.0",
|
||||
"@yaakapp/cli": "^0.5.1",
|
||||
"dotenv-cli": "^11.0.0",
|
||||
"husky": "^9.1.7",
|
||||
"nodejs-file-downloader": "^4.13.0",
|
||||
@@ -4303,9 +4303,9 @@
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@yaakapp/cli": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli/-/cli-0.4.0.tgz",
|
||||
"integrity": "sha512-8xnu2oFWlgV+xeIAHMuEgsqX6Sxq4UYrSH2WbafwDLbSep6fxpO74tiBH7xp4wakt/7Bcy9a2Q5R9nkAc1ZUdA==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli/-/cli-0.5.1.tgz",
|
||||
"integrity": "sha512-kAhX9SvjAiEsg2xwCuyuEOJRyEIg7jEGzGFCGzWy9I9Ew2hD0huIDGy9l4IMJUR84gh1V/62dxeiZREptWpIFg==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"bin": {
|
||||
@@ -4313,18 +4313,18 @@
|
||||
"yaakcli": "bin/cli.js"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@yaakapp/cli-darwin-arm64": "0.4.0",
|
||||
"@yaakapp/cli-darwin-x64": "0.4.0",
|
||||
"@yaakapp/cli-linux-arm64": "0.4.0",
|
||||
"@yaakapp/cli-linux-x64": "0.4.0",
|
||||
"@yaakapp/cli-win32-arm64": "0.4.0",
|
||||
"@yaakapp/cli-win32-x64": "0.4.0"
|
||||
"@yaakapp/cli-darwin-arm64": "0.5.1",
|
||||
"@yaakapp/cli-darwin-x64": "0.5.1",
|
||||
"@yaakapp/cli-linux-arm64": "0.5.1",
|
||||
"@yaakapp/cli-linux-x64": "0.5.1",
|
||||
"@yaakapp/cli-win32-arm64": "0.5.1",
|
||||
"@yaakapp/cli-win32-x64": "0.5.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@yaakapp/cli-darwin-arm64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-darwin-arm64/-/cli-darwin-arm64-0.4.0.tgz",
|
||||
"integrity": "sha512-bl8+VQNPMabXNGQCa7u6w0JGe3CmzYZPsGE8Q+5wGSxa3trGf1bmq/fMW5JXrMi1P7Laepnyad0TGGP/2C8uwQ==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-darwin-arm64/-/cli-darwin-arm64-0.5.1.tgz",
|
||||
"integrity": "sha512-08FJ35vYGUXVC5r4/kLchEUI8YJN0iiB6KPZ9NuNHD0QmEWAN1451roUrXzz+dGFUw9tLb7HDGuZ6c4YL4Va7A==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -4335,9 +4335,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yaakapp/cli-darwin-x64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-darwin-x64/-/cli-darwin-x64-0.4.0.tgz",
|
||||
"integrity": "sha512-R+ETXNBWvmA3W88ZoTk/JtG/PZaUb85y3SwBgMbwcgdhBVwNS/g+DbCspcTFI5zs8Txsf5VuiFU+dW9M9olZ6A==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-darwin-x64/-/cli-darwin-x64-0.5.1.tgz",
|
||||
"integrity": "sha512-UqN9Bn2Z5Ns9ATWWQyvhlCJ3qdk1rM5b9CbGzV61F/LkfcPbvBuTFGAWprQVTun7iy7PjI35R6Cfj126+Z/ehA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -4348,9 +4348,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yaakapp/cli-linux-arm64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-linux-arm64/-/cli-linux-arm64-0.4.0.tgz",
|
||||
"integrity": "sha512-Pf7VyQf4r85FsI0qYnnst7URQF8/RxSZZj79cXLai0FnN3fDiypX4CmHx765bJxgfQZlBvqVmvPAaMW/TeiJEQ==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-linux-arm64/-/cli-linux-arm64-0.5.1.tgz",
|
||||
"integrity": "sha512-YdQXNNPLSzkmwWEqnv2V8C8Bl9atQFQYI3FtPTYa2Ljp54omgMxuikn0gauhsHFMtFg8GOStVEENbBFW0W0Ovg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -4361,9 +4361,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yaakapp/cli-linux-x64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-linux-x64/-/cli-linux-x64-0.4.0.tgz",
|
||||
"integrity": "sha512-bYWWfHAIW81A+ydJChjH1Qo3+aihz9gFLh7/9MOa6CJgnC6H3V5cnapmh50Hddt9l5ic02aA1FB8ORQOXxb01A==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-linux-x64/-/cli-linux-x64-0.5.1.tgz",
|
||||
"integrity": "sha512-03sVYmD3ksH6lJr6YEwqEQCADoVP5fzq6vBkoCBSrQOj9iInk06DuFHME7IjEa7uKXBaF4WeUms/yQEA03jHBA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -4374,9 +4374,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yaakapp/cli-win32-arm64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-win32-arm64/-/cli-win32-arm64-0.4.0.tgz",
|
||||
"integrity": "sha512-8X12xkyidyYZ5vtarZGFSYR6HJbUMFUsNxYPNQccnYJIY+soNkjJHOWDjaRvBzCbR8MLT9N04Y5PE/Jv20gXpA==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-win32-arm64/-/cli-win32-arm64-0.5.1.tgz",
|
||||
"integrity": "sha512-bYBe0PpgvjEx/4jvDKOA9/Kg9qzAP1NmUCcPWZueOJItqPdPk2b/1/7pX1eeoh80Qsj7nSmz5PbJaxkygfa0IQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -4387,9 +4387,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yaakapp/cli-win32-x64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-win32-x64/-/cli-win32-x64-0.4.0.tgz",
|
||||
"integrity": "sha512-wansfrCCycFcFclowQQxfsNLIAyATyqnnbITED5gUfUrBf8NFHrG0sWVCWlXUhHU7YvpmqL7CsdtlMkIGiZCPQ==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/cli-win32-x64/-/cli-win32-x64-0.5.1.tgz",
|
||||
"integrity": "sha512-Mx/LelqQ7X8Fz9og3qOauuU8kemqja5kQzVQ0pHDJhb9bbmhXUK4dSBYTLdkW3a/X+ofo3K5Z/PkS7FMyXxwdA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.13",
|
||||
"@tauri-apps/cli": "^2.9.6",
|
||||
"@yaakapp/cli": "^0.4.0",
|
||||
"@yaakapp/cli": "^0.5.1",
|
||||
"dotenv-cli": "^11.0.0",
|
||||
"husky": "^9.1.7",
|
||||
"nodejs-file-downloader": "^4.13.0",
|
||||
|
||||
@@ -13,12 +13,16 @@ describe('template-function-faker', () => {
|
||||
it('renders date results as unquoted ISO strings', async () => {
|
||||
const { plugin } = await import('../src/index');
|
||||
const fn = plugin.templateFunctions?.find((fn) => fn.name === 'faker.date.future');
|
||||
const onRender = fn?.onRender;
|
||||
|
||||
expect(fn?.onRender).toBeTypeOf('function');
|
||||
expect(onRender).toBeTypeOf('function');
|
||||
if (onRender == null) {
|
||||
throw new Error("Expected template function 'faker.date.future' to define onRender");
|
||||
}
|
||||
|
||||
const result = await fn!.onRender!(
|
||||
{} as Parameters<NonNullable<typeof fn.onRender>>[0],
|
||||
{ values: {} } as Parameters<NonNullable<typeof fn.onRender>>[1],
|
||||
const result = await onRender(
|
||||
{} as Parameters<typeof onRender>[0],
|
||||
{ values: {} } as Parameters<typeof onRender>[1],
|
||||
);
|
||||
|
||||
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
|
||||
|
||||
@@ -206,7 +206,10 @@ export const plugin: PluginDefinition = {
|
||||
// Create snippet generator
|
||||
const snippet = new HTTPSnippet(harRequest);
|
||||
const generateSnippet = (target: string, client: string): string => {
|
||||
const result = snippet.convert(target as any, client);
|
||||
const result = snippet.convert(
|
||||
target as Parameters<typeof snippet.convert>[0],
|
||||
client as Parameters<typeof snippet.convert>[1],
|
||||
);
|
||||
return (Array.isArray(result) ? result.join('\n') : result || '').replace(/\r\n/g, '\n');
|
||||
};
|
||||
|
||||
|
||||
@@ -82,7 +82,9 @@ function splitCommands(rawData: string): string[] {
|
||||
let inDollarQuote = false;
|
||||
|
||||
for (let i = 0; i < joined.length; i++) {
|
||||
const ch = joined[i]!;
|
||||
if (joined[i] === undefined) break; // Make TS happy
|
||||
|
||||
const ch = joined[i];
|
||||
const next = joined[i + 1];
|
||||
|
||||
// Track quoting state to avoid splitting inside quoted strings
|
||||
@@ -121,7 +123,11 @@ function splitCommands(rawData: string): string[] {
|
||||
const inQuote = inSingleQuote || inDoubleQuote || inDollarQuote;
|
||||
|
||||
// Split on ;, newline, or CRLF when not inside quotes and not escaped
|
||||
if (!inQuote && !isEscaped(i) && (ch === ';' || ch === '\n' || (ch === '\r' && next === '\n'))) {
|
||||
if (
|
||||
!inQuote &&
|
||||
!isEscaped(i) &&
|
||||
(ch === ';' || ch === '\n' || (ch === '\r' && next === '\n'))
|
||||
) {
|
||||
if (ch === '\r') i++; // Skip the \n in \r\n
|
||||
if (current.trim()) {
|
||||
commands.push(current.trim());
|
||||
|
||||
@@ -32,6 +32,8 @@ import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
||||
import { useScrollIntoView } from '../hooks/useScrollIntoView';
|
||||
import { useSendAnyHttpRequest } from '../hooks/useSendAnyHttpRequest';
|
||||
import { useSidebarHidden } from '../hooks/useSidebarHidden';
|
||||
import { appInfo } from '../lib/appInfo';
|
||||
import { copyToClipboard } from '../lib/copy';
|
||||
import { createRequestAndNavigate } from '../lib/createRequestAndNavigate';
|
||||
import { deleteModelWithConfirm } from '../lib/deleteModelWithConfirm';
|
||||
import { showDialog } from '../lib/dialog';
|
||||
@@ -162,6 +164,14 @@ export function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
|
||||
label: 'Send Request',
|
||||
onSelect: () => sendRequest(activeRequest.id),
|
||||
});
|
||||
if (appInfo.cliVersion != null) {
|
||||
commands.push({
|
||||
key: 'request.copy_cli_send',
|
||||
searchText: `copy cli send yaak request send ${activeRequest.id}`,
|
||||
label: 'Copy CLI Send Command',
|
||||
onSelect: () => copyToClipboard(`yaak request send ${activeRequest.id}`),
|
||||
});
|
||||
}
|
||||
httpRequestActions.forEach((a, i) => {
|
||||
commands.push({
|
||||
key: `http_request_action.${i}`,
|
||||
|
||||
@@ -8,7 +8,6 @@ import { useHttpResponseEvents } from '../hooks/useHttpResponseEvents';
|
||||
import { Editor } from './core/Editor/LazyEditor';
|
||||
import { type EventDetailAction, EventDetailHeader, EventViewer } from './core/EventViewer';
|
||||
import { EventViewerRow } from './core/EventViewerRow';
|
||||
import { HttpMethodTagRaw } from './core/HttpMethodTag';
|
||||
import { HttpStatusTagRaw } from './core/HttpStatusTag';
|
||||
import { Icon, type IconProps } from './core/Icon';
|
||||
import { KeyValueRow, KeyValueRows } from './core/KeyValueRow';
|
||||
|
||||
@@ -4,6 +4,7 @@ import { invokeCmd } from './tauri';
|
||||
export interface AppInfo {
|
||||
isDev: boolean;
|
||||
version: string;
|
||||
cliVersion: string | null;
|
||||
name: string;
|
||||
appDataDir: string;
|
||||
appLogDir: string;
|
||||
|
||||
Reference in New Issue
Block a user