UNPKG

@gsb-core/core

Version:

GSB core services and classes for platform-independent web applications

66 lines (55 loc) 2.37 kB
const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); async function runPublish() { let isRestored = false; try { console.log('🚀 Starting publish process...'); // Step 1: Prepare files for publishing console.log('📝 Preparing files for publishing...'); execSync('node prepare-publish.js', { stdio: 'inherit' }); // Step 2: Version bump (with better error handling) console.log('📈 Attempting to bump version...'); try { execSync('npm version patch', { stdio: 'inherit' }); } catch (versionError) { console.log('⚠️ Version bump failed. Common causes:'); console.log(' - Uncommitted changes in git'); console.log(' - Not in a git repository'); console.log(' - Git user not configured'); console.log(''); console.log('🔄 Continuing with current version...'); // Check if we should continue or abort const shouldContinue = process.argv.includes('--skip-version') || process.env.SKIP_VERSION === 'true'; if (!shouldContinue) { console.log('💡 To skip version bump, run: npm run publish -- --skip-version'); console.log(' Or set environment variable: SKIP_VERSION=true npm run publish'); throw new Error('Version bump failed. Use --skip-version to continue without version bump.'); } } // Step 3: Publish console.log('📦 Publishing to npm...'); execSync('npm publish', { stdio: 'inherit' }); console.log('✅ Publish completed successfully!'); } catch (error) { console.error('❌ Error during publish process:', error.message); console.log('🔄 Restoring original files...'); } finally { // Always restore the original files, regardless of success or failure try { execSync('node restore-package.js', { stdio: 'inherit' }); isRestored = true; console.log('✅ Files restored successfully'); } catch (restoreError) { console.error('❌ Failed to restore files:', restoreError.message); console.log('⚠️ You may need to manually restore from backups:'); console.log(' - package.json.backup'); console.log(' - tsconfig.json.backup'); } } if (!isRestored) { process.exit(1); } } runPublish();