diff --git a/Jenkinsfile b/Jenkinsfile index 8771de4..8e59a90 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,14 +3,12 @@ pipeline { parameters { string(name: 'VERSION', defaultValue: '', description: '发布版本号(留空使用 package.json 中的 version)') - booleanParam(name: 'RUN_TESTS', defaultValue: true, description: '是否运行测试') booleanParam(name: 'PUBLISH', defaultValue: true, description: '是否发布到 Nexus npm 仓库') } environment { NEXUS_REGISTRY = 'https://nexus.xuqinmin.com/repository/npm-hosted/' - GIT_URL = 'https://xuqinmin.com/xuqinmin12/XuqmGroup-H5SDK.git' - NODE_VERSION = '22' + GIT_URL = 'https://xuqinmin.com/xuqmGroup/XuqmGroup-H5SDK.git' } options { @@ -33,18 +31,15 @@ pipeline { if (params.VERSION?.trim()) { sh "npm version ${params.VERSION} --no-git-tag-version" } - env.PUBLISH_VERSION = sh(script: 'node -p "require(\"./package.json\").version"', returnStdout: true).trim() + env.PUBLISH_VERSION = sh(script: 'node -p "require(\'./package.json\').version"', returnStdout: true).trim() } } } stage('Build Info') { steps { - script { - echo "🚀 构建分支: ${params.BRANCH}" - echo "🏷️ 发布版本: ${env.PUBLISH_VERSION}" - echo "🔨 Git Commit: ${env.GIT_COMMIT_SHORT}" - } + echo "发布版本: ${env.PUBLISH_VERSION}" + echo "Git Commit: ${env.GIT_COMMIT_SHORT}" } } @@ -71,30 +66,50 @@ pipeline { expression { return params.PUBLISH } } steps { - withCredentials([usernamePassword(credentialsId: 'nexus-npm-credentials', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) { + withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) { sh """ echo "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=\$(echo -n '\${NPM_USER}:\${NPM_PASS}' | base64)" > .npmrc npm publish --registry ${NEXUS_REGISTRY} """ } } + post { + always { + sh 'rm -f .npmrc 2>/dev/null || true' + } + } + } + + stage('Publish Private SDK to Nexus') { + when { + expression { return params.PUBLISH } + } + steps { + withCredentials([usernamePassword(credentialsId: 'NEXUS_CREDS', passwordVariable: 'NPM_PASS', usernameVariable: 'NPM_USER')]) { + sh """ + echo "//nexus.xuqinmin.com/repository/npm-hosted/:_auth=\$(echo -n '\${NPM_USER}:\${NPM_PASS}' | base64)" > .npmrc + cp package.json package.json.bak + cp package.private.json package.json + npm publish --registry ${NEXUS_REGISTRY} + mv package.json.bak package.json + """ + } + } + post { + always { + sh 'rm -f .npmrc 2>/dev/null || true' + sh 'if [ -f package.json.bak ]; then mv package.json.bak package.json; fi' + } + } } } post { success { - script { - echo "✅ H5 SDK v${env.PUBLISH_VERSION} 构建成功 (Commit: ${env.GIT_COMMIT_SHORT})" - if (params.PUBLISH) { - echo "📦 已发布到 Nexus npm 仓库: ${NEXUS_REGISTRY}" - } - } + echo "H5 SDK v${env.PUBLISH_VERSION} 构建成功 (Commit: ${env.GIT_COMMIT_SHORT})" } failure { - echo "❌ H5 SDK 构建失败,请检查日志" - } - always { - sh 'rm -f .npmrc 2>/dev/null || true' + echo "H5 SDK 构建失败,请检查日志" } } } diff --git a/package.private.json b/package.private.json new file mode 100644 index 0000000..d66ea78 --- /dev/null +++ b/package.private.json @@ -0,0 +1,22 @@ +{ + "name": "@xuqm-private/h5-sdk", + "version": "0.2.0", + "description": "XuqmGroup H5 Private SDK — for private deployment environments", + "private": false, + "publishConfig": { + "registry": "https://nexus.xuqinmin.com/repository/npm-hosted/" + }, + "main": "dist/private/index.umd.js", + "module": "dist/private/index.es.js", + "types": "dist/private/index.d.ts", + "exports": { + ".": { + "types": "./dist/private/index.d.ts", + "import": "./dist/private/index.es.js", + "require": "./dist/private/index.umd.js" + } + }, + "files": [ + "dist/private" + ] +}