mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat: enhance logging capabilities and update query options in sdk-typescript
- Introduced a new logging system with adjustable log levels (debug, info, warn, error). - Updated query options to include a logLevel parameter for controlling verbosity. - Refactored existing code to utilize the new logging system for better error handling and debugging. - Cleaned up unused code and improved the structure of the SDK.
This commit is contained in:
95
packages/sdk-typescript/scripts/build.js
Executable file
95
packages/sdk-typescript/scripts/build.js
Executable file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Qwen Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import { rmSync, mkdirSync, existsSync, cpSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import esbuild from 'esbuild';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const rootDir = join(__dirname, '..');
|
||||
|
||||
rmSync(join(rootDir, 'dist'), { recursive: true, force: true });
|
||||
mkdirSync(join(rootDir, 'dist'), { recursive: true });
|
||||
|
||||
execSync('tsc --project tsconfig.build.json', {
|
||||
stdio: 'inherit',
|
||||
cwd: rootDir,
|
||||
});
|
||||
|
||||
try {
|
||||
execSync(
|
||||
'npx dts-bundle-generator -o dist/index.d.ts src/index.ts --no-check',
|
||||
{
|
||||
stdio: 'inherit',
|
||||
cwd: rootDir,
|
||||
},
|
||||
);
|
||||
|
||||
const dirsToRemove = ['mcp', 'query', 'transport', 'types', 'utils'];
|
||||
for (const dir of dirsToRemove) {
|
||||
const dirPath = join(rootDir, 'dist', dir);
|
||||
if (existsSync(dirPath)) {
|
||||
rmSync(dirPath, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'Could not bundle type definitions, keeping separate .d.ts files',
|
||||
error.message,
|
||||
);
|
||||
}
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints: [join(rootDir, 'src', 'index.ts')],
|
||||
bundle: true,
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
target: 'node18',
|
||||
outfile: join(rootDir, 'dist', 'index.mjs'),
|
||||
external: ['@modelcontextprotocol/sdk'],
|
||||
sourcemap: false,
|
||||
minify: true,
|
||||
minifyWhitespace: true,
|
||||
minifyIdentifiers: true,
|
||||
minifySyntax: true,
|
||||
legalComments: 'none',
|
||||
keepNames: false,
|
||||
treeShaking: true,
|
||||
});
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints: [join(rootDir, 'src', 'index.ts')],
|
||||
bundle: true,
|
||||
format: 'cjs',
|
||||
platform: 'node',
|
||||
target: 'node18',
|
||||
outfile: join(rootDir, 'dist', 'index.cjs'),
|
||||
external: ['@modelcontextprotocol/sdk'],
|
||||
sourcemap: false,
|
||||
minify: true,
|
||||
minifyWhitespace: true,
|
||||
minifyIdentifiers: true,
|
||||
minifySyntax: true,
|
||||
legalComments: 'none',
|
||||
keepNames: false,
|
||||
treeShaking: true,
|
||||
});
|
||||
|
||||
const filesToCopy = ['README.md', 'LICENSE'];
|
||||
for (const file of filesToCopy) {
|
||||
const sourcePath = join(rootDir, '..', '..', file);
|
||||
const targetPath = join(rootDir, 'dist', file);
|
||||
if (existsSync(sourcePath)) {
|
||||
try {
|
||||
cpSync(sourcePath, targetPath);
|
||||
} catch (error) {
|
||||
console.warn(`Could not copy ${file}:`, error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user