feat: Add workflow dashboard template and utility functions

- Implemented a new HTML template for the workflow dashboard, featuring a responsive design with dark/light theme support, session statistics, and task management UI.
- Created a browser launcher utility to open HTML files in the default browser across platforms.
- Developed file utility functions for safe reading and writing of JSON and text files.
- Added path resolver utilities to validate and resolve file paths, ensuring security against path traversal attacks.
- Introduced UI utilities for displaying styled messages and banners in the console.
This commit is contained in:
catlog22
2025-12-04 09:40:12 +08:00
parent 0f9adc59f9
commit 35bd0aa8f6
22 changed files with 8272 additions and 24 deletions

View File

@@ -0,0 +1,49 @@
import open from 'open';
import { platform } from 'os';
import { resolve } from 'path';
/**
* Launch a file in the default browser
* Cross-platform compatible (Windows/macOS/Linux)
* @param {string} filePath - Path to HTML file
* @returns {Promise<void>}
*/
export async function launchBrowser(filePath) {
const absolutePath = resolve(filePath);
// Construct file:// URL based on platform
let url;
if (platform() === 'win32') {
// Windows: file:///C:/path/to/file.html
url = `file:///${absolutePath.replace(/\\/g, '/')}`;
} else {
// Unix: file:///path/to/file.html
url = `file://${absolutePath}`;
}
try {
// Use the 'open' package which handles cross-platform browser launching
await open(url);
} catch (error) {
// Fallback: try opening the file path directly
try {
await open(absolutePath);
} catch (fallbackError) {
throw new Error(`Failed to open browser: ${error.message}`);
}
}
}
/**
* Check if we're running in a headless/CI environment
* @returns {boolean}
*/
export function isHeadlessEnvironment() {
return !!(
process.env.CI ||
process.env.CONTINUOUS_INTEGRATION ||
process.env.GITHUB_ACTIONS ||
process.env.GITLAB_CI ||
process.env.JENKINS_URL
);
}