remove webpack
This commit is contained in:
parent
696be2a28c
commit
7ec8a001de
32
package.json
32
package.json
@ -6,22 +6,18 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "abearxiong",
|
"author": "abearxiong",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "cross-env ENV=production webpack --mode=production --watch",
|
"watch": "rollup -c rollup.config.mjs -w",
|
||||||
"dev": "cross-env NODE_ENV=development nodemon --delay 2.5 -e js,cjs,mjs --watch dist --exec node dist/app.cjs",
|
"dev": "cross-env NODE_ENV=development nodemon --delay 2.5 -e js,cjs,mjs --exec node dist/app.mjs",
|
||||||
"test": "tsx test/**/*.ts",
|
"test": "tsx test/**/*.ts",
|
||||||
"dev:watch": "concurrently -n \"Watch,Dev\" -c \"green,blue\" \"npm run watch\" \"sleep 1 && npm run dev\" ",
|
"dev:watch": "concurrently -n \"Watch,Dev\" -c \"green,blue\" \"npm run watch\" \"sleep 1 && npm run dev\" ",
|
||||||
"build": "cross-env ENV=production webpack --mode=production ",
|
"build": "rimraf dist && rollup -c rollup.config.mjs",
|
||||||
"build:sh": "cross-env webpack --mode=production -c ./webpack.shell.config.cjs",
|
|
||||||
"deploy": "rsync -avz --delete ./dist/ --exclude='app.config.json5' light:~/apps/codeflow/backend",
|
"deploy": "rsync -avz --delete ./dist/ --exclude='app.config.json5' light:~/apps/codeflow/backend",
|
||||||
"deploy:sh": "",
|
|
||||||
"clean": "rm -rf dist",
|
"clean": "rm -rf dist",
|
||||||
"reload": "ssh light pm2 restart codeflow",
|
"reload": "ssh light pm2 restart codeflow",
|
||||||
"docker:build": "docker build -t docker.xiongxiao.me/code-flow:v0.0.2 .",
|
"docker:build": "docker build -t docker.xiongxiao.me/code-flow:v0.0.2 .",
|
||||||
"docker:push": "docker push docker.xiongxiao.me/code-flow:v0.0.2",
|
"docker:push": "docker push docker.xiongxiao.me/code-flow:v0.0.2",
|
||||||
"docker:run": "docker run -it --name code-flow -p 4000:4000 docker.xiongxiao.me/code-flow:v0.0.2",
|
"docker:run": "docker run -it --name code-flow -p 4000:4000 docker.xiongxiao.me/code-flow:v0.0.2",
|
||||||
"pub": "npm run build && npm run deploy && npm run reload",
|
"pub": "npm run build && npm run deploy && npm run reload",
|
||||||
"bud": "rimraf dist && rollup -c",
|
|
||||||
"bud:watch": "rollup -c -w",
|
|
||||||
"apps:build": "rollup -c rollup.apps.config.mjs",
|
"apps:build": "rollup -c rollup.apps.config.mjs",
|
||||||
"apps:watch": "rollup -c rollup.apps.config.mjs -w"
|
"apps:watch": "rollup -c rollup.apps.config.mjs -w"
|
||||||
},
|
},
|
||||||
@ -40,10 +36,11 @@
|
|||||||
"@babel/preset-typescript": "^7.26.0",
|
"@babel/preset-typescript": "^7.26.0",
|
||||||
"@kevisual/ai-graph": "workspace:^",
|
"@kevisual/ai-graph": "workspace:^",
|
||||||
"@kevisual/ai-lang": "workspace:^",
|
"@kevisual/ai-lang": "workspace:^",
|
||||||
"@kevisual/router": "0.0.4-alpha-7",
|
"@kevisual/router": "0.0.4-alpha-8",
|
||||||
"@supabase/supabase-js": "^2.46.1",
|
"@supabase/supabase-js": "^2.46.1",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
|
"bullmq": "^5.25.6",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"dts-bundle-generator": "^9.5.1",
|
"dts-bundle-generator": "^9.5.1",
|
||||||
"formidable": "^3.5.2",
|
"formidable": "^3.5.2",
|
||||||
@ -56,18 +53,21 @@
|
|||||||
"neo4j-driver": "^5.26.0",
|
"neo4j-driver": "^5.26.0",
|
||||||
"neode": "^0.4.9",
|
"neode": "^0.4.9",
|
||||||
"node-fetch": "^3.3.2",
|
"node-fetch": "^3.3.2",
|
||||||
"ollama": "^0.5.9",
|
"ollama": "^0.5.10",
|
||||||
|
"p-queue": "^8.0.1",
|
||||||
"pg": "^8.13.1",
|
"pg": "^8.13.1",
|
||||||
|
"rollup-plugin-esbuild": "^6.1.1",
|
||||||
"semver": "^7.6.3",
|
"semver": "^7.6.3",
|
||||||
"sequelize": "^6.37.5",
|
"sequelize": "^6.37.5",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"sqlite3": "^5.1.7",
|
"sqlite3": "^5.1.7",
|
||||||
"strip-ansi": "^7.1.0",
|
"strip-ansi": "^7.1.0",
|
||||||
"uuid": "^11.0.2",
|
"uuid": "^11.0.3",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@abearxiong/use-file-store": "^0.0.1",
|
"@abearxiong/use-file-store": "^0.0.1",
|
||||||
|
"@rollup/plugin-alias": "^5.1.1",
|
||||||
"@rollup/plugin-commonjs": "^28.0.1",
|
"@rollup/plugin-commonjs": "^28.0.1",
|
||||||
"@rollup/plugin-json": "^6.1.0",
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.3.0",
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
||||||
@ -80,26 +80,20 @@
|
|||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
"@types/react": "^18.3.12",
|
"@types/react": "^18.3.12",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"@types/webpack-env": "^1.18.5",
|
|
||||||
"concurrently": "^9.1.0",
|
"concurrently": "^9.1.0",
|
||||||
"copy-webpack-plugin": "^12.0.2",
|
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
||||||
"glob": "^11.0.0",
|
"glob": "^11.0.0",
|
||||||
"nodemon": "^3.1.7",
|
"nodemon": "^3.1.7",
|
||||||
"patch-package": "^8.0.0",
|
"patch-package": "^8.0.0",
|
||||||
"postinstall-postinstall": "^2.1.0",
|
"pm2": "^5.4.3",
|
||||||
"rimraf": "^6.0.1",
|
"rimraf": "^6.0.1",
|
||||||
"rollup": "^4.25.0",
|
"rollup": "^4.26.0",
|
||||||
"rollup-plugin-copy": "^3.5.0",
|
"rollup-plugin-copy": "^3.5.0",
|
||||||
"rollup-plugin-dts": "^6.1.1",
|
"rollup-plugin-dts": "^6.1.1",
|
||||||
"tape": "^5.9.0",
|
"tape": "^5.9.0",
|
||||||
"ts-loader": "^9.5.1",
|
"ts-loader": "^9.5.1",
|
||||||
"tsx": "^4.19.2",
|
"tsx": "^4.19.2",
|
||||||
"typescript": "^5.6.3",
|
"typescript": "^5.6.3"
|
||||||
"webpack": "^5.96.1",
|
|
||||||
"webpack-cli": "^5.1.4",
|
|
||||||
"webpack-node-externals": "^3.0.0"
|
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"glob": "latest",
|
"glob": "latest",
|
||||||
|
1686
pnpm-lock.yaml
generated
1686
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,20 +1,20 @@
|
|||||||
import typescript from '@rollup/plugin-typescript';
|
import typescript from '@rollup/plugin-typescript'
|
||||||
import resolve from '@rollup/plugin-node-resolve';
|
import resolve from '@rollup/plugin-node-resolve'
|
||||||
import commonjs from '@rollup/plugin-commonjs';
|
import commonjs from '@rollup/plugin-commonjs'
|
||||||
import copy from 'rollup-plugin-copy';
|
import copy from 'rollup-plugin-copy'
|
||||||
import { dts } from 'rollup-plugin-dts';
|
import { dts } from 'rollup-plugin-dts'
|
||||||
import json from '@rollup/plugin-json';
|
import json from '@rollup/plugin-json'
|
||||||
import * as glob from 'glob';
|
import * as glob from 'glob'
|
||||||
import path from 'path';
|
import path from 'path'
|
||||||
|
|
||||||
const files = glob.sync('src-apps/**/index.ts');
|
const files = glob.sync('src-apps/**/index.ts')
|
||||||
console.log(files);
|
console.log(files)
|
||||||
const configs = files.map((file) => {
|
const configs = files.map((file) => {
|
||||||
const inputFile = file;
|
const inputFile = file
|
||||||
const directory = file.split('/').slice(0, -1).join('/');
|
const directory = file.split('/').slice(0, -1).join('/')
|
||||||
const outputDirectory = directory.replace('src-apps', 'dist/apps');
|
const outputDirectory = directory.replace('src-apps', 'dist/apps')
|
||||||
console.log(directory);
|
console.log(directory)
|
||||||
console.log(outputDirectory);
|
console.log(outputDirectory)
|
||||||
/**
|
/**
|
||||||
* @type {import('rollup').RollupOptions}
|
* @type {import('rollup').RollupOptions}
|
||||||
*/
|
*/
|
||||||
@ -22,16 +22,16 @@ const configs = files.map((file) => {
|
|||||||
input: inputFile,
|
input: inputFile,
|
||||||
output: {
|
output: {
|
||||||
outDir: outputDirectory,
|
outDir: outputDirectory,
|
||||||
file: path.join(outputDirectory, 'index.cjs'),
|
file: path.join(outputDirectory, 'index.mjs'),
|
||||||
format: 'cjs',
|
// format: 'cjs'
|
||||||
// format: 'esm',
|
format: 'esm',
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
resolve(),
|
resolve(),
|
||||||
// commonjs(),
|
commonjs(),
|
||||||
typescript({
|
typescript({
|
||||||
declaration: false,
|
declaration: false
|
||||||
}),
|
})
|
||||||
// json(),
|
// json(),
|
||||||
// copy({
|
// copy({
|
||||||
// targets: [
|
// targets: [
|
||||||
@ -42,8 +42,8 @@ const configs = files.map((file) => {
|
|||||||
// ],
|
// ],
|
||||||
// }),
|
// }),
|
||||||
],
|
],
|
||||||
external: ['sequelize'],
|
external: ['sequelize', '@kevisual/router']
|
||||||
};
|
}
|
||||||
return config;
|
return config
|
||||||
});
|
})
|
||||||
export default [...configs];
|
export default [...configs]
|
||||||
|
@ -1,25 +1,70 @@
|
|||||||
import typescript from '@rollup/plugin-typescript';
|
import typescript from '@rollup/plugin-typescript'
|
||||||
import resolve from '@rollup/plugin-node-resolve';
|
import resolve from '@rollup/plugin-node-resolve'
|
||||||
import commonjs from '@rollup/plugin-commonjs';
|
import commonjs from '@rollup/plugin-commonjs'
|
||||||
import copy from 'rollup-plugin-copy';
|
import copy from 'rollup-plugin-copy'
|
||||||
import { dts } from 'rollup-plugin-dts';
|
import { dts } from 'rollup-plugin-dts'
|
||||||
import json from '@rollup/plugin-json';
|
import json from '@rollup/plugin-json'
|
||||||
import path from 'path';
|
import * as glob from 'glob'
|
||||||
|
import path from 'path'
|
||||||
|
import esbuild from 'rollup-plugin-esbuild'
|
||||||
|
import alias from '@rollup/plugin-alias'
|
||||||
|
// import ignore from 'rollup-plugin-ignore';
|
||||||
|
// ignore(['xmlbuilder']),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {import('rollup').RollupOptions}
|
||||||
|
*/
|
||||||
const config = {
|
const config = {
|
||||||
input: 'src/index.ts',
|
input: './src/index.ts',
|
||||||
output: {
|
output: {
|
||||||
dir: 'dist',
|
dir: './dist',
|
||||||
// file: path.join('dist', 'app.cjs'),
|
// file: path.join('./dist', 'app.mjs'),
|
||||||
format: 'esm',
|
entryFileNames: 'app.mjs',
|
||||||
|
chunkFileNames: '[name]-[hash].mjs',
|
||||||
|
// format: 'cjs'
|
||||||
|
format: 'esm'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
resolve(),
|
alias({
|
||||||
commonjs(),
|
// only esbuild needs to be configured
|
||||||
typescript({
|
entries: [
|
||||||
declaration: false,
|
{ find: '@', replacement: path.resolve('src') }, // 配置 @ 为 src 目录
|
||||||
|
{ find: 'http', replacement: 'node:http' },
|
||||||
|
{ find: 'https', replacement: 'node:https' },
|
||||||
|
{ find: 'fs', replacement: 'node:fs' },
|
||||||
|
{ find: 'path', replacement: 'node:path' },
|
||||||
|
{ find: 'crypto', replacement: 'node:crypto' },
|
||||||
|
{ find: 'zlib', replacement: 'node:zlib' },
|
||||||
|
{ find: 'stream', replacement: 'node:stream' },
|
||||||
|
{ find: 'net', replacement: 'node:net' },
|
||||||
|
{ find: 'tty', replacement: 'node:tty' },
|
||||||
|
{ find: 'tls', replacement: 'node:tls' },
|
||||||
|
{ find: 'buffer', replacement: 'node:buffer' },
|
||||||
|
{ find: 'timers', replacement: 'node:timers' },
|
||||||
|
// { find: 'string_decoder', replacement: 'node:string_decoder' },
|
||||||
|
{ find: 'dns', replacement: 'node:dns' },
|
||||||
|
{ find: 'domain', replacement: 'node:domain' },
|
||||||
|
{ find: 'os', replacement: 'node:os' },
|
||||||
|
{ find: 'events', replacement: 'node:events' },
|
||||||
|
{ find: 'url', replacement: 'node:url' },
|
||||||
|
{ find: 'assert', replacement: 'node:assert' },
|
||||||
|
{ find: 'util', replacement: 'node:util' }
|
||||||
|
]
|
||||||
}),
|
}),
|
||||||
json(),
|
resolve({
|
||||||
|
preferBuiltins: true // 强制优先使用内置模块
|
||||||
|
}),
|
||||||
|
commonjs(),
|
||||||
|
// typescript({
|
||||||
|
// declaration: false
|
||||||
|
// }),
|
||||||
|
esbuild({
|
||||||
|
target: 'node22', // 目标为 Node.js 14
|
||||||
|
minify: false, // 启用代码压缩
|
||||||
|
tsconfig: 'tsconfig.json'
|
||||||
|
}),
|
||||||
|
|
||||||
|
json()
|
||||||
// copy({
|
// copy({
|
||||||
// targets: [
|
// targets: [
|
||||||
// {
|
// {
|
||||||
@ -28,10 +73,8 @@ const config = {
|
|||||||
// },
|
// },
|
||||||
// ],
|
// ],
|
||||||
// }),
|
// }),
|
||||||
|
|
||||||
],
|
],
|
||||||
external: ['sequelize'],
|
external: ['sequelize', '@kevisual/router', 'ioredis', 'socket.io', 'minio']
|
||||||
resolve: {
|
}
|
||||||
stream: true,
|
export default config
|
||||||
},
|
|
||||||
};
|
|
||||||
export default [config];
|
|
||||||
|
@ -5,8 +5,12 @@
|
|||||||
"@babel/core": "^7.24.7",
|
"@babel/core": "^7.24.7",
|
||||||
"@babel/preset-env": "^7.24.7",
|
"@babel/preset-env": "^7.24.7",
|
||||||
"@babel/preset-typescript": "^7.24.7",
|
"@babel/preset-typescript": "^7.24.7",
|
||||||
"sequelize": "^6.37.3",
|
"@kevisual/router": "^0.0.4-alpha-8",
|
||||||
"socket.io": "^4.7.5",
|
"ioredis": "^5.4.1",
|
||||||
"pg": "^8.12.0"
|
"minio": "^8.0.2",
|
||||||
|
"pg": "^8.13.1",
|
||||||
|
"sequelize": "^6.37.5",
|
||||||
|
"sqlite3": "^5.1.7",
|
||||||
|
"socket.io": "^4.8.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
130
src-apps/demo/index.ts
Normal file
130
src-apps/demo/index.ts
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
import type { App, RouteContext } from '@kevisual/router';
|
||||||
|
import { DataTypes, Model } from 'sequelize';
|
||||||
|
|
||||||
|
type AppContext = {
|
||||||
|
import: any;
|
||||||
|
sequelize: any;
|
||||||
|
};
|
||||||
|
type Ctx = RouteContext<AppContext>;
|
||||||
|
|
||||||
|
class AppModel extends Model {
|
||||||
|
declare id: string;
|
||||||
|
declare title: string;
|
||||||
|
declare description: string;
|
||||||
|
declare cover: string;
|
||||||
|
declare url: string;
|
||||||
|
declare share: boolean;
|
||||||
|
declare tags: string[];
|
||||||
|
declare uid: string;
|
||||||
|
declare username: string;
|
||||||
|
}
|
||||||
|
export const getModel = async (ctx: Ctx) => {
|
||||||
|
const sequelize = ctx.sequelize;
|
||||||
|
if (!sequelize) {
|
||||||
|
ctx.throw?.('sequelize instance not found');
|
||||||
|
}
|
||||||
|
AppModel.init(
|
||||||
|
{
|
||||||
|
id: {
|
||||||
|
type: DataTypes.UUID,
|
||||||
|
primaryKey: true,
|
||||||
|
defaultValue: DataTypes.UUIDV4,
|
||||||
|
},
|
||||||
|
cover: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: '',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: '',
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
share: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
tags: {
|
||||||
|
type: DataTypes.JSONB,
|
||||||
|
defaultValue: [],
|
||||||
|
},
|
||||||
|
uid: {
|
||||||
|
type: DataTypes.UUID,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
username: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
modelName: 'apps_demo',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return AppModel;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 初始化模型
|
||||||
|
* @param ctx
|
||||||
|
*/
|
||||||
|
export const initModel = async (ctx: RouteContext<AppContext>) => {
|
||||||
|
try {
|
||||||
|
const AppModel = await getModel(ctx);
|
||||||
|
const res = await AppModel.sync({ alter: true });
|
||||||
|
ctx.body = 'success';
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.throw?.(error.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const render = (app: App) => {
|
||||||
|
app
|
||||||
|
.route({
|
||||||
|
path: 'apps-demo',
|
||||||
|
key: 'init',
|
||||||
|
middleware: ['auth'],
|
||||||
|
})
|
||||||
|
.define(initModel)
|
||||||
|
.addTo(app);
|
||||||
|
|
||||||
|
app
|
||||||
|
.route({
|
||||||
|
path: 'apps-demo',
|
||||||
|
key: 'list',
|
||||||
|
})
|
||||||
|
.define<AppContext>(async (ctx) => {
|
||||||
|
const AppModel = await getModel(ctx);
|
||||||
|
const res = await AppModel.findAll();
|
||||||
|
ctx.body = res;
|
||||||
|
})
|
||||||
|
.addTo(app);
|
||||||
|
|
||||||
|
app
|
||||||
|
.route({
|
||||||
|
path: 'apps-demo',
|
||||||
|
key: 'delete',
|
||||||
|
})
|
||||||
|
.define(async (ctx) => {
|
||||||
|
ctx.body = 'success';
|
||||||
|
})
|
||||||
|
.addTo(app);
|
||||||
|
app
|
||||||
|
.route({
|
||||||
|
path: 'apps-demo',
|
||||||
|
key: 'update',
|
||||||
|
})
|
||||||
|
.define(async (ctx) => {
|
||||||
|
ctx.body = 'update success';
|
||||||
|
})
|
||||||
|
.addTo(app);
|
||||||
|
};
|
@ -2,7 +2,6 @@ import { App } from '@kevisual/router';
|
|||||||
import { useConfig } from '@abearxiong/use-config';
|
import { useConfig } from '@abearxiong/use-config';
|
||||||
import { dynamicImport } from './lib/dynamic-import.ts';
|
import { dynamicImport } from './lib/dynamic-import.ts';
|
||||||
import { redisPublisher, redisSubscriber, redis } from './modules/redis.ts';
|
import { redisPublisher, redisSubscriber, redis } from './modules/redis.ts';
|
||||||
import { neode, getSession } from './modules/neo4j.ts';
|
|
||||||
import { minioClient } from './modules/minio.ts';
|
import { minioClient } from './modules/minio.ts';
|
||||||
import { sequelize } from './modules/sequelize.ts';
|
import { sequelize } from './modules/sequelize.ts';
|
||||||
|
|
||||||
@ -10,7 +9,7 @@ useConfig();
|
|||||||
export const emit = (channel: string, message?: any) => {
|
export const emit = (channel: string, message?: any) => {
|
||||||
redisPublisher.publish(channel, JSON.stringify(message));
|
redisPublisher.publish(channel, JSON.stringify(message));
|
||||||
};
|
};
|
||||||
export { neode, getSession, redis, minioClient, sequelize };
|
export { redis, minioClient, sequelize };
|
||||||
|
|
||||||
export const app = new App<{ import: any; emit: typeof emit; sequelize: typeof sequelize }>({
|
export const app = new App<{ import: any; emit: typeof emit; sequelize: typeof sequelize }>({
|
||||||
serverOptions: {
|
serverOptions: {
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import path, { dirname } from 'path';
|
import path, { dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
export const getRequire = () => {
|
|
||||||
return eval('require') as NodeRequire;
|
|
||||||
};
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
@ -22,14 +19,15 @@ export const defaultImportModules = [
|
|||||||
export const dynamicImport = async (name: string) => {
|
export const dynamicImport = async (name: string) => {
|
||||||
// const nodeModules = path.resolve(directoryPath, 'node_modules');
|
// const nodeModules = path.resolve(directoryPath, 'node_modules');
|
||||||
// const nodeName = path.resolve(nodeModules, name);
|
// const nodeName = path.resolve(nodeModules, name);
|
||||||
const require = getRequire();
|
|
||||||
console.log(`Dynamic import module ${name}`);
|
console.log(`Dynamic import module ${name}`);
|
||||||
try {
|
try {
|
||||||
const nodeCache = require.cache[require.resolve(name)];
|
return await import(name);
|
||||||
if (nodeCache) {
|
// const require = getRequire();
|
||||||
console.log(`${name} is cached`);
|
// const nodeCache = require.cache[require.resolve(name)];
|
||||||
}
|
// if (nodeCache) {
|
||||||
return require(name);
|
// console.log(`${name} is cached`);
|
||||||
|
// }
|
||||||
|
// return require(name);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Failed to import module ${name}: ${e.message}`);
|
console.error(`Failed to import module ${name}: ${e.message}`);
|
||||||
throw `Failed to import module ${name}: ${e.message}`;
|
throw `Failed to import module ${name}: ${e.message}`;
|
||||||
|
@ -2,6 +2,11 @@ import { exec } from 'child_process';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
import { dirname } from 'path'
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = dirname(__filename)
|
||||||
|
|
||||||
export const directoryPath = path.resolve(__dirname);
|
export const directoryPath = path.resolve(__dirname);
|
||||||
const packagePath = path.resolve(directoryPath, 'package.json');
|
const packagePath = path.resolve(directoryPath, 'package.json');
|
||||||
const exists = (filePath: string) => {
|
const exists = (filePath: string) => {
|
||||||
|
@ -16,6 +16,7 @@ const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
|||||||
// -F "description=This is a test upload" \
|
// -F "description=This is a test upload" \
|
||||||
// -F "username=testuser"
|
// -F "username=testuser"
|
||||||
|
|
||||||
|
let clients = [];
|
||||||
export const uploadMiddleware = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
export const uploadMiddleware = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
if (req.method === 'GET' && req.url === '/api/app/upload') {
|
if (req.method === 'GET' && req.url === '/api/app/upload') {
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||||
@ -104,8 +105,19 @@ export const uploadMiddleware = async (req: http.IncomingMessage, res: http.Serv
|
|||||||
allowEmptyFiles: true, // 允许空
|
allowEmptyFiles: true, // 允许空
|
||||||
minFileSize: 0, // 最小文件大小
|
minFileSize: 0, // 最小文件大小
|
||||||
createDirsFromUploads: false, // 根据上传的文件夹结构创建目录
|
createDirsFromUploads: false, // 根据上传的文件夹结构创建目录
|
||||||
|
keepExtensions: true, // 保留文件
|
||||||
|
hashAlgorithm: 'md5', // 文件哈希算法
|
||||||
|
});
|
||||||
|
form.on('progress', (bytesReceived, bytesExpected) => {
|
||||||
|
const progress = (bytesReceived / bytesExpected) * 100;
|
||||||
|
console.log(`Upload progress: ${progress.toFixed(2)}%`);
|
||||||
|
const data = {
|
||||||
|
progress: progress.toFixed(2),
|
||||||
|
message: `Upload progress: ${progress.toFixed(2)}%`,
|
||||||
|
};
|
||||||
|
// 向所有连接的客户端推送进度信息
|
||||||
|
clients.forEach((client) => client.write(`${JSON.stringify(data)}\n`));
|
||||||
});
|
});
|
||||||
|
|
||||||
// 解析上传的文件
|
// 解析上传的文件
|
||||||
form.parse(req, async (err, fields, files) => {
|
form.parse(req, async (err, fields, files) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -192,4 +204,17 @@ export const uploadMiddleware = async (req: http.IncomingMessage, res: http.Serv
|
|||||||
res.end(JSON.stringify(data));
|
res.end(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (req.url === '/api/events') {
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'text/event-stream',
|
||||||
|
'Cache-Control': 'no-cache',
|
||||||
|
Connection: 'keep-alive',
|
||||||
|
});
|
||||||
|
clients.push(res);
|
||||||
|
|
||||||
|
// 移除客户端连接
|
||||||
|
req.on('close', () => {
|
||||||
|
clients = clients.filter((client) => client !== res);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,28 @@
|
|||||||
import * as glob from 'glob';
|
import path from 'path'
|
||||||
import * as path from 'path';
|
import * as glob from 'glob'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
import { dirname } from 'path'
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = dirname(__filename)
|
||||||
|
|
||||||
const files = glob.sync(path.resolve(__dirname, './apps/**/index.cjs'));
|
const files = glob.sync(path.resolve(__dirname, './apps/**/index.mjs'))
|
||||||
|
|
||||||
export const loadApps = async (app: any) => {
|
export const loadApps = async (app: any) => {
|
||||||
|
const directory = files.map((file: string) => {
|
||||||
|
const dirname = path.dirname(file)
|
||||||
|
const lastDirectory = path.basename(dirname)
|
||||||
|
return lastDirectory
|
||||||
|
})
|
||||||
|
console.log('directory', directory)
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const module = __non_webpack_require__(file);
|
try {
|
||||||
if (module.render) {
|
const module = await import(file)
|
||||||
module.render(app);
|
|
||||||
|
if (module.render) {
|
||||||
|
module.render(app)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { neode } from '@/app.ts';
|
import { neode } from '@/modules/neo4j.ts';
|
||||||
import { getSession } from '@/modules/neo4j.ts';
|
import { getSession } from '@/modules/neo4j.ts';
|
||||||
import Neode from 'neode';
|
import Neode from 'neode';
|
||||||
|
|
||||||
|
12
src/modules/bullmq.ts
Normal file
12
src/modules/bullmq.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import { useConfig } from '@abearxiong/use-config';
|
||||||
|
const config = useConfig();
|
||||||
|
|
||||||
|
export const connection = {
|
||||||
|
host: config.redis?.host || 'localhost',
|
||||||
|
port: config.redis?.port || 6379,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const quene = new Queue('test', {
|
||||||
|
connection: connection,
|
||||||
|
});
|
@ -4,7 +4,7 @@ import './page/index.ts';
|
|||||||
|
|
||||||
import './resource/index.ts';
|
import './resource/index.ts';
|
||||||
|
|
||||||
import './prompt-graph/index.ts';
|
// import './prompt-graph/index.ts';
|
||||||
|
|
||||||
import './agent/index.ts';
|
import './agent/index.ts';
|
||||||
|
|
||||||
|
13
typings.d.ts
vendored
13
typings.d.ts
vendored
@ -1,16 +1,3 @@
|
|||||||
type SimpleObject = {
|
type SimpleObject = {
|
||||||
[key: string | number]: any;
|
[key: string | number]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
declare module 'koa2-cors';
|
|
||||||
|
|
||||||
declare module 'cors-anywhere';
|
|
||||||
|
|
||||||
// mockjs http://mockjs.com/
|
|
||||||
declare module 'mockjs';
|
|
||||||
|
|
||||||
// type CTX: ParameterizedContext<any, DefaultContext & Router.IRouterParamContext<any, DefaultContext>>
|
|
||||||
|
|
||||||
// declare module 'jsonwebtoken';
|
|
||||||
|
|
||||||
// declare var global: NodeJS.Global & typeof globalThis;
|
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
const path = require('path');
|
|
||||||
const webpack = require('webpack');
|
|
||||||
// const nodeExternals = require('webpack-node-externals');
|
|
||||||
const pkgs = require('./package.json');
|
|
||||||
const CopyPlugin = require('copy-webpack-plugin');
|
|
||||||
/** 解决esmodule中noEmit报错问题 */
|
|
||||||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
||||||
|
|
||||||
const ENV = process.env.ENV;
|
|
||||||
|
|
||||||
const plugins = [new ForkTsCheckerWebpackPlugin()];
|
|
||||||
if (ENV === 'init') {
|
|
||||||
plugins.push(
|
|
||||||
new CopyPlugin({
|
|
||||||
patterns: [{ from: 'src/app.config.json5', to: 'app.config.json5' }],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @type {webpack.Configuration}
|
|
||||||
*/
|
|
||||||
module.exports = {
|
|
||||||
mode: 'production',
|
|
||||||
entry: path.join(__dirname, './src/index.ts'),
|
|
||||||
target: 'node',
|
|
||||||
output: {
|
|
||||||
path: path.join(__dirname, './dist'),
|
|
||||||
// filename: 'app.mjs',
|
|
||||||
filename: 'app.cjs',
|
|
||||||
},
|
|
||||||
|
|
||||||
optimization: {
|
|
||||||
minimize: true,
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.tsx?$/,
|
|
||||||
exclude: '/node_modules/',
|
|
||||||
use: {
|
|
||||||
loader: 'ts-loader',
|
|
||||||
options: {
|
|
||||||
allowTsInNodeModules: true,
|
|
||||||
transpileOnly: true, // 可选,加快构建速度
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 忽略特定警告
|
|
||||||
ignoreWarnings: [
|
|
||||||
{
|
|
||||||
message: /Critical dependency: the request of a dependency is an expression/,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: /[DEP0040] DeprecationWarning: The `punycode`/,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.ts', '.js'],
|
|
||||||
alias: {
|
|
||||||
'@': path.join(__dirname, './src'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
externals: {
|
|
||||||
sequelize: 'commonjs sequelize',
|
|
||||||
'socket.io': 'commonjs socket.io',
|
|
||||||
'@babel/preset-env': 'commonjs @babel/preset-env',
|
|
||||||
'@babel/preset-typescript': 'commonjs @babel/preset-typescript',
|
|
||||||
},
|
|
||||||
plugins: [...plugins],
|
|
||||||
node: {},
|
|
||||||
stats: {
|
|
||||||
errorDetails: true,
|
|
||||||
all: false,
|
|
||||||
errors: true,
|
|
||||||
warnings: false,
|
|
||||||
},
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user