mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-30 12:40:44 +00:00
feat(insight): Refactor code structure for improved readability and maintainability
This commit is contained in:
parent
2edce464ae
commit
e66c203cb0
18 changed files with 423 additions and 229 deletions
63
packages/cli/assets/insight/build.mjs
Normal file
63
packages/cli/assets/insight/build.mjs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable no-undef */
|
||||
import { writeFile, readFile } from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { build } from 'vite';
|
||||
|
||||
const assetsDir = dirname(fileURLToPath(import.meta.url));
|
||||
const distDir = join(assetsDir, 'dist');
|
||||
|
||||
const templateModulePath = join(
|
||||
assetsDir,
|
||||
'..',
|
||||
'..',
|
||||
'src',
|
||||
'services',
|
||||
'insight',
|
||||
'templates',
|
||||
'insightTemplate.ts',
|
||||
);
|
||||
|
||||
console.log('Building insight assets with Vite...');
|
||||
await build();
|
||||
|
||||
console.log('Reading generated files...');
|
||||
let jsContent = '';
|
||||
let cssContent = '';
|
||||
|
||||
try {
|
||||
jsContent = await readFile(join(distDir, 'main.js'), 'utf-8');
|
||||
} catch (e) {
|
||||
console.error('Failed to read main.js from dist');
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
// Try style.css first (standard Vite lib mode output)
|
||||
cssContent = await readFile(join(distDir, 'style.css'), 'utf-8');
|
||||
} catch (e) {
|
||||
try {
|
||||
// Try main.css (if configured via assetFileNames)
|
||||
cssContent = await readFile(join(distDir, 'main.css'), 'utf-8');
|
||||
} catch (e2) {
|
||||
console.warn(
|
||||
'No CSS file found in dist (style.css or main.css). Using empty string.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const templateModule = `/**
|
||||
* @license
|
||||
* Copyright 2025 Qwen Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* This file is code-generated; do not edit manually.
|
||||
*/
|
||||
|
||||
export const INSIGHT_JS = ${JSON.stringify(jsContent.trim())};
|
||||
export const INSIGHT_CSS = ${JSON.stringify(cssContent.trim())};
|
||||
`;
|
||||
|
||||
await writeFile(templateModulePath, templateModule);
|
||||
console.log(`Successfully generated ${templateModulePath}`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue