diff --git a/ecom-deploy/.gitignore b/ecom-deploy/.gitignore new file mode 100644 index 00000000..b6d65023 --- /dev/null +++ b/ecom-deploy/.gitignore @@ -0,0 +1,18 @@ +node_modules/ +dist/ +*.tsbuildinfo + +.env +.env.* + +# 部署配置(含服务器地址、凭据) +config.json + +logs/ +*.log +pnpm-debug.log* + +.DS_Store +.idea/ +.vscode/ +*.swp diff --git a/ecom-deploy/config.example.json b/ecom-deploy/config.example.json new file mode 100644 index 00000000..944d2ec1 --- /dev/null +++ b/ecom-deploy/config.example.json @@ -0,0 +1,65 @@ +{ + "currentEnv": "test", + "services": { + "frontend": { + "test": { + "server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/var/www/ecom-frontend", "authType": "password" }, + "port": 80, + "extractDir": "/var/www/ecom-frontend" + }, + "pre": { + "server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/var/www/ecom-frontend", "authType": "password" }, + "port": 80, + "extractDir": "/var/www/ecom-frontend" + }, + "production": { + "server": { "host": "frontend.prod.com", "port": 22, "username": "root", "deployPath": "/var/www/ecom-frontend", "authType": "password" }, + "port": 80, + "extractDir": "/var/www/ecom-frontend" + } + }, + "backend": { + "test": { + "server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-backend", "authType": "password" }, + "port": 8080, + "springProfile": "test", + "dbUrl": "", + "redisUrl": "" + }, + "pre": { + "server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-backend", "authType": "password" }, + "port": 8080, + "springProfile": "staging", + "dbUrl": "", + "redisUrl": "" + }, + "production": { + "server": { "host": "backend.prod.com", "port": 22, "username": "root", "deployPath": "/opt/ecom-backend", "authType": "password" }, + "port": 8080, + "springProfile": "prod", + "dbUrl": "", + "redisUrl": "" + } + }, + "license": { + "test": { + "server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-license", "authType": "password" }, + "port": 3100, + "nodeEnv": "test", + "licenseDbUrl": "" + }, + "pre": { + "server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-license", "authType": "password" }, + "port": 3100, + "nodeEnv": "pre", + "licenseDbUrl": "" + }, + "production": { + "server": { "host": "license.prod.com", "port": 22, "username": "root", "deployPath": "/opt/ecom-license", "authType": "password" }, + "port": 3100, + "nodeEnv": "production", + "licenseDbUrl": "" + } + } + } +} diff --git a/ecom-deploy/package.json b/ecom-deploy/package.json new file mode 100644 index 00000000..a23c7559 --- /dev/null +++ b/ecom-deploy/package.json @@ -0,0 +1,32 @@ +{ + "name": "ecom-deploy", + "version": "0.1.0", + "private": true, + "type": "module", + "pnpm": { + "onlyBuiltDependencies": [ + "cpu-features", + "esbuild", + "ssh2" + ] + }, + "scripts": { + "dev": "tsx src/index.ts", + "build": "tsc", + "start": "node dist/index.js" + }, + "dependencies": { + "@inquirer/prompts": "^7.2.0", + "boxen": "^8.0.1", + "chalk": "^5.4.1", + "gradient-string": "^3.0.0", + "ora": "^8.1.1", + "ssh2": "^1.16.0" + }, + "devDependencies": { + "@types/node": "^22.10.2", + "@types/ssh2": "^1.15.1", + "tsx": "^4.19.2", + "typescript": "^5.7.2" + } +} diff --git a/ecom-deploy/pnpm-lock.yaml b/ecom-deploy/pnpm-lock.yaml new file mode 100644 index 00000000..f8d6c4ad --- /dev/null +++ b/ecom-deploy/pnpm-lock.yaml @@ -0,0 +1,1009 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@inquirer/prompts': + specifier: ^7.2.0 + version: 7.10.1(@types/node@22.20.0) + boxen: + specifier: ^8.0.1 + version: 8.0.1 + chalk: + specifier: ^5.4.1 + version: 5.6.2 + gradient-string: + specifier: ^3.0.0 + version: 3.0.0 + ora: + specifier: ^8.1.1 + version: 8.2.0 + ssh2: + specifier: ^1.16.0 + version: 1.17.0 + devDependencies: + '@types/node': + specifier: ^22.10.2 + version: 22.20.0 + '@types/ssh2': + specifier: ^1.15.1 + version: 1.15.5 + tsx: + specifier: ^4.19.2 + version: 4.23.0 + typescript: + specifier: ^5.7.2 + version: 5.9.3 + +packages: + + '@esbuild/aix-ppc64@0.28.1': + resolution: {integrity: sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [aix] + + '@esbuild/android-arm64@0.28.1': + resolution: {integrity: sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==} + engines: {node: '>=18'} + cpu: [arm64] + os: [android] + + '@esbuild/android-arm@0.28.1': + resolution: {integrity: sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==} + engines: {node: '>=18'} + cpu: [arm] + os: [android] + + '@esbuild/android-x64@0.28.1': + resolution: {integrity: sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==} + engines: {node: '>=18'} + cpu: [x64] + os: [android] + + '@esbuild/darwin-arm64@0.28.1': + resolution: {integrity: sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==} + engines: {node: '>=18'} + cpu: [arm64] + os: [darwin] + + '@esbuild/darwin-x64@0.28.1': + resolution: {integrity: sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==} + engines: {node: '>=18'} + cpu: [x64] + os: [darwin] + + '@esbuild/freebsd-arm64@0.28.1': + resolution: {integrity: sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [freebsd] + + '@esbuild/freebsd-x64@0.28.1': + resolution: {integrity: sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==} + engines: {node: '>=18'} + cpu: [x64] + os: [freebsd] + + '@esbuild/linux-arm64@0.28.1': + resolution: {integrity: sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==} + engines: {node: '>=18'} + cpu: [arm64] + os: [linux] + + '@esbuild/linux-arm@0.28.1': + resolution: {integrity: sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==} + engines: {node: '>=18'} + cpu: [arm] + os: [linux] + + '@esbuild/linux-ia32@0.28.1': + resolution: {integrity: sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==} + engines: {node: '>=18'} + cpu: [ia32] + os: [linux] + + '@esbuild/linux-loong64@0.28.1': + resolution: {integrity: sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==} + engines: {node: '>=18'} + cpu: [loong64] + os: [linux] + + '@esbuild/linux-mips64el@0.28.1': + resolution: {integrity: sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==} + engines: {node: '>=18'} + cpu: [mips64el] + os: [linux] + + '@esbuild/linux-ppc64@0.28.1': + resolution: {integrity: sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [linux] + + '@esbuild/linux-riscv64@0.28.1': + resolution: {integrity: sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==} + engines: {node: '>=18'} + cpu: [riscv64] + os: [linux] + + '@esbuild/linux-s390x@0.28.1': + resolution: {integrity: sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==} + engines: {node: '>=18'} + cpu: [s390x] + os: [linux] + + '@esbuild/linux-x64@0.28.1': + resolution: {integrity: sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==} + engines: {node: '>=18'} + cpu: [x64] + os: [linux] + + '@esbuild/netbsd-arm64@0.28.1': + resolution: {integrity: sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [netbsd] + + '@esbuild/netbsd-x64@0.28.1': + resolution: {integrity: sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==} + engines: {node: '>=18'} + cpu: [x64] + os: [netbsd] + + '@esbuild/openbsd-arm64@0.28.1': + resolution: {integrity: sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openbsd] + + '@esbuild/openbsd-x64@0.28.1': + resolution: {integrity: sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==} + engines: {node: '>=18'} + cpu: [x64] + os: [openbsd] + + '@esbuild/openharmony-arm64@0.28.1': + resolution: {integrity: sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openharmony] + + '@esbuild/sunos-x64@0.28.1': + resolution: {integrity: sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==} + engines: {node: '>=18'} + cpu: [x64] + os: [sunos] + + '@esbuild/win32-arm64@0.28.1': + resolution: {integrity: sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==} + engines: {node: '>=18'} + cpu: [arm64] + os: [win32] + + '@esbuild/win32-ia32@0.28.1': + resolution: {integrity: sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==} + engines: {node: '>=18'} + cpu: [ia32] + os: [win32] + + '@esbuild/win32-x64@0.28.1': + resolution: {integrity: sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==} + engines: {node: '>=18'} + cpu: [x64] + os: [win32] + + '@inquirer/ansi@1.0.2': + resolution: {integrity: sha512-S8qNSZiYzFd0wAcyG5AXCvUHC5Sr7xpZ9wZ2py9XR88jUz8wooStVx5M6dRzczbBWjic9NP7+rY0Xi7qqK/aMQ==} + engines: {node: '>=18'} + + '@inquirer/checkbox@4.3.2': + resolution: {integrity: sha512-VXukHf0RR1doGe6Sm4F0Em7SWYLTHSsbGfJdS9Ja2bX5/D5uwVOEjr07cncLROdBvmnvCATYEWlHqYmXv2IlQA==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/confirm@5.1.21': + resolution: {integrity: sha512-KR8edRkIsUayMXV+o3Gv+q4jlhENF9nMYUZs9PA2HzrXeHI8M5uDag70U7RJn9yyiMZSbtF5/UexBtAVtZGSbQ==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/core@10.3.2': + resolution: {integrity: sha512-43RTuEbfP8MbKzedNqBrlhhNKVwoK//vUFNW3Q3vZ88BLcrs4kYpGg+B2mm5p2K/HfygoCxuKwJJiv8PbGmE0A==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/editor@4.2.23': + resolution: {integrity: sha512-aLSROkEwirotxZ1pBaP8tugXRFCxW94gwrQLxXfrZsKkfjOYC1aRvAZuhpJOb5cu4IBTJdsCigUlf2iCOu4ZDQ==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/expand@4.0.23': + resolution: {integrity: sha512-nRzdOyFYnpeYTTR2qFwEVmIWypzdAx/sIkCMeTNTcflFOovfqUk+HcFhQQVBftAh9gmGrpFj6QcGEqrDMDOiew==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/external-editor@1.0.3': + resolution: {integrity: sha512-RWbSrDiYmO4LbejWY7ttpxczuwQyZLBUyygsA9Nsv95hpzUWwnNTVQmAq3xuh7vNwCp07UTmE5i11XAEExx4RA==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/figures@1.0.15': + resolution: {integrity: sha512-t2IEY+unGHOzAaVM5Xx6DEWKeXlDDcNPeDyUpsRc6CUhBfU3VQOEl+Vssh7VNp1dR8MdUJBWhuObjXCsVpjN5g==} + engines: {node: '>=18'} + + '@inquirer/input@4.3.1': + resolution: {integrity: sha512-kN0pAM4yPrLjJ1XJBjDxyfDduXOuQHrBB8aLDMueuwUGn+vNpF7Gq7TvyVxx8u4SHlFFj4trmj+a2cbpG4Jn1g==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/number@3.0.23': + resolution: {integrity: sha512-5Smv0OK7K0KUzUfYUXDXQc9jrf8OHo4ktlEayFlelCjwMXz0299Y8OrI+lj7i4gCBY15UObk76q0QtxjzFcFcg==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/password@4.0.23': + resolution: {integrity: sha512-zREJHjhT5vJBMZX/IUbyI9zVtVfOLiTO66MrF/3GFZYZ7T4YILW5MSkEYHceSii/KtRk+4i3RE7E1CUXA2jHcA==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/prompts@7.10.1': + resolution: {integrity: sha512-Dx/y9bCQcXLI5ooQ5KyvA4FTgeo2jYj/7plWfV5Ak5wDPKQZgudKez2ixyfz7tKXzcJciTxqLeK7R9HItwiByg==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/rawlist@4.1.11': + resolution: {integrity: sha512-+LLQB8XGr3I5LZN/GuAHo+GpDJegQwuPARLChlMICNdwW7OwV2izlCSCxN6cqpL0sMXmbKbFcItJgdQq5EBXTw==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/search@3.2.2': + resolution: {integrity: sha512-p2bvRfENXCZdWF/U2BXvnSI9h+tuA8iNqtUKb9UWbmLYCRQxd8WkvwWvYn+3NgYaNwdUkHytJMGG4MMLucI1kA==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/select@4.4.2': + resolution: {integrity: sha512-l4xMuJo55MAe+N7Qr4rX90vypFwCajSakx59qe/tMaC1aEHWLyw68wF4o0A4SLAY4E0nd+Vt+EyskeDIqu1M6w==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@inquirer/type@3.0.10': + resolution: {integrity: sha512-BvziSRxfz5Ov8ch0z/n3oijRSEcEsHnhggm4xFZe93DHcUCTlutlq9Ox4SVENAfcRD22UQq7T/atg9Wr3k09eA==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + + '@types/node@18.19.130': + resolution: {integrity: sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg==} + + '@types/node@22.20.0': + resolution: {integrity: sha512-QWlFW2wf3nTjC13/DqRnBpR4ZO36VJH/JVBkA/vcnmbTBNQIlnObqyqZE1tUR7+Ni23Lda8R1BxMfbXRpCUx5g==} + + '@types/ssh2@1.15.5': + resolution: {integrity: sha512-N1ASjp/nXH3ovBHddRJpli4ozpk6UdDYIX4RJWFa9L1YKnzdhTlVmiGHm4DZnj/jLbqZpes4aeR30EFGQtvhQQ==} + + '@types/tinycolor2@1.4.6': + resolution: {integrity: sha512-iEN8J0BoMnsWBqjVbWH/c0G0Hh7O21lpR2/+PrvAVgWdzL7eexIFm4JN/Wn10PTcmNdtS6U67r499mlWMXOxNw==} + + ansi-align@3.0.1: + resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==} + + ansi-regex@5.0.1: + resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} + engines: {node: '>=8'} + + ansi-regex@6.2.2: + resolution: {integrity: sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==} + engines: {node: '>=12'} + + ansi-styles@4.3.0: + resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} + engines: {node: '>=8'} + + ansi-styles@6.2.3: + resolution: {integrity: sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==} + engines: {node: '>=12'} + + asn1@0.2.6: + resolution: {integrity: sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==} + + bcrypt-pbkdf@1.0.2: + resolution: {integrity: sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==} + + boxen@8.0.1: + resolution: {integrity: sha512-F3PH5k5juxom4xktynS7MoFY+NUWH5LC4CnH11YB8NPew+HLpmBLCybSAEyb2F+4pRXhuhWqFesoQd6DAyc2hw==} + engines: {node: '>=18'} + + buildcheck@0.0.7: + resolution: {integrity: sha512-lHblz4ahamxpTmnsk+MNTRWsjYKv965MwOrSJyeD588rR3Jcu7swE+0wN5F+PbL5cjgu/9ObkhfzEPuofEMwLA==} + engines: {node: '>=10.0.0'} + + camelcase@8.0.0: + resolution: {integrity: sha512-8WB3Jcas3swSvjIeA2yvCJ+Miyz5l1ZmB6HFb9R1317dt9LCQoswg/BGrmAmkWVEszSrrg4RwmO46qIm2OEnSA==} + engines: {node: '>=16'} + + chalk@5.6.2: + resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + + chardet@2.2.0: + resolution: {integrity: sha512-rddelWYNPRrXq6PtNEN2S3f6t9ILzvqaN5pVgi4kqt9jHQaXIial9PznB5iSPVlQSLNaaH22ItWz3EJtQ10+OA==} + + cli-boxes@3.0.0: + resolution: {integrity: sha512-/lzGpEWL/8PfI0BmBOPRwp0c/wFNX1RdUML3jK/RcSBA9T8mZDdQpqYBKtCFTOfQbwPqWEOpjqW+Fnayc0969g==} + engines: {node: '>=10'} + + cli-cursor@5.0.0: + resolution: {integrity: sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==} + engines: {node: '>=18'} + + cli-spinners@2.9.2: + resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==} + engines: {node: '>=6'} + + cli-width@4.1.0: + resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==} + engines: {node: '>= 12'} + + color-convert@2.0.1: + resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} + engines: {node: '>=7.0.0'} + + color-name@1.1.4: + resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + + cpu-features@0.0.10: + resolution: {integrity: sha512-9IkYqtX3YHPCzoVg1Py+o9057a3i0fp7S530UWokCSaFVTc7CwXPRiOjRjBQQ18ZCNafx78YfnG+HALxtVmOGA==} + engines: {node: '>=10.0.0'} + + emoji-regex@10.6.0: + resolution: {integrity: sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A==} + + emoji-regex@8.0.0: + resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + + esbuild@0.28.1: + resolution: {integrity: sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==} + engines: {node: '>=18'} + hasBin: true + + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + + get-east-asian-width@1.6.0: + resolution: {integrity: sha512-QRbvDIbx6YklUe6RxeTeleMR0yv3cYH6PsPZHcnVn7xv7zO1BHN8r0XETu8n6Ye3Q+ahtSarc3WgtNWmehIBfA==} + engines: {node: '>=18'} + + gradient-string@3.0.0: + resolution: {integrity: sha512-frdKI4Qi8Ihp4C6wZNB565de/THpIaw3DjP5ku87M+N9rNSGmPTjfkq61SdRXB7eCaL8O1hkKDvf6CDMtOzIAg==} + engines: {node: '>=14'} + + iconv-lite@0.7.3: + resolution: {integrity: sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==} + engines: {node: '>=0.10.0'} + + is-fullwidth-code-point@3.0.0: + resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} + engines: {node: '>=8'} + + is-interactive@2.0.0: + resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} + engines: {node: '>=12'} + + is-unicode-supported@1.3.0: + resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} + engines: {node: '>=12'} + + is-unicode-supported@2.1.0: + resolution: {integrity: sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==} + engines: {node: '>=18'} + + log-symbols@6.0.0: + resolution: {integrity: sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==} + engines: {node: '>=18'} + + mimic-function@5.0.1: + resolution: {integrity: sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==} + engines: {node: '>=18'} + + mute-stream@2.0.0: + resolution: {integrity: sha512-WWdIxpyjEn+FhQJQQv9aQAYlHoNVdzIzUySNV1gHUPDSdZJ3yZn7pAAbQcV7B56Mvu881q9FZV+0Vx2xC44VWA==} + engines: {node: ^18.17.0 || >=20.5.0} + + nan@2.28.0: + resolution: {integrity: sha512-fTsDz99OTq2sVePhGdp4qQhggZFtKr64ZNVyVajRKtMOkJxYekplBh577PiJB12v/D3s2E5cGtOI45LWp6rnLQ==} + + onetime@7.0.0: + resolution: {integrity: sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==} + engines: {node: '>=18'} + + ora@8.2.0: + resolution: {integrity: sha512-weP+BZ8MVNnlCm8c0Qdc1WSWq4Qn7I+9CJGm7Qali6g44e/PUzbjNqJX5NJ9ljlNMosfJvg1fKEGILklK9cwnw==} + engines: {node: '>=18'} + + restore-cursor@5.1.0: + resolution: {integrity: sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==} + engines: {node: '>=18'} + + safer-buffer@2.1.2: + resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} + + signal-exit@4.1.0: + resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} + engines: {node: '>=14'} + + ssh2@1.17.0: + resolution: {integrity: sha512-wPldCk3asibAjQ/kziWQQt1Wh3PgDFpC0XpwclzKcdT1vql6KeYxf5LIt4nlFkUeR8WuphYMKqUA56X4rjbfgQ==} + engines: {node: '>=10.16.0'} + + stdin-discarder@0.2.2: + resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==} + engines: {node: '>=18'} + + string-width@4.2.3: + resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} + engines: {node: '>=8'} + + string-width@7.2.0: + resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==} + engines: {node: '>=18'} + + strip-ansi@6.0.1: + resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} + engines: {node: '>=8'} + + strip-ansi@7.2.0: + resolution: {integrity: sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==} + engines: {node: '>=12'} + + tinycolor2@1.6.0: + resolution: {integrity: sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==} + + tinygradient@1.1.5: + resolution: {integrity: sha512-8nIfc2vgQ4TeLnk2lFj4tRLvvJwEfQuabdsmvDdQPT0xlk9TaNtpGd6nNRxXoK6vQhN6RSzj+Cnp5tTQmpxmbw==} + + tsx@4.23.0: + resolution: {integrity: sha512-eUdUIaCr963q2h5u3+QwvYp0+eqPvn+egeqZUm0hwERCqqx1E3kK5ehbGCvqSE5MQAULr67ww0cA3jKc3YkM1w==} + engines: {node: '>=18.0.0'} + hasBin: true + + tweetnacl@0.14.5: + resolution: {integrity: sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==} + + type-fest@4.41.0: + resolution: {integrity: sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==} + engines: {node: '>=16'} + + typescript@5.9.3: + resolution: {integrity: sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==} + engines: {node: '>=14.17'} + hasBin: true + + undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + + undici-types@6.21.0: + resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} + + widest-line@5.0.0: + resolution: {integrity: sha512-c9bZp7b5YtRj2wOe6dlj32MK+Bx/M/d+9VB2SHM1OtsUHR0aV0tdP6DWh/iMt0kWi1t5g1Iudu6hQRNd1A4PVA==} + engines: {node: '>=18'} + + wrap-ansi@6.2.0: + resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} + engines: {node: '>=8'} + + wrap-ansi@9.0.2: + resolution: {integrity: sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww==} + engines: {node: '>=18'} + + yoctocolors-cjs@2.1.3: + resolution: {integrity: sha512-U/PBtDf35ff0D8X8D0jfdzHYEPFxAI7jJlxZXwCSez5M3190m+QobIfh+sWDWSHMCWWJN2AWamkegn6vr6YBTw==} + engines: {node: '>=18'} + +snapshots: + + '@esbuild/aix-ppc64@0.28.1': + optional: true + + '@esbuild/android-arm64@0.28.1': + optional: true + + '@esbuild/android-arm@0.28.1': + optional: true + + '@esbuild/android-x64@0.28.1': + optional: true + + '@esbuild/darwin-arm64@0.28.1': + optional: true + + '@esbuild/darwin-x64@0.28.1': + optional: true + + '@esbuild/freebsd-arm64@0.28.1': + optional: true + + '@esbuild/freebsd-x64@0.28.1': + optional: true + + '@esbuild/linux-arm64@0.28.1': + optional: true + + '@esbuild/linux-arm@0.28.1': + optional: true + + '@esbuild/linux-ia32@0.28.1': + optional: true + + '@esbuild/linux-loong64@0.28.1': + optional: true + + '@esbuild/linux-mips64el@0.28.1': + optional: true + + '@esbuild/linux-ppc64@0.28.1': + optional: true + + '@esbuild/linux-riscv64@0.28.1': + optional: true + + '@esbuild/linux-s390x@0.28.1': + optional: true + + '@esbuild/linux-x64@0.28.1': + optional: true + + '@esbuild/netbsd-arm64@0.28.1': + optional: true + + '@esbuild/netbsd-x64@0.28.1': + optional: true + + '@esbuild/openbsd-arm64@0.28.1': + optional: true + + '@esbuild/openbsd-x64@0.28.1': + optional: true + + '@esbuild/openharmony-arm64@0.28.1': + optional: true + + '@esbuild/sunos-x64@0.28.1': + optional: true + + '@esbuild/win32-arm64@0.28.1': + optional: true + + '@esbuild/win32-ia32@0.28.1': + optional: true + + '@esbuild/win32-x64@0.28.1': + optional: true + + '@inquirer/ansi@1.0.2': {} + + '@inquirer/checkbox@4.3.2(@types/node@22.20.0)': + dependencies: + '@inquirer/ansi': 1.0.2 + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/figures': 1.0.15 + '@inquirer/type': 3.0.10(@types/node@22.20.0) + yoctocolors-cjs: 2.1.3 + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/confirm@5.1.21(@types/node@22.20.0)': + dependencies: + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/type': 3.0.10(@types/node@22.20.0) + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/core@10.3.2(@types/node@22.20.0)': + dependencies: + '@inquirer/ansi': 1.0.2 + '@inquirer/figures': 1.0.15 + '@inquirer/type': 3.0.10(@types/node@22.20.0) + cli-width: 4.1.0 + mute-stream: 2.0.0 + signal-exit: 4.1.0 + wrap-ansi: 6.2.0 + yoctocolors-cjs: 2.1.3 + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/editor@4.2.23(@types/node@22.20.0)': + dependencies: + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/external-editor': 1.0.3(@types/node@22.20.0) + '@inquirer/type': 3.0.10(@types/node@22.20.0) + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/expand@4.0.23(@types/node@22.20.0)': + dependencies: + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/type': 3.0.10(@types/node@22.20.0) + yoctocolors-cjs: 2.1.3 + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/external-editor@1.0.3(@types/node@22.20.0)': + dependencies: + chardet: 2.2.0 + iconv-lite: 0.7.3 + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/figures@1.0.15': {} + + '@inquirer/input@4.3.1(@types/node@22.20.0)': + dependencies: + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/type': 3.0.10(@types/node@22.20.0) + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/number@3.0.23(@types/node@22.20.0)': + dependencies: + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/type': 3.0.10(@types/node@22.20.0) + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/password@4.0.23(@types/node@22.20.0)': + dependencies: + '@inquirer/ansi': 1.0.2 + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/type': 3.0.10(@types/node@22.20.0) + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/prompts@7.10.1(@types/node@22.20.0)': + dependencies: + '@inquirer/checkbox': 4.3.2(@types/node@22.20.0) + '@inquirer/confirm': 5.1.21(@types/node@22.20.0) + '@inquirer/editor': 4.2.23(@types/node@22.20.0) + '@inquirer/expand': 4.0.23(@types/node@22.20.0) + '@inquirer/input': 4.3.1(@types/node@22.20.0) + '@inquirer/number': 3.0.23(@types/node@22.20.0) + '@inquirer/password': 4.0.23(@types/node@22.20.0) + '@inquirer/rawlist': 4.1.11(@types/node@22.20.0) + '@inquirer/search': 3.2.2(@types/node@22.20.0) + '@inquirer/select': 4.4.2(@types/node@22.20.0) + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/rawlist@4.1.11(@types/node@22.20.0)': + dependencies: + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/type': 3.0.10(@types/node@22.20.0) + yoctocolors-cjs: 2.1.3 + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/search@3.2.2(@types/node@22.20.0)': + dependencies: + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/figures': 1.0.15 + '@inquirer/type': 3.0.10(@types/node@22.20.0) + yoctocolors-cjs: 2.1.3 + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/select@4.4.2(@types/node@22.20.0)': + dependencies: + '@inquirer/ansi': 1.0.2 + '@inquirer/core': 10.3.2(@types/node@22.20.0) + '@inquirer/figures': 1.0.15 + '@inquirer/type': 3.0.10(@types/node@22.20.0) + yoctocolors-cjs: 2.1.3 + optionalDependencies: + '@types/node': 22.20.0 + + '@inquirer/type@3.0.10(@types/node@22.20.0)': + optionalDependencies: + '@types/node': 22.20.0 + + '@types/node@18.19.130': + dependencies: + undici-types: 5.26.5 + + '@types/node@22.20.0': + dependencies: + undici-types: 6.21.0 + + '@types/ssh2@1.15.5': + dependencies: + '@types/node': 18.19.130 + + '@types/tinycolor2@1.4.6': {} + + ansi-align@3.0.1: + dependencies: + string-width: 4.2.3 + + ansi-regex@5.0.1: {} + + ansi-regex@6.2.2: {} + + ansi-styles@4.3.0: + dependencies: + color-convert: 2.0.1 + + ansi-styles@6.2.3: {} + + asn1@0.2.6: + dependencies: + safer-buffer: 2.1.2 + + bcrypt-pbkdf@1.0.2: + dependencies: + tweetnacl: 0.14.5 + + boxen@8.0.1: + dependencies: + ansi-align: 3.0.1 + camelcase: 8.0.0 + chalk: 5.6.2 + cli-boxes: 3.0.0 + string-width: 7.2.0 + type-fest: 4.41.0 + widest-line: 5.0.0 + wrap-ansi: 9.0.2 + + buildcheck@0.0.7: + optional: true + + camelcase@8.0.0: {} + + chalk@5.6.2: {} + + chardet@2.2.0: {} + + cli-boxes@3.0.0: {} + + cli-cursor@5.0.0: + dependencies: + restore-cursor: 5.1.0 + + cli-spinners@2.9.2: {} + + cli-width@4.1.0: {} + + color-convert@2.0.1: + dependencies: + color-name: 1.1.4 + + color-name@1.1.4: {} + + cpu-features@0.0.10: + dependencies: + buildcheck: 0.0.7 + nan: 2.28.0 + optional: true + + emoji-regex@10.6.0: {} + + emoji-regex@8.0.0: {} + + esbuild@0.28.1: + optionalDependencies: + '@esbuild/aix-ppc64': 0.28.1 + '@esbuild/android-arm': 0.28.1 + '@esbuild/android-arm64': 0.28.1 + '@esbuild/android-x64': 0.28.1 + '@esbuild/darwin-arm64': 0.28.1 + '@esbuild/darwin-x64': 0.28.1 + '@esbuild/freebsd-arm64': 0.28.1 + '@esbuild/freebsd-x64': 0.28.1 + '@esbuild/linux-arm': 0.28.1 + '@esbuild/linux-arm64': 0.28.1 + '@esbuild/linux-ia32': 0.28.1 + '@esbuild/linux-loong64': 0.28.1 + '@esbuild/linux-mips64el': 0.28.1 + '@esbuild/linux-ppc64': 0.28.1 + '@esbuild/linux-riscv64': 0.28.1 + '@esbuild/linux-s390x': 0.28.1 + '@esbuild/linux-x64': 0.28.1 + '@esbuild/netbsd-arm64': 0.28.1 + '@esbuild/netbsd-x64': 0.28.1 + '@esbuild/openbsd-arm64': 0.28.1 + '@esbuild/openbsd-x64': 0.28.1 + '@esbuild/openharmony-arm64': 0.28.1 + '@esbuild/sunos-x64': 0.28.1 + '@esbuild/win32-arm64': 0.28.1 + '@esbuild/win32-ia32': 0.28.1 + '@esbuild/win32-x64': 0.28.1 + + fsevents@2.3.3: + optional: true + + get-east-asian-width@1.6.0: {} + + gradient-string@3.0.0: + dependencies: + chalk: 5.6.2 + tinygradient: 1.1.5 + + iconv-lite@0.7.3: + dependencies: + safer-buffer: 2.1.2 + + is-fullwidth-code-point@3.0.0: {} + + is-interactive@2.0.0: {} + + is-unicode-supported@1.3.0: {} + + is-unicode-supported@2.1.0: {} + + log-symbols@6.0.0: + dependencies: + chalk: 5.6.2 + is-unicode-supported: 1.3.0 + + mimic-function@5.0.1: {} + + mute-stream@2.0.0: {} + + nan@2.28.0: + optional: true + + onetime@7.0.0: + dependencies: + mimic-function: 5.0.1 + + ora@8.2.0: + dependencies: + chalk: 5.6.2 + cli-cursor: 5.0.0 + cli-spinners: 2.9.2 + is-interactive: 2.0.0 + is-unicode-supported: 2.1.0 + log-symbols: 6.0.0 + stdin-discarder: 0.2.2 + string-width: 7.2.0 + strip-ansi: 7.2.0 + + restore-cursor@5.1.0: + dependencies: + onetime: 7.0.0 + signal-exit: 4.1.0 + + safer-buffer@2.1.2: {} + + signal-exit@4.1.0: {} + + ssh2@1.17.0: + dependencies: + asn1: 0.2.6 + bcrypt-pbkdf: 1.0.2 + optionalDependencies: + cpu-features: 0.0.10 + nan: 2.28.0 + + stdin-discarder@0.2.2: {} + + string-width@4.2.3: + dependencies: + emoji-regex: 8.0.0 + is-fullwidth-code-point: 3.0.0 + strip-ansi: 6.0.1 + + string-width@7.2.0: + dependencies: + emoji-regex: 10.6.0 + get-east-asian-width: 1.6.0 + strip-ansi: 7.2.0 + + strip-ansi@6.0.1: + dependencies: + ansi-regex: 5.0.1 + + strip-ansi@7.2.0: + dependencies: + ansi-regex: 6.2.2 + + tinycolor2@1.6.0: {} + + tinygradient@1.1.5: + dependencies: + '@types/tinycolor2': 1.4.6 + tinycolor2: 1.6.0 + + tsx@4.23.0: + dependencies: + esbuild: 0.28.1 + optionalDependencies: + fsevents: 2.3.3 + + tweetnacl@0.14.5: {} + + type-fest@4.41.0: {} + + typescript@5.9.3: {} + + undici-types@5.26.5: {} + + undici-types@6.21.0: {} + + widest-line@5.0.0: + dependencies: + string-width: 7.2.0 + + wrap-ansi@6.2.0: + dependencies: + ansi-styles: 4.3.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + + wrap-ansi@9.0.2: + dependencies: + ansi-styles: 6.2.3 + string-width: 7.2.0 + strip-ansi: 7.2.0 + + yoctocolors-cjs@2.1.3: {} diff --git a/ecom-deploy/src/config.ts b/ecom-deploy/src/config.ts new file mode 100644 index 00000000..64af7dcb --- /dev/null +++ b/ecom-deploy/src/config.ts @@ -0,0 +1,146 @@ +import { readFile, writeFile } from 'fs/promises'; +import { homedir } from 'os'; +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; + +import type { DeployConfig, Environment, Service, ServiceEnvConfig, ServerConfig } from './types.js'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const CONFIG_PATH = process.env.ECOM_DEPLOY_CONFIG || join(__dirname, '..', 'config.json'); +const SSH_KEY_PATH = join(homedir(), '.ssh', 'ecom-deploy'); + +export function getSshKeyPath(): string { + return SSH_KEY_PATH; +} + +function defaultServiceConfig(host: string, port: number, extractDir?: string): ServiceEnvConfig { + const deployPath = extractDir || '/opt/ecom-dmb'; + return { + server: { host, port: 22, username: 'root', deployPath, authType: 'password' }, + port, + ...(extractDir ? { extractDir } : {}), + }; +} + +function defaultConfig(): DeployConfig { + return { + currentEnv: 'test', + services: { + frontend: { + test: defaultServiceConfig('192.168.1.100', 80, '/var/www/ecom-frontend'), + pre: defaultServiceConfig('192.168.1.101', 80, '/var/www/ecom-frontend'), + production: defaultServiceConfig('frontend.prod.com', 80, '/var/www/ecom-frontend'), + }, + backend: { + test: { ...defaultServiceConfig('192.168.1.100', 8080), springProfile: 'test', dbUrl: '', redisUrl: '' }, + pre: { ...defaultServiceConfig('192.168.1.101', 8080), springProfile: 'pre', dbUrl: '', redisUrl: '' }, + production: { ...defaultServiceConfig('backend.prod.com', 8080), springProfile: 'prod', dbUrl: '', redisUrl: '' }, + }, + license: { + test: { ...defaultServiceConfig('192.168.1.100', 3100), nodeEnv: 'test', licenseDbUrl: '' }, + pre: { ...defaultServiceConfig('192.168.1.101', 3100), nodeEnv: 'pre', licenseDbUrl: '' }, + production: { ...defaultServiceConfig('license.prod.com', 3100), nodeEnv: 'production', licenseDbUrl: '' }, + }, + }, + }; +} + +export async function loadConfig(): Promise { + try { + const raw = await readFile(CONFIG_PATH, 'utf8'); + return JSON.parse(raw) as DeployConfig; + } catch { + const cfg = defaultConfig(); + await saveConfig(cfg); + return cfg; + } +} + +export async function saveConfig(config: DeployConfig): Promise { + await writeFile(CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8'); +} + +export function getServiceConfig(config: DeployConfig, service: Service, env?: Environment): ServiceEnvConfig { + return config.services[service][env || config.currentEnv]; +} + +export async function updateServiceServerConfig( + service: Service, + env: Environment, + updates: Partial, +): Promise { + const config = await loadConfig(); + config.services[service][env].server = { ...config.services[service][env].server, ...updates }; + await saveConfig(config); + return config; +} + +export async function updateServiceEnvConfig( + service: Service, + env: Environment, + updates: Partial, +): Promise { + const config = await loadConfig(); + config.services[service][env] = { ...config.services[service][env], ...updates }; + await saveConfig(config); + return config; +} + +export function getConfigPath(): string { + return CONFIG_PATH; +} + +/** 部署环境 pre 对应 Spring profile staging */ +export function resolveSpringProfile(profile?: string): string { + if (profile === 'pre') return 'staging'; + return profile || 'prod'; +} + +/** 同一 host+username 的服务共享 SSH 密钥配置 */ +export async function syncServerKeyAuth( + host: string, + username: string, + updates: Partial, +): Promise { + const config = await loadConfig(); + for (const service of Object.keys(config.services) as Service[]) { + for (const env of Object.keys(config.services[service]) as Environment[]) { + const srv = config.services[service][env].server; + if (srv.host === host && srv.username === username) { + config.services[service][env].server = { ...srv, ...updates }; + } + } + } + await saveConfig(config); + return config; +} + +const PROJECT_ROOT = join(__dirname, '..', '..'); + +export function getFrontendDir(): string { + return join(PROJECT_ROOT, 'ecom-dmb-frontend'); +} + +export function getBackendDir(): string { + return join(PROJECT_ROOT, 'ecom-dmb-backend'); +} + +export function getLicenseDir(): string { + return join(PROJECT_ROOT, 'ecom-license'); +} + +function getProjectDeployDir(project: string): string { + return join(PROJECT_ROOT, project, 'deploy'); +} + +export function getFrontendDeployDir(): string { + return getProjectDeployDir('ecom-dmb-frontend'); +} + +export function getBackendDeployDir(): string { + return getProjectDeployDir('ecom-dmb-backend'); +} + +export function getLicenseDeployDir(): string { + return getProjectDeployDir('ecom-license'); +} diff --git a/ecom-deploy/src/deploy/backend.ts b/ecom-deploy/src/deploy/backend.ts new file mode 100644 index 00000000..2040dd4d --- /dev/null +++ b/ecom-deploy/src/deploy/backend.ts @@ -0,0 +1,52 @@ +import { execSync } from 'child_process'; +import { writeFileSync, readFileSync, existsSync } from 'fs'; +import { join } from 'path'; + +import { Client } from 'ssh2'; +import { getBackendDir, getBackendDeployDir } from '../config.js'; +import { uploadFile, ensureRemoteDir } from '../ssh.js'; +import { remoteBuildImage } from '../docker.js'; +import { printInfo, printSuccess } from '../ui/render.js'; +import type { Service, ServiceEnvConfig } from '../types.js'; + +export const serviceType: Service = 'backend'; + +export async function build(cfg: ServiceEnvConfig): Promise { + const backendDir = getBackendDir(); + if (!existsSync(backendDir)) throw new Error(`后端项目目录不存在: ${backendDir}`); + + const mvnw = join(backendDir, 'mvnw'); + const mvnCmd = existsSync(mvnw) ? `"${mvnw}"` : 'mvn'; + + printInfo('构建后端 (Maven)...'); + // Spring profile 在容器启动时注入,Maven 构建不使用 -P + execSync(`${mvnCmd} clean package -DskipTests`, { + stdio: 'inherit', cwd: backendDir, + }); + printSuccess('后端构建完成'); + + const jarDir = join(backendDir, 'target'); + if (!existsSync(jarDir)) throw new Error(`构建产物目录不存在: ${jarDir}`); + return jarDir; +} + +export async function deploy(conn: Client, cfg: ServiceEnvConfig, buildDir: string): Promise { + const serviceDir = `${cfg.server.deployPath}/backend`; + await ensureRemoteDir(conn, serviceDir); + + const jars = execSync(`ls "${buildDir}"/*.jar 2>/dev/null`, { encoding: 'utf8' }).trim(); + if (!jars) throw new Error('未找到 JAR 文件'); + + await uploadFile(conn, jars.split('\n')[0], `${serviceDir}/app.jar`); + + const dockerfileSrc = join(getBackendDeployDir(), 'Dockerfile'); + if (!existsSync(dockerfileSrc)) { + printInfo('后端 deploy/Dockerfile 不存在,使用默认模板'); + writeFileSync('/tmp/ecom-backend.Dockerfile', 'FROM eclipse-temurin:17-jre-alpine\nWORKDIR /app\nRUN addgroup -S app && adduser -S app -G app\nCOPY app.jar app.jar\nRUN chown -R app:app /app\nUSER app\nEXPOSE 8080\nENTRYPOINT ["java", "-jar", "app.jar"]\n'); + } else { + writeFileSync('/tmp/ecom-backend.Dockerfile', readFileSync(dockerfileSrc, 'utf8')); + } + await uploadFile(conn, '/tmp/ecom-backend.Dockerfile', `${serviceDir}/Dockerfile`); + + await remoteBuildImage(conn, 'backend', serviceDir); +} diff --git a/ecom-deploy/src/deploy/frontend.ts b/ecom-deploy/src/deploy/frontend.ts new file mode 100644 index 00000000..b9492a7e --- /dev/null +++ b/ecom-deploy/src/deploy/frontend.ts @@ -0,0 +1,58 @@ +import { execSync } from 'child_process'; +import { existsSync } from 'fs'; +import { join } from 'path'; + +import { Client } from 'ssh2'; +import { getFrontendDir } from '../config.js'; +import { execRemote, uploadFile, ensureRemoteDir } from '../ssh.js'; +import { printInfo, printSuccess } from '../ui/render.js'; +import type { Service, ServiceEnvConfig } from '../types.js'; + +export const serviceType: Service = 'frontend'; + +export async function build(): Promise { + const frontendDir = getFrontendDir(); + if (!existsSync(frontendDir)) throw new Error(`前端项目目录不存在: ${frontendDir}`); + + printInfo('构建前端...'); + execSync('pnpm install && pnpm build', { stdio: 'inherit', cwd: frontendDir }); + printSuccess('前端构建完成'); + + const distDir = join(frontendDir, 'apps', 'web-antd', 'dist'); + if (!existsSync(distDir)) throw new Error(`构建产物目录不存在: ${distDir}`); + return distDir; +} + +export async function deploy(conn: Client, cfg: ServiceEnvConfig, buildDir: string): Promise { + if (cfg.extractDir) { + await ensureRemoteDir(conn, cfg.extractDir); + + const tmpTar = '/tmp/ecom-frontend-build.tar.gz'; + try { + execSync(`tar -czf "${tmpTar}" -C "${buildDir}" .`, { stdio: 'pipe' }); + } catch (e: any) { + throw new Error(`打包失败 (${buildDir}): ${e.message}`); + } + await uploadFile(conn, tmpTar, `${cfg.extractDir}/frontend.tar.gz`); + + const { code, stderr } = await execRemote( + conn, + `cd "${cfg.extractDir}" && rm -rf frontend && mkdir frontend && tar -xzf frontend.tar.gz -C frontend && rm frontend.tar.gz`, + ); + if (code !== 0) throw new Error(`解压失败: ${stderr}`); + printSuccess(`前端文件已部署到 ${cfg.extractDir}/frontend`); + return; + } + + const serviceDir = `${cfg.server.deployPath}/frontend`; + await ensureRemoteDir(conn, serviceDir); + + const tmpTar = '/tmp/ecom-frontend-build.tar.gz'; + execSync(`tar -czf "${tmpTar}" -C "${buildDir}" .`, { stdio: 'pipe' }); + await uploadFile(conn, tmpTar, `${serviceDir}/build.tar.gz`); + + const { code, stderr } = await execRemote(conn, `cd "${serviceDir}" && tar -xzf build.tar.gz && rm build.tar.gz`); + if (code !== 0) throw new Error(`解压失败: ${stderr}`); + + printSuccess(`前端文件已部署到 ${serviceDir}`); +} diff --git a/ecom-deploy/src/deploy/index.ts b/ecom-deploy/src/deploy/index.ts new file mode 100644 index 00000000..9a4a33af --- /dev/null +++ b/ecom-deploy/src/deploy/index.ts @@ -0,0 +1,129 @@ +import { connectWithRetry, installKeyAfterPasswordAuth, execRemote } from '../ssh.js'; +import { composeUp, composeRestart, composeLogs, composeStatus, composeDown, uploadComposeFile } from '../docker.js'; +import { loadConfig, getServiceConfig, syncServerKeyAuth } from '../config.js'; +import { printError, printInfo, printSuccess } from '../ui/render.js'; +import type { Environment, Service, ServiceEnvConfig } from '../types.js'; + +import * as frontendDeploy from './frontend.js'; +import * as backendDeploy from './backend.js'; +import * as licenseDeploy from './license.js'; + +const deployers: Record Promise; deploy: (conn: any, cfg: ServiceEnvConfig, buildDir: string) => Promise }> = { + frontend: frontendDeploy as any, + backend: backendDeploy as any, + license: licenseDeploy as any, +}; + +export async function buildService(service: Service, cfg: ServiceEnvConfig): Promise { + const deployer = deployers[service]; + if (!deployer) throw new Error(`未知服务: ${service}`); + printInfo(`构建 ${service}...`); + const buildDir = await deployer.build(cfg); + printSuccess(`${service} 构建完成`); + return buildDir; +} + +export async function deployService(conn: any, service: Service, cfg: ServiceEnvConfig, buildDir: string): Promise { + const deployer = deployers[service]; + if (!deployer) throw new Error(`未知服务: ${service}`); + printInfo(`部署 ${service} 到 ${cfg.server.host}...`); + await deployer.deploy(conn, cfg, buildDir); +} + +/** 连接 SSH;密码登录成功后自动安装公钥并持久化到 config.json */ +async function connectForService( + cfg: ServiceEnvConfig, + onPassword?: () => Promise, +): Promise { + const { conn, authMethod } = await connectWithRetry(cfg.server, undefined, onPassword); + + if (authMethod === 'password') { + printInfo('首次密码登录成功,正在配置 SSH 密钥免密...'); + const keyPath = await installKeyAfterPasswordAuth(conn, cfg.server); + await syncServerKeyAuth(cfg.server.host, cfg.server.username, { + authType: 'key', + keyPath, + lastPassword: undefined, + }); + cfg.server.authType = 'key'; + cfg.server.keyPath = keyPath; + printSuccess(`已配置免密登录 (${cfg.server.host}),后续部署不再询问密码`); + } + + return conn; +} + +export async function buildAndDeployServices( + services: Service[], + onPassword?: (service: Service) => Promise, +): Promise { + for (const service of services) { + const config = await loadConfig(); + const cfg = getServiceConfig(config, service); + console.clear(); + const buildDir = await buildService(service, cfg); + + // 若同 host 已配置密钥,connectWithRetry 会直接免密,不再触发 onPassword + const conn = await connectForService( + cfg, + onPassword ? () => onPassword(service) : undefined, + ); + + try { + if (cfg.extractDir) { + await deployService(conn, service, cfg, buildDir); + } else { + await uploadComposeFile(conn, service, cfg); + await deployService(conn, service, cfg, buildDir); + await composeUp(conn, cfg, service); + } + } finally { + conn.end(); + } + printSuccess(`${service} 部署完成`); + } +} + +export async function restartService(service: Service, onPassword?: () => Promise): Promise { + const config = await loadConfig(); + const cfg = getServiceConfig(config, service); + const conn = await connectForService(cfg, onPassword); + try { await composeRestart(conn, cfg, service); } finally { conn.end(); } +} + +export async function stopService(service: Service, onPassword?: () => Promise): Promise { + const config = await loadConfig(); + const cfg = getServiceConfig(config, service); + const conn = await connectForService(cfg, onPassword); + try { await composeDown(conn, cfg, service); } finally { conn.end(); } +} + +export async function serviceLogs(service: Service, tail = 50, onPassword?: () => Promise): Promise { + const config = await loadConfig(); + const cfg = getServiceConfig(config, service); + const conn = await connectForService(cfg, onPassword); + try { return await composeLogs(conn, cfg, service, tail); } finally { conn.end(); } +} + +export async function serviceStatus(service: Service, onPassword?: () => Promise): Promise { + const config = await loadConfig(); + const cfg = getServiceConfig(config, service); + const conn = await connectForService(cfg, onPassword); + try { return await composeStatus(conn, cfg); } finally { conn.end(); } +} + +export async function checkRemoteDocker(service: Service, onPassword?: () => Promise): Promise { + const config = await loadConfig(); + const cfg = getServiceConfig(config, service); + try { + const conn = await connectForService(cfg, onPassword); + try { + const { stdout } = await execRemote(conn, 'docker --version && docker compose version'); + printInfo(stdout.trim()); + return true; + } finally { conn.end(); } + } catch (e: any) { + printError(`Docker 检查失败: ${e.message}`); + return false; + } +} diff --git a/ecom-deploy/src/deploy/license.ts b/ecom-deploy/src/deploy/license.ts new file mode 100644 index 00000000..309c4f5e --- /dev/null +++ b/ecom-deploy/src/deploy/license.ts @@ -0,0 +1,58 @@ +import { execSync } from 'child_process'; +import { writeFileSync, readFileSync, existsSync, mkdirSync, rmSync } from 'fs'; +import { join } from 'path'; + +import { Client } from 'ssh2'; +import { getLicenseDir, getLicenseDeployDir } from '../config.js'; +import { execRemote, uploadFile, ensureRemoteDir } from '../ssh.js'; +import { remoteBuildImage } from '../docker.js'; +import { printInfo, printSuccess } from '../ui/render.js'; +import type { Service, ServiceEnvConfig } from '../types.js'; + +export const serviceType: Service = 'license'; + +export async function build(): Promise { + const licenseDir = getLicenseDir(); + const serverDir = join(licenseDir, 'server'); + if (!existsSync(serverDir)) throw new Error(`许可证项目目录不存在: ${serverDir}`); + + printInfo('构建许可证 (NestJS)...'); + execSync('pnpm install && pnpm build', { stdio: 'inherit', cwd: serverDir }); + printSuccess('许可证构建完成'); + + const tmpDir = '/tmp/ecom-license-build'; + if (existsSync(tmpDir)) rmSync(tmpDir, { recursive: true }); + mkdirSync(tmpDir, { recursive: true }); + + execSync(`cp -r "${serverDir}/dist" "${tmpDir}/dist"`, { stdio: 'pipe' }); + execSync(`cp "${serverDir}/package.json" "${tmpDir}/"`, { stdio: 'pipe' }); + execSync(`cp "${serverDir}/pnpm-lock.yaml" "${tmpDir}/" 2>/dev/null || true`, { stdio: 'pipe' }); + if (existsSync(join(serverDir, 'keys'))) execSync(`cp -r "${serverDir}/keys" "${tmpDir}/keys"`, { stdio: 'pipe' }); + execSync(`cp "${serverDir}/.env" "${tmpDir}/.env" 2>/dev/null || true`, { stdio: 'pipe' }); + + return tmpDir; +} + +export async function deploy(conn: Client, cfg: ServiceEnvConfig, buildDir: string): Promise { + const serviceDir = `${cfg.server.deployPath}/license`; + await ensureRemoteDir(conn, serviceDir); + + const tmpTar = '/tmp/ecom-license-build.tar.gz'; + execSync(`tar -czf "${tmpTar}" -C "${buildDir}" .`, { stdio: 'pipe' }); + + const dockerfileSrc = join(getLicenseDeployDir(), 'Dockerfile'); + if (!existsSync(dockerfileSrc)) { + printInfo('许可证 deploy/Dockerfile 不存在,使用默认模板'); + writeFileSync('/tmp/ecom-license.Dockerfile', 'FROM node:22-alpine\nWORKDIR /app\nRUN addgroup -S app && adduser -S app -G app\nCOPY package.json pnpm-lock.yaml ./\nRUN corepack enable && pnpm install --prod --frozen-lockfile 2>/dev/null; exit 0\nCOPY dist ./dist\nCOPY keys ./keys\nCOPY .env ./.env\nRUN chown -R app:app /app\nUSER app\nEXPOSE 3100\nCMD ["node", "dist/main.js"]\n'); + } else { + writeFileSync('/tmp/ecom-license.Dockerfile', readFileSync(dockerfileSrc, 'utf8')); + } + + await uploadFile(conn, tmpTar, `${serviceDir}/build.tar.gz`); + await uploadFile(conn, '/tmp/ecom-license.Dockerfile', `${serviceDir}/Dockerfile`); + + const { code, stderr } = await execRemote(conn, `cd "${serviceDir}" && tar -xzf build.tar.gz && rm build.tar.gz`); + if (code !== 0) throw new Error(`解压失败: ${stderr}`); + + await remoteBuildImage(conn, 'license', serviceDir); +} diff --git a/ecom-deploy/src/docker.ts b/ecom-deploy/src/docker.ts new file mode 100644 index 00000000..11a75f8e --- /dev/null +++ b/ecom-deploy/src/docker.ts @@ -0,0 +1,92 @@ +import { writeFileSync } from 'fs'; + +import { Client } from 'ssh2'; +import { resolveSpringProfile } from './config.js'; +import { execRemote, ensureRemoteDir, uploadFile } from './ssh.js'; +import { printSuccess } from './ui/render.js'; +import type { Service, ServiceEnvConfig } from './types.js'; + +export function generateComposeFile(service: Service, cfg: ServiceEnvConfig): string { + const tag = `ecom-${service}:latest`; + + let envBlock = ''; + if (service === 'frontend') { + envBlock = ` - NGINX_PORT=${cfg.port}`; + } else if (service === 'backend') { + envBlock = [ + ` - SERVER_PORT=${cfg.port}`, + ` - SPRING_PROFILES_ACTIVE=${resolveSpringProfile(cfg.springProfile)}`, + cfg.dbUrl ? ` - DB_URL=${cfg.dbUrl}` : '', + cfg.redisUrl ? ` - REDIS_URL=${cfg.redisUrl}` : '', + ].filter(Boolean).join('\n'); + } else if (service === 'license') { + envBlock = [ + ` - NODE_ENV=${cfg.nodeEnv || 'production'}`, + ` - PORT=${cfg.port}`, + cfg.licenseDbUrl ? ` - DB_URL=${cfg.licenseDbUrl}` : '', + ].filter(Boolean).join('\n'); + } + + return `services: + ${service}: + image: ${tag} + container_name: ecom-${service} + network_mode: host + environment: +${envBlock} + restart: unless-stopped + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" +`; +} + +export async function remoteBuildImage(conn: Client, service: Service, serviceDir: string): Promise { + const tag = `ecom-${service}:latest`; + const { code, stdout, stderr } = await execRemote(conn, `cd "${serviceDir}" && docker build -t ${tag} . 2>&1`); + if (code !== 0) { + throw new Error(`${service} 镜像构建失败:\n${stdout || stderr}`); + } + printSuccess(`${service} 镜像构建完成`); +} + +export async function uploadComposeFile(conn: Client, service: Service, cfg: ServiceEnvConfig): Promise { + const deployPath = cfg.server.deployPath; + const tmpCompose = `/tmp/ecom-${service}-docker-compose.yml`; + writeFileSync(tmpCompose, generateComposeFile(service, cfg), 'utf8'); + await ensureRemoteDir(conn, deployPath); + await uploadFile(conn, tmpCompose, `${deployPath}/docker-compose.yml`); +} + +export async function composeUp(conn: Client, cfg: ServiceEnvConfig, service: Service): Promise { + const { code, stdout, stderr } = await execRemote(conn, `cd "${cfg.server.deployPath}" && docker compose up -d ${service} 2>&1`); + if (code !== 0) { + throw new Error(`${service} 启动失败:\n${stdout || stderr}`); + } + printSuccess(`${service} 已启动`); +} + +export async function composeDown(conn: Client, cfg: ServiceEnvConfig, service: Service): Promise { + await execRemote(conn, `cd "${cfg.server.deployPath}" && docker compose down ${service}`); + printSuccess(`${service} 已停止`); +} + +export async function composeRestart(conn: Client, cfg: ServiceEnvConfig, service: Service): Promise { + const { code, stdout, stderr } = await execRemote(conn, `cd "${cfg.server.deployPath}" && docker compose restart ${service} 2>&1`); + if (code !== 0) { + throw new Error(`${service} 重启失败:\n${stdout || stderr}`); + } + printSuccess(`${service} 已重启`); +} + +export async function composeLogs(conn: Client, cfg: ServiceEnvConfig, service: Service, tail = 50): Promise { + const { stdout } = await execRemote(conn, `cd "${cfg.server.deployPath}" && docker compose logs --tail=${tail} ${service}`); + return stdout; +} + +export async function composeStatus(conn: Client, cfg: ServiceEnvConfig): Promise { + const { stdout } = await execRemote(conn, `cd "${cfg.server.deployPath}" && docker compose ps`); + return stdout; +} diff --git a/ecom-deploy/src/index.ts b/ecom-deploy/src/index.ts new file mode 100644 index 00000000..8a44d509 --- /dev/null +++ b/ecom-deploy/src/index.ts @@ -0,0 +1,321 @@ +#!/usr/bin/env node +import { input, password as pwPrompt, select } from '@inquirer/prompts'; + +import { loadConfig, saveConfig, updateServiceServerConfig, getServiceConfig, getSshKeyPath, syncServerKeyAuth } from './config.js'; +import { + buildAndDeployServices, + checkRemoteDocker, + restartService, + serviceLogs, + serviceStatus, + stopService, +} from './deploy/index.js'; +import { ensureKeyPair, setupSSHKey, testConnection } from './ssh.js'; +import { printBanner, printBox, printError, printInfo, printSuccess } from './ui/render.js'; +import { ENV_LABELS, SERVICE_LABELS } from './types.js'; +import type { Environment, Service } from './types.js'; + +async function pause() { + await input({ message: '按 Enter 返回' }); +} + +async function selectEnv(): Promise { + const config = await loadConfig(); + const env = await select({ + message: '选择环境', + choices: (['test', 'pre', 'production'] as Environment[]).map((e) => ({ + name: `${e === config.currentEnv ? '● ' : ' '}${ENV_LABELS[e]}`, + value: e, + })), + }); + config.currentEnv = env; + await saveConfig(config); + return env; +} + +async function selectService(): Promise { + return await select({ + message: '选择服务', + choices: [ + { name: '前端', value: 'frontend' }, + { name: '后端', value: 'backend' }, + { name: '许可证服务', value: 'license' }, + ], + }) as Service; +} + +async function selectServices(): Promise { + const selected = await select({ + message: '选择服务', + choices: [ + { name: '全部服务', value: 'all' as any }, + { name: '前端', value: 'frontend' }, + { name: '后端', value: 'backend' }, + { name: '许可证服务', value: 'license' }, + ], + }); + if (selected === 'all') return ['frontend', 'backend', 'license']; + return [selected as Service]; +} + +function showServiceHosts(config: { services: Record>; currentEnv: string }): string { + const env = config.currentEnv; + const services: Service[] = ['frontend', 'backend', 'license']; + return services.map((s) => + ` ${SERVICE_LABELS[s]}: ${config.services[s][env].server.host}:${config.services[s][env].server.deployPath}` + ).join('\n'); +} + +async function configureService() { + const config = await loadConfig(); + const service = await selectService(); + const env = await selectEnv(); + const cfg = config.services[service][env]; + const srv = cfg.server; + + console.clear(); + printBox(`${SERVICE_LABELS[service]} · ${ENV_LABELS[env]} 配置`, [ + `服务器: ${srv.host}:${srv.port}`, + `用户: ${srv.username}`, + `部署目录: ${srv.deployPath}`, + `端口: ${cfg.port}`, + `认证方式: ${srv.authType === 'key' ? '密钥' : '密码'}`, + ].join('\n')); + + const action = await select({ + message: '配置操作', + choices: [ + { name: '修改服务器地址', value: 'host' }, + { name: '修改端口', value: 'port' }, + { name: '修改服务端口', value: 'svcPort' }, + { name: '修改用户名', value: 'username' }, + { name: '修改部署目录', value: 'deployPath' }, + { name: '测试 SSH 连接', value: 'test' }, + { name: '配置 SSH 密钥 (首次免密)', value: 'setupKey' }, + { name: '返回', value: 'back' }, + ], + }); + + switch (action) { + case 'host': { + const host = await input({ message: '服务器地址', default: srv.host }); + await updateServiceServerConfig(service, env, { host }); + break; + } + case 'port': { + const p = await input({ message: 'SSH 端口', default: String(srv.port) }); + await updateServiceServerConfig(service, env, { port: Number(p) }); + break; + } + case 'svcPort': { + const p = await input({ message: '服务端口', default: String(cfg.port) }); + const { updateServiceEnvConfig } = await import('./config.js'); + await updateServiceEnvConfig(service, env, { port: Number(p) }); + break; + } + case 'username': { + const u = await input({ message: 'SSH 用户', default: srv.username }); + await updateServiceServerConfig(service, env, { username: u }); + break; + } + case 'deployPath': { + const d = await input({ message: '部署目录', default: srv.deployPath }); + await updateServiceServerConfig(service, env, { deployPath: d }); + break; + } + case 'test': { + const ok = await testConnection(srv); + if (ok) printSuccess('SSH 连接成功'); + else printError('SSH 连接失败'); + break; + } + case 'setupKey': { + const pwd = await pwPrompt({ message: `输入 ${srv.host} 的 SSH 密码`, mask: true }); + try { + await setupSSHKey(srv, pwd); + await syncServerKeyAuth(srv.host, srv.username, { authType: 'key', keyPath: getSshKeyPath() }); + } catch (e: any) { + printError(`密钥配置失败: ${e.message}`); + } + break; + } + } +} + +async function deployMenu() { + const config = await loadConfig(); + const env = config.currentEnv; + printBox('当前环境', `${ENV_LABELS[env]}\n${showServiceHosts(config)}`, 'yellow'); + + const services = await selectServices(); + printBox('待部署服务', services.map((s) => `${SERVICE_LABELS[s]} → ${config.services[s][env].server.host}`).join('\n'), 'cyan'); + + const ok = await select({ + message: '确认部署?', + choices: [{ name: '开始部署', value: 'go' }, { name: '取消', value: 'cancel' }], + }); + if (ok === 'cancel') return; + + try { + console.clear(); + await buildAndDeployServices(services, async (s) => { + const cfg = config.services[s][env]; + return await pwPrompt({ message: `输入 ${cfg.server.host} 的 SSH 密码`, mask: true }); + }); + } catch (e: any) { + printError(`部署失败: ${e.message}`); + } +} + +async function serviceMenu() { + const service = await selectService(); + const config = await loadConfig(); + const cfg = getServiceConfig(config, service); + const srv = cfg.server; + + const action = await select({ + message: `${SERVICE_LABELS[service]} 管理 (${srv.host})`, + choices: [ + { name: '查看状态', value: 'status' }, + { name: '查看日志', value: 'logs' }, + { name: '重启服务', value: 'restart' }, + { name: '停止服务', value: 'stop' }, + { name: '检查 Docker 环境', value: 'checkDocker' }, + { name: '返回', value: 'back' }, + ], + }); + if (action === 'back') return; + + console.clear(); + const onPassword = async () => await pwPrompt({ message: `输入 ${srv.host} 的 SSH 密码`, mask: true }); + + try { + switch (action) { + case 'status': { + const ps = await serviceStatus(service, onPassword); + console.log(ps || '暂无运行的服务'); + break; + } + case 'logs': { + const lines = await input({ message: '日志行数', default: '50' }); + const logs = await serviceLogs(service, Number(lines) || 50, onPassword); + console.log(logs || '(无日志)'); + break; + } + case 'restart': + await restartService(service, onPassword); + break; + case 'stop': + await stopService(service, onPassword); + break; + case 'checkDocker': + await checkRemoteDocker(service, onPassword); + break; + } + } catch (e: any) { + printError(`操作失败: ${e.message}`); + } +} + +async function sshMenu() { + const config = await loadConfig(); + const service = await selectService(); + const env = config.currentEnv; + const srv = config.services[service][env].server; + + const action = await select({ + message: `${SERVICE_LABELS[service]} SSH 管理 (${srv.host})`, + choices: [ + { name: '查看 SSH 密钥状态', value: 'status' }, + { name: '生成 SSH 密钥对', value: 'genKey' }, + { name: '上传公钥到服务器', value: 'uploadKey' }, + { name: '测试连接', value: 'test' }, + { name: '返回', value: 'back' }, + ], + }); + if (action === 'back') return; + + console.clear(); + switch (action) { + case 'status': { + const { existsSync } = await import('fs'); + if (existsSync(getSshKeyPath())) printSuccess(`密钥存在: ${getSshKeyPath()}`); + else printInfo('尚未生成 SSH 密钥对'); + break; + } + case 'genKey': { + ensureKeyPair(); + printSuccess('SSH 密钥对已生成'); + break; + } + case 'uploadKey': { + const pwd = await pwPrompt({ message: `输入 ${srv.host} 的 SSH 密码`, mask: true }); + try { + await setupSSHKey(srv, pwd); + await syncServerKeyAuth(srv.host, srv.username, { authType: 'key', keyPath: getSshKeyPath() }); + } catch (e: any) { + printError(`上传失败: ${e.message}`); + } + break; + } + case 'test': { + const pwd = srv.authType === 'password' + ? await pwPrompt({ message: `输入 ${srv.host} 的 SSH 密码`, mask: true }) + : undefined; + const ok = await testConnection(srv, pwd); + if (ok) printSuccess('SSH 连接成功'); + else printError('SSH 连接失败'); + break; + } + } +} + +async function mainMenu() { + console.clear(); + printBanner(); + + const config = await loadConfig(); + const env = config.currentEnv; + printInfo(`当前环境: ${ENV_LABELS[env]}`); + console.log(showServiceHosts(config)); + + const action = await select({ + message: '主菜单', + choices: [ + { name: '部署服务', value: 'deploy' }, + { name: '服务管理', value: 'service' }, + { name: '配置服务', value: 'config' }, + { name: 'SSH 密钥管理', value: 'ssh' }, + { name: '切换环境', value: 'switchEnv' }, + { name: '退出', value: 'exit' }, + ], + }); + + switch (action) { + case 'deploy': console.clear(); await deployMenu(); break; + case 'service': console.clear(); await serviceMenu(); break; + case 'config': await configureService(); break; + case 'ssh': await sshMenu(); break; + case 'switchEnv': { + const newEnv = await selectEnv(); + printSuccess(`已切换到: ${ENV_LABELS[newEnv]}`); + break; + } + case 'exit': process.exit(0); + } +} + +async function main() { + while (true) { + try { + await mainMenu(); + await pause(); + } catch (e: any) { + if (e?.name === 'ExitPromptError') process.exit(0); + printError(String(e?.message || e)); + await pause(); + } + } +} + +main(); diff --git a/ecom-deploy/src/ssh.ts b/ecom-deploy/src/ssh.ts new file mode 100644 index 00000000..1969e8eb --- /dev/null +++ b/ecom-deploy/src/ssh.ts @@ -0,0 +1,234 @@ +import { execSync } from 'child_process'; +import { existsSync, mkdirSync, readFileSync } from 'fs'; +import { homedir } from 'os'; +import { join } from 'path'; +import { Client } from 'ssh2'; + +import { printInfo, printSuccess } from './ui/render.js'; +import type { ServerConfig } from './types.js'; +import { getSshKeyPath } from './config.js'; + +export interface SSHExecResult { + stdout: string; + stderr: string; + code: number; +} + +export interface SSHConnectResult { + conn: Client; + /** 本次连接使用的认证方式 */ + authMethod: 'key' | 'password'; +} + +export function resolveKeyPath(config: ServerConfig): string { + return config.keyPath || getSshKeyPath(); +} + +export function ensureKeyPair(keyPath: string = getSshKeyPath()): { publicKey: string; privateKeyPath: string } { + if (existsSync(keyPath)) { + const publicKeyPath = `${keyPath}.pub`; + const publicKey = existsSync(publicKeyPath) ? readFileSync(publicKeyPath, 'utf8').trim() : ''; + return { publicKey, privateKeyPath: keyPath }; + } + + const dir = join(homedir(), '.ssh'); + mkdirSync(dir, { recursive: true }); + + execSync(`ssh-keygen -t ed25519 -f "${keyPath}" -N "" -C "ecom-deploy"`, { stdio: 'pipe' }); + const publicKey = readFileSync(`${keyPath}.pub`, 'utf8').trim(); + printSuccess(`SSH 密钥已生成: ${keyPath}.pub`); + + return { publicKey, privateKeyPath: keyPath }; +} + +function sshConnect(config: ServerConfig, password?: string, keyPath?: string): Promise { + return new Promise((resolve, reject) => { + const conn = new Client(); + const privateKeyPath = keyPath || resolveKeyPath(config); + + const opts: any = { + host: config.host, + port: config.port, + username: config.username, + readyTimeout: 15000, + keepaliveInterval: 10000, + }; + + if (password) { + opts.password = password; + opts.tryKeyboard = true; + } else if (existsSync(privateKeyPath)) { + opts.privateKey = readFileSync(privateKeyPath, 'utf8'); + } + + conn.on('ready', () => resolve(conn)); + conn.on('error', (err) => reject(err)); + conn.on('keyboard-interactive', (_name, _instructions, _instructionsLang, _prompts, finish) => { + finish([password || '']); + }); + + conn.connect(opts); + }); +} + +export async function connectWithRetry( + config: ServerConfig, + password?: string, + onPassword?: () => Promise, +): Promise { + let lastError: Error | null = null; + const keyPath = resolveKeyPath(config); + + // 优先尝试密钥(只要本地密钥文件存在) + if (existsSync(keyPath)) { + try { + const conn = await sshConnect(config, undefined, keyPath); + return { conn, authMethod: 'key' }; + } catch (e: any) { + lastError = e; + printInfo(`密钥认证失败 (${e.message}),尝试密码...`); + } + } + + if (password || config.lastPassword) { + try { + const conn = await sshConnect(config, password || config.lastPassword); + return { conn, authMethod: 'password' }; + } catch (e: any) { + lastError = e; + } + } + + if (onPassword) { + password = await onPassword(); + try { + const conn = await sshConnect(config, password); + return { conn, authMethod: 'password' }; + } catch (e: any) { + lastError = e; + throw new Error(`SSH 连接失败: ${lastError?.message || '未知错误'}`); + } + } + + throw new Error(`SSH 连接失败: ${lastError?.message || '无法连接'}`); +} + +/** 远程 shell 初始化:passwd home 不可用时回退到 /tmp,避免 docker 等命令 mkdir home 失败 */ +export const REMOTE_SHELL_INIT = ` +PASSWD_HOME=$(getent passwd "$(whoami)" | cut -d: -f6) +FALLBACK_HOME="/tmp/ecom-deploy-$(whoami)" +if [ -n "$PASSWD_HOME" ] && [ -d "$PASSWD_HOME" ] && [ -w "$PASSWD_HOME" ]; then + export HOME="$PASSWD_HOME" +elif [ -n "$PASSWD_HOME" ] && mkdir -p "$PASSWD_HOME" 2>/dev/null && [ -w "$PASSWD_HOME" ]; then + export HOME="$PASSWD_HOME" +else + mkdir -p "$FALLBACK_HOME" + export HOME="$FALLBACK_HOME" +fi +`.trim(); + +export function wrapRemoteCommand(command: string): string { + return `${REMOTE_SHELL_INIT}\n${command}`; +} + +export async function execRemote(conn: Client, command: string): Promise { + return new Promise((resolve, reject) => { + let stdout = ''; + let stderr = ''; + conn.exec(wrapRemoteCommand(command), (err, stream) => { + if (err) return reject(err); + stream.on('close', (code: number) => { + resolve({ stdout, stderr, code }); + }); + stream.on('data', (data: Buffer) => { + stdout += data.toString(); + }); + stream.stderr.on('data', (data: Buffer) => { + stderr += data.toString(); + }); + }); + }); +} + +export async function uploadFile(conn: Client, localPath: string, remotePath: string): Promise { + return new Promise((resolve, reject) => { + conn.sftp((err, sftp) => { + if (err) return reject(new Error(`SFTP 连接失败: ${err.message}`)); + sftp.fastPut(localPath, remotePath, (err2) => { + sftp.end(); + if (err2) reject(new Error(`上传失败 ${localPath} → ${remotePath}: ${err2.message}`)); + else resolve(); + }); + }); + }); +} + +export async function ensureRemoteDir(conn: Client, dir: string): Promise { + const { code, stderr } = await execRemote(conn, `mkdir -p "${dir}"`); + if (code !== 0) throw new Error(`创建远程目录失败 ${dir}: ${stderr}`); +} + +/** 将公钥写入远程 authorized_keys(必须能创建 passwd 中的 home 目录,sshd 才认密钥) */ +export async function uploadPublicKey(conn: Client, publicKey: string): Promise { + const keyBody = publicKey.trim().split(/\s+/)[1] || publicKey.trim().slice(0, 32); + const escapedKey = publicKey.trim().replace(/'/g, `'\\''`); + + const script = ` +PASSWD_HOME=$(getent passwd "$(whoami)" | cut -d: -f6) +if [ -z "$PASSWD_HOME" ]; then echo "ERR: 无法解析用户 home 目录"; exit 1; fi +if ! mkdir -p "$PASSWD_HOME/.ssh" 2>/dev/null; then + echo "ERR: 无法创建 $PASSWD_HOME/.ssh" + echo "请在服务器执行: sudo mkdir -p $PASSWD_HOME && sudo chown $(whoami):$(whoami) $PASSWD_HOME" + exit 1 +fi +chmod 700 "$PASSWD_HOME/.ssh" +AUTH_FILE="$PASSWD_HOME/.ssh/authorized_keys" +touch "$AUTH_FILE" && chmod 600 "$AUTH_FILE" +if grep -Fq '${keyBody}' "$AUTH_FILE" 2>/dev/null; then + echo "公钥已存在" +else + printf '%s\\n' '${escapedKey}' >> "$AUTH_FILE" + echo "公钥已写入" +fi +`.trim(); + + const { code, stdout, stderr } = await execRemote(conn, script); + if (code !== 0) { + throw new Error(`上传公钥失败: ${stderr || stdout}`); + } + if (stdout.includes('公钥已存在')) { + printInfo('公钥已存在,跳过'); + } else { + printSuccess('公钥已上传到服务器'); + } +} + +/** 密码登录成功后自动安装公钥,供后续免密连接 */ +export async function installKeyAfterPasswordAuth(conn: Client, config: ServerConfig): Promise { + const { publicKey, privateKeyPath } = ensureKeyPair(resolveKeyPath(config)); + await uploadPublicKey(conn, publicKey); + return privateKeyPath; +} + +export async function setupSSHKey(config: ServerConfig, password: string): Promise { + const { conn } = await connectWithRetry(config, password); + try { + await installKeyAfterPasswordAuth(conn, config); + config.authType = 'key'; + config.keyPath = resolveKeyPath(config); + config.lastPassword = undefined; + printSuccess('SSH 密钥认证已配置完成'); + } finally { + conn.end(); + } +} + +export async function testConnection(config: ServerConfig, password?: string): Promise { + try { + const { conn } = await connectWithRetry(config, password); + conn.end(); + return true; + } catch { + return false; + } +} diff --git a/ecom-deploy/src/types.ts b/ecom-deploy/src/types.ts new file mode 100644 index 00000000..fe73e0a6 --- /dev/null +++ b/ecom-deploy/src/types.ts @@ -0,0 +1,40 @@ +export type Environment = 'test' | 'pre' | 'production'; +export type Service = 'frontend' | 'backend' | 'license'; + +export interface ServerConfig { + host: string; + port: number; + username: string; + deployPath: string; + authType: 'password' | 'key'; + keyPath?: string; + lastPassword?: string; +} + +export interface ServiceEnvConfig { + server: ServerConfig; + port: number; + springProfile?: string; + nodeEnv?: string; + dbUrl?: string; + redisUrl?: string; + licenseDbUrl?: string; + extractDir?: string; +} + +export interface DeployConfig { + currentEnv: Environment; + services: Record>; +} + +export const SERVICE_LABELS: Record = { + frontend: '前端', + backend: '后端', + license: '许可证服务', +}; + +export const ENV_LABELS: Record = { + test: '测试环境', + pre: '预发布环境', + production: '生产环境', +}; diff --git a/ecom-deploy/src/ui/render.ts b/ecom-deploy/src/ui/render.ts new file mode 100644 index 00000000..42dea42f --- /dev/null +++ b/ecom-deploy/src/ui/render.ts @@ -0,0 +1,54 @@ +import boxen from 'boxen'; +import chalk from 'chalk'; +import gradient from 'gradient-string'; +import ora, { type Ora } from 'ora'; + +export function printBanner() { + const title = gradient.pastel('Ecom Deploy'); + console.log( + boxen(`${title}\n${chalk.gray('部署管理工具 · Docker 编排')}`, { + padding: 1, + borderColor: 'cyan', + borderStyle: 'round', + }), + ); +} + +export function printSuccess(msg: string) { + console.log(chalk.green('✔'), msg); +} + +export function printError(msg: string) { + console.error(chalk.red('✖'), msg); +} + +export function printInfo(msg: string) { + console.log(chalk.blue('ℹ'), msg); +} + +export function printBox(title: string, content: string, borderColor: 'green' | 'cyan' | 'yellow' = 'cyan') { + console.log( + boxen(content, { + title: chalk.bold(title), + padding: 1, + borderColor, + }), + ); +} + +let activeSpinner: Ora | null = null; + +export async function runSpinner(fn: () => Promise, text: string): Promise { + const spinner = ora(text).start(); + activeSpinner = spinner; + try { + const result = await fn(); + spinner.succeed(); + return result; + } catch (e) { + spinner.fail(); + throw e; + } finally { + activeSpinner = null; + } +} diff --git a/ecom-deploy/tsconfig.json b/ecom-deploy/tsconfig.json new file mode 100644 index 00000000..717d4a09 --- /dev/null +++ b/ecom-deploy/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": false, + "resolveJsonModule": true + }, + "include": ["src/**/*"] +}