pipeline {
    agent any

    environment {
        NODE_VERSION = '22'
        PNPM_VERSION = '10'
    }

    stages {
        stage('Install') {
            steps {
                sh '''
                    if ! command -v pnpm &> /dev/null; then
                        npm install -g pnpm@${PNPM_VERSION}
                    fi
                    pnpm install --frozen-lockfile
                '''
            }
        }

        stage('Lint') {
            steps {
                sh 'pnpm run lint || true'
            }
        }

        stage('Build') {
            steps {
                sh 'pnpm run build:antd'
            }
        }

        stage('Archive') {
            steps {
                archiveArtifacts artifacts: 'apps/web-antd/dist/**', allowEmptyArchive: true, fingerprint: true
            }
        }
    }

    post {
        success {
            echo 'Frontend build succeeded!'
        }
        failure {
            echo 'Frontend build failed!'
        }
        always {
            cleanWs()
        }
    }
}
