mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 12:21:20 +00:00
fix(core): add VERSION file handling and comprehensive test coverage
This commit fixes version management and argument parsing issues across both Windows and Linux/macOS platforms, achieving 100% test coverage. Changes: - Add VERSION file installation to both installers (install.sh, install.ps1) - Fix version/help command detection when using 'powershell -File' syntax - Rename PowerShell param from $Profile to $ProfileOrFlag for clarity - Add $FirstArg detection to check both ProfileOrFlag and RemainingArgs - Create comprehensive edge case test suites for both platforms: * tests/edge-cases.ps1 - 31 tests for Windows (100% pass) * tests/edge-cases.sh - 37 tests for Linux/macOS (100% pass) - Fix multiline regex matching in tests for error messages - Update test expectations to match platform-specific behavior - Reorganize project structure: * Move installers to installers/ directory * Add scripts/ directory for version management * Add config/ directory for configuration templates * Add docs/ directory for documentation Test Results: - Windows (PowerShell): 31/31 tests passing (100%) - Linux/macOS (Bash): 37/37 tests passing (100%) Breaking Changes: None - Installers moved but GitHub URLs updated in README files - All existing functionality preserved Co-authored-by: Claude Code <claude@anthropic.com>
This commit is contained in:
co-authored by
Claude Code
parent
7bd2e9e4ba
commit
e9eb215d1f
@@ -0,0 +1,46 @@
|
||||
export default {
|
||||
async fetch(request) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
// Detect platform from User-Agent header
|
||||
const userAgent = request.headers.get('user-agent') || '';
|
||||
const isWindows = userAgent.includes('Windows') || userAgent.includes('Win32');
|
||||
const isPowerShell = userAgent.includes('PowerShell') || userAgent.includes('pwsh');
|
||||
|
||||
// Smart routing with platform detection
|
||||
let filePath;
|
||||
if (url.pathname === '/install' || url.pathname === '/install.sh') {
|
||||
filePath = (isWindows && isPowerShell) ? 'installers/install.ps1' : 'installers/install.sh';
|
||||
} else if (url.pathname === '/install.ps1') {
|
||||
filePath = 'installers/install.ps1';
|
||||
} else if (url.pathname === '/uninstall' || url.pathname === '/uninstall.sh') {
|
||||
filePath = (isWindows && isPowerShell) ? 'installers/uninstall.ps1' : 'installers/uninstall.sh';
|
||||
} else if (url.pathname === '/uninstall.ps1') {
|
||||
filePath = 'installers/uninstall.ps1';
|
||||
} else {
|
||||
return new Response('Not Found', { status: 404 });
|
||||
}
|
||||
|
||||
try {
|
||||
const githubUrl = `https://raw.githubusercontent.com/kaitranntt/ccs/main/${filePath}`;
|
||||
const response = await fetch(githubUrl);
|
||||
|
||||
if (!response.ok) {
|
||||
return new Response('File not found on GitHub', { status: 404 });
|
||||
}
|
||||
|
||||
const contentType = filePath.endsWith('.ps1')
|
||||
? 'text/plain; charset=utf-8'
|
||||
: 'text/x-shellscript; charset=utf-8';
|
||||
|
||||
return new Response(response.body, {
|
||||
headers: {
|
||||
'Content-Type': contentType,
|
||||
'Cache-Control': 'public, max-age=300'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
return new Response('Server Error', { status: 500 });
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user