tdpw
Version:
CLI tool for uploading Playwright test reports to TestDino platform with Azure storage support
68 lines (59 loc) • 2.19 kB
JavaScript
/**
* TDP CLI Executable Entry Point
* Production-ready binary for tdpw package
*/
const path = require('path');
const fs = require('fs');
// Check Node.js version requirement
const nodeVersion = process.version;
const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0], 10);
if (majorVersion < 18) {
console.error('❌ TDP CLI requires Node.js 18 or higher.');
console.error(` Current version: ${nodeVersion}`);
console.error(' Please upgrade Node.js: https://nodejs.org/');
process.exit(1);
}
// Determine if we're running from source or compiled
const packageRoot = path.join(__dirname, '..');
const isCompiled = fs.existsSync(path.join(packageRoot, 'dist'));
const entryPoint = isCompiled
? path.join(packageRoot, 'dist', 'cli', 'index.js')
: path.join(packageRoot, 'src', 'cli', 'index.ts');
// Check if the entry point exists
if (!fs.existsSync(entryPoint)) {
console.error('❌ TDP CLI entry point not found.');
console.error('💡 This might be a corrupted installation.');
console.error(' Try reinstalling: npm install -g tdpw');
process.exit(1);
}
// For TypeScript source execution (development)
if (!isCompiled && entryPoint.endsWith('.ts')) {
try {
// Try to use tsx for TypeScript execution
require('tsx/cjs').register();
require(entryPoint);
} catch (error) {
console.error('❌ Failed to execute TypeScript source.');
console.error('💡 Please run "npm run build" first or install tsx globally.');
console.error(` Error: ${error.message}`);
process.exit(1);
}
} else {
// Execute compiled JavaScript
try {
require(entryPoint);
} catch (error) {
console.error('❌ Failed to execute TDP CLI.');
// Provide helpful error messages for common issues
if (error.code === 'MODULE_NOT_FOUND') {
console.error('💡 Missing dependencies. Try reinstalling:');
console.error(' npm install -g tdpw');
} else if (error.message.includes('permission')) {
console.error('💡 Permission denied. Try running with appropriate permissions.');
} else {
console.error(` Error: ${error.message}`);
}
process.exit(1);
}
}