59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const esbuild = require('esbuild');
|
|
|
|
async function build() {
|
|
console.log('Building host entry: src/index.ts -> lib/index.js...');
|
|
await esbuild.build({
|
|
entryPoints: [path.resolve(__dirname, 'src/index.ts')],
|
|
outfile: path.resolve(__dirname, 'lib/index.js'),
|
|
bundle: false,
|
|
format: 'esm',
|
|
platform: 'node',
|
|
target: 'node18'
|
|
});
|
|
|
|
console.log('Building client bundle: src/client/index.ts -> lib/client.js...');
|
|
const clientBuildResult = await esbuild.build({
|
|
entryPoints: [path.resolve(__dirname, 'src/client/index.ts')],
|
|
bundle: true,
|
|
write: false,
|
|
format: 'cjs',
|
|
platform: 'browser',
|
|
target: 'es2022',
|
|
external: [
|
|
'react',
|
|
'react-dom',
|
|
'react/jsx-runtime',
|
|
'@deepseek-ai/cordis',
|
|
'@deepseek-ai/dsh-client-store',
|
|
'@deepseek-ai/dsh-client-ui-slots',
|
|
'@deepseek-ai/dsh-client-ui-primitives',
|
|
'@deepseek-ai/dsh-client-ui-dockkit'
|
|
]
|
|
});
|
|
|
|
const bundledCjs = clientBuildResult.outputFiles[0].text;
|
|
|
|
// Wrap in window.__ModuleLoader__.load({ id: "dsh-plugin-model-enhancer", factory: (require) => { ... } })
|
|
const wrappedClientCode = `window.__ModuleLoader__.load({
|
|
id: "dsh-plugin-model-enhancer",
|
|
factory: (require) => {
|
|
var module = { exports: {} };
|
|
var exports = module.exports;
|
|
${bundledCjs}
|
|
return module.exports;
|
|
}
|
|
});
|
|
`;
|
|
|
|
fs.mkdirSync(path.resolve(__dirname, 'lib'), { recursive: true });
|
|
fs.writeFileSync(path.resolve(__dirname, 'lib/client.js'), wrappedClientCode, 'utf8');
|
|
console.log('Successfully generated lib/client.js (length: ' + wrappedClientCode.length + ')');
|
|
}
|
|
|
|
build().catch((err) => {
|
|
console.error('Build failed:', err);
|
|
process.exit(1);
|
|
});
|