commit 943d664c364f352698953633619ae477bad36000 Author: abearxiong Date: Wed Oct 15 14:47:53 2025 +0800 灵感 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..58768e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +node_modules + +dist + +app.config.json5 + +apps.config.json + +deploy.tar.gz +cache-file + +/apps + +logs + +release/* +!release/.gitkeep + +.turbo + +.env* +!.env.example + +pack-dist +app.config.json5.envision diff --git a/package.json b/package.json new file mode 100644 index 0000000..8d52bdf --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "light-code", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "abearxiong (https://www.xiongxiao.me)", + "license": "MIT", + "packageManager": "pnpm@10.16.1", + "type": "module" +} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..862b530 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,3 @@ +packages: + - 'web' + - 'server' \ No newline at end of file diff --git a/server/bun.config.ts b/server/bun.config.ts new file mode 100644 index 0000000..53ef40c --- /dev/null +++ b/server/bun.config.ts @@ -0,0 +1,21 @@ +// @ts-check +import { resolvePath } from '@kevisual/use-config'; +import { execSync } from 'node:child_process'; + +const entry = 'src/index.ts'; +const naming = 'app'; +const external = ['sequelize', 'pg', 'ioredis', 'pm2']; +/** + * @type {import('bun').BuildConfig} + */ +await Bun.build({ + target: 'node', + format: 'esm', + entrypoints: [resolvePath(entry, { meta: import.meta })], + outdir: resolvePath('./dist', { meta: import.meta }), + naming: { + entry: `${naming}.js`, + }, + external, + env: 'KEVISUAL_*', +}); diff --git a/server/package.json b/server/package.json new file mode 100644 index 0000000..15a9c69 --- /dev/null +++ b/server/package.json @@ -0,0 +1,24 @@ +{ + "name": "light-code", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "dev": "bun run --watch --hot src/index.ts", + "build": "NODE_ENV=production bun bun.config.ts" + }, + "keywords": [], + "author": "abearxiong (https://www.xiongxiao.me)", + "license": "MIT", + "packageManager": "pnpm@10.16.1", + "type": "module", + "devDependencies": { + "@kevisual/types": "^0.0.10", + "@kevisual/use-config": "^1.0.19", + "@types/bun": "^1.3.0", + "bun": "^1.3.0" + }, + "dependencies": { + "@kevisual/router": "^0.0.28" + } +} \ No newline at end of file diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml new file mode 100644 index 0000000..8574d98 --- /dev/null +++ b/server/pnpm-lock.yaml @@ -0,0 +1,384 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@kevisual/router': + specifier: ^0.0.28 + version: 0.0.28 + devDependencies: + '@kevisual/types': + specifier: ^0.0.10 + version: 0.0.10 + '@kevisual/use-config': + specifier: ^1.0.19 + version: 1.0.19(dotenv@16.6.1) + '@types/bun': + specifier: ^1.3.0 + version: 1.3.0(@types/react@19.2.2) + bun: + specifier: ^1.3.0 + version: 1.3.0 + +packages: + + '@kevisual/load@0.0.6': + resolution: {integrity: sha512-+3YTFehRcZ1haGel5DKYMUwmi5i6f2psyaPZlfkKU/cOXgkpwoG9/BEqPCnPjicKqqnksEpixVRkyHJ+5bjLVA==} + + '@kevisual/router@0.0.28': + resolution: {integrity: sha512-MqpnRqBRt2TkM9KyDDaz/AjbBFi8L2y2/MwChu28fK6g0OL5fJ45NQQBGNpNrj2rsUVmpCA2wDr2SqjVxE3CLA==} + + '@kevisual/types@0.0.10': + resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==} + + '@kevisual/use-config@1.0.19': + resolution: {integrity: sha512-Q1IH4eMqUe5w6Bq8etoqOSls9FPIy0xwwD3wHf26EsQLZadhccI9qkDuFzP/rFWDa57mwFPEfwbGE5UlqWOCkw==} + peerDependencies: + dotenv: ^16.4.7 + + '@oven/bun-darwin-aarch64@1.3.0': + resolution: {integrity: sha512-WeXSaL29ylJEZMYHHW28QZ6rgAbxQ1KuNSZD9gvd3fPlo0s6s2PglvPArjjP07nmvIK9m4OffN0k4M98O7WmAg==} + cpu: [arm64] + os: [darwin] + + '@oven/bun-darwin-x64-baseline@1.3.0': + resolution: {integrity: sha512-+FSr/ub5vA/EkD3fMhHJUzYioSf/sXd50OGxNDAntVxcDu4tXL/81Ka3R/gkZmjznpLFIzovU/1Ts+b7dlkrfw==} + cpu: [x64] + os: [darwin] + + '@oven/bun-darwin-x64@1.3.0': + resolution: {integrity: sha512-CFKjoUWQH0Oz3UHYfKbdKLq0wGryrFsTJEYq839qAwHQSECvVZYAnxVVDYUDa0yQFonhO2qSHY41f6HK+b7xtw==} + cpu: [x64] + os: [darwin] + + '@oven/bun-linux-aarch64-musl@1.3.0': + resolution: {integrity: sha512-HT5sr7N8NDYbQRjAnT7ISpx64y+ewZZRQozOJb0+KQObKvg4UUNXGm4Pn1xA4/WPMZDDazjO8E2vtOQw1nJlAQ==} + cpu: [arm64] + os: [linux] + + '@oven/bun-linux-aarch64@1.3.0': + resolution: {integrity: sha512-WHthS/eLkCNcp9pk4W8aubRl9fIUgt2XhHyLrP0GClB1FVvmodu/zIOtG0NXNpzlzB8+gglOkGo4dPjfVf4Z+g==} + cpu: [arm64] + os: [linux] + + '@oven/bun-linux-x64-baseline@1.3.0': + resolution: {integrity: sha512-OmlEH3nlxQyv7HOvTH21vyNAZGv9DIPnrTznzvKiOQxkOphhCyKvPTlF13ydw4s/i18iwaUrhHy+YG9HSSxa4Q==} + cpu: [x64] + os: [linux] + + '@oven/bun-linux-x64-musl-baseline@1.3.0': + resolution: {integrity: sha512-hrr7mDvUjMX1tuJaXz448tMsgKIqGJBY8+rJqztKOw1U5+a/v2w5HuIIW1ce7ut0ZwEn+KIDvAujlPvpH33vpQ==} + cpu: [x64] + os: [linux] + + '@oven/bun-linux-x64-musl@1.3.0': + resolution: {integrity: sha512-rtzUEzCynl3Rhgn/iR9DQezSFiZMcAXAbU+xfROqsweMGKwvwIA2ckyyckO08psEP8XcUZTs3LT9CH7PnaMiEA==} + cpu: [x64] + os: [linux] + + '@oven/bun-linux-x64@1.3.0': + resolution: {integrity: sha512-sGEWoJQXO4GDr0x4t/yJQ/Bq1yNkOdX9tHbZZ+DBGJt3z3r7jeb4Digv8xQUk6gdTFC9vnGHuin+KW3/yD1Aww==} + cpu: [x64] + os: [linux] + + '@oven/bun-windows-x64-baseline@1.3.0': + resolution: {integrity: sha512-/jVZ8eYjpYHLDFNoT86cP+AjuWvpkzFY+0R0a1bdeu0sQ6ILuy1FV6hz1hUAP390E09VCo5oP76fnx29giHTtA==} + cpu: [x64] + os: [win32] + + '@oven/bun-windows-x64@1.3.0': + resolution: {integrity: sha512-xXwtpZVVP7T+vkxcF/TUVVOGRjEfkByO4mKveKYb4xnHWV4u4NnV0oNmzyMKkvmj10to5j2h0oZxA4ZVVv4gfA==} + cpu: [x64] + os: [win32] + + '@types/bun@1.3.0': + resolution: {integrity: sha512-+lAGCYjXjip2qY375xX/scJeVRmZ5cY0wyHYyCYxNcdEXrQ4AOe3gACgd4iQ8ksOslJtW4VNxBJ8llUwc3a6AA==} + + '@types/node@24.7.2': + resolution: {integrity: sha512-/NbVmcGTP+lj5oa4yiYxxeBjRivKQ5Ns1eSZeB99ExsEQ6rX5XYU1Zy/gGxY/ilqtD4Etx9mKyrPxZRetiahhA==} + + '@types/react@19.2.2': + resolution: {integrity: sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==} + + bun-types@1.3.0: + resolution: {integrity: sha512-u8X0thhx+yJ0KmkxuEo9HAtdfgCBaM/aI9K90VQcQioAmkVp3SG3FkwWGibUFz3WdXAdcsqOcbU40lK7tbHdkQ==} + peerDependencies: + '@types/react': ^19 + + bun@1.3.0: + resolution: {integrity: sha512-YI7mFs7iWc/VsGsh2aw6eAPD2cjzn1j+LKdYVk09x1CrdTWKYIHyd+dG5iQoN9//3hCDoZj8U6vKpZzEf5UARA==} + cpu: [arm64, x64] + os: [darwin, linux, win32] + hasBin: true + + csstype@3.1.3: + resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} + + debug@4.4.3: + resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + + depd@2.0.0: + resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} + engines: {node: '>= 0.8'} + + dotenv@16.6.1: + resolution: {integrity: sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==} + engines: {node: '>=12'} + + ee-first@1.1.1: + resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} + + encodeurl@2.0.0: + resolution: {integrity: sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==} + engines: {node: '>= 0.8'} + + escape-html@1.0.3: + resolution: {integrity: sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==} + + etag@1.8.1: + resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==} + engines: {node: '>= 0.6'} + + eventemitter3@5.0.1: + resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==} + + fresh@2.0.0: + resolution: {integrity: sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==} + engines: {node: '>= 0.8'} + + http-errors@2.0.0: + resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==} + engines: {node: '>= 0.8'} + + inherits@2.0.4: + resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + + mime-db@1.54.0: + resolution: {integrity: sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==} + engines: {node: '>= 0.6'} + + mime-types@3.0.1: + resolution: {integrity: sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==} + engines: {node: '>= 0.6'} + + ms@2.1.3: + resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + + node-forge@1.3.1: + resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==} + engines: {node: '>= 6.13.0'} + + on-finished@2.4.1: + resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} + engines: {node: '>= 0.8'} + + path-to-regexp@8.3.0: + resolution: {integrity: sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==} + + range-parser@1.2.1: + resolution: {integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==} + engines: {node: '>= 0.6'} + + selfsigned@3.0.1: + resolution: {integrity: sha512-6U6w6kSLrM9Zxo0D7mC7QdGS6ZZytMWBnj/vhF9p+dAHx6CwGezuRcO4VclTbrrI7mg7SD6zNiqXUuBHOVopNQ==} + engines: {node: '>=10'} + + send@1.2.0: + resolution: {integrity: sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw==} + engines: {node: '>= 18'} + + setprototypeof@1.2.0: + resolution: {integrity: sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==} + + statuses@2.0.1: + resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} + engines: {node: '>= 0.8'} + + statuses@2.0.2: + resolution: {integrity: sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==} + engines: {node: '>= 0.8'} + + toidentifier@1.0.1: + resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} + engines: {node: '>=0.6'} + + undici-types@7.14.0: + resolution: {integrity: sha512-QQiYxHuyZ9gQUIrmPo3IA+hUl4KYk8uSA7cHrcKd/l3p1OTpZcM0Tbp9x7FAtXdAYhlasd60ncPpgu6ihG6TOA==} + +snapshots: + + '@kevisual/load@0.0.6': + dependencies: + eventemitter3: 5.0.1 + + '@kevisual/router@0.0.28': + dependencies: + path-to-regexp: 8.3.0 + selfsigned: 3.0.1 + send: 1.2.0 + transitivePeerDependencies: + - supports-color + + '@kevisual/types@0.0.10': {} + + '@kevisual/use-config@1.0.19(dotenv@16.6.1)': + dependencies: + '@kevisual/load': 0.0.6 + dotenv: 16.6.1 + + '@oven/bun-darwin-aarch64@1.3.0': + optional: true + + '@oven/bun-darwin-x64-baseline@1.3.0': + optional: true + + '@oven/bun-darwin-x64@1.3.0': + optional: true + + '@oven/bun-linux-aarch64-musl@1.3.0': + optional: true + + '@oven/bun-linux-aarch64@1.3.0': + optional: true + + '@oven/bun-linux-x64-baseline@1.3.0': + optional: true + + '@oven/bun-linux-x64-musl-baseline@1.3.0': + optional: true + + '@oven/bun-linux-x64-musl@1.3.0': + optional: true + + '@oven/bun-linux-x64@1.3.0': + optional: true + + '@oven/bun-windows-x64-baseline@1.3.0': + optional: true + + '@oven/bun-windows-x64@1.3.0': + optional: true + + '@types/bun@1.3.0(@types/react@19.2.2)': + dependencies: + bun-types: 1.3.0(@types/react@19.2.2) + transitivePeerDependencies: + - '@types/react' + + '@types/node@24.7.2': + dependencies: + undici-types: 7.14.0 + + '@types/react@19.2.2': + dependencies: + csstype: 3.1.3 + + bun-types@1.3.0(@types/react@19.2.2): + dependencies: + '@types/node': 24.7.2 + '@types/react': 19.2.2 + + bun@1.3.0: + optionalDependencies: + '@oven/bun-darwin-aarch64': 1.3.0 + '@oven/bun-darwin-x64': 1.3.0 + '@oven/bun-darwin-x64-baseline': 1.3.0 + '@oven/bun-linux-aarch64': 1.3.0 + '@oven/bun-linux-aarch64-musl': 1.3.0 + '@oven/bun-linux-x64': 1.3.0 + '@oven/bun-linux-x64-baseline': 1.3.0 + '@oven/bun-linux-x64-musl': 1.3.0 + '@oven/bun-linux-x64-musl-baseline': 1.3.0 + '@oven/bun-windows-x64': 1.3.0 + '@oven/bun-windows-x64-baseline': 1.3.0 + + csstype@3.1.3: {} + + debug@4.4.3: + dependencies: + ms: 2.1.3 + + depd@2.0.0: {} + + dotenv@16.6.1: {} + + ee-first@1.1.1: {} + + encodeurl@2.0.0: {} + + escape-html@1.0.3: {} + + etag@1.8.1: {} + + eventemitter3@5.0.1: {} + + fresh@2.0.0: {} + + http-errors@2.0.0: + dependencies: + depd: 2.0.0 + inherits: 2.0.4 + setprototypeof: 1.2.0 + statuses: 2.0.1 + toidentifier: 1.0.1 + + inherits@2.0.4: {} + + mime-db@1.54.0: {} + + mime-types@3.0.1: + dependencies: + mime-db: 1.54.0 + + ms@2.1.3: {} + + node-forge@1.3.1: {} + + on-finished@2.4.1: + dependencies: + ee-first: 1.1.1 + + path-to-regexp@8.3.0: {} + + range-parser@1.2.1: {} + + selfsigned@3.0.1: + dependencies: + node-forge: 1.3.1 + + send@1.2.0: + dependencies: + debug: 4.4.3 + encodeurl: 2.0.0 + escape-html: 1.0.3 + etag: 1.8.1 + fresh: 2.0.0 + http-errors: 2.0.0 + mime-types: 3.0.1 + ms: 2.1.3 + on-finished: 2.4.1 + range-parser: 1.2.1 + statuses: 2.0.2 + transitivePeerDependencies: + - supports-color + + setprototypeof@1.2.0: {} + + statuses@2.0.1: {} + + statuses@2.0.2: {} + + toidentifier@1.0.1: {} + + undici-types@7.14.0: {} diff --git a/server/src/demo.ts b/server/src/demo.ts new file mode 100644 index 0000000..bdc5db5 --- /dev/null +++ b/server/src/demo.ts @@ -0,0 +1,38 @@ +import { App } from '@kevisual/router' +import { fork } from 'child_process' +const app = new App() +import path from 'path' + +// http://localhost:3000/api/router?path=call +app.route({ + path: 'call' +}).define(async (ctx) => { + ctx.body = 'Hello World' + const pwd = process.cwd() + const testA = path.join(pwd, 'src/test/a.ts') + const child = fork(testA, { + }) + console.log('Child process started with PID:', child.pid) + child.on('message', (msg) => { + console.log('Message from child', msg) + setTimeout(() => { + console.log('child process connected:', child.connected) + console.log('child process killed:', child.killed) + console.log('child process exit code:', child.exitCode) + }, 20) + }) + + child.on('exit', (code, signal) => { + console.log('子进程已退出,退出码:', code, '信号:', signal) + }) + + child.on('close', (code, signal) => { + console.log('子进程已关闭,退出码:', code, '信号:', signal) + }) + child.send({ hello: 'world' }) + +}).addTo(app) + +app.listen(3000, () => { + console.log('Server is running on http://localhost:3000') +}) \ No newline at end of file diff --git a/server/src/index.ts b/server/src/index.ts new file mode 100644 index 0000000..7aa5857 --- /dev/null +++ b/server/src/index.ts @@ -0,0 +1,51 @@ +import { App } from '@kevisual/router' +import { fork } from 'child_process' +const app = new App() +import path from 'path' + +// http://localhost:3000/api/router?path=call +app.route({ + path: 'call' +}).define(async (ctx) => { + ctx.body = 'Hello World' + const pwd = process.cwd() + const testA = path.join(pwd, 'src/test/a.ts') + + // 使用 Bun 的 fork 模式启动子进程 + const child = fork(testA, [], { + execArgv: [], + cwd: "/tmp", // 限制工作目录 + }) + + console.log('Child process started with PID:', child.pid) + + // 监听来自子进程的消息 + child.on('message', (msg) => { + console.log('Message from child:', msg) + setTimeout(() => { + console.log('child process connected:', child.connected) + console.log('child process killed:', child.killed) + console.log('child process exit code:', child.exitCode) + }, 20) + }) + + child.on('exit', (code, signal) => { + console.log('子进程已退出,退出码:', code, '信号:', signal) + }) + + child.on('close', (code, signal) => { + console.log('子进程已关闭,退出码:', code, '信号:', signal) + }) + + child.on('error', (error) => { + console.error('子进程错误:', error) + }) + + // 向子进程发送消息 + child.send({ hello: 'world' }) + +}).addTo(app) + +app.listen(3000, () => { + console.log('Server is running on http://localhost:3000') +}) \ No newline at end of file diff --git a/server/src/test/a.ts b/server/src/test/a.ts new file mode 100644 index 0000000..1df770d --- /dev/null +++ b/server/src/test/a.ts @@ -0,0 +1,58 @@ +import fs from 'node:fs' +const main = () => { + const random = Math.random().toString(36).slice(-6) + return 'hello a' + random +} + +fs.writeFileSync('./a.txt', main() + '\n', { flag: 'a' }) +console.log('pwd', process.cwd()) +// const value = fs.readFileSync('./bun.config.ts', 'utf-8') +// console.log('a.txt 内容:', value) +const listen = async () => { + console.log('子进程启动,等待消息...') + + const getParams = async () => { + return new Promise((resolve) => { + process.on('message', (msg) => { + console.log('子进程收到消息:', msg) + resolve(msg) + }) + }) + } + + try { + const params = await getParams() + console.log('处理参数:', params) + + // 执行主要逻辑 + const result = main() + + // 发送结果回主进程 + const response = { + success: true, + foo: 'bar', + params, + main: result, + timestamp: new Date().toISOString() + } + + process.send?.(response, (error) => { + if (error) { + console.error('发送消息失败:', error) + } else { + console.log('成功发送响应:', response) + } + process.exit(0) + }) + } catch (error) { + console.error('子进程执行出错:', error) + process.send?.({ + success: false, + error: error.message + }) + process.exit(1) + } +} + +// 启动监听 +listen().catch(console.error) \ No newline at end of file diff --git a/server/tsconfig.json b/server/tsconfig.json new file mode 100644 index 0000000..b2f3b7c --- /dev/null +++ b/server/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "@kevisual/types/json/backend.json", + "compilerOptions": { + "baseUrl": ".", + "module": "NodeNext", + "target": "esnext", + "typeRoots": [ + "./node_modules/@types" + ], + "paths": { + "@/*": [ + "server/src/*" + ] + }, + }, + "include": [ + "server/src/**/*", + ], +} \ No newline at end of file