清理代码

This commit is contained in:
2025-11-27 17:38:42 +08:00
parent 5dc4dcfb58
commit 7cba8ae8b1
10 changed files with 34 additions and 1372 deletions

View File

@@ -1,35 +0,0 @@
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export const directoryPath = path.resolve(__dirname);
export const defaultImportModules = [
{
name: 'sequelize',
version: '^6.6.5',
},
{
name: 'pg',
version: '^8.12.1',
},
];
export const dynamicImport = async (name: string) => {
// const nodeModules = path.resolve(directoryPath, 'node_modules');
// const nodeName = path.resolve(nodeModules, name);
console.log(`Dynamic import module ${name}`);
try {
return await import(name);
// const require = getRequire();
// const nodeCache = require.cache[require.resolve(name)];
// if (nodeCache) {
// console.log(`${name} is cached`);
// }
// return require(name);
} catch (e) {
console.error(`Failed to import module ${name}: ${e.message}`);
throw `Failed to import module ${name}: ${e.message}`;
}
};

View File

View File

@@ -1,51 +0,0 @@
import { exec } from 'child_process';
import path from 'path';
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);
const packagePath = path.resolve(directoryPath, 'package.json');
const exists = (filePath: string) => {
try {
fs.accessSync(filePath);
return true;
} catch (e) {
return false;
}
};
export const installPackage = async (packageName: string) => {
if (!exists(packagePath)) {
fs.writeFileSync(packagePath, JSON.stringify({ name: 'npm-install', version: '1.0.0' }), 'utf-8');
}
return await new Promise((resolve, reject) => {
console.log(`Starting installation of ${packageName}...`);
// 在程序运行路径下执行 npm install 命令
console.log(`npm install ${packageName}`);
exec(`npm install ${packageName}`, { cwd: directoryPath }, (error, stdout, stderr) => {
if (error) {
console.error(`Error installing package: ${stderr}`);
reject(new Error(`Failed to install package ${packageName}`));
} else {
console.log(`Package ${packageName} installed successfully: ${stdout}`);
resolve(stdout);
}
});
});
};
export const getPackage = async () => {
if (!exists(packagePath)) {
return {};
}
try {
return JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
} catch (e) {
console.error('Failed to read package.json');
return {};
}
};

View File

@@ -1,5 +1,4 @@
import fetch from 'node-fetch';
import { useConfig } from '@kevisual/use-config/env';
import { useConfig } from '@kevisual/use-config';
type GithubConfig = {
clientId: string;

View File

@@ -9,11 +9,7 @@ export const existDenpend = [
'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 };

View File

@@ -1,7 +1,7 @@
import { CustomError } from '@kevisual/router';
import { app } from '../../app.ts';
import { PageModel } from './models/index.ts';
import { v4 as uuidv4 } from 'uuid';
import { nanoid, customAlphabet } from 'nanoid'
import { ContainerModel } from '../container/models/index.ts';
import { Op } from 'sequelize';
import { getDeck } from './module/cache-file.ts';
@@ -12,6 +12,11 @@ export const clearBlank = (newStyle: any) => {
}
}
};
const uuidv4 = () => {
const alphabet = '0123456789abcdef';
const nanoidCustom = customAlphabet(alphabet, 36);
return nanoidCustom();
}
app
.route({
path: 'page',

View File

@@ -1,9 +1,6 @@
import { CustomError } from '@kevisual/router';
import { app } from '../../app.ts';
import { PageModel } from './models/index.ts';
import { v4 as uuidv4 } from 'uuid';
import { ContainerModel } from '../container/models/index.ts';
import { Op } from 'sequelize';
import { AppListModel, AppModel } from '../app-manager/index.ts';
import { cachePage, getZip } from './module/cache-file.ts';
import { uniqBy } from 'lodash-es';