update
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
57
demo-origin.ts
Normal file
57
demo-origin.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
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 = {
|
||||
foo: 'bar',
|
||||
params,
|
||||
success: true,
|
||||
data: { code: 200, data: 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)
|
||||
14
demo-router.ts
Normal file
14
demo-router.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { QueryRouterServer } from "@kevisual/router";
|
||||
|
||||
const app = new QueryRouterServer();
|
||||
|
||||
app.route({
|
||||
path: 'main'
|
||||
}).define(async (ctx) => {
|
||||
ctx.body = {
|
||||
message: 'this is main. filename: root/listen-demo/router.ts',
|
||||
params: ctx.query
|
||||
}
|
||||
}).addTo(app)
|
||||
|
||||
app.wait()
|
||||
24
main.ts
Normal file
24
main.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { QueryRouterServer } from "@kevisual/router";
|
||||
|
||||
const app = new QueryRouterServer();
|
||||
|
||||
app.route({
|
||||
path: 'main'
|
||||
}).define(async (ctx) => {
|
||||
ctx.body = {
|
||||
message: 'this is main. filename: root/light-code-demo/main.ts',
|
||||
params: ctx.query
|
||||
}
|
||||
}).addTo(app)
|
||||
|
||||
app.route({
|
||||
path: 'main2'
|
||||
}).define(async (ctx) => {
|
||||
ctx.body = {
|
||||
message: 'this is main2. filename: root/light-code-demo/main.ts',
|
||||
params: ctx.query
|
||||
}
|
||||
}).addTo(app)
|
||||
|
||||
|
||||
app.wait()
|
||||
24
package.json
Normal file
24
package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@kevisual/light-code-demo",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"pub": "ev deploy . -v 0.0.1 -k light-code-demo -u"
|
||||
},
|
||||
"app": {
|
||||
"type": "script-app"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
|
||||
"license": "MIT",
|
||||
"packageManager": "pnpm@10.19.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@kevisual/noco": "^0.0.1",
|
||||
"@kevisual/router": "^0.0.30"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.10.0"
|
||||
}
|
||||
}
|
||||
211
pnpm-lock.yaml
generated
Normal file
211
pnpm-lock.yaml
generated
Normal file
@@ -0,0 +1,211 @@
|
||||
lockfileVersion: '9.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
'@kevisual/noco':
|
||||
specifier: ^0.0.1
|
||||
version: 0.0.1
|
||||
'@kevisual/router':
|
||||
specifier: ^0.0.30
|
||||
version: 0.0.30
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^24.10.0
|
||||
version: 24.10.0
|
||||
|
||||
packages:
|
||||
|
||||
'@kevisual/noco@0.0.1':
|
||||
resolution: {integrity: sha512-N0wYcxasxXe3S6jQtD5SSUwOOmaPaL+9S9Qe+iwA2oXYNUmheNXgz2vQJUmKa3SZHgOrwsKMMe3ZhAHftJizQg==, tarball: https://registry.npmjs.org/@kevisual/noco/-/noco-0.0.1.tgz}
|
||||
|
||||
'@kevisual/router@0.0.30':
|
||||
resolution: {integrity: sha512-/mBo7aZFWjT4QfHkI5HPXfdgSwZzt3mAVei7dcNSBTPe9KQSoYKZ8BTq9VTUj3XE0sI6o1bZjlLYvinpVnZilw==}
|
||||
|
||||
'@types/node@24.10.0':
|
||||
resolution: {integrity: sha512-qzQZRBqkFsYyaSWXuEHc2WR9c0a0CXwiE5FWUvn7ZM+vdy1uZLfCunD38UzhuB7YN/J11ndbDBcTmOdxJo9Q7A==}
|
||||
|
||||
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'}
|
||||
|
||||
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'}
|
||||
|
||||
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.16.0:
|
||||
resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==}
|
||||
|
||||
snapshots:
|
||||
|
||||
'@kevisual/noco@0.0.1': {}
|
||||
|
||||
'@kevisual/router@0.0.30':
|
||||
dependencies:
|
||||
path-to-regexp: 8.3.0
|
||||
selfsigned: 3.0.1
|
||||
send: 1.2.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@types/node@24.10.0':
|
||||
dependencies:
|
||||
undici-types: 7.16.0
|
||||
|
||||
debug@4.4.3:
|
||||
dependencies:
|
||||
ms: 2.1.3
|
||||
|
||||
depd@2.0.0: {}
|
||||
|
||||
ee-first@1.1.1: {}
|
||||
|
||||
encodeurl@2.0.0: {}
|
||||
|
||||
escape-html@1.0.3: {}
|
||||
|
||||
etag@1.8.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.16.0: {}
|
||||
10
readme.md
Normal file
10
readme.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# light-code-demo
|
||||
|
||||
|
||||
```sh
|
||||
asst app download -i root/light-code-demo
|
||||
```
|
||||
|
||||
## code的代码的例子
|
||||
|
||||
什么情况
|
||||
46
sign.ts
Normal file
46
sign.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { QueryRouterServer as Mini } from "@kevisual/router";
|
||||
import { NocoApi } from "@kevisual/noco";
|
||||
const config = {
|
||||
NOCODB_URL: process.env.NOCODB_URL || 'https://nocodb.xiongxiao.me',
|
||||
NOCODB_API_KEY: process.env.NOCODB_API_KEY || 'uca1Zx3p_**'
|
||||
}
|
||||
const table = 'mcby44q8zrayvn9'
|
||||
const nocoAPi = new NocoApi({
|
||||
baseURL: config.NOCODB_URL,
|
||||
token: config.NOCODB_API_KEY,
|
||||
table,
|
||||
});
|
||||
console.log('nocoAPi', await nocoAPi.record.list())
|
||||
const app = new Mini();
|
||||
|
||||
|
||||
app.route({
|
||||
path: 'sign'
|
||||
}).define(async (ctx) => {
|
||||
const { Title, Description } = ctx.query
|
||||
// 这里可以处理签到
|
||||
await nocoAPi.record.create({ Title, Description })
|
||||
const list = await nocoAPi.record.list({ sort: '-CreatedAt' })
|
||||
ctx.body = { message: '签到成功', list }
|
||||
}).addTo(app)
|
||||
|
||||
app.route({
|
||||
path: 'sign',
|
||||
key: 'list'
|
||||
}).define(async (ctx) => {
|
||||
// 这里可以处理签到
|
||||
ctx.body = await nocoAPi.record.list()
|
||||
}).addTo(app)
|
||||
|
||||
app.route({
|
||||
path: 'sign',
|
||||
key: 'delete'
|
||||
}).define(async (ctx) => {
|
||||
const { id } = ctx.query
|
||||
// 这里可以处理签到
|
||||
await nocoAPi.record.delete({ Id: id })
|
||||
const list = await nocoAPi.record.list({ sort: '-CreatedAt' })
|
||||
ctx.body = { message: '删除成功', list }
|
||||
}).addTo(app)
|
||||
|
||||
app.wait()
|
||||
56
weather.ts
Normal file
56
weather.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
const weatherHost = 'n65khufe5n.re.qweatherapi.com';
|
||||
const token = 'fdad5aeb2ba54949a8a1df2a0f3d1efb'
|
||||
const xihu = '101210113'; // 西湖
|
||||
export const getWeather = async (location: string = xihu) => {
|
||||
const url = `https://${weatherHost}/v7/weather/3d?location=${location}`;
|
||||
const headers = {
|
||||
'Authorization': `Bearer ${token}`
|
||||
};
|
||||
const res = await fetch(url, { headers });
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error! status: ${res.status}`);
|
||||
}
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
// getWeather().then(console.log).catch(console.error);
|
||||
|
||||
// https://dev.qweather.com/
|
||||
class Weather {
|
||||
host: string;
|
||||
token: string;
|
||||
constructor(opts: { host: string; token: string }) {
|
||||
this.host = opts.host;
|
||||
this.token = opts.token;
|
||||
console.log(this.host, this.token);
|
||||
}
|
||||
getWeather(location: string) {
|
||||
return fetch(`https://${this.host}/v7/weather/now?location=${location}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-QW-Api-Key': '<KEY>'.replace('<KEY>', this.token),
|
||||
},
|
||||
}).then((res) => res.json());
|
||||
}
|
||||
}
|
||||
const newWeather = new Weather({
|
||||
host: process.env?.QWEATHER_HOST || weatherHost,
|
||||
token: process.env?.QWEATHER_TOKEN || token,
|
||||
});
|
||||
|
||||
|
||||
// newWeather.getWeather(xihu).then(console.log).catch(console.error);
|
||||
|
||||
|
||||
import { QueryRouterServer as Mini } from "@kevisual/router";
|
||||
|
||||
const app = new Mini();
|
||||
|
||||
app.route({
|
||||
path: 'main'
|
||||
}).define(async (ctx) => {
|
||||
ctx.body = await newWeather.getWeather(xihu);
|
||||
}).addTo(app)
|
||||
|
||||
|
||||
app.wait()
|
||||
Reference in New Issue
Block a user