add external export
This commit is contained in:
parent
a1344b9220
commit
1f380478ba
@ -1,11 +1,8 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
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 { 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 'fast-glob';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import esbuild from 'rollup-plugin-esbuild';
|
import esbuild from 'rollup-plugin-esbuild';
|
||||||
import alias from '@rollup/plugin-alias';
|
import alias from '@rollup/plugin-alias';
|
||||||
@ -19,7 +16,6 @@ const isDev = process.env.NODE_ENV === 'development';
|
|||||||
*/
|
*/
|
||||||
const config = {
|
const config = {
|
||||||
input: './src/index.ts',
|
input: './src/index.ts',
|
||||||
// input: './src/micro-client.ts',
|
|
||||||
output: {
|
output: {
|
||||||
dir: './dist',
|
dir: './dist',
|
||||||
entryFileNames: 'app.mjs',
|
entryFileNames: 'app.mjs',
|
||||||
@ -114,5 +110,50 @@ const configs = [
|
|||||||
'@msgpack/msgpack',
|
'@msgpack/msgpack',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: './src/scripts/init-data.ts',
|
||||||
|
output: {
|
||||||
|
file: './dist/init-data.d.ts',
|
||||||
|
},
|
||||||
|
plugins: [dts()],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: './src/index.ts',
|
||||||
|
output: {
|
||||||
|
file: './dist/app.d.ts',
|
||||||
|
},
|
||||||
|
plugins: [dts()],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
export default [...configs, config];
|
const external = [
|
||||||
|
{
|
||||||
|
input: './src/shared/external.ts',
|
||||||
|
output: {
|
||||||
|
file: './dist/external.mjs',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
alias({
|
||||||
|
// only esbuild needs to be configured
|
||||||
|
entries: [
|
||||||
|
{ find: '@', replacement: path.resolve('src') }, // 配置 @ 为 src 目录
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
resolve(),
|
||||||
|
commonjs(),
|
||||||
|
esbuild({
|
||||||
|
target: 'node22',
|
||||||
|
minify: false,
|
||||||
|
tsconfig: 'tsconfig.json',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: './src/shared/external.ts',
|
||||||
|
output: {
|
||||||
|
file: './dist/external.d.ts',
|
||||||
|
},
|
||||||
|
plugins: [dts()],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default [...configs, config, ...external];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { spawn } from 'child_process';
|
import { spawn, ChildProcess } from 'child_process';
|
||||||
import { DevData, DevModel } from '../route/dev/model.ts';
|
import { DevData, DevModel } from '../route/dev/model.ts';
|
||||||
import { fileIsExist } from '@kevisual/use-config';
|
import { fileIsExist } from '@kevisual/use-config';
|
||||||
import { transformToMJS } from './build/convert.ts';
|
import { transformToMJS } from './build/convert.ts';
|
||||||
@ -156,4 +156,25 @@ export class DevManater {
|
|||||||
async getList() {
|
async getList() {
|
||||||
return this.devList;
|
return this.devList;
|
||||||
}
|
}
|
||||||
|
async runScript(loadScript: string, dev: DevModel) {
|
||||||
|
const data = dev.data;
|
||||||
|
const { cwd } = data;
|
||||||
|
const childProcess = spawn(loadScript, [], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
shell: true,
|
||||||
|
cwd: cwd,
|
||||||
|
detached: true,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
...data.env,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return childProcess;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const runScript = (dev: DevModel) => {
|
||||||
|
const data = dev.data;
|
||||||
|
const { type, code } = data;
|
||||||
|
//
|
||||||
|
};
|
||||||
|
@ -103,3 +103,5 @@ app
|
|||||||
ctx.body = 'ok';
|
ctx.body = 'ok';
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ export type DevData = {
|
|||||||
codeStatus?: 'success' | 'error'; // 转换状态
|
codeStatus?: 'success' | 'error'; // 转换状态
|
||||||
status: 'active' | 'inactive'; // 状态, 是否生成codePath
|
status: 'active' | 'inactive'; // 状态, 是否生成codePath
|
||||||
path?: string; // esbuild 打包路径,用于 node 启动, vite 配置 esbuild 配置,rollup配置路径等
|
path?: string; // esbuild 打包路径,用于 node 启动, vite 配置 esbuild 配置,rollup配置路径等
|
||||||
|
scripts?: {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
export type Dev = Partial<InstanceType<typeof DevModel>>;
|
export type Dev = Partial<InstanceType<typeof DevModel>>;
|
||||||
|
|
||||||
|
@ -113,3 +113,35 @@ app
|
|||||||
ctx.body = dev;
|
ctx.body = dev;
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
|
|
||||||
|
app
|
||||||
|
.route({
|
||||||
|
path: 'dev-app',
|
||||||
|
key: 'runScript',
|
||||||
|
})
|
||||||
|
.define(async (ctx) => {
|
||||||
|
const id = ctx.query.id;
|
||||||
|
const script = ctx.query.script;
|
||||||
|
if (!id) {
|
||||||
|
ctx.throw(400, 'id is required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!script) {
|
||||||
|
ctx.throw(400, 'script is required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const dev = await DevModel.findByPk(id);
|
||||||
|
if (!dev) {
|
||||||
|
ctx.throw(404, 'dev not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const scripts = dev.data.scripts || {};
|
||||||
|
const loadScript = scripts[script];
|
||||||
|
if (!loadScript) {
|
||||||
|
ctx.throw(404, 'script not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await devManager.runScript(loadScript, dev);
|
||||||
|
ctx.body = result;
|
||||||
|
})
|
||||||
|
.addTo(app);
|
||||||
|
14
src/shared/external.ts
Normal file
14
src/shared/external.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export const nodeExternals = [
|
||||||
|
/@kevisual\/router(\/.*)?/, //, // 路由
|
||||||
|
/@kevisual\/use-config(\/.*)?/, //
|
||||||
|
|
||||||
|
'sequelize', // 数据库 orm
|
||||||
|
'ioredis', // redis
|
||||||
|
'socket.io', // socket.io
|
||||||
|
'minio', // minio
|
||||||
|
|
||||||
|
'pg', // pg
|
||||||
|
'pino', // pino
|
||||||
|
'pino-pretty', // pino-pretty
|
||||||
|
'@msgpack/msgpack', // msgpack
|
||||||
|
];
|
Loading…
x
Reference in New Issue
Block a user