From 3efc3b3cc5c1b5008684d45b4a55ac56cc628127 Mon Sep 17 00:00:00 2001 From: xion Date: Fri, 6 Dec 2024 22:36:08 +0800 Subject: [PATCH] temp remove local-microapp --- package.json | 14 +- pnpm-lock.yaml | 367 +++++++++++++++++++----- src/app.ts | 31 +- src/route.ts | 16 ++ src/routes-simple/code/upload.ts | 2 +- src/routes-simple/upload.ts | 2 +- src/routes/micro-app/index.ts | 4 +- src/routes/micro-app/lib/app-file.ts | 44 +-- src/routes/micro-app/list.ts | 61 ---- src/routes/micro-app/manager-app.ts | 18 +- src/routes/micro-app/module/load-app.ts | 55 ---- src/routes/micro-app/module/manager.ts | 250 ---------------- src/routes/micro-app/routes/manager.ts | 56 ---- src/routes/page/module/cache-file.ts | 2 +- 14 files changed, 362 insertions(+), 560 deletions(-) delete mode 100644 src/routes/micro-app/module/load-app.ts delete mode 100644 src/routes/micro-app/routes/manager.ts diff --git a/package.json b/package.json index 2ea69ce..e8825e8 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,12 @@ "@babel/preset-typescript": "^7.26.0", "@kevisual/ai-graph": "workspace:^", "@kevisual/ai-lang": "workspace:^", - "@kevisual/auth": "1.0.4", - "@kevisual/router": "0.0.5", + "@kevisual/auth": "1.0.5", + "@kevisual/local-app-manager": "0.1.6-alpha.2", + "@kevisual/router": "^0.0.6-alpha-2", "@types/semver": "^7.5.8", "archiver": "^7.0.1", - "bullmq": "^5.29.1", + "bullmq": "^5.31.2", "dayjs": "^1.11.13", "dts-bundle-generator": "^9.5.1", "formidable": "^3.5.2", @@ -65,8 +66,7 @@ "zod": "^3.23.8" }, "devDependencies": { - "@abearxiong/use-file-store": "^0.0.1", - "@kevisual/use-config": "^1.0.3", + "@kevisual/use-config": "^1.0.5", "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-commonjs": "^28.0.1", "@rollup/plugin-json": "^6.1.0", @@ -79,7 +79,7 @@ "@types/jsonwebtoken": "^9.0.7", "@types/lodash-es": "^4.17.12", "@types/node": "^22.10.1", - "@types/react": "^18.3.12", + "@types/react": "^19.0.0", "@types/uuid": "^10.0.0", "concurrently": "^9.1.0", "cross-env": "^7.0.3", @@ -87,7 +87,7 @@ "pm2": "^5.4.3", "pm2-dev": "^5.4.1", "rimraf": "^6.0.1", - "rollup": "^4.27.4", + "rollup": "^4.28.1", "rollup-plugin-copy": "^3.5.0", "rollup-plugin-dts": "^6.1.1", "tape": "^5.9.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d9ed283..fa97cf8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,11 +29,14 @@ importers: specifier: workspace:^ version: link:packages/ai-lang '@kevisual/auth': - specifier: 1.0.4 - version: 1.0.4(@kevisual/router@0.0.5) + specifier: 1.0.5 + version: 1.0.5 + '@kevisual/local-app-manager': + specifier: 0.1.6-alpha.2 + version: 0.1.6-alpha.2(@kevisual/router@0.0.6-alpha-2)(@kevisual/types@0.0.1)(@kevisual/use-config@1.0.5) '@kevisual/router': - specifier: 0.0.5 - version: 0.0.5 + specifier: ^0.0.6-alpha-2 + version: 0.0.6-alpha-2 '@types/semver': specifier: ^7.5.8 version: 7.5.8 @@ -41,8 +44,8 @@ importers: specifier: ^7.0.1 version: 7.0.1 bullmq: - specifier: ^5.29.1 - version: 5.29.1 + specifier: ^5.31.2 + version: 5.31.2 dayjs: specifier: ^1.11.13 version: 1.11.13 @@ -90,7 +93,7 @@ importers: version: 8.13.1 rollup-plugin-esbuild: specifier: ^6.1.1 - version: 6.1.1(esbuild@0.23.1)(rollup@4.27.4) + version: 6.1.1(esbuild@0.23.1)(rollup@4.28.1) semver: specifier: ^7.6.3 version: 7.6.3 @@ -116,30 +119,27 @@ importers: specifier: ^3.23.8 version: 3.23.8 devDependencies: - '@abearxiong/use-file-store': - specifier: ^0.0.1 - version: 0.0.1(esbuild@0.23.1)(typescript@5.7.2) '@kevisual/use-config': - specifier: ^1.0.3 - version: 1.0.3 + specifier: ^1.0.5 + version: 1.0.5 '@rollup/plugin-alias': specifier: ^5.1.1 - version: 5.1.1(rollup@4.27.4) + version: 5.1.1(rollup@4.28.1) '@rollup/plugin-commonjs': specifier: ^28.0.1 - version: 28.0.1(rollup@4.27.4) + version: 28.0.1(rollup@4.28.1) '@rollup/plugin-json': specifier: ^6.1.0 - version: 6.1.0(rollup@4.27.4) + version: 6.1.0(rollup@4.28.1) '@rollup/plugin-node-resolve': specifier: ^15.3.0 - version: 15.3.0(rollup@4.27.4) + version: 15.3.0(rollup@4.28.1) '@rollup/plugin-replace': specifier: ^6.0.1 - version: 6.0.1(rollup@4.27.4) + version: 6.0.1(rollup@4.28.1) '@rollup/plugin-typescript': specifier: ^12.1.1 - version: 12.1.1(rollup@4.27.4)(tslib@2.8.1)(typescript@5.7.2) + version: 12.1.1(rollup@4.28.1)(tslib@2.8.1)(typescript@5.7.2) '@types/archiver': specifier: ^6.0.3 version: 6.0.3 @@ -159,8 +159,8 @@ importers: specifier: ^22.10.1 version: 22.10.1 '@types/react': - specifier: ^18.3.12 - version: 18.3.12 + specifier: ^19.0.0 + version: 19.0.0 '@types/uuid': specifier: ^10.0.0 version: 10.0.0 @@ -183,14 +183,14 @@ importers: specifier: latest version: 6.0.1 rollup: - specifier: ^4.27.4 - version: 4.27.4 + specifier: ^4.28.1 + version: 4.28.1 rollup-plugin-copy: specifier: ^3.5.0 version: 3.5.0 rollup-plugin-dts: specifier: ^6.1.1 - version: 6.1.1(rollup@4.27.4)(typescript@5.7.2) + version: 6.1.1(rollup@4.28.1)(typescript@5.7.2) tape: specifier: ^5.9.0 version: 5.9.0 @@ -1048,20 +1048,28 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} - '@kevisual/auth@1.0.4': - resolution: {integrity: sha512-PcSVQdawOqMOTm1ZKumkC8n3SJSaNOcCYAma0XeutwJEpUMUcHWl5eB2Tado3RwOJx1F1TF5jlbgFcRJZwerog==} - peerDependencies: - '@kevisual/router': ^0.0.4 + '@kevisual/auth@1.0.5': + resolution: {integrity: sha512-GwsLj7unKXi7lmMiIIgdig4LwwLiDJnOy15HHZR5gMbyK6s5/uJiMY5RXPB2+onGzTNDqFo/hXjsD2wkerHPVg==} - '@kevisual/router@0.0.5': - resolution: {integrity: sha512-ALDsOrKwgxKWwwrnWgrcYoCPPSX0D6aU4P784HQslkLMRoQQ4xgsGr95BW+Wk9LeesXWsUhEpDW3QjUSzYoPlA==} + '@kevisual/local-app-manager@0.1.6-alpha.2': + resolution: {integrity: sha512-sVcq0/ICqRIPEffAoAanoFchYSdc/sdBbUHydF+4THF9ocU2cztgAZC261lC9gmA8a0PuIwGSoOmszQPvqxsKw==} + peerDependencies: + '@kevisual/router': ^0.0.6-alpha-2 + '@kevisual/types': ^0.0.1 + '@kevisual/use-config': ^1.0.5 '@kevisual/router@0.0.6-alpha-2': resolution: {integrity: sha512-P9rarSQG0tp8L3GSgivYZQ//SugEt6/YCzNE8087KsRIdF1g0v8rXGfi1G3b8cXRz/ip79Lb+caU7LsoAQhmOQ==} + '@kevisual/types@0.0.1': + resolution: {integrity: sha512-3Wn6WjpfbOGTqIVS7YQ/0CIQEEbZEp+uCTbIWqTZyuytiA/Xoglr5kG3AbTuLFQ81AvfxjEjp5dAnFub+2IhhQ==} + '@kevisual/use-config@1.0.3': resolution: {integrity: sha512-pACKQP6488CMUT7685NJCkrzItQaIWC2gOSq3+a7gHfLpIjgTiGWLZoE8OozJCFf7HYsCYgYpsx5EgWv553nrg==} + '@kevisual/use-config@1.0.5': + resolution: {integrity: sha512-KENc9AI9rd8ooT/EkyXGCpfpLQi1cdmQIXIVDQJBXVLoXNSaFoCYDsaFWA6jlbiMPRwOHN99cx91elgUt7Asig==} + '@langchain/core@0.3.3': resolution: {integrity: sha512-WAtkmhbdl2T41qzimTzhb3pXCHQxO4onqxzPxgdf3KftQdTwLq0YYBDhozRMZLNAd/+cfH0ymZGaZSsnc9Ogsg==} engines: {node: '>=18'} @@ -1253,6 +1261,11 @@ packages: cpu: [arm] os: [android] + '@rollup/rollup-android-arm-eabi@4.28.1': + resolution: {integrity: sha512-2aZp8AES04KI2dy3Ss6/MDjXbwBzj+i0GqKtWXgw2/Ma6E4jJvujryO6gJAghIRVz7Vwr9Gtl/8na3nDUKpraQ==} + cpu: [arm] + os: [android] + '@rollup/rollup-android-arm64@4.27.2': resolution: {integrity: sha512-xsPeJgh2ThBpUqlLgRfiVYBEf/P1nWlWvReG+aBWfNv3XEBpa6ZCmxSVnxJgLgkNz4IbxpLy64h2gCmAAQLneQ==} cpu: [arm64] @@ -1263,6 +1276,11 @@ packages: cpu: [arm64] os: [android] + '@rollup/rollup-android-arm64@4.28.1': + resolution: {integrity: sha512-EbkK285O+1YMrg57xVA+Dp0tDBRB93/BZKph9XhMjezf6F4TpYjaUSuPt5J0fZXlSag0LmZAsTmdGGqPp4pQFA==} + cpu: [arm64] + os: [android] + '@rollup/rollup-darwin-arm64@4.27.2': resolution: {integrity: sha512-KnXU4m9MywuZFedL35Z3PuwiTSn/yqRIhrEA9j+7OSkji39NzVkgxuxTYg5F8ryGysq4iFADaU5osSizMXhU2A==} cpu: [arm64] @@ -1273,6 +1291,11 @@ packages: cpu: [arm64] os: [darwin] + '@rollup/rollup-darwin-arm64@4.28.1': + resolution: {integrity: sha512-prduvrMKU6NzMq6nxzQw445zXgaDBbMQvmKSJaxpaZ5R1QDM8w+eGxo6Y/jhT/cLoCvnZI42oEqf9KQNYz1fqQ==} + cpu: [arm64] + os: [darwin] + '@rollup/rollup-darwin-x64@4.27.2': resolution: {integrity: sha512-Hj77A3yTvUeCIx/Vi+4d4IbYhyTwtHj07lVzUgpUq9YpJSEiGJj4vXMKwzJ3w5zp5v3PFvpJNgc/J31smZey6g==} cpu: [x64] @@ -1283,6 +1306,11 @@ packages: cpu: [x64] os: [darwin] + '@rollup/rollup-darwin-x64@4.28.1': + resolution: {integrity: sha512-WsvbOunsUk0wccO/TV4o7IKgloJ942hVFK1CLatwv6TJspcCZb9umQkPdvB7FihmdxgaKR5JyxDjWpCOp4uZlQ==} + cpu: [x64] + os: [darwin] + '@rollup/rollup-freebsd-arm64@4.27.2': resolution: {integrity: sha512-RjgKf5C3xbn8gxvCm5VgKZ4nn0pRAIe90J0/fdHUsgztd3+Zesb2lm2+r6uX4prV2eUByuxJNdt647/1KPRq5g==} cpu: [arm64] @@ -1293,6 +1321,11 @@ packages: cpu: [arm64] os: [freebsd] + '@rollup/rollup-freebsd-arm64@4.28.1': + resolution: {integrity: sha512-HTDPdY1caUcU4qK23FeeGxCdJF64cKkqajU0iBnTVxS8F7H/7BewvYoG+va1KPSL63kQ1PGNyiwKOfReavzvNA==} + cpu: [arm64] + os: [freebsd] + '@rollup/rollup-freebsd-x64@4.27.2': resolution: {integrity: sha512-duq21FoXwQtuws+V9H6UZ+eCBc7fxSpMK1GQINKn3fAyd9DFYKPJNcUhdIKOrMFjLEJgQskoMoiuizMt+dl20g==} cpu: [x64] @@ -1303,6 +1336,11 @@ packages: cpu: [x64] os: [freebsd] + '@rollup/rollup-freebsd-x64@4.28.1': + resolution: {integrity: sha512-m/uYasxkUevcFTeRSM9TeLyPe2QDuqtjkeoTpP9SW0XxUWfcYrGDMkO/m2tTw+4NMAF9P2fU3Mw4ahNvo7QmsQ==} + cpu: [x64] + os: [freebsd] + '@rollup/rollup-linux-arm-gnueabihf@4.27.2': resolution: {integrity: sha512-6npqOKEPRZkLrMcvyC/32OzJ2srdPzCylJjiTJT2c0bwwSGm7nz2F9mNQ1WrAqCBZROcQn91Fno+khFhVijmFA==} cpu: [arm] @@ -1315,6 +1353,12 @@ packages: os: [linux] libc: [glibc] + '@rollup/rollup-linux-arm-gnueabihf@4.28.1': + resolution: {integrity: sha512-QAg11ZIt6mcmzpNE6JZBpKfJaKkqTm1A9+y9O+frdZJEuhQxiugM05gnCWiANHj4RmbgeVJpTdmKRmH/a+0QbA==} + cpu: [arm] + os: [linux] + libc: [glibc] + '@rollup/rollup-linux-arm-musleabihf@4.27.2': resolution: {integrity: sha512-V9Xg6eXtgBtHq2jnuQwM/jr2mwe2EycnopO8cbOvpzFuySCGtKlPCI3Hj9xup/pJK5Q0388qfZZy2DqV2J8ftw==} cpu: [arm] @@ -1327,6 +1371,12 @@ packages: os: [linux] libc: [musl] + '@rollup/rollup-linux-arm-musleabihf@4.28.1': + resolution: {integrity: sha512-dRP9PEBfolq1dmMcFqbEPSd9VlRuVWEGSmbxVEfiq2cs2jlZAl0YNxFzAQS2OrQmsLBLAATDMb3Z6MFv5vOcXg==} + cpu: [arm] + os: [linux] + libc: [musl] + '@rollup/rollup-linux-arm64-gnu@4.27.2': resolution: {integrity: sha512-uCFX9gtZJoQl2xDTpRdseYuNqyKkuMDtH6zSrBTA28yTfKyjN9hQ2B04N5ynR8ILCoSDOrG/Eg+J2TtJ1e/CSA==} cpu: [arm64] @@ -1339,6 +1389,12 @@ packages: os: [linux] libc: [glibc] + '@rollup/rollup-linux-arm64-gnu@4.28.1': + resolution: {integrity: sha512-uGr8khxO+CKT4XU8ZUH1TTEUtlktK6Kgtv0+6bIFSeiSlnGJHG1tSFSjm41uQ9sAO/5ULx9mWOz70jYLyv1QkA==} + cpu: [arm64] + os: [linux] + libc: [glibc] + '@rollup/rollup-linux-arm64-musl@4.27.2': resolution: {integrity: sha512-/PU9P+7Rkz8JFYDHIi+xzHabOu9qEWR07L5nWLIUsvserrxegZExKCi2jhMZRd0ATdboKylu/K5yAXbp7fYFvA==} cpu: [arm64] @@ -1351,6 +1407,18 @@ packages: os: [linux] libc: [musl] + '@rollup/rollup-linux-arm64-musl@4.28.1': + resolution: {integrity: sha512-QF54q8MYGAqMLrX2t7tNpi01nvq5RI59UBNx+3+37zoKX5KViPo/gk2QLhsuqok05sSCRluj0D00LzCwBikb0A==} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@rollup/rollup-linux-loongarch64-gnu@4.28.1': + resolution: {integrity: sha512-vPul4uodvWvLhRco2w0GcyZcdyBfpfDRgNKU+p35AWEbJ/HPs1tOUrkSueVbBS0RQHAf/A+nNtDpvw95PeVKOA==} + cpu: [loong64] + os: [linux] + libc: [glibc] + '@rollup/rollup-linux-powerpc64le-gnu@4.27.2': resolution: {integrity: sha512-eCHmol/dT5odMYi/N0R0HC8V8QE40rEpkyje/ZAXJYNNoSfrObOvG/Mn+s1F/FJyB7co7UQZZf6FuWnN6a7f4g==} cpu: [ppc64] @@ -1363,6 +1431,12 @@ packages: os: [linux] libc: [glibc] + '@rollup/rollup-linux-powerpc64le-gnu@4.28.1': + resolution: {integrity: sha512-pTnTdBuC2+pt1Rmm2SV7JWRqzhYpEILML4PKODqLz+C7Ou2apEV52h19CR7es+u04KlqplggmN9sqZlekg3R1A==} + cpu: [ppc64] + os: [linux] + libc: [glibc] + '@rollup/rollup-linux-riscv64-gnu@4.27.2': resolution: {integrity: sha512-DEP3Njr9/ADDln3kNi76PXonLMSSMiCir0VHXxmGSHxCxDfQ70oWjHcJGfiBugzaqmYdTC7Y+8Int6qbnxPBIQ==} cpu: [riscv64] @@ -1375,6 +1449,12 @@ packages: os: [linux] libc: [glibc] + '@rollup/rollup-linux-riscv64-gnu@4.28.1': + resolution: {integrity: sha512-vWXy1Nfg7TPBSuAncfInmAI/WZDd5vOklyLJDdIRKABcZWojNDY0NJwruY2AcnCLnRJKSaBgf/GiJfauu8cQZA==} + cpu: [riscv64] + os: [linux] + libc: [glibc] + '@rollup/rollup-linux-s390x-gnu@4.27.2': resolution: {integrity: sha512-NHGo5i6IE/PtEPh5m0yw5OmPMpesFnzMIS/lzvN5vknnC1sXM5Z/id5VgcNPgpD+wHmIcuYYgW+Q53v+9s96lQ==} cpu: [s390x] @@ -1387,6 +1467,12 @@ packages: os: [linux] libc: [glibc] + '@rollup/rollup-linux-s390x-gnu@4.28.1': + resolution: {integrity: sha512-/yqC2Y53oZjb0yz8PVuGOQQNOTwxcizudunl/tFs1aLvObTclTwZ0JhXF2XcPT/zuaymemCDSuuUPXJJyqeDOg==} + cpu: [s390x] + os: [linux] + libc: [glibc] + '@rollup/rollup-linux-x64-gnu@4.27.2': resolution: {integrity: sha512-PaW2DY5Tan+IFvNJGHDmUrORadbe/Ceh8tQxi8cmdQVCCYsLoQo2cuaSj+AU+YRX8M4ivS2vJ9UGaxfuNN7gmg==} cpu: [x64] @@ -1399,6 +1485,12 @@ packages: os: [linux] libc: [glibc] + '@rollup/rollup-linux-x64-gnu@4.28.1': + resolution: {integrity: sha512-fzgeABz7rrAlKYB0y2kSEiURrI0691CSL0+KXwKwhxvj92VULEDQLpBYLHpF49MSiPG4sq5CK3qHMnb9tlCjBw==} + cpu: [x64] + os: [linux] + libc: [glibc] + '@rollup/rollup-linux-x64-musl@4.27.2': resolution: {integrity: sha512-dOlWEMg2gI91Qx5I/HYqOD6iqlJspxLcS4Zlg3vjk1srE67z5T2Uz91yg/qA8sY0XcwQrFzWWiZhMNERylLrpQ==} cpu: [x64] @@ -1411,6 +1503,12 @@ packages: os: [linux] libc: [musl] + '@rollup/rollup-linux-x64-musl@4.28.1': + resolution: {integrity: sha512-xQTDVzSGiMlSshpJCtudbWyRfLaNiVPXt1WgdWTwWz9n0U12cI2ZVtWe/Jgwyv/6wjL7b66uu61Vg0POWVfz4g==} + cpu: [x64] + os: [linux] + libc: [musl] + '@rollup/rollup-win32-arm64-msvc@4.27.2': resolution: {integrity: sha512-euMIv/4x5Y2/ImlbGl88mwKNXDsvzbWUlT7DFky76z2keajCtcbAsN9LUdmk31hAoVmJJYSThgdA0EsPeTr1+w==} cpu: [arm64] @@ -1421,6 +1519,11 @@ packages: cpu: [arm64] os: [win32] + '@rollup/rollup-win32-arm64-msvc@4.28.1': + resolution: {integrity: sha512-wSXmDRVupJstFP7elGMgv+2HqXelQhuNf+IS4V+nUpNVi/GUiBgDmfwD0UGN3pcAnWsgKG3I52wMOBnk1VHr/A==} + cpu: [arm64] + os: [win32] + '@rollup/rollup-win32-ia32-msvc@4.27.2': resolution: {integrity: sha512-RsnE6LQkUHlkC10RKngtHNLxb7scFykEbEwOFDjr3CeCMG+Rr+cKqlkKc2/wJ1u4u990urRHCbjz31x84PBrSQ==} cpu: [ia32] @@ -1431,6 +1534,11 @@ packages: cpu: [ia32] os: [win32] + '@rollup/rollup-win32-ia32-msvc@4.28.1': + resolution: {integrity: sha512-ZkyTJ/9vkgrE/Rk9vhMXhf8l9D+eAhbAVbsGsXKy2ohmJaWg0LPQLnIxRdRp/bKyr8tXuPlXhIoGlEB5XpJnGA==} + cpu: [ia32] + os: [win32] + '@rollup/rollup-win32-x64-msvc@4.27.2': resolution: {integrity: sha512-foJM5vv+z2KQmn7emYdDLyTbkoO5bkHZE1oth2tWbQNGW7mX32d46Hz6T0MqXdWS2vBZhaEtHqdy9WYwGfiliA==} cpu: [x64] @@ -1441,6 +1549,11 @@ packages: cpu: [x64] os: [win32] + '@rollup/rollup-win32-x64-msvc@4.28.1': + resolution: {integrity: sha512-ZvK2jBafvttJjoIdKm/Q/Bh7IJ1Ose9IBOwpOXcOvW3ikGTQGmKDgxTC6oCAzW6PynbkKP8+um1du81XJHZ0JA==} + cpu: [x64] + os: [win32] + '@socket.io/component-emitter@3.1.2': resolution: {integrity: sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==} @@ -1520,11 +1633,8 @@ packages: '@types/node@22.9.0': resolution: {integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==} - '@types/prop-types@15.7.13': - resolution: {integrity: sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==} - - '@types/react@18.3.12': - resolution: {integrity: sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw==} + '@types/react@19.0.0': + resolution: {integrity: sha512-MY3oPudxvMYyesqs/kW1Bh8y9VqSmf+tzqw3ae8a9DZW68pUe3zAdHeI1jc6iAysuRdACnVknHP8AhwD4/dxtg==} '@types/readdir-glob@1.1.5': resolution: {integrity: sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==} @@ -1827,8 +1937,8 @@ packages: buffer@6.0.3: resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} - bullmq@5.29.1: - resolution: {integrity: sha512-TZWiwRlPnpaN+Qwh4D8IQf2cYLpkiDX1LbaaWEabc6y37ojIttWOSynxDewpVHyW233LssSIC4+aLMSvAjtpmg==} + bullmq@5.31.2: + resolution: {integrity: sha512-MUW6j1V79NRnrGZtxKyfyTv/YJ5Ljy0IrbMElpuQNCaLXoXEcCtU6kwdGiHxso9dUi1Wp4yo3GYEGg8vyWWLsw==} cacache@15.3.0: resolution: {integrity: sha512-VVdYzXEn+cnbXpFgWs5hTT7OScegHVmLhJIR8Ufqk3iFD6A6j5iSX1KuBTfNEv4tdJWE2PzA6IVFtcLC7fN9wQ==} @@ -3518,6 +3628,11 @@ packages: engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true + rollup@4.28.1: + resolution: {integrity: sha512-61fXYl/qNVinKmGSTHAZ6Yy8I3YIJC/r2m9feHo6SwVAVcLT5MPwOUFe7EuURA/4m0NR8lXG4BBXuo/IZEsjMg==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -3898,9 +4013,6 @@ packages: tslib@1.9.3: resolution: {integrity: sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==} - tslib@2.7.0: - resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==} - tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} @@ -5040,18 +5152,13 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 - '@kevisual/auth@1.0.4(@kevisual/router@0.0.5)': - dependencies: - '@kevisual/router': 0.0.5 + '@kevisual/auth@1.0.5': {} - '@kevisual/router@0.0.5': + '@kevisual/local-app-manager@0.1.6-alpha.2(@kevisual/router@0.0.6-alpha-2)(@kevisual/types@0.0.1)(@kevisual/use-config@1.0.5)': dependencies: - path-to-regexp: 8.2.0 - selfsigned: 2.4.1 - ws: 8.18.0 - transitivePeerDependencies: - - bufferutil - - utf-8-validate + '@kevisual/router': 0.0.6-alpha-2 + '@kevisual/types': 0.0.1 + '@kevisual/use-config': 1.0.5 '@kevisual/router@0.0.6-alpha-2': dependencies: @@ -5062,8 +5169,12 @@ snapshots: - bufferutil - utf-8-validate + '@kevisual/types@0.0.1': {} + '@kevisual/use-config@1.0.3': {} + '@kevisual/use-config@1.0.5': {} + '@langchain/core@0.3.3(openai@4.65.0(encoding@0.1.13)(zod@3.23.8))': dependencies: ansi-styles: 5.2.0 @@ -5232,9 +5343,9 @@ snapshots: transitivePeerDependencies: - supports-color - '@rollup/plugin-alias@5.1.1(rollup@4.27.4)': + '@rollup/plugin-alias@5.1.1(rollup@4.28.1)': optionalDependencies: - rollup: 4.27.4 + rollup: 4.28.1 '@rollup/plugin-commonjs@28.0.1(rollup@4.27.2)': dependencies: @@ -5260,12 +5371,30 @@ snapshots: optionalDependencies: rollup: 4.27.4 + '@rollup/plugin-commonjs@28.0.1(rollup@4.28.1)': + dependencies: + '@rollup/pluginutils': 5.1.2(rollup@4.28.1) + commondir: 1.0.1 + estree-walker: 2.0.2 + fdir: 6.3.0(picomatch@4.0.2) + is-reference: 1.2.1 + magic-string: 0.30.11 + picomatch: 4.0.2 + optionalDependencies: + rollup: 4.28.1 + '@rollup/plugin-json@6.1.0(rollup@4.27.4)': dependencies: '@rollup/pluginutils': 5.1.2(rollup@4.27.4) optionalDependencies: rollup: 4.27.4 + '@rollup/plugin-json@6.1.0(rollup@4.28.1)': + dependencies: + '@rollup/pluginutils': 5.1.2(rollup@4.28.1) + optionalDependencies: + rollup: 4.28.1 + '@rollup/plugin-node-resolve@15.3.0(rollup@4.27.2)': dependencies: '@rollup/pluginutils': 5.1.2(rollup@4.27.2) @@ -5286,12 +5415,22 @@ snapshots: optionalDependencies: rollup: 4.27.4 - '@rollup/plugin-replace@6.0.1(rollup@4.27.4)': + '@rollup/plugin-node-resolve@15.3.0(rollup@4.28.1)': dependencies: - '@rollup/pluginutils': 5.1.2(rollup@4.27.4) + '@rollup/pluginutils': 5.1.2(rollup@4.28.1) + '@types/resolve': 1.20.2 + deepmerge: 4.3.1 + is-module: 1.0.0 + resolve: 1.22.8 + optionalDependencies: + rollup: 4.28.1 + + '@rollup/plugin-replace@6.0.1(rollup@4.28.1)': + dependencies: + '@rollup/pluginutils': 5.1.2(rollup@4.28.1) magic-string: 0.30.11 optionalDependencies: - rollup: 4.27.4 + rollup: 4.28.1 '@rollup/plugin-typescript@12.1.1(rollup@4.27.2)(tslib@2.8.1)(typescript@5.7.2)': dependencies: @@ -5311,6 +5450,15 @@ snapshots: rollup: 4.27.4 tslib: 2.8.1 + '@rollup/plugin-typescript@12.1.1(rollup@4.28.1)(tslib@2.8.1)(typescript@5.7.2)': + dependencies: + '@rollup/pluginutils': 5.1.2(rollup@4.28.1) + resolve: 1.22.8 + typescript: 5.7.2 + optionalDependencies: + rollup: 4.28.1 + tslib: 2.8.1 + '@rollup/pluginutils@5.1.2(rollup@4.27.2)': dependencies: '@types/estree': 1.0.6 @@ -5327,114 +5475,179 @@ snapshots: optionalDependencies: rollup: 4.27.4 + '@rollup/pluginutils@5.1.2(rollup@4.28.1)': + dependencies: + '@types/estree': 1.0.6 + estree-walker: 2.0.2 + picomatch: 4.0.2 + optionalDependencies: + rollup: 4.28.1 + '@rollup/rollup-android-arm-eabi@4.27.2': optional: true '@rollup/rollup-android-arm-eabi@4.27.4': optional: true + '@rollup/rollup-android-arm-eabi@4.28.1': + optional: true + '@rollup/rollup-android-arm64@4.27.2': optional: true '@rollup/rollup-android-arm64@4.27.4': optional: true + '@rollup/rollup-android-arm64@4.28.1': + optional: true + '@rollup/rollup-darwin-arm64@4.27.2': optional: true '@rollup/rollup-darwin-arm64@4.27.4': optional: true + '@rollup/rollup-darwin-arm64@4.28.1': + optional: true + '@rollup/rollup-darwin-x64@4.27.2': optional: true '@rollup/rollup-darwin-x64@4.27.4': optional: true + '@rollup/rollup-darwin-x64@4.28.1': + optional: true + '@rollup/rollup-freebsd-arm64@4.27.2': optional: true '@rollup/rollup-freebsd-arm64@4.27.4': optional: true + '@rollup/rollup-freebsd-arm64@4.28.1': + optional: true + '@rollup/rollup-freebsd-x64@4.27.2': optional: true '@rollup/rollup-freebsd-x64@4.27.4': optional: true + '@rollup/rollup-freebsd-x64@4.28.1': + optional: true + '@rollup/rollup-linux-arm-gnueabihf@4.27.2': optional: true '@rollup/rollup-linux-arm-gnueabihf@4.27.4': optional: true + '@rollup/rollup-linux-arm-gnueabihf@4.28.1': + optional: true + '@rollup/rollup-linux-arm-musleabihf@4.27.2': optional: true '@rollup/rollup-linux-arm-musleabihf@4.27.4': optional: true + '@rollup/rollup-linux-arm-musleabihf@4.28.1': + optional: true + '@rollup/rollup-linux-arm64-gnu@4.27.2': optional: true '@rollup/rollup-linux-arm64-gnu@4.27.4': optional: true + '@rollup/rollup-linux-arm64-gnu@4.28.1': + optional: true + '@rollup/rollup-linux-arm64-musl@4.27.2': optional: true '@rollup/rollup-linux-arm64-musl@4.27.4': optional: true + '@rollup/rollup-linux-arm64-musl@4.28.1': + optional: true + + '@rollup/rollup-linux-loongarch64-gnu@4.28.1': + optional: true + '@rollup/rollup-linux-powerpc64le-gnu@4.27.2': optional: true '@rollup/rollup-linux-powerpc64le-gnu@4.27.4': optional: true + '@rollup/rollup-linux-powerpc64le-gnu@4.28.1': + optional: true + '@rollup/rollup-linux-riscv64-gnu@4.27.2': optional: true '@rollup/rollup-linux-riscv64-gnu@4.27.4': optional: true + '@rollup/rollup-linux-riscv64-gnu@4.28.1': + optional: true + '@rollup/rollup-linux-s390x-gnu@4.27.2': optional: true '@rollup/rollup-linux-s390x-gnu@4.27.4': optional: true + '@rollup/rollup-linux-s390x-gnu@4.28.1': + optional: true + '@rollup/rollup-linux-x64-gnu@4.27.2': optional: true '@rollup/rollup-linux-x64-gnu@4.27.4': optional: true + '@rollup/rollup-linux-x64-gnu@4.28.1': + optional: true + '@rollup/rollup-linux-x64-musl@4.27.2': optional: true '@rollup/rollup-linux-x64-musl@4.27.4': optional: true + '@rollup/rollup-linux-x64-musl@4.28.1': + optional: true + '@rollup/rollup-win32-arm64-msvc@4.27.2': optional: true '@rollup/rollup-win32-arm64-msvc@4.27.4': optional: true + '@rollup/rollup-win32-arm64-msvc@4.28.1': + optional: true + '@rollup/rollup-win32-ia32-msvc@4.27.2': optional: true '@rollup/rollup-win32-ia32-msvc@4.27.4': optional: true + '@rollup/rollup-win32-ia32-msvc@4.28.1': + optional: true + '@rollup/rollup-win32-x64-msvc@4.27.2': optional: true '@rollup/rollup-win32-x64-msvc@4.27.4': optional: true + '@rollup/rollup-win32-x64-msvc@4.28.1': + optional: true + '@socket.io/component-emitter@3.1.2': {} '@tootallnate/once@1.1.2': @@ -5524,11 +5737,8 @@ snapshots: dependencies: undici-types: 6.19.8 - '@types/prop-types@15.7.13': {} - - '@types/react@18.3.12': + '@types/react@19.0.0': dependencies: - '@types/prop-types': 15.7.13 csstype: 3.1.3 '@types/readdir-glob@1.1.5': @@ -5879,14 +6089,14 @@ snapshots: base64-js: 1.5.1 ieee754: 1.2.1 - bullmq@5.29.1: + bullmq@5.31.2: dependencies: cron-parser: 4.9.0 ioredis: 5.4.1 msgpackr: 1.11.2 node-abort-controller: 3.1.1 semver: 7.6.3 - tslib: 2.7.0 + tslib: 2.8.1 uuid: 9.0.1 transitivePeerDependencies: - supports-color @@ -7779,22 +7989,22 @@ snapshots: globby: 10.0.1 is-plain-object: 3.0.1 - rollup-plugin-dts@6.1.1(rollup@4.27.4)(typescript@5.7.2): + rollup-plugin-dts@6.1.1(rollup@4.28.1)(typescript@5.7.2): dependencies: magic-string: 0.30.11 - rollup: 4.27.4 + rollup: 4.28.1 typescript: 5.7.2 optionalDependencies: '@babel/code-frame': 7.26.2 - rollup-plugin-esbuild@6.1.1(esbuild@0.23.1)(rollup@4.27.4): + rollup-plugin-esbuild@6.1.1(esbuild@0.23.1)(rollup@4.28.1): dependencies: - '@rollup/pluginutils': 5.1.2(rollup@4.27.4) + '@rollup/pluginutils': 5.1.2(rollup@4.28.1) debug: 4.3.7(supports-color@5.5.0) es-module-lexer: 1.5.4 esbuild: 0.23.1 get-tsconfig: 4.8.1 - rollup: 4.27.4 + rollup: 4.28.1 transitivePeerDependencies: - supports-color @@ -7846,6 +8056,31 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.27.4 fsevents: 2.3.3 + rollup@4.28.1: + dependencies: + '@types/estree': 1.0.6 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.28.1 + '@rollup/rollup-android-arm64': 4.28.1 + '@rollup/rollup-darwin-arm64': 4.28.1 + '@rollup/rollup-darwin-x64': 4.28.1 + '@rollup/rollup-freebsd-arm64': 4.28.1 + '@rollup/rollup-freebsd-x64': 4.28.1 + '@rollup/rollup-linux-arm-gnueabihf': 4.28.1 + '@rollup/rollup-linux-arm-musleabihf': 4.28.1 + '@rollup/rollup-linux-arm64-gnu': 4.28.1 + '@rollup/rollup-linux-arm64-musl': 4.28.1 + '@rollup/rollup-linux-loongarch64-gnu': 4.28.1 + '@rollup/rollup-linux-powerpc64le-gnu': 4.28.1 + '@rollup/rollup-linux-riscv64-gnu': 4.28.1 + '@rollup/rollup-linux-s390x-gnu': 4.28.1 + '@rollup/rollup-linux-x64-gnu': 4.28.1 + '@rollup/rollup-linux-x64-musl': 4.28.1 + '@rollup/rollup-win32-arm64-msvc': 4.28.1 + '@rollup/rollup-win32-ia32-msvc': 4.28.1 + '@rollup/rollup-win32-x64-msvc': 4.28.1 + fsevents: 2.3.3 + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -8290,8 +8525,6 @@ snapshots: tslib@1.9.3: {} - tslib@2.7.0: {} - tslib@2.8.1: {} tsx@4.19.2: diff --git a/src/app.ts b/src/app.ts index 1e2f84b..dc28d10 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,26 +4,31 @@ import { dynamicImport } from './lib/dynamic-import.ts'; import { redisPublisher, redisSubscriber, redis } from './modules/redis.ts'; import { minioClient } from './modules/minio.ts'; import { sequelize } from './modules/sequelize.ts'; - +import { useContextKey , useContext} from '@kevisual/use-config/context'; +useContext({}); useConfig(); export const emit = (channel: string, message?: any) => { redisPublisher.publish(channel, JSON.stringify(message)); }; export { redis, minioClient, sequelize }; -export const app = new App<{ import: any; emit: typeof emit; sequelize: typeof sequelize }>({ - serverOptions: { - cors: { - origin: '*', +const init = () => { + console.log('init app', global.context); + return new App<{ import: any; emit: typeof emit; sequelize: typeof sequelize }>({ + serverOptions: { + cors: { + origin: '*', + }, }, - }, - io: true, - routerContext: { - import: dynamicImport, - emit, - sequelize, - }, -}); + io: true, + routerContext: { + import: dynamicImport, + emit, + sequelize, + }, + }); +}; +export const app = useContextKey('app', init); const clients = []; // 订阅频道 pageEdit, container 单个页面预览 container 整个页面预览 diff --git a/src/route.ts b/src/route.ts index fb63ec4..0508630 100644 --- a/src/route.ts +++ b/src/route.ts @@ -14,3 +14,19 @@ createAuthRoute({ // app.importApp(adminApp); // appendTo(app); + +app + .route({ + path: 'test', + key: 'test', + }) + .define(async (ctx) => { + ctx.body = app.router.routes.map((item) => { + return { + path: item.path, + key: item.key, + description: item.description, + }; + }); + }) + .addTo(app); diff --git a/src/routes-simple/code/upload.ts b/src/routes-simple/code/upload.ts index 190aa77..070e800 100644 --- a/src/routes-simple/code/upload.ts +++ b/src/routes-simple/code/upload.ts @@ -4,7 +4,7 @@ import { router } from '../router.ts'; import { error } from '../middleware/auth.ts'; import fs from 'fs'; import { clients } from '../upload.ts'; -import { useFileStore } from '@abearxiong/use-file-store'; +import { useFileStore } from '@kevisual/use-config/file-store'; import { app, minioClient } from '@/app.ts'; import { bucketName } from '@/modules/minio.ts'; import { getContentType } from '@/utils/get-content-type.ts'; diff --git a/src/routes-simple/upload.ts b/src/routes-simple/upload.ts index 3fad932..e748806 100644 --- a/src/routes-simple/upload.ts +++ b/src/routes-simple/upload.ts @@ -1,4 +1,4 @@ -import { useFileStore } from '@abearxiong/use-file-store'; +import { useFileStore } from '@kevisual/use-config/file-store'; import http from 'http'; import fs, { rm } from 'fs'; import path from 'path'; diff --git a/src/routes/micro-app/index.ts b/src/routes/micro-app/index.ts index 4369fe9..366cb31 100644 --- a/src/routes/micro-app/index.ts +++ b/src/routes/micro-app/index.ts @@ -1,3 +1 @@ -import './list.ts'; - -import './routes/manager.ts' \ No newline at end of file +import './list.ts'; \ No newline at end of file diff --git a/src/routes/micro-app/lib/app-file.ts b/src/routes/micro-app/lib/app-file.ts index c68d853..6b53bdd 100644 --- a/src/routes/micro-app/lib/app-file.ts +++ b/src/routes/micro-app/lib/app-file.ts @@ -1,45 +1,3 @@ -import { useFileStore } from '@abearxiong/use-file-store'; -import { getConfigFile } from '@kevisual/use-config'; -import path from 'path'; -import fs from 'fs'; +import { useFileStore } from '@kevisual/use-config/file-store'; export const appsPath = useFileStore('apps', { needExists: true }); - -export type AppInfoConfig = { - list: any[]; - [key: string]: any; -}; -/** - * 加载应用信息 - * @returns - */ -export const loadAppInfo = async (): Promise => { - const pkgs = getConfigFile(); - let configFile = getConfigFile('apps.config.json'); - if (!pkgs) { - console.error('未找到配置文件'); - return; - } - const basePath = path.dirname(pkgs); - if (!configFile) { - configFile = path.join(basePath, 'apps.config.json'); - fs.writeFileSync(configFile, JSON.stringify({ list: [] })); - return { list: [] }; - } - const config = fs.readFileSync(configFile, 'utf-8'); - return JSON.parse(config); -}; - -/** - * - * 保存应用信息 - * @param data - * @returns - */ -export const saveAppInfo = async (data: any) => { - const configFile = getConfigFile('apps.config.json'); - if (!configFile) { - return; - } - fs.writeFileSync(configFile, JSON.stringify(data)); -}; diff --git a/src/routes/micro-app/list.ts b/src/routes/micro-app/list.ts index e2fe094..4fa30b2 100644 --- a/src/routes/micro-app/list.ts +++ b/src/routes/micro-app/list.ts @@ -1,8 +1,6 @@ import { app } from '@/app.ts'; import { MicroAppModel } from './models.ts'; import { appPathCheck, installApp } from './module/install-app.ts'; -import { getAppPathKeys, installAppFromKey } from './module/manager.ts'; -import { loadApp } from './module/load-app.ts'; import { manager } from './manager-app.ts'; // 应用上传到 应用管理 的平台 @@ -82,29 +80,6 @@ app }) .addTo(app); -// curl http://localhost:4002/api/router?path=micro-app&key=load -app - .route({ - path: 'micro-app', - key: 'load', - description: 'Load micro app, no use', - }) - .define(async (ctx) => { - const { key } = ctx.query?.data; - // const key = 'mark'; - try { - const main = await loadApp(key); - if (main?.loadApp) { - await main.loadApp(app); - ctx.body = 'success'; - return; - } - ctx.throw(400, 'Invalid app'); - } catch (e) { - ctx.throw(400, e.message); - } - }); - // curl http://localhost:4002/api/router?path=micro-app&key=unload app .route({ @@ -122,39 +97,3 @@ app ctx.body = main; }) .addTo(app); - -app - .route({ - path: 'micro-app', - key: 'detect', - description: 'Detect micro app,检测apps的没有加载进来的app模块', - }) - .define(async (ctx) => { - const list = manager.getAllAppShowInfo(); - const appPathKeys = await getAppPathKeys(); - const notIn = appPathKeys.filter((key) => !list.find((item) => item.key === key)); - console.log('Not in', notIn); - const loadInfo = []; - if (notIn.length <= 0) { - loadInfo.push('ok'); - ctx.body = { - data: loadInfo, - }; - ctx.message = 'All apps are loaded'; - return; - } - for (const key of notIn) { - try { - const { showAppInfo } = await installAppFromKey(key); - await manager.add(showAppInfo); - loadInfo.push(`Load ${key} success`); - } catch (e) { - loadInfo.push(`Load ${key} error`); - } - } - ctx.body = { - data: loadInfo, - notIn, - }; - }) - .addTo(app); diff --git a/src/routes/micro-app/manager-app.ts b/src/routes/micro-app/manager-app.ts index 320e66c..5f76fbb 100644 --- a/src/routes/micro-app/manager-app.ts +++ b/src/routes/micro-app/manager-app.ts @@ -1,4 +1,18 @@ import { app } from '@/app.ts'; -import { Manager } from './module/manager.ts'; +import { manager, loadManager, app as ManagerApp } from '@kevisual/local-app-manager'; +export const existDenpend = [ + 'sequelize', // commonjs + 'pg', // commonjs + '@kevisual/router', // 共享模块 + 'ioredis', // commonjs + 'socket.io', // commonjs + 'minio', // commonjs + 'pino', // commonjs + 'pino-pretty', // commonjs + '@msgpack/msgpack', // commonjs +]; +// export const manager = new Manager({ mainApp: app }); +export { manager }; -export const manager = new Manager({ mainApp: app }); +console.log('app equal', app === ManagerApp); +loadManager(); diff --git a/src/routes/micro-app/module/load-app.ts b/src/routes/micro-app/module/load-app.ts deleted file mode 100644 index b823986..0000000 --- a/src/routes/micro-app/module/load-app.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { fileIsExist } from '@kevisual/use-config'; - -import { useFileStore } from '@abearxiong/use-file-store'; -import fs from 'fs'; -import path from 'path'; - -export const appsPath = useFileStore('apps', { needExists: true }); - -export const loadFileAppInfo = async (key: string) => { - const directory = path.join(appsPath, key); - if (!fileIsExist(directory)) { - throw new Error('app not found'); - } - const pkgs = path.join(directory, 'package.json'); - if (!fileIsExist(pkgs)) { - throw new Error('Invalid package.json'); - } - const json = fs.readFileSync(pkgs, 'utf-8'); - const pkg = JSON.parse(json); - const { name, version, app } = pkg; - if (!name || !version || !app) { - throw new Error('Invalid package.json'); - } - - const mainEntry = path.join(directory, app.entry); - if (!fileIsExist(mainEntry)) { - throw new Error('Invalid main entry'); - } - return { mainEntry, app }; -}; -export const deleteFileAppInfo = async (key: string) => { - const directory = path.join(appsPath, key); - if (!fileIsExist(directory)) { - return; - } - fs.rmSync(directory, { recursive: true }); -}; - -/** - * @deprecated - * @param key - * @returns - */ -export const loadApp = async (key: string) => { - const { mainEntry, app } = await loadFileAppInfo(key); - // 1. 查询数据库,获取app信息,查看是否运行中 - // 2. 如果运行中,直接返回 - // 3. 如果不在运行中,加载app - // 3.1 查看app的类型,如果是 system-app,直接加载 - // 3.2 如果是 micro-app,查找相关的依赖,如果依赖不存在,先加载依赖 - // 3.3 使用fork加载app - // 4. 记录app的运行状态,程序重新启动时,重新加载 - const main = await import(mainEntry); - return main; -}; diff --git a/src/routes/micro-app/module/manager.ts b/src/routes/micro-app/module/manager.ts index a0c7d58..f0052db 100644 --- a/src/routes/micro-app/module/manager.ts +++ b/src/routes/micro-app/module/manager.ts @@ -1,258 +1,8 @@ -import { App } from '@kevisual/router'; -import { loadAppInfo, AppInfoConfig, saveAppInfo } from '../lib/app-file.ts'; -import { fork } from 'child_process'; -import { merge } from 'lodash-es'; -import { deleteFileAppInfo } from './load-app.ts'; import { fileIsExist } from '@kevisual/use-config'; import path from 'path'; import fs from 'fs'; import { appsPath } from '../lib/index.ts'; -// 共享 -export const existDenpend = [ - 'sequelize', // commonjs - 'pg', // commonjs - '@kevisual/router', // 共享模块 - 'ioredis', // commonjs - 'socket.io', // commonjs - 'minio', // commonjs - 'pino', // commonjs - 'pino-pretty', // commonjs - '@msgpack/msgpack', // commonjs -]; -export enum AppType { - SystemApp = 'system-app', - MicroApp = 'micro-app', - GatewayApp = 'gateway-app', -} -export type AppInfo = { - key: string; - status?: 'inactive' | 'running' | 'stop' | 'error'; // 运行状态 - version?: string; // 版本 - type?: AppType; // 默认类型 - description?: string; // 描述 - timestamp?: number; // 时间戳, 每次更新更新时间戳 - process?: any; // 进程 - - origin?: Record; // 原始数据 - entry?: string; // 入口文件 - path?: string; // 文件路径 -}; -export const onAppShowInfo = (app: AppInfo) => { - return { - key: app.key, - status: app.status, - type: app.type, - description: app.description, - version: app.version, - }; -}; -export const createAppShowInfo = (app: any) => { - return { - key: app.key, - status: app.status, - type: app.type, - description: app.description, - version: app.version, - }; -}; -type managerOptions = { - mainApp: App; -}; -export class Manager { - apps: Map; - mainApp: App; - appInfo: AppInfoConfig; - constructor(opts: managerOptions) { - this.apps = new Map(); - this.mainApp = opts.mainApp; - this.appInfo = {} as any; - } - /** - * 检查key是否存在 - * @param key - * @returns - */ - checkKey(key: string) { - return this.apps.has(key); - } - /* - * 获取app信息 - * @param key - */ - async loadApp(app: T) { - const mainApp = this.mainApp; - this.apps.set(app.key, app); - if (app.status !== 'running') { - return; - } - if (!fileIsExist(app.path)) { - console.error('app is not found'); - return; - } - const pathEntry = path.join(app.path, app.entry); - if (!fileIsExist(pathEntry)) { - console.error('file entry not found'); - return; - } - const entry = app.entry + `?timestamp=${app?.timestamp}`; - // 注册路由 - if (app.type === AppType.MicroApp) { - const process = fork(app.entry, [], { - stdio: 'inherit', // 共享主进程的标准输入输出 - cwd: app.path, - }); - app.process = process; - } else if (app.type === AppType.SystemApp) { - const module = await import(entry); - if (module.loadApp) { - await module.loadApp?.(mainApp); - } - } else if (app.type === AppType.GatewayApp) { - console.log('gateway app not support'); - } - return true; - } - /** - * create new app info - * @param app - */ - async saveAppInfo(app: T, newTimeData = false) { - const list = this.appInfo.list || []; - if (newTimeData) { - app.timestamp = Date.now(); - } - const { process, ...info } = app; - list.push(info); - this.appInfo.list = list; - await saveAppInfo(this.appInfo); - } - - /** - * 初始化应用的时候加载 - */ - async load() { - // 从apps文件夹列表当中中加载app信息 - const appInfos = await loadAppInfo(); - this.appInfo = appInfos; - const list = appInfos?.list || []; - for (const app of list) { - try { - const loaded = await this.loadApp(app); - if (!loaded) { - // 加载失败,如果是running状态,设置为error - if (app.status === 'running') { - app.status = 'error'; - console.log('load app error', app); // save app error info - await this.saveAppInfo(app); - } - } else { - // console.log('load app success', app); - } - } catch (e) { - console.error('load app', e); - } - } - } - async add(app: T) { - if (this.checkKey(app.key)) { - console.error('key is loaded'); - return false; - } - - await this.saveAppInfo(app, true); - this.loadApp(app); - } - // 启动 - async start(key: string) { - const app = this.apps.get(key); - if (!app) { - return; - } - if (app.status === 'running') { - return; - } - app.status = 'running'; - this.loadApp(app); - await this.saveAppInfo(app); - } - // 停止 - async stop(key: string) { - const app = this.apps.get(key); - if (!app) { - return; - } - if (app.status === 'stop') { - return; - } - app.status = 'stop'; - if (app.process) { - app.process.kill(); - } - await this.saveAppInfo(app); - } - /** - * 获取app信息, 用于展示 - * @param key - * @returns - */ - getAppShowInfo(key: string) { - const app = this.apps.get(key); - if (!app) { - return; - } - return onAppShowInfo(app); - } - /** - * 获取所有app信息, 用于展示 - * @returns - */ - getAllAppShowInfo() { - const list = []; - for (const [key, value] of this.apps) { - list.push(onAppShowInfo(value)); - } - return list; - } - /** - * 更新app信息, 用于展示, 加上一些功能,启动,停止程序 - * @param key - * @param info - * @returns - */ - async updateAppInfo(key: string, info: Partial) { - const app = this.apps.get(key); - if (!app) { - return; - } - merge(app, info); - this.loadApp(app); - await this.saveAppInfo(app); - return onAppShowInfo(app); - } - /** - * 删除app信息 - * @param key - * @returns - */ - async removeApp(key: string) { - const app = this.apps.get(key); - if (!app) { - return; - } - if (app.process) { - app.process.kill(); - } - this.apps.delete(key); - await this.saveAppInfo(app); - try { - deleteFileAppInfo(key); - } catch (e) { - console.error('delete file app error', e); - } - } -} - export const installAppFromKey = async (key: string) => { const directory = path.join(appsPath, key); if (!fileIsExist(directory)) { diff --git a/src/routes/micro-app/routes/manager.ts b/src/routes/micro-app/routes/manager.ts deleted file mode 100644 index cd62f5d..0000000 --- a/src/routes/micro-app/routes/manager.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { app } from '@/app.ts'; -import { manager } from '../manager-app.ts'; - -app - .route({ - path: 'micro-app-manager', - key: 'list', - }) - .define(async (ctx) => { - const list = manager.getAllAppShowInfo(); - ctx.body = list; - }) - .addTo(app); - -app - .route({ - path: 'micro-app-manager', - key: 'updateStatus', - }) - .define(async (ctx) => { - const { status, key } = ctx.query; - if (!status || !key) { - ctx.body = 'status or key is required'; - return; - } - if (status === 'start') { - await manager.start(key); - } else if (status === 'stop') { - await manager.stop(key); - } - const appShow = manager.getAppShowInfo(key); - ctx.body = appShow; - }) - .addTo(app); - -app - .route({ - path: 'micro-app-manager', - key: 'update', - }) - .define(async (ctx) => { - const { key } = ctx.query.data || {}; - if (!key) { - ctx.body = 'key is required'; - return; - } - const appInfo = await manager.updateAppInfo(key, ctx.query.data); - ctx.body = appInfo; - }) - .addTo(app); - -setTimeout(() => { - manager.load().then(() => { - console.log('load success'); - }); -}, 1000); diff --git a/src/routes/page/module/cache-file.ts b/src/routes/page/module/cache-file.ts index 185b662..9e88870 100644 --- a/src/routes/page/module/cache-file.ts +++ b/src/routes/page/module/cache-file.ts @@ -1,4 +1,4 @@ -import { useFileStore } from '@abearxiong/use-file-store'; +import { useFileStore } from '@kevisual/use-config/file-store'; import { PageModel } from '../models/index.ts'; import { ContainerModel } from '@/routes/container/models/index.ts'; import { Op } from 'sequelize';