From ba171fb7440b9de572f55f8f0e2fd9505f532934 Mon Sep 17 00:00:00 2001 From: abearixong Date: Mon, 17 Nov 2025 18:14:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=92=8Cpack=E7=9A=84=20cmd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assistant/src/services/init/index.ts | 28 +- package.json | 18 +- pnpm-lock.yaml | 369 +++++++++++++++++++++++++-- src/command/deploy.ts | 40 --- src/command/publish.ts | 211 +++------------ 5 files changed, 408 insertions(+), 258 deletions(-) diff --git a/assistant/src/services/init/index.ts b/assistant/src/services/init/index.ts index 8cbeda2..3057f75 100644 --- a/assistant/src/services/init/index.ts +++ b/assistant/src/services/init/index.ts @@ -37,6 +37,7 @@ export class AssistantInit extends AssistantConfig { this.createAssistantConfig(); this.createEnvConfig(); this.createOtherConfig(); + this.initPnpm(); } checkConfigPath() { const assistantPath = path.join(this.configDir, 'assistant-app', 'assistant-config.json'); @@ -106,16 +107,23 @@ export class AssistantInit extends AssistantConfig { "author": "", "license": "ISC", "dependencies": { - "@kevisual/router": "^0.0.20", - "@kevisual/use-config": "^1.0.17", - "ioredis": "^5.6.1", - "minio": "^8.0.5", - "pg": "^8.16.0", - "pm2": "^6.0.6", - "sequelize": "^6.37.7", - "sqlite3": "^5.1.7", - "socket.io": "^4.8.1", - "dotenv": "^16.5.0" + "@kevisual/router": "latest", + "@kevisual/use-config": "latest", + "ioredis": "latest", + "minio": "latest", + "pg": "latest", + "pm2": "latest", + "sequelize": "latest", + "crypto-js": "latest", + "better-sqlite3": "latest", + "unstorage": "latest", + "dayjs": "latest", + "es-toolkit": "latest", + "dotenv": "latest" + }, + "devDependencies": { + "@types/node": "latest", + "@types/crypto-js": "latest" } } `, diff --git a/package.json b/package.json index 384b5b7..051ffa2 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,8 @@ { "name": "@kevisual/cli", - "version": "0.0.61", - "description": "envision command tools", - "main": "dist/app.mjs", + "version": "0.0.62", + "description": "envision 命令行工具", "type": "module", - "private": false, "basename": "/root/cli", "app": { "key": "cli", @@ -28,13 +26,12 @@ "bun.config.mjs" ], "scripts": { - "dev": "cross-env NODE_ENV=development bun src/run.ts ", + "dev": "bun src/run.ts ", "dev:tsx": "tsx src/run.ts ", "build": "rimraf dist && bun run bun.config.mjs", "pub:me": "npm publish --registry https://npm.xiongxiao.me --tag beta", "postbuild": "cd assistant && pnpm build ", - "dts": "dts-bundle-generator --external-inlines=@types/jsonwebtoken src/index.ts -o dist/index.d.ts ", - "build:all": "rimraf dist && bun run bun.config.mjs && bun run assistant/bun.config.mjs" + "dts": "dts-bundle-generator --external-inlines=@types/jsonwebtoken src/index.ts -o dist/index.d.ts " }, "keywords": [ "kevisual", @@ -55,16 +52,15 @@ "@types/crypto-js": "^4.2.2", "@types/jsonwebtoken": "^9.0.10", "@types/micromatch": "^4.0.10", - "@types/node": "^24.10.0", + "@types/node": "^24.10.1", "chalk": "^5.6.2", "commander": "^14.0.2", - "cross-env": "^10.1.0", "crypto-js": "^4.2.0", "fast-glob": "^3.3.3", "filesize": "^11.0.13", - "form-data": "^4.0.4", + "form-data": "^4.0.5", "ignore": "^7.0.5", - "inquirer": "^12.11.0", + "inquirer": "^13.0.1", "jsonwebtoken": "^9.0.2", "tar": "^7.5.2", "zustand": "^5.0.8" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ffa267a..4d64f81 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,8 +43,8 @@ importers: specifier: ^4.0.10 version: 4.0.10 '@types/node': - specifier: ^24.10.0 - version: 24.10.0 + specifier: ^24.10.1 + version: 24.10.1 chalk: specifier: ^5.6.2 version: 5.6.2 @@ -64,14 +64,14 @@ importers: specifier: ^11.0.13 version: 11.0.13 form-data: - specifier: ^4.0.4 - version: 4.0.4 + specifier: ^4.0.5 + version: 4.0.5 ignore: specifier: ^7.0.5 version: 7.0.5 inquirer: - specifier: ^12.11.0 - version: 12.11.0(@types/node@24.10.0) + specifier: ^13.0.1 + version: 13.0.1(@types/node@24.10.1) jsonwebtoken: specifier: ^9.0.2 version: 9.0.2 @@ -199,6 +199,10 @@ packages: resolution: {integrity: sha512-S8qNSZiYzFd0wAcyG5AXCvUHC5Sr7xpZ9wZ2py9XR88jUz8wooStVx5M6dRzczbBWjic9NP7+rY0Xi7qqK/aMQ==} engines: {node: '>=18'} + '@inquirer/ansi@2.0.1': + resolution: {integrity: sha512-QAZUk6BBncv/XmSEZTscd8qazzjV3E0leUMrEPjxCd51QBgCKmprUGLex5DTsNtURm7LMzv+CLcd6S86xvBfYg==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + '@inquirer/checkbox@4.3.1': resolution: {integrity: sha512-rOcLotrptYIy59SGQhKlU0xBg1vvcVl2FdPIEclUvKHh0wo12OfGkId/01PIMJ/V+EimJ77t085YabgnQHBa5A==} engines: {node: '>=18'} @@ -208,6 +212,15 @@ packages: '@types/node': optional: true + '@inquirer/checkbox@5.0.1': + resolution: {integrity: sha512-5VPFBK8jKdsjMK3DTFOlbR0+Kkd4q0AWB7VhWQn6ppv44dr3b7PU8wSJQTC5oA0f/aGW7v/ZozQJAY9zx6PKig==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/confirm@5.1.20': resolution: {integrity: sha512-HDGiWh2tyRZa0M1ZnEIUCQro25gW/mN8ODByicQrbR1yHx4hT+IOpozCMi5TgBtUdklLwRI2mv14eNpftDluEw==} engines: {node: '>=18'} @@ -217,6 +230,15 @@ packages: '@types/node': optional: true + '@inquirer/confirm@6.0.1': + resolution: {integrity: sha512-wD+pM7IxLn1TdcQN12Q6wcFe5VpyCuh/I2sSmqO5KjWH2R4v+GkUToHb+PsDGobOe1MtAlXMwGNkZUPc2+L6NA==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/core@10.3.1': resolution: {integrity: sha512-hzGKIkfomGFPgxKmnKEKeA+uCYBqC+TKtRx5LgyHRCrF6S2MliwRIjp3sUaWwVzMp7ZXVs8elB0Tfe682Rpg4w==} engines: {node: '>=18'} @@ -226,6 +248,15 @@ packages: '@types/node': optional: true + '@inquirer/core@11.0.1': + resolution: {integrity: sha512-Tpf49h50e4KYffVUCXzkx4gWMafUi3aDQDwfVAAGBNnVcXiwJIj4m2bKlZ7Kgyf6wjt1eyXH1wDGXcAokm4Ssw==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/editor@4.2.22': resolution: {integrity: sha512-8yYZ9TCbBKoBkzHtVNMF6PV1RJEUvMlhvmS3GxH4UvXMEHlS45jFyqFy0DU+K42jBs5slOaA78xGqqqWAx3u6A==} engines: {node: '>=18'} @@ -235,6 +266,15 @@ packages: '@types/node': optional: true + '@inquirer/editor@5.0.1': + resolution: {integrity: sha512-zDKobHI7Ry++4noiV9Z5VfYgSVpPZoMApviIuGwLOMciQaP+dGzCO+1fcwI441riklRiZg4yURWyEoX0Zy2zZw==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/expand@4.0.22': resolution: {integrity: sha512-9XOjCjvioLjwlq4S4yXzhvBmAXj5tG+jvva0uqedEsQ9VD8kZ+YT7ap23i0bIXOtow+di4+u3i6u26nDqEfY4Q==} engines: {node: '>=18'} @@ -244,6 +284,15 @@ packages: '@types/node': optional: true + '@inquirer/expand@5.0.1': + resolution: {integrity: sha512-TBrTpAB6uZNnGQHtSEkbvJZIQ3dXZOrwqQSO9uUbwct3G2LitwBCE5YZj98MbQ5nzihzs5pRjY1K9RRLH4WgoA==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/external-editor@1.0.3': resolution: {integrity: sha512-RWbSrDiYmO4LbejWY7ttpxczuwQyZLBUyygsA9Nsv95hpzUWwnNTVQmAq3xuh7vNwCp07UTmE5i11XAEExx4RA==} engines: {node: '>=18'} @@ -253,10 +302,23 @@ packages: '@types/node': optional: true + '@inquirer/external-editor@2.0.1': + resolution: {integrity: sha512-BPYWJXCAK9w6R+pb2s3WyxUz9ts9SP/LDOUwA9fu7LeuyYgojz83i0DSRwezu736BgMwz14G63Xwj70hSzHohQ==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/figures@1.0.15': resolution: {integrity: sha512-t2IEY+unGHOzAaVM5Xx6DEWKeXlDDcNPeDyUpsRc6CUhBfU3VQOEl+Vssh7VNp1dR8MdUJBWhuObjXCsVpjN5g==} engines: {node: '>=18'} + '@inquirer/figures@2.0.1': + resolution: {integrity: sha512-KtMxyjLCuDFqAWHmCY9qMtsZ09HnjMsm8H3OvpSIpfhHdfw3/AiGWHNrfRwbyvHPtOJpumm8wGn5fkhtvkWRsg==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + '@inquirer/input@4.3.0': resolution: {integrity: sha512-h4fgse5zeGsBSW3cRQqu9a99OXRdRsNCvHoBqVmz40cjYjYFzcfwD0KA96BHIPlT7rZw0IpiefQIqXrjbzjS4Q==} engines: {node: '>=18'} @@ -266,6 +328,15 @@ packages: '@types/node': optional: true + '@inquirer/input@5.0.1': + resolution: {integrity: sha512-cEhEUohCpE2BCuLKtFFZGp4Ief05SEcqeAOq9NxzN5ThOQP8Rl5N/Nt9VEDORK1bRb2Sk/zoOyQYfysPQwyQtA==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/number@3.0.22': resolution: {integrity: sha512-oAdMJXz++fX58HsIEYmvuf5EdE8CfBHHXjoi9cTcQzgFoHGZE+8+Y3P38MlaRMeBvAVnkWtAxMUF6urL2zYsbg==} engines: {node: '>=18'} @@ -275,6 +346,15 @@ packages: '@types/node': optional: true + '@inquirer/number@4.0.1': + resolution: {integrity: sha512-4//zgBGHe8Q/FfCoUXZUrUHyK/q5dyqiwsePz3oSSPSmw1Ijo35ZkjaftnxroygcUlLYfXqm+0q08lnB5hd49A==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/password@4.0.22': resolution: {integrity: sha512-CbdqK1ioIr0Y3akx03k/+Twf+KSlHjn05hBL+rmubMll7PsDTGH0R4vfFkr+XrkB0FOHrjIwVP9crt49dgt+1g==} engines: {node: '>=18'} @@ -284,6 +364,15 @@ packages: '@types/node': optional: true + '@inquirer/password@5.0.1': + resolution: {integrity: sha512-UJudHpd7Ia30Q+x+ctYqI9Nh6SyEkaBscpa7J6Ts38oc1CNSws0I1hJEdxbQBlxQd65z5GEJPM4EtNf6tzfWaQ==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/prompts@7.10.0': resolution: {integrity: sha512-X2HAjY9BClfFkJ2RP3iIiFxlct5JJVdaYYXhA7RKxsbc9KL+VbId79PSoUGH/OLS011NFbHHDMDcBKUj3T89+Q==} engines: {node: '>=18'} @@ -293,6 +382,15 @@ packages: '@types/node': optional: true + '@inquirer/prompts@8.0.1': + resolution: {integrity: sha512-MURRu/cyvLm9vchDDaVZ9u4p+ADnY0Mz3LQr0KTgihrrvuKZlqcWwlBC4lkOMvd0KKX4Wz7Ww9+uA7qEpQaqjg==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/rawlist@4.1.10': resolution: {integrity: sha512-Du4uidsgTMkoH5izgpfyauTL/ItVHOLsVdcY+wGeoGaG56BV+/JfmyoQGniyhegrDzXpfn3D+LFHaxMDRygcAw==} engines: {node: '>=18'} @@ -302,6 +400,15 @@ packages: '@types/node': optional: true + '@inquirer/rawlist@5.0.1': + resolution: {integrity: sha512-vVfVHKUgH6rZmMlyd0jOuGZo0Fw1jfcOqZF96lMwlgavx7g0x7MICe316bV01EEoI+c68vMdbkTTawuw3O+Fgw==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/search@3.2.1': resolution: {integrity: sha512-cKiuUvETublmTmaOneEermfG2tI9ABpb7fW/LqzZAnSv4ZaJnbEis05lOkiBuYX5hNdnX0Q9ryOQyrNidb55WA==} engines: {node: '>=18'} @@ -311,6 +418,15 @@ packages: '@types/node': optional: true + '@inquirer/search@4.0.1': + resolution: {integrity: sha512-XwiaK5xBvr31STX6Ji8iS3HCRysBXfL/jUbTzufdWTS6LTGtvDQA50oVETt1BJgjKyQBp9vt0VU6AmU/AnOaGA==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/select@4.4.1': resolution: {integrity: sha512-E9hbLU4XsNe2SAOSsFrtYtYQDVi1mfbqJrPDvXKnGlnRiApBdWMJz7r3J2Ff38AqULkPUD3XjQMD4492TymD7Q==} engines: {node: '>=18'} @@ -320,6 +436,15 @@ packages: '@types/node': optional: true + '@inquirer/select@5.0.1': + resolution: {integrity: sha512-gPByrgYoezGyKMq5KjV7Tuy1JU2ArIy6/sI8sprw0OpXope3VGQwP5FK1KD4eFFqEhKu470Dwe6/AyDPmGRA0Q==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@inquirer/type@3.0.10': resolution: {integrity: sha512-BvziSRxfz5Ov8ch0z/n3oijRSEcEsHnhggm4xFZe93DHcUCTlutlq9Ox4SVENAfcRD22UQq7T/atg9Wr3k09eA==} engines: {node: '>=18'} @@ -329,6 +454,15 @@ packages: '@types/node': optional: true + '@inquirer/type@4.0.1': + resolution: {integrity: sha512-odO8YwoQAw/eVu/PSPsDDVPmqO77r/Mq7zcoF5VduVqIu2wSRWUgmYb5K9WH1no0SjLnOe8MDKtDL++z6mfo2g==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + '@isaacs/fs-minipass@4.0.1': resolution: {integrity: sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==} engines: {node: '>=18.0.0'} @@ -486,67 +620,56 @@ packages: resolution: {integrity: sha512-gTJ/JnnjCMc15uwB10TTATBEhK9meBIY+gXP4s0sHD1zHOaIh4Dmy1X9wup18IiY9tTNk5gJc4yx9ctj/fjrIw==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.43.0': resolution: {integrity: sha512-ZJ3gZynL1LDSIvRfz0qXtTNs56n5DI2Mq+WACWZ7yGHFUEirHBRt7fyIk0NsCKhmRhn7WAcjgSkSVVxKlPNFFw==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.43.0': resolution: {integrity: sha512-8FnkipasmOOSSlfucGYEu58U8cxEdhziKjPD2FIa0ONVMxvl/hmONtX/7y4vGjdUhjcTHlKlDhw3H9t98fPvyA==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.43.0': resolution: {integrity: sha512-KPPyAdlcIZ6S9C3S2cndXDkV0Bb1OSMsX0Eelr2Bay4EsF9yi9u9uzc9RniK3mcUGCLhWY9oLr6er80P5DE6XA==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-loongarch64-gnu@4.43.0': resolution: {integrity: sha512-HPGDIH0/ZzAZjvtlXj6g+KDQ9ZMHfSP553za7o2Odegb/BEfwJcR0Sw0RLNpQ9nC6Gy8s+3mSS9xjZ0n3rhcYg==} cpu: [loong64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-powerpc64le-gnu@4.43.0': resolution: {integrity: sha512-gEmwbOws4U4GLAJDhhtSPWPXUzDfMRedT3hFMyRAvM9Mrnj+dJIFIeL7otsv2WF3D7GrV0GIewW0y28dOYWkmw==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.43.0': resolution: {integrity: sha512-XXKvo2e+wFtXZF/9xoWohHg+MuRnvO29TI5Hqe9xwN5uN8NKUYy7tXUG3EZAlfchufNCTHNGjEx7uN78KsBo0g==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.43.0': resolution: {integrity: sha512-ruf3hPWhjw6uDFsOAzmbNIvlXFXlBQ4nk57Sec8E8rUxs/AI4HD6xmiiasOOx/3QxS2f5eQMKTAwk7KHwpzr/Q==} cpu: [riscv64] os: [linux] - libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.43.0': resolution: {integrity: sha512-QmNIAqDiEMEvFV15rsSnjoSmO0+eJLoKRD9EAa9rrYNwO/XRCtOGM3A5A0X+wmG+XRrw9Fxdsw+LnyYiZWWcVw==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.43.0': resolution: {integrity: sha512-jAHr/S0iiBtFyzjhOkAics/2SrXE092qyqEg96e90L3t9Op8OTzS6+IX0Fy5wCt2+KqeHAkti+eitV0wvblEoQ==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.43.0': resolution: {integrity: sha512-3yATWgdeXyuHtBhrLt98w+5fKurdqvs8B53LaoKD7P7H7FKOONLsBVMNl9ghPQZQuYcceV5CDyPfyfGpMWD9mQ==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.43.0': resolution: {integrity: sha512-wVzXp2qDSCOpcBCT5WRWLmpJRIzv23valvcTwMHEobkjippNf+C3ys/+wf07poPkeNix0paTNemB2XrHr2TnGw==} @@ -596,6 +719,9 @@ packages: '@types/node@24.10.0': resolution: {integrity: sha512-qzQZRBqkFsYyaSWXuEHc2WR9c0a0CXwiE5FWUvn7ZM+vdy1uZLfCunD38UzhuB7YN/J11ndbDBcTmOdxJo9Q7A==} + '@types/node@24.10.1': + resolution: {integrity: sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==} + '@types/react@19.1.9': resolution: {integrity: sha512-WmdoynAX8Stew/36uTSVMcLJJ1KRh6L3IZRx1PZ7qJtBqT3dYTgyDTx8H1qoRghErydW7xw9mSJ3wS//tCRpFA==} @@ -626,10 +752,18 @@ packages: 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'} + ansis@4.0.0-node10: resolution: {integrity: sha512-BRrU0Bo1X9dFGw6KgGz6hWrqQuOlVEDOzkb0QSLZY9sXHqA7pNj7yHPVJRz7y/rj4EOJ3d/D5uxH+ee9leYgsg==} engines: {node: '>=10'} @@ -854,6 +988,9 @@ packages: ee-first@1.1.1: resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} + emoji-regex@10.6.0: + resolution: {integrity: sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A==} + emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -963,8 +1100,8 @@ packages: debug: optional: true - form-data@4.0.4: - resolution: {integrity: sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==} + form-data@4.0.5: + resolution: {integrity: sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==} engines: {node: '>= 6'} fresh@2.0.0: @@ -979,6 +1116,10 @@ packages: function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + get-east-asian-width@1.4.0: + resolution: {integrity: sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q==} + engines: {node: '>=18'} + get-intrinsic@1.3.0: resolution: {integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==} engines: {node: '>= 0.4'} @@ -1075,6 +1216,15 @@ packages: '@types/node': optional: true + inquirer@13.0.1: + resolution: {integrity: sha512-+Qob/OSCmHIgyFKa4S+bDk36Nudwt+zpUBGZaSttGMnvsrzbIqtNFS9RutEPc2QAzpQxBP0cV3wmY/c5Vy73qg==} + engines: {node: '>=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0'} + peerDependencies: + '@types/node': '>=18' + peerDependenciesMeta: + '@types/node': + optional: true + ip-address@9.0.5: resolution: {integrity: sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==} engines: {node: '>= 12'} @@ -1513,10 +1663,18 @@ packages: 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.1.2: + resolution: {integrity: sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==} + engines: {node: '>=12'} + supports-color@10.2.2: resolution: {integrity: sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==} engines: {node: '>=18'} @@ -1649,6 +1807,10 @@ packages: 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'} + ws@7.5.10: resolution: {integrity: sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==} engines: {node: '>=8.3.0'} @@ -1718,6 +1880,8 @@ snapshots: '@inquirer/ansi@1.0.2': {} + '@inquirer/ansi@2.0.1': {} + '@inquirer/checkbox@4.3.1(@types/node@24.10.0)': dependencies: '@inquirer/ansi': 1.0.2 @@ -1728,6 +1892,15 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/checkbox@5.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/ansi': 2.0.1 + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/figures': 2.0.1 + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/confirm@5.1.20(@types/node@24.10.0)': dependencies: '@inquirer/core': 10.3.1(@types/node@24.10.0) @@ -1735,6 +1908,13 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/confirm@6.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/core@10.3.1(@types/node@24.10.0)': dependencies: '@inquirer/ansi': 1.0.2 @@ -1748,6 +1928,18 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/core@11.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/ansi': 2.0.1 + '@inquirer/figures': 2.0.1 + '@inquirer/type': 4.0.1(@types/node@24.10.1) + cli-width: 4.1.0 + mute-stream: 3.0.0 + signal-exit: 4.1.0 + wrap-ansi: 9.0.2 + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/editor@4.2.22(@types/node@24.10.0)': dependencies: '@inquirer/core': 10.3.1(@types/node@24.10.0) @@ -1756,6 +1948,14 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/editor@5.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/external-editor': 2.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/expand@4.0.22(@types/node@24.10.0)': dependencies: '@inquirer/core': 10.3.1(@types/node@24.10.0) @@ -1764,6 +1964,13 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/expand@5.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/external-editor@1.0.3(@types/node@24.10.0)': dependencies: chardet: 2.1.1 @@ -1771,8 +1978,17 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/external-editor@2.0.1(@types/node@24.10.1)': + dependencies: + chardet: 2.1.1 + iconv-lite: 0.7.0 + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/figures@1.0.15': {} + '@inquirer/figures@2.0.1': {} + '@inquirer/input@4.3.0(@types/node@24.10.0)': dependencies: '@inquirer/core': 10.3.1(@types/node@24.10.0) @@ -1780,6 +1996,13 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/input@5.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/number@3.0.22(@types/node@24.10.0)': dependencies: '@inquirer/core': 10.3.1(@types/node@24.10.0) @@ -1787,6 +2010,13 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/number@4.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/password@4.0.22(@types/node@24.10.0)': dependencies: '@inquirer/ansi': 1.0.2 @@ -1795,6 +2025,14 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/password@5.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/ansi': 2.0.1 + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/prompts@7.10.0(@types/node@24.10.0)': dependencies: '@inquirer/checkbox': 4.3.1(@types/node@24.10.0) @@ -1810,6 +2048,21 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/prompts@8.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/checkbox': 5.0.1(@types/node@24.10.1) + '@inquirer/confirm': 6.0.1(@types/node@24.10.1) + '@inquirer/editor': 5.0.1(@types/node@24.10.1) + '@inquirer/expand': 5.0.1(@types/node@24.10.1) + '@inquirer/input': 5.0.1(@types/node@24.10.1) + '@inquirer/number': 4.0.1(@types/node@24.10.1) + '@inquirer/password': 5.0.1(@types/node@24.10.1) + '@inquirer/rawlist': 5.0.1(@types/node@24.10.1) + '@inquirer/search': 4.0.1(@types/node@24.10.1) + '@inquirer/select': 5.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/rawlist@4.1.10(@types/node@24.10.0)': dependencies: '@inquirer/core': 10.3.1(@types/node@24.10.0) @@ -1818,6 +2071,13 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/rawlist@5.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/search@3.2.1(@types/node@24.10.0)': dependencies: '@inquirer/core': 10.3.1(@types/node@24.10.0) @@ -1827,6 +2087,14 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/search@4.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/figures': 2.0.1 + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/select@4.4.1(@types/node@24.10.0)': dependencies: '@inquirer/ansi': 1.0.2 @@ -1837,10 +2105,23 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + '@inquirer/select@5.0.1(@types/node@24.10.1)': + dependencies: + '@inquirer/ansi': 2.0.1 + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/figures': 2.0.1 + '@inquirer/type': 4.0.1(@types/node@24.10.1) + optionalDependencies: + '@types/node': 24.10.1 + '@inquirer/type@3.0.10(@types/node@24.10.0)': optionalDependencies: '@types/node': 24.10.0 + '@inquirer/type@4.0.1(@types/node@24.10.1)': + optionalDependencies: + '@types/node': 24.10.1 + '@isaacs/fs-minipass@4.0.1': dependencies: minipass: 7.1.2 @@ -2121,7 +2402,7 @@ snapshots: '@types/jsonwebtoken@9.0.10': dependencies: '@types/ms': 0.7.34 - '@types/node': 24.10.0 + '@types/node': 24.10.1 '@types/lodash-es@4.17.12': dependencies: @@ -2139,6 +2420,10 @@ snapshots: dependencies: undici-types: 7.16.0 + '@types/node@24.10.1': + dependencies: + undici-types: 7.16.0 + '@types/react@19.1.9': dependencies: csstype: 3.1.3 @@ -2147,11 +2432,11 @@ snapshots: '@types/send@1.2.1': dependencies: - '@types/node': 24.10.0 + '@types/node': 24.10.1 '@types/ws@8.18.1': dependencies: - '@types/node': 24.10.0 + '@types/node': 24.10.1 agent-base@7.1.3: {} @@ -2165,10 +2450,14 @@ snapshots: 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: {} + ansis@4.0.0-node10: {} anymatch@3.1.3: @@ -2206,7 +2495,7 @@ snapshots: bun-types@1.3.2(@types/react@19.1.9): dependencies: - '@types/node': 24.10.0 + '@types/node': 24.10.1 '@types/react': 19.1.9 call-bind-apply-helpers@1.0.2: @@ -2354,6 +2643,8 @@ snapshots: ee-first@1.1.1: {} + emoji-regex@10.6.0: {} + emoji-regex@8.0.0: {} encodeurl@2.0.0: {} @@ -2441,7 +2732,7 @@ snapshots: optionalDependencies: debug: 4.3.7(supports-color@10.2.2) - form-data@4.0.4: + form-data@4.0.5: dependencies: asynckit: 0.4.0 combined-stream: 1.0.8 @@ -2456,6 +2747,8 @@ snapshots: function-bind@1.1.2: {} + get-east-asian-width@1.4.0: {} + get-intrinsic@1.3.0: dependencies: call-bind-apply-helpers: 1.0.2 @@ -2570,6 +2863,18 @@ snapshots: optionalDependencies: '@types/node': 24.10.0 + inquirer@13.0.1(@types/node@24.10.1): + dependencies: + '@inquirer/ansi': 2.0.1 + '@inquirer/core': 11.0.1(@types/node@24.10.1) + '@inquirer/prompts': 8.0.1(@types/node@24.10.1) + '@inquirer/type': 4.0.1(@types/node@24.10.1) + mute-stream: 3.0.0 + run-async: 4.0.6 + rxjs: 7.8.2 + optionalDependencies: + '@types/node': 24.10.1 + ip-address@9.0.5: dependencies: jsbn: 1.1.0 @@ -3053,10 +3358,20 @@ snapshots: 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.4.0 + strip-ansi: 7.1.2 + strip-ansi@6.0.1: dependencies: ansi-regex: 5.0.1 + strip-ansi@7.1.2: + dependencies: + ansi-regex: 6.2.2 + supports-color@10.2.2: {} supports-color@7.2.0: @@ -3131,6 +3446,12 @@ snapshots: 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.1.2 + ws@7.5.10: {} ws@8.18.0: diff --git a/src/command/deploy.ts b/src/command/deploy.ts index b4175a3..1342665 100644 --- a/src/command/deploy.ts +++ b/src/command/deploy.ts @@ -6,7 +6,6 @@ import FormData from 'form-data'; import { getBaseURL, query, storage } from '@/module/query.ts'; import { getConfig } from '@/module/index.ts'; import inquirer from 'inquirer'; -import { packLib, unpackLib } from './publish.ts'; import chalk from 'chalk'; import { installDeps } from '@/uitls/npm.ts'; import { upload } from '@/module/download/upload.ts'; @@ -293,42 +292,3 @@ const deployLoad = new Command('deploy-load') }); app.addCommand(deployLoad); -const local = new Command('local') - .description('本地部署') - .argument('', 'key') - .option('-i, --ignore', '使用 .npmignore 文件模式去忽略文件进行打包, 不需要package.json中的files字段') - .option('-u, --update', 'query查询 127.0.0.1:11015/api/router?path=local-apps&key=detect') - .action(async (key, opts) => { - console.log('local deploy'); - const { outputFilePath } = await packLib(opts?.ignore); - const mainAppPath = getConfig().mainAppPath; - const appsPath = getConfig().appsPath || path.join(mainAppPath, 'apps'); - if (!key) { - console.error(chalk.red('key is required')); - return; - } - const appPath = path.join(appsPath, key); - if (!fs.existsSync(appPath)) { - fs.mkdirSync(appPath, { recursive: true }); - } - // 复制应用到apps目录下 - if (outputFilePath) { - await unpackLib(outputFilePath, appPath); - fs.unlinkSync(outputFilePath); - installDeps({ appPath }); - if (opts?.update) { - const res = await query.post( - { path: 'local-apps', key: 'detect' }, - { - url: `http://127.0.0.1:11015/api/router?path=local-apps&key=detect`, - }, - ); - if (res.code === 200) { - console.log('local deploy success'); - } else { - console.error('local deploy failed', res.message); - } - } - } - }); -app.addCommand(local); diff --git a/src/command/publish.ts b/src/command/publish.ts index e4b9563..0ab91de 100644 --- a/src/command/publish.ts +++ b/src/command/publish.ts @@ -1,11 +1,9 @@ -import fs, { createReadStream } from 'fs'; +import fs from 'fs'; import path from 'path'; -import * as tar from 'tar'; import glob from 'fast-glob'; import { program, Command } from '@/program.ts'; import { getConfig, query } from '@/module/index.ts'; import { fileIsExist } from '@/uitls/file.ts'; -import ignore from 'ignore'; import { chalk } from '@/module/chalk.ts'; import * as backServices from '@/query/services/index.ts'; import inquirer from 'inquirer'; @@ -33,43 +31,11 @@ async function collectFileInfo(filePath: string, baseDir = '.'): Promise return []; } -// 解析 .npmignore 文件 -async function loadNpmIgnore(cwd: string): Promise { - const npmIgnorePath = path.join(cwd, '.npmignore'); - const ig = ignore(); - - try { - const content = fs.readFileSync(npmIgnorePath, 'utf-8'); - ig.add(content); - } catch (err) { - console.warn('.npmignore not found, using default ignore rules'); - // 如果没有 .npmignore 文件,使用默认规则 - ig.add(['node_modules', '.git']); - } - - return ig; -} -// 获取文件列表,兼容 .npmignore -async function getFiles(cwd: string, patterns: string[]): Promise { - const ig = await loadNpmIgnore(cwd); - - // 使用 fast-glob 匹配文件 - const allFiles = await glob(patterns, { - cwd, - dot: true, // 包括隐藏文件 - onlyFiles: false, // 包括目录 - followSymbolicLinks: true, - }); - - // 过滤忽略的文件 - const filteredFiles = allFiles.filter((file) => !ig.ignores(file)); - return filteredFiles; -} /** * 复制文件到 pack-dist - * @param files 文件列表 + * @param files 文件列表, 或者文件夹列表 * @param cwd 当前工作目录 - * @param packDist 打包目录 + * @param packDist 打包目录 pack-dist */ export const copyFilesToPackDist = async (files: string[], cwd: string, packDist = 'pack-dist') => { const packDistPath = path.join(cwd, packDist); @@ -80,10 +46,16 @@ export const copyFilesToPackDist = async (files: string[], cwd: string, packDist } files.forEach((file) => { const stat = fs.statSync(path.join(cwd, file)); + let outputFile = file; + if (file.startsWith('dist/')) { + outputFile = file.replace(/^dist\//, ''); + } else if (file === 'dist') { + outputFile = ''; + } if (stat.isDirectory()) { - fs.cpSync(path.join(cwd, file), path.join(packDistPath, file), { recursive: true }); + fs.cpSync(path.join(cwd, file), path.join(packDistPath, outputFile), { recursive: true }); } else { - fs.copyFileSync(path.join(cwd, file), path.join(packDistPath, file), fs.constants.COPYFILE_EXCL); + fs.copyFileSync(path.join(cwd, file), path.join(packDistPath, outputFile)); } }); const packageInfo = await getPackageInfo(); @@ -117,10 +89,11 @@ ${filesString} `; - fs.writeFileSync(indexHtmlPath, indexHtmlContent); + if (!fileIsExist(indexHtmlPath)) { + fs.writeFileSync(indexHtmlPath, indexHtmlContent); + } }; -export const pack = async (opts: { isTar: boolean; packDist?: string }) => { - const isTar = opts.isTar; +export const pack = async (opts: { packDist?: string }) => { const cwd = process.cwd(); const collection: Record = {}; const packageJsonPath = path.join(cwd, 'package.json'); @@ -137,22 +110,17 @@ export const pack = async (opts: { isTar: boolean; packDist?: string }) => { console.error('Invalid package.json:', error); return; } - - let outputFileName = `${packageJson.name}-${packageJson.version}.tgz` - .replace('@', '') // 替换特殊字符 @ - .replace(/[\/\\:*?"<>|]/g, '-'); // 替换特殊字符 - - // 当 opts.isTar 为 true 时,输出文件为 tgz 文件 - const outputFilePath = path.join(cwd, outputFileName); + let files = packageJson.files; // 从 package.json 的 files 字段收集文件 - const filesToInclude = packageJson.files - ? await glob(packageJson.files, { - cwd: cwd, - dot: true, // 包括隐藏文件 - onlyFiles: false, // 包括目录 - followSymbolicLinks: true, // 处理符号链接 - }) + const filesToInclude = files + ? await glob(files, { + cwd: cwd, + dot: true, // 包括隐藏文件 + onlyFiles: false, // 包括目录 + followSymbolicLinks: true, // 处理符号链接 + ignore: ['node_modules/**', ".git/**", opts.packDist ? opts.packDist + '/**' : ''], + }) : []; // 确保 README.md 和 dist 存在(忽略大小写检测 README.md) const readmeFile = await findFileInsensitive('README.md'); @@ -166,38 +134,23 @@ export const pack = async (opts: { isTar: boolean; packDist?: string }) => { const allFiles = (await Promise.all(filesToInclude.map((file) => collectFileInfo(file)))).flat(); // 输出文件详细信息 - console.log('Tarball Contents:'); + console.log('文件列表:'); allFiles.forEach((file) => { console.log(`${file.size}B ${file.path}`); }); const totalSize = allFiles.reduce((sum, file) => sum + file.size, 0); - const packageSize = (totalSize / 1024).toFixed(2) + ' kB'; collection.files = allFiles; collection.packageJson = packageJson; collection.totalSize = totalSize; collection.tags = packageJson.app?.tags || packageJson.keywords || []; - console.log('\nTarball Details'); + console.log('\n基本信息'); console.log(`name: ${packageJson.name}`); console.log(`version: ${packageJson.version}`); - isTar && console.log(`filename: ${outputFileName}`); - isTar && console.log(`package size: ${packageSize}`); console.log(`total files: ${allFiles.length}`); - opts?.isTar && console.log(`Created package: ${outputFileName}`); try { - if (opts.isTar) { - await tar.c( - { - gzip: true, - file: outputFilePath, - cwd: cwd, - }, - filesToInclude, - ); - } else { - copyFilesToPackDist(filesToInclude, cwd, opts.packDist); - } + copyFilesToPackDist(filesToInclude, cwd, opts.packDist); } catch (error) { console.error('Error creating tarball:', error); } @@ -206,7 +159,7 @@ export const pack = async (opts: { isTar: boolean; packDist?: string }) => { const readmeContent = fs.readFileSync(readme, 'utf-8'); collection.readme = readmeContent; } - return { collection, outputFilePath, dir: cwd }; + return { collection, dir: cwd }; }; export const getPackageInfo = async () => { const cwd = process.cwd(); @@ -220,104 +173,16 @@ export const getPackageInfo = async () => { } }; -type PackByIgnoreOpts = { - isTar: boolean; - packDist?: string; -}; -export const packByIgnore = async (opts: PackByIgnoreOpts) => { - let collection: Record = {}; - const cwd = process.cwd(); - const patterns = ['**/*']; // 匹配所有文件 - const packageJsonPath = path.join(cwd, 'package.json'); - let packageJson; - try { - const packageContent = fs.readFileSync(packageJsonPath, 'utf-8'); - packageJson = JSON.parse(packageContent); - } catch (error) { - console.error('Invalid package.json:', error); - return; - } - - let outputFileName = `${packageJson.name}-${packageJson.version}.tgz` - .replace('@', '') // 替换特殊字符 @ - .replace(/[\/\\:*?"<>|]/g, '-'); // 替换特殊字符 - - const outputFilePath = path.join(cwd, outputFileName); - - // 获取符合条件的文件列表 - const files = await getFiles(cwd, patterns); - - console.log('Files to include in the package:'); - // files 获取 size 和 path - const filesInfo = await Promise.all(files.map((file) => collectFileInfo(file))); - const allFiles = filesInfo.flat(); - allFiles.forEach((file) => { - console.log(`${file.size}B ${file.path}`); - }); - - const totalSize = allFiles.reduce((sum, file) => sum + file.size, 0); - const packageSize = (totalSize / 1024).toFixed(2) + ' kB'; - - collection.files = allFiles; - collection.packageJson = packageJson; - collection.totalSize = totalSize; - collection.tags = packageJson.app?.tags || packageJson.keywords || []; - - console.log('\nTarball Details'); - console.log(`package size: ${packageSize}`); - console.log(`total files: ${allFiles.length}`); - const filesToInclude = files.map((file) => path.relative(cwd, file)); - try { - if (opts.isTar) { - await tar.c( - { - gzip: true, - file: outputFilePath, - cwd: cwd, - }, - filesToInclude, - ); - } else { - copyFilesToPackDist(filesToInclude, cwd, opts.packDist); - } - } catch (error) { - console.error('Error creating tarball:', error); - } - const readme = await findFileInsensitive('README.md'); - if (readme) { - const readmeContent = fs.readFileSync(readme, 'utf-8'); - collection.readme = readmeContent; - } - return { collection, outputFilePath, dir: cwd }; -}; /** * 打包应用 - * @param ignore 是否忽略 .npmignore 文件 * @returns 打包结果 */ export const packLib = async ({ - ignore = false, - tar = false, packDist = 'pack-dist', }: { - ignore?: boolean; - tar?: boolean; packDist?: string; -}): Promise<{ collection: Record; outputFilePath: string; dir: string }> => { - if (ignore) { - return await packByIgnore({ isTar: tar, packDist }); - } - return await pack({ isTar: tar, packDist }); -}; -export const unpackLib = async (filePath: string, cwd: string) => { - try { - await tar.x({ - file: filePath, - cwd: cwd, - }); - } catch (error) { - console.error('Error extracting tarball:', error); - } +}): Promise<{ collection: Record; dir: string }> => { + return await pack({ packDist }); }; const publishCommand = new Command('publish') .description('发布应用') @@ -384,12 +249,10 @@ const deployLoadFn = async (id: string, fileKey: string, force = false, install }; const packCommand = new Command('pack') - .description('打包应用, 默认使用 package.json 中的 files 字段') - .option('-i, --ignore', '使用 .npmignore 文件模式去忽略文件进行打包, 不需要package.json中的files字段') + .description('打包应用, 使用 package.json 中的 files 字段,如果是 dist 的路径,直接复制到 pack-dist 的根目录') .option('-p, --publish', '打包并发布') .option('-u, --update', '发布后显示更新命令, show command for deploy to server') - .option('-t, --tar', '打包为 tgz 文件') - .option('-d, --packDist ', '打包目录') + .option('-d, --packDist ', '打包到的目录') .option('-y, --yes', '确定,直接打包', true) .option('-c, --clean', '清理 package.json中的 devDependencies') .action(async (opts) => { @@ -435,8 +298,6 @@ const packCommand = new Command('pack') appKey = answers.appKey || appKey; } let value = await packLib({ - ignore: opts.ignore, - tar: opts.tar, packDist, }); if (opts?.clean) { @@ -448,7 +309,7 @@ const packCommand = new Command('pack') // 运行 deploy 命令 // const runDeployCommand = 'envision pack-deploy ' + value.outputFilePath + ' -k ' + appKey; const [_app, _command] = process.argv; - let deployDist = opts.isTar ? value.outputFilePath : packDist; + let deployDist = packDist; const deployCommand = [_app, _command, 'deploy', deployDist, '-k', appKey, '-v', version, '-u', '-d']; if (opts.org) { deployCommand.push('-o', opts.org); @@ -504,10 +365,14 @@ enum AppType { * pm2 启动 */ Pm2SystemApp = 'pm2-system-app', + /** + * 脚本应用 + */ + ScriptApp = 'script-app', } type ServiceItem = { key: string; - status: 'inactive' | 'running' | 'stop' | 'error'; + status: 'inactive' | 'running' | 'stop' | 'error' | 'unknown'; type: AppType; description: string; version: string;