feat(insight): enhance template loading logic and add insight templates copying

This commit is contained in:
DragonnZhang 2026-02-02 11:01:51 +08:00
parent 338387f93a
commit 7e21ba4983
3 changed files with 62 additions and 43 deletions

View file

@ -14,6 +14,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { execSync } from 'node:child_process';
import { copyRecursiveSync } from './copy_bundle_assets.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@ -69,24 +70,6 @@ const localesSourceDir = path.join(
const localesDestDir = path.join(distDir, 'locales');
if (fs.existsSync(localesSourceDir)) {
// Recursive copy function
function copyRecursiveSync(src, dest) {
const stats = fs.statSync(src);
if (stats.isDirectory()) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const entries = fs.readdirSync(src);
for (const entry of entries) {
const srcPath = path.join(src, entry);
const destPath = path.join(dest, entry);
copyRecursiveSync(srcPath, destPath);
}
} else {
fs.copyFileSync(src, dest);
}
}
copyRecursiveSync(localesSourceDir, localesDestDir);
console.log('Copied locales folder');
} else {
@ -107,24 +90,6 @@ const extensionExamplesDir = path.join(
const extensionExamplesDestDir = path.join(distDir, 'examples');
if (fs.existsSync(extensionExamplesDir)) {
// Recursive copy function
function copyRecursiveSync(src, dest) {
const stats = fs.statSync(src);
if (stats.isDirectory()) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const entries = fs.readdirSync(src);
for (const entry of entries) {
const srcPath = path.join(src, entry);
const destPath = path.join(dest, entry);
copyRecursiveSync(srcPath, destPath);
}
} else {
fs.copyFileSync(src, dest);
}
}
copyRecursiveSync(extensionExamplesDir, extensionExamplesDestDir);
console.log('Copied extension examples folder');
} else {
@ -133,6 +98,28 @@ if (fs.existsSync(extensionExamplesDir)) {
);
}
// Copy insight templates directory
console.log('Copying insight templates...');
const insightTemplatesDir = path.join(
rootDir,
'packages',
'cli',
'src',
'services',
'insight',
'templates',
);
const destTemplatesDir = path.join(distDir, 'templates');
if (fs.existsSync(insightTemplatesDir)) {
copyRecursiveSync(insightTemplatesDir, destTemplatesDir);
console.log('Copied insight templates to dist/');
} else {
console.warn(
`Warning: Insight templates directory not found at ${insightTemplatesDir}`,
);
}
// Copy package.json from root and modify it for publishing
console.log('Creating package.json for distribution...');
const rootPackageJson = JSON.parse(
@ -151,7 +138,15 @@ const distPackageJson = {
bin: {
qwen: 'cli.js',
},
files: ['cli.js', 'vendor', '*.sb', 'README.md', 'LICENSE', 'locales'],
files: [
'cli.js',
'vendor',
'*.sb',
'README.md',
'LICENSE',
'locales',
'templates',
],
config: rootPackageJson.config,
dependencies: {},
optionalDependencies: {