dsh-im-ops/plugin-src/host/build.mjs

47 lines
1.5 KiB
JavaScript

import { mkdir } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { build } from 'esbuild';
import { larkSdkHandshakePatch } from './lark-sdk-handshake-patch.mjs';
const sourceDirectory = dirname(fileURLToPath(import.meta.url));
const packageRoot = resolve(sourceDirectory, '../..');
const outputPath = resolve(packageRoot, 'lib/index.js');
const externalRuntimePackages = [
'@tencent-connect/qqbot-connector',
'@tencent-connect/qqbot-nodejs',
'@wecom/aibot-node-sdk',
'dingtalk-stream',
'qrcode',
];
const external = externalRuntimePackages.flatMap((name) => [name, `${name}/*`]);
await mkdir(dirname(outputPath), { recursive: true });
await build({
entryPoints: [resolve(sourceDirectory, 'index.mjs')],
bundle: true,
format: 'esm',
platform: 'node',
target: ['node22'],
mainFields: ['module', 'main'],
external,
plugins: [larkSdkHandshakePatch],
outfile: outputPath,
banner: {
js: [
"import { createRequire as __dshCreateRequire } from 'node:module';",
"import { dirname as __dshDirname } from 'node:path';",
"import { fileURLToPath as __dshFileURLToPath } from 'node:url';",
'const require = __dshCreateRequire(import.meta.url);',
'const __filename = __dshFileURLToPath(import.meta.url);',
'const __dirname = __dshDirname(__filename);',
].join('\n'),
},
sourcemap: false,
minify: true,
legalComments: 'eof',
});
console.log(`Wrote ${outputPath}`);