feat: 修改为bun,优化代码
This commit is contained in:
parent
3de5754f24
commit
1f4404fa5c
37
bun.config.mjs
Normal file
37
bun.config.mjs
Normal file
@ -0,0 +1,37 @@
|
||||
// @ts-check
|
||||
import { resolvePath } from '@kevisual/use-config/env';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
const entry = 'src/index.ts';
|
||||
const naming = 'app';
|
||||
const external = ['sequelize', 'pg', 'sqlite3', '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_*',
|
||||
});
|
||||
|
||||
// const cmd = `dts -i src/index.ts -o app.d.ts`;
|
||||
// const cmd = `dts -i ${entry} -o ${naming}.d.ts`;
|
||||
// execSync(cmd, { stdio: 'inherit' });
|
||||
|
||||
await Bun.build({
|
||||
target: 'node',
|
||||
format: 'esm',
|
||||
entrypoints: [resolvePath('./src/run.ts', { meta: import.meta })],
|
||||
outdir: resolvePath('./dist', { meta: import.meta }),
|
||||
naming: {
|
||||
entry: `${'run'}.js`,
|
||||
},
|
||||
external,
|
||||
env: 'KEVISUAL_*',
|
||||
});
|
@ -1,22 +1,26 @@
|
||||
{
|
||||
"name": "codecenter",
|
||||
"version": "1.0.0",
|
||||
"author": "abearxiong",
|
||||
"basename": "/root/code-center",
|
||||
"app": {
|
||||
"type": "pm2-system-app",
|
||||
"key": "code-center",
|
||||
"entry": "./dist/app.mjs"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "pm2 start dist/app.mjs --name codecenter"
|
||||
"start": "pm2 start apps/code-center/dist/app.mjs --name code-center"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kevisual/router": "^0.0.10-beta.1",
|
||||
"@kevisual/use-config": "^1.0.10",
|
||||
"ioredis": "^5.6.0",
|
||||
"@kevisual/router": "^0.0.20",
|
||||
"@kevisual/use-config": "^1.0.17",
|
||||
"ioredis": "^5.6.1",
|
||||
"minio": "^8.0.5",
|
||||
"pg": "^8.14.1",
|
||||
"sequelize": "^6.37.6",
|
||||
"pg": "^8.16.0",
|
||||
"sequelize": "^6.37.7",
|
||||
"sqlite3": "^5.1.7",
|
||||
"socket.io": "^4.8.1",
|
||||
"@msgpack/msgpack": "3.1.1",
|
||||
"pino": "^9.6.0",
|
||||
"pino-pretty": "^13.0.0",
|
||||
"pm2": "^6.0.5",
|
||||
"dotenv": "^16.4.7"
|
||||
"pm2": "^6.0.6",
|
||||
"dotenv": "^16.5.0"
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const currentPath = process.cwd();
|
||||
const packagePath = path.join(currentPath, 'script/package/package.json');
|
||||
|
||||
fs.writeFileSync(
|
||||
packagePath,
|
||||
JSON.stringify(
|
||||
{
|
||||
name: 'codecenter',
|
||||
version: '1.0.0',
|
||||
scripts: {
|
||||
start: 'pm2 start dist/app.mjs --name codecenter',
|
||||
},
|
||||
dependencies: {
|
||||
'@kevisual/router': '^0.0.6-alpha-5',
|
||||
'@kevisual/use-config': '^1.0.7',
|
||||
ioredis: '^5.5.0',
|
||||
minio: '^8.0.4',
|
||||
pg: '^8.13.3',
|
||||
sequelize: '^6.37.5',
|
||||
sqlite3: '^5.1.7',
|
||||
'socket.io': '^4.8.1',
|
||||
'@msgpack/msgpack': '3.0.1',
|
||||
pino: '^9.6.0',
|
||||
'pino-pretty': '^13.0.0',
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
'utf-8',
|
||||
);
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "codecenter",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"start": "pm2 start dist/app.mjs --name codecenter"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kevisual/router": "^0.0.6-alpha-5",
|
||||
"@kevisual/use-config": "^1.0.7",
|
||||
"ioredis": "^5.5.0",
|
||||
"minio": "^8.0.4",
|
||||
"pg": "^8.13.3",
|
||||
"sequelize": "^6.37.5",
|
||||
"sqlite3": "^5.1.7",
|
||||
"socket.io": "^4.8.1",
|
||||
"@msgpack/msgpack": "3.0.1",
|
||||
"pino": "^9.6.0",
|
||||
"pino-pretty": "^13.0.0"
|
||||
}
|
||||
}
|
27
dockerfile
27
dockerfile
@ -1,27 +0,0 @@
|
||||
# 使用官方 Node.js 运行时镜像作为基础镜像
|
||||
FROM node:22-alpine
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
COPY script/package/package.json ./
|
||||
# 复制 package.json 和 package-lock.json
|
||||
# COPY package*.json ./
|
||||
|
||||
# 复制 dist 文件夹
|
||||
COPY dist ./dist
|
||||
COPY app.config.json5 ./app.config.json5
|
||||
COPY .npmrc .
|
||||
|
||||
# 安装依赖
|
||||
RUN npm install --production --registry=https://registry.npmmirror.com/
|
||||
|
||||
# 如果有其他静态资源文件夹,也可以一并复制
|
||||
# COPY public ./public
|
||||
|
||||
# 暴露应用运行的端口(假设应用运行在 3000 端口)
|
||||
EXPOSE 4000
|
||||
|
||||
# 启动应用
|
||||
CMD ["node", "dist/app.cjs"]
|
||||
# CMD ["tail", "-f", "/dev/null"]
|
@ -1,18 +0,0 @@
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'codecenter', // 应用名称
|
||||
script: './dist/app.mjs', // 入口文件
|
||||
// cwd: '.', // 设置当前工作目录
|
||||
output: './logs/codflow.log',
|
||||
error: './logs/codflow.log',
|
||||
log_date_format: 'YYYY-MM-DD HH:mm:ss',
|
||||
// watch: true, // 自动监控文件变化
|
||||
watch: ['dist'], // 监控的文件夹
|
||||
ignore_watch: ['node_modules', 'logs'], // 忽略的文件夹
|
||||
env: {
|
||||
NODE_ENV: 'development'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
98
package.json
98
package.json
@ -1,20 +1,28 @@
|
||||
{
|
||||
"name": "@kevisual/code-center",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"description": "code center",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"author": "abearxiong",
|
||||
"basename": "/root/code-center",
|
||||
"app": {
|
||||
"type": "pm2-system-app",
|
||||
"key": "code-center",
|
||||
"entry": "./dist/app.js",
|
||||
"runtime": [
|
||||
"client"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "rollup -c rollup.config.mjs -w",
|
||||
"dev": "cross-env NODE_ENV=development nodemon --delay 2.5 -e js,cjs,mjs --exec node dist/app.mjs",
|
||||
"test": "tsx test/**/*.ts",
|
||||
"dev:watch": "cross-env NODE_ENV=development concurrently -n \"Watch,Dev\" -c \"green,blue\" \"npm run watch\" \"sleep 1 && npm run dev\" ",
|
||||
"build": "rimraf dist && rollup -c rollup.config.mjs",
|
||||
"deploy": "rsync -avz --delete ./dist/ --exclude='app.config.json5' light:~/apps/codecenter/dist",
|
||||
"deploy:sky": "rsync -avz --delete ./dist/ --exclude='app.config.json5' sky:~/kevisual/dist",
|
||||
"deploy:envision": "rsync -avz --delete ./dist/ --exclude='app.config.json5' envision:~/kevisual/dist",
|
||||
"dev": "bun run --watch --hot --inspect src/index.ts",
|
||||
"cmd": "bun run src/run.ts ",
|
||||
"prebuild": "rimraf dist",
|
||||
"build": "NODE_ENV=production bun bun.config.mjs",
|
||||
"deploy": "rsync -avz --delete ./dist/ light:~/apps/codecenter/dist",
|
||||
"deploy:sky": "rsync -avz --delete ./dist/ sky:~/kevisual/dist",
|
||||
"deploy:envision": "rsync -avz --delete ./dist/ envision:~/kevisual/dist",
|
||||
"clean": "rm -rf dist",
|
||||
"reload": "ssh light pm2 restart codecenter",
|
||||
"reload:sky": "ssh sky pm2 restart codecenter",
|
||||
@ -22,11 +30,9 @@
|
||||
"pub:me": "npm run build && npm run deploy && npm run reload",
|
||||
"pub:sky": "npm run build && npm run deploy:sky && npm run reload:sky",
|
||||
"pub:envision": "npm run build && npm run deploy:envision && npm run reload:envision",
|
||||
"start": "pm2 start dist/app.mjs --name codecenter",
|
||||
"release": "node ./config/release/index.mjs",
|
||||
"pub": "envision pack -p -u",
|
||||
"ssh": "ssh -L 6379:localhost:6379 -L 5432:localhost:5432 -L 9000:localhost:9000 light ",
|
||||
"ssh:sky": "ssh -L 6379:172.21.32.13:6379 sky",
|
||||
"start": "pm2 start dist/app.js --name code-center",
|
||||
"client:start": "pm2 start apps/code-center/dist/app.js --name code-center",
|
||||
"pub": "envision pack -p -u -c",
|
||||
"dev:lib": "turbo run dev:lib",
|
||||
"build:lib": "turbo run build",
|
||||
"dev:oss": "turbo run dev:lib --filter=@kevisual/oss"
|
||||
@ -38,40 +44,23 @@
|
||||
],
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@kevisual/local-app-manager": "0.1.17",
|
||||
"@kevisual/logger": "^0.0.1",
|
||||
"@kevisual/router": "0.0.13",
|
||||
"@kevisual/use-config": "^1.0.15",
|
||||
"@types/semver": "^7.7.0",
|
||||
"archiver": "^7.0.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"dayjs": "^1.11.13",
|
||||
"dotenv": "^16.5.0",
|
||||
"formidable": "3.5.4",
|
||||
"commander": "^14.0.0",
|
||||
"ioredis": "^5.6.1",
|
||||
"json5": "^2.2.3",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash-es": "^4.17.21",
|
||||
"minio": "^8.0.5",
|
||||
"nanoid": "^5.1.5",
|
||||
"node-fetch": "^3.3.2",
|
||||
"p-queue": "^8.1.0",
|
||||
"pg": "^8.15.6",
|
||||
"pm2": "^6.0.5",
|
||||
"rollup-plugin-esbuild": "^6.2.1",
|
||||
"semver": "^7.7.1",
|
||||
"pg": "^8.16.0",
|
||||
"pm2": "^6.0.6",
|
||||
"sequelize": "^6.37.7",
|
||||
"socket.io": "^4.8.1",
|
||||
"strip-ansi": "^7.1.0",
|
||||
"tar": "^7.4.3",
|
||||
"uuid": "^11.1.0",
|
||||
"zod": "^3.24.4"
|
||||
"sqlite3": "^5.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kevisual/code-center-module": "workspace:*",
|
||||
"@kevisual/local-app-manager": "0.1.19",
|
||||
"@kevisual/logger": "^0.0.3",
|
||||
"@kevisual/oss": "workspace:*",
|
||||
"@kevisual/permission": "workspace:*",
|
||||
"@kevisual/router": "0.0.20",
|
||||
"@kevisual/types": "^0.0.10",
|
||||
"@kevisual/use-config": "^1.0.17",
|
||||
"@rollup/plugin-alias": "^5.1.1",
|
||||
"@rollup/plugin-commonjs": "^28.0.3",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
@ -83,20 +72,43 @@
|
||||
"@types/formidable": "^3.4.5",
|
||||
"@types/jsonwebtoken": "^9.0.9",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^22.15.17",
|
||||
"@types/react": "^19.1.3",
|
||||
"@types/node": "^22.15.19",
|
||||
"@types/react": "^19.1.4",
|
||||
"@types/semver": "^7.7.0",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"archiver": "^7.0.1",
|
||||
"concurrently": "^9.1.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"crypto-js": "^4.2.0",
|
||||
"dayjs": "^1.11.13",
|
||||
"dotenv": "^16.5.0",
|
||||
"formidable": "3.5.4",
|
||||
"ioredis": "^5.6.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash-es": "^4.17.21",
|
||||
"minio": "^8.0.5",
|
||||
"nanoid": "^5.1.5",
|
||||
"node-fetch": "^3.3.2",
|
||||
"nodemon": "^3.1.10",
|
||||
"p-queue": "^8.1.0",
|
||||
"pg": "^8.16.0",
|
||||
"pm2": "^6.0.6",
|
||||
"rimraf": "^6.0.1",
|
||||
"rollup": "^4.40.2",
|
||||
"rollup": "^4.41.0",
|
||||
"rollup-plugin-copy": "^3.5.0",
|
||||
"rollup-plugin-dts": "^6.2.1",
|
||||
"rollup-plugin-esbuild": "^6.2.1",
|
||||
"semver": "^7.7.2",
|
||||
"sequelize": "^6.37.7",
|
||||
"socket.io": "^4.8.1",
|
||||
"strip-ansi": "^7.1.0",
|
||||
"tape": "^5.9.0",
|
||||
"tar": "^7.4.3",
|
||||
"tsx": "^4.19.4",
|
||||
"turbo": "^2.5.3",
|
||||
"typescript": "^5.8.3"
|
||||
"typescript": "^5.8.3",
|
||||
"uuid": "^11.1.0",
|
||||
"zod": "^3.25.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"inflight": "latest",
|
||||
@ -104,5 +116,5 @@
|
||||
"picomatch": "^4.0.2"
|
||||
},
|
||||
"pnpm": {},
|
||||
"packageManager": "pnpm@10.10.0"
|
||||
"packageManager": "pnpm@10.11.0"
|
||||
}
|
1091
pnpm-lock.yaml
generated
1091
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,84 +0,0 @@
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import json from '@rollup/plugin-json';
|
||||
import * as glob from 'fast-glob';
|
||||
import path from 'path';
|
||||
import esbuild from 'rollup-plugin-esbuild';
|
||||
import alias from '@rollup/plugin-alias';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import pkgs from './package.json' with { type: 'json' };
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const version = pkgs.version|| '1.0.0';
|
||||
/**
|
||||
* @type {import('rollup').RollupOptions}
|
||||
*/
|
||||
const config = {
|
||||
input: './src/index.ts',
|
||||
output: {
|
||||
dir: './dist',
|
||||
entryFileNames: 'app.mjs',
|
||||
chunkFileNames: '[name]-[hash].mjs',
|
||||
format: 'esm',
|
||||
},
|
||||
plugins: [
|
||||
replace({
|
||||
preventAssignment: true, // 防止意外赋值
|
||||
DEV_SERVER: JSON.stringify(isDev), // 替换 process.env.NODE_ENV
|
||||
VERSION: JSON.stringify(version), // 替换版本号
|
||||
}),
|
||||
alias({
|
||||
// only esbuild needs to be configured
|
||||
entries: [
|
||||
{ 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' },
|
||||
],
|
||||
}),
|
||||
resolve({
|
||||
preferBuiltins: true, // 强制优先使用内置模块
|
||||
}),
|
||||
commonjs(),
|
||||
esbuild({
|
||||
target: 'node22', // 目标为 Node.js 14
|
||||
minify: false, // 启用代码压缩
|
||||
tsconfig: 'tsconfig.json',
|
||||
}),
|
||||
json(),
|
||||
],
|
||||
external: [
|
||||
/@kevisual\/router(\/.*)?/, //, // 路由
|
||||
/@kevisual\/use-config(\/.*)?/, //
|
||||
|
||||
'sequelize', // 数据库 orm
|
||||
'ioredis', // redis
|
||||
'socket.io', // socket.io
|
||||
'minio', // minio
|
||||
|
||||
'pm2',
|
||||
|
||||
'pg', // pg
|
||||
'pino', // pino
|
||||
'pino-pretty', // pino-pretty
|
||||
'@msgpack/msgpack', // msgpack
|
||||
],
|
||||
};
|
||||
export default config;
|
@ -3,3 +3,5 @@
|
||||
pnpm i -g npm-check-updates
|
||||
ncu -u
|
||||
pnpm install
|
||||
|
||||
# /home/ubuntu/.nvm/versions/node/v22.14.0/bin/ncu -u
|
@ -2,10 +2,11 @@ import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
// import { useConfig } from '@kevisual/use-config/env';
|
||||
|
||||
const envFiles = [
|
||||
export const envFiles = [
|
||||
path.resolve(process.cwd(), process.env.NODE_ENV === 'development' ? '.env.dev' : '.env'),
|
||||
// path.resolve(process.cwd(), '.env'), //
|
||||
];
|
||||
console.log('envFiles', envFiles);
|
||||
export const config = dotenv.config({
|
||||
path: envFiles,
|
||||
override: true,
|
||||
|
@ -1,18 +1,29 @@
|
||||
import { Redis } from 'ioredis';
|
||||
|
||||
import { config } from './config.ts';
|
||||
const redisConfig = {
|
||||
host: config.REDIS_HOST || 'localhost',
|
||||
port: parseInt(config.REDIS_PORT || '6379'),
|
||||
password: config.REDIS_PASSWORD,
|
||||
};
|
||||
export const createRedisClient = (options = {}) => {
|
||||
const redisClient = new Redis({
|
||||
host: 'localhost', // Redis 服务器的主机名或 IP 地址
|
||||
port: 6379, // Redis 服务器的端口号
|
||||
// password: 'your_password', // Redis 的密码 (如果有)
|
||||
db: 0, // 要使用的 Redis 数据库索引 (0-15)
|
||||
keyPrefix: '', // key 前缀
|
||||
retryStrategy(times) {
|
||||
// 连接重试策略
|
||||
return Math.min(times * 50, 2000); // 每次重试时延迟增加
|
||||
},
|
||||
maxRetriesPerRequest: null, // 允许请求重试的次数 (如果需要无限次重试)
|
||||
...redisConfig,
|
||||
...options,
|
||||
});
|
||||
return redisClient;
|
||||
};
|
||||
// 配置 Redis 连接
|
||||
export const redis = new Redis({
|
||||
host: 'localhost', // Redis 服务器的主机名或 IP 地址
|
||||
port: 6379, // Redis 服务器的端口号
|
||||
// password: 'your_password', // Redis 的密码 (如果有)
|
||||
db: 0, // 要使用的 Redis 数据库索引 (0-15)
|
||||
keyPrefix: '', // key 前缀
|
||||
retryStrategy(times) {
|
||||
// 连接重试策略
|
||||
return Math.min(times * 50, 2000); // 每次重试时延迟增加
|
||||
},
|
||||
maxRetriesPerRequest: null, // 允许请求重试的次数 (如果需要无限次重试)
|
||||
});
|
||||
export const redis = createRedisClient();
|
||||
|
||||
// 监听连接事件
|
||||
redis.on('connect', () => {
|
||||
@ -24,5 +35,5 @@ redis.on('error', (err) => {
|
||||
});
|
||||
|
||||
// 初始化 Redis 客户端
|
||||
export const redisPublisher = new Redis(); // 用于发布消息
|
||||
export const redisSubscriber = new Redis(); // 用于订阅消息
|
||||
export const redisPublisher = createRedisClient(); // 用于发布消息
|
||||
export const redisSubscriber = createRedisClient(); // 用于订阅消息
|
||||
|
@ -11,7 +11,8 @@ export type PostgresConfig = {
|
||||
};
|
||||
};
|
||||
if (!config.POSTGRES_PASSWORD || !config.POSTGRES_USER) {
|
||||
console.error('postgres config is required password and user');
|
||||
log.error('postgres config is required password and user');
|
||||
log.error('config', config);
|
||||
process.exit(1);
|
||||
}
|
||||
const postgresConfig = {
|
||||
|
16
src/program.ts
Normal file
16
src/program.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { program, Command } from 'commander';
|
||||
// import { useContextKey } from '@kevisual/use-config/context';
|
||||
// import * as redisLib from './modules/redis.ts';
|
||||
// import * as sequelizeLib from './modules/sequelize.ts';
|
||||
// import * as minioLib from './modules/minio.ts';
|
||||
|
||||
// export const redis = useContextKey('redis', () => redisLib.redis);
|
||||
// export const redisPublisher = useContextKey('redisPublisher', () => redisLib.redisPublisher);
|
||||
// export const redisSubscriber = useContextKey('redisSubscriber', () => redisLib.redisSubscriber);
|
||||
// export const minioClient = useContextKey('minioClient', () => minioLib.minioClient);
|
||||
// export const sequelize = useContextKey('sequelize', () => sequelizeLib.sequelize);
|
||||
|
||||
export { program, Command };
|
||||
|
||||
program.description('code-center的一部分工具');
|
||||
program.version('1.0.0', '-v, --version');
|
@ -16,7 +16,7 @@ export { manager };
|
||||
// console.log('app', app, );
|
||||
// console.log('app2 context', global.context);
|
||||
// console.log('app equal', app === ManagerApp);
|
||||
loadManager();
|
||||
loadManager({ runtime: 'server' });
|
||||
|
||||
// middleware: ['auth-admin']
|
||||
/*
|
||||
|
@ -3,8 +3,8 @@ import { PageModel } from '../models/index.ts';
|
||||
import { ContainerModel } from '@/routes/container/models/index.ts';
|
||||
import { Op } from 'sequelize';
|
||||
import { getContainerData } from './get-container.ts';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import { getHTML, getDataJs, getOneHTML } from './file-template.ts';
|
||||
import { minioClient } from '@/app.ts';
|
||||
import { bucketName } from '@/modules/minio.ts';
|
||||
@ -174,7 +174,7 @@ export const getZip = async (page: PageModel, opts: { tokenUser: any }) => {
|
||||
|
||||
// 添加 JavaScript 字符串作为文件到 zip 中
|
||||
zip.append(dataJs, { name: 'data.js' });
|
||||
zip.append(JSON.stringify(page), { name: 'app.config.json5' });
|
||||
zip.append(JSON.stringify(page), { name: 'app.config.json' });
|
||||
// 可以继续添加更多内容,文件或目录等
|
||||
// zip.append('Another content', { name: 'other.txt' });
|
||||
|
||||
|
9
src/run.ts
Normal file
9
src/run.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { program } from './program.ts';
|
||||
|
||||
//
|
||||
import './scripts/change-user-pwd.ts';
|
||||
import './scripts/list-app.ts';
|
||||
|
||||
//
|
||||
|
||||
program.parse(process.argv);
|
50
src/scripts/change-user-pwd.ts
Normal file
50
src/scripts/change-user-pwd.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { program, Command } from '../program.ts';
|
||||
import { initUser, logger, close } from './common.ts';
|
||||
const usrCommand = new Command('user').description('用户相关操作');
|
||||
program.addCommand(usrCommand);
|
||||
|
||||
const changePwd = new Command('pwd')
|
||||
.description('修改用户密码')
|
||||
.option('-u, --username <username>', '用户名')
|
||||
.option('-p, --password <password>', '新密码')
|
||||
.action(async (opts) => {
|
||||
const username = opts.username;
|
||||
const password = opts.password;
|
||||
if (!username) {
|
||||
logger.error('用户名不能为空');
|
||||
close();
|
||||
return;
|
||||
}
|
||||
const { User } = await initUser();
|
||||
const newPassword = password || 'kevisual';
|
||||
|
||||
logger.info(`用户名: ${username}`);
|
||||
logger.info(`新密码: ${newPassword}`);
|
||||
const user = await User.findOne({ where: { username: username }, logging: false });
|
||||
if (!user) {
|
||||
logger.error('用户不存在');
|
||||
return;
|
||||
}
|
||||
const newP = await user.createPassword(newPassword);
|
||||
logger.info('新密码加密成功', '新密码: ', newPassword);
|
||||
close();
|
||||
});
|
||||
usrCommand.addCommand(changePwd);
|
||||
|
||||
const list = new Command('list').description('列出所有用户').action(async () => {
|
||||
console.log('列出所有用户 start');
|
||||
const { User } = await initUser();
|
||||
console.log('列出所有用户');
|
||||
const users = await User.findAll({ limit: 10, order: [['createdAt', 'DESC']] });
|
||||
if (users.length === 0) {
|
||||
logger.info('没有用户');
|
||||
return;
|
||||
}
|
||||
users.forEach((user) => {
|
||||
console.log(`用户名: ${user.username}`);
|
||||
});
|
||||
console.log(`用户数量: ${users.length}`);
|
||||
await close();
|
||||
});
|
||||
|
||||
usrCommand.addCommand(list);
|
29
src/scripts/common.ts
Normal file
29
src/scripts/common.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { config } from '../modules/config.ts';
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
export { program, Command } from '../program.ts';
|
||||
import { User, UserInit, OrgInit, Org } from '@kevisual/code-center-module/models';
|
||||
import { Logger } from '@kevisual/logger';
|
||||
export const close = async () => {
|
||||
process.exit(0);
|
||||
};
|
||||
export { sequelize };
|
||||
export const logger = new Logger({
|
||||
level: (config?.LOG_LEVEL || 'info') as any,
|
||||
showTime: true,
|
||||
});
|
||||
|
||||
export const initUser = async () => {
|
||||
console.log('init user');
|
||||
await UserInit(sequelize, undefined, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
await OrgInit(sequelize, undefined, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
return {
|
||||
User: User,
|
||||
Org: Org,
|
||||
};
|
||||
};
|
12
src/scripts/list-app.ts
Normal file
12
src/scripts/list-app.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { AppListModel, AppModel } from '../routes/app-manager/module/index.ts';
|
||||
|
||||
import { program, Command, close } from './common.ts';
|
||||
|
||||
const app = program.command('app');
|
||||
|
||||
const appList = new Command('list').action(async () => {
|
||||
const list = await AppListModel.findAll();
|
||||
console.log(list.map((item) => item.toJSON()));
|
||||
close();
|
||||
});
|
||||
app.addCommand(appList);
|
@ -26,7 +26,7 @@ export const main = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// main();
|
||||
main();
|
||||
export const changeRootPassword = async () => {
|
||||
await OrgInit(sequelize, null, {
|
||||
alter: true,
|
||||
@ -38,11 +38,11 @@ export const changeRootPassword = async () => {
|
||||
});
|
||||
const user = await User.findOne({ where: { username: 'root' } });
|
||||
if (user) {
|
||||
await user.createPassword('Abear123456x');
|
||||
await user.createPassword('');
|
||||
await user.save();
|
||||
console.log('change root password done');
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
changeRootPassword();
|
||||
// changeRootPassword();
|
@ -1 +1 @@
|
||||
Subproject commit 460f80657c8b8adc93dd34f41c3eec1704f86c46
|
||||
Subproject commit 2a53b82fde2d39c846d831d579ce50dafc491b79
|
@ -1,40 +1,17 @@
|
||||
{
|
||||
"extends": "@kevisual/types/json/backend.json",
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"target": "esnext",
|
||||
"noImplicitAny": false,
|
||||
"outDir": "./dist",
|
||||
"sourceMap": false,
|
||||
"allowJs": true,
|
||||
"newLine": "LF",
|
||||
"baseUrl": "./",
|
||||
"baseUrl": ".",
|
||||
"typeRoots": [
|
||||
"node_modules/@types",
|
||||
"//node_modules/@kevisual/types"
|
||||
"./node_modules/@types"
|
||||
],
|
||||
"declaration": true,
|
||||
"noEmit": false,
|
||||
"allowImportingTsExtensions": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"moduleResolution": "NodeNext",
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"esModuleInterop": true,
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
"include": [
|
||||
"typings.d.ts",
|
||||
"src/**/*.ts",
|
||||
"test/**/*.ts",
|
||||
"src-apps/**/*.ts",
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"src/**/*.test.ts"
|
||||
"src/**/*",
|
||||
],
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user