This is an automated email from the ASF dual-hosted git repository.

ovilia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/echarts-theme-builder.git

commit 805673434cb5d26f22ee58c76d37b94f37bbd4fb
Author: Ovilia <[email protected]>
AuthorDate: Wed Sep 17 13:56:56 2025 +0800

    chore: update release script
---
 vite.config.ts | 165 ++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 100 insertions(+), 65 deletions(-)

diff --git a/vite.config.ts b/vite.config.ts
index adca3b2..d13f052 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -2,76 +2,106 @@ import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import path from 'path'
 import fs from 'fs'
+import fse from 'fs-extra'
+
+/**
+ * Load release config from env.asf.js
+ */
+function loadReleaseConfig() {
+  const configModule = require('./config/env.asf.js')
+  return configModule.default || configModule
+}
+
+// Check if release mode is enabled with RELEASE=true environment variable
+const isRelease = process.env.RELEASE === 'true'
 
 // https://vite.dev/config/
 export default defineConfig({
+  define: {
+    // 设置环境变量,在前端代码中可以通过import.meta.env访问
+    'import.meta.env.VITE_MODE': JSON.stringify(isRelease ? 'release' : 
'development')
+  },
   plugins: [
     vue(),
     {
-      name: 'theme-builder-post-process',
+      name: 'theme-builder-processor',
       closeBundle: async () => {
-        // Handle HTML files
+        // Handle HTML files - Create language-specific index.html files
         if (fs.existsSync('app/index.html')) {
-          // Create directories if they don't exist
-          if (!fs.existsSync('app/en')) {
-            fs.mkdirSync('app/en', { recursive: true });
-          }
+          console.log('Processing HTML output...')
 
-          // Read the content from index.html but only extract the body content
-          const content = fs.readFileSync('app/index.html', 'utf-8');
-          const bodyContent = content.match(/<body>(.*?)<\/body>/s)?.[1] || '';
-
-          // Write to body.html for English version
-          fs.writeFileSync('app/en/body.html', bodyContent.trim(), 'utf-8');
-
-          // Do the same for zh version
-          if (!fs.existsSync('app/zh')) {
-            fs.mkdirSync('app/zh', { recursive: true });
-          }
-          fs.writeFileSync('app/zh/body.html', bodyContent.trim(), 'utf-8');
+          // Create directories if they don't exist
+          fs.mkdirSync('app/en', { recursive: true })
+          fs.mkdirSync('app/zh', { recursive: true })
+          fs.mkdirSync('app/en/theme-builder', { recursive: true })
+          fs.mkdirSync('app/zh/theme-builder', { recursive: true })
 
-          // Remove the original index.html
-          fs.unlinkSync('app/index.html');
-        }
-        
-        // Move CSS file to app/styles directory (common for both languages)
-        if (fs.existsSync('app/en/theme-builder/main.css')) {
-          const stylesDir = 'app/styles';
-          if (!fs.existsSync(stylesDir)) {
-            fs.mkdirSync(stylesDir, { recursive: true });
-          }
+          // Generate HTML content - just div + script tag
+          const divContent = '<div id="theme-builder"></div>'
+          const scriptTag = '<script type="module" 
src="./theme-builder/app.min.js"></script>'
           
-          // Move CSS to shared styles directory
-          fs.copyFileSync('app/en/theme-builder/main.css', 
`${stylesDir}/main.css`);
+          // Create simplified index.html for both languages
+          const indexHTML = `${divContent}\n  ${scriptTag}`
           
-          // Clean up the language-specific CSS files
-          if (fs.existsSync('app/en/theme-builder/main.css')) {
-            fs.unlinkSync('app/en/theme-builder/main.css');
-          }
+          // Write index.html files (only these, no body.html)
+          fs.writeFileSync('app/en/index.html', indexHTML, 'utf-8')
+          fs.writeFileSync('app/zh/index.html', indexHTML, 'utf-8')
+
+          // Remove the original index.html
+          fs.unlinkSync('app/index.html')
         }
-        
-        // Create shared assets directory if needed
-        const sharedAssetsDir = 'app/assets';
-        if (!fs.existsSync(sharedAssetsDir)) {
-          fs.mkdirSync(sharedAssetsDir, { recursive: true });
+
+        // Move CSS to shared styles directory
+        console.log('Processing CSS and shared resources...')
+        fs.mkdirSync('app/styles', { recursive: true })
+
+        if (fs.existsSync('app/styles/main.css')) {
+          // CSS is already in the correct location from the build output
+          console.log('CSS output already in correct location')
         }
 
-        // Copy theme files to app root directory
-        const themesDir = 'public/themes';
-        const themesDestination = 'app/themes';
+        // Copy theme files from public to app/themes (common resource)
+        const themesDir = 'public/themes'
+        const themesDestination = 'app/themes'
 
         if (fs.existsSync(themesDir)) {
-          // Create themes directory in app root
-          if (!fs.existsSync(themesDestination)) {
-            fs.mkdirSync(themesDestination, { recursive: true });
-          }
+          fs.mkdirSync(themesDestination, { recursive: true })
 
-          // Copy theme files to app/themes
-          fs.readdirSync(themesDir).forEach((file: string) => {
+          // Copy theme JSON files
+          fs.readdirSync(themesDir).forEach((file) => {
             if (file.endsWith('.json')) {
-              fs.copyFileSync(`${themesDir}/${file}`, 
`${themesDestination}/${file}`);
+              fs.copyFileSync(`${themesDir}/${file}`, 
`${themesDestination}/${file}`)
             }
-          });
+          })
+        }
+
+        // Handle release mode - copy files from app to ecWWWGeneratedDir
+        if (isRelease) {
+          console.log('Starting release process...')
+          const config = loadReleaseConfig()
+
+          // Validate target directories
+          if (!config.ecWWWGeneratedDir) {
+            console.error('Error: ecWWWGeneratedDir not defined in config')
+            return
+          }
+
+          const ecWWWBaseDir = config.ecWWWGeneratedDir.replace('_generated', 
'')
+          if (!fs.existsSync(ecWWWBaseDir)) {
+            console.error(`Error: ECharts www project not found: 
${ecWWWBaseDir}`)
+            return
+          }
+          
+          // Create destination directory if needed
+          fse.ensureDirSync(config.ecWWWGeneratedDir)
+          
+          // Copy the entire app directory to ecWWWGeneratedDir
+          console.log(`Copying app contents to ${config.ecWWWGeneratedDir}`)
+          
+          // Copy app directory to ecWWWGeneratedDir
+          fse.copySync('app', config.ecWWWGeneratedDir)
+
+          console.log('Release process completed successfully!')
         }
       }
     }
@@ -81,32 +111,37 @@ export default defineConfig({
     emptyOutDir: true,
     rollupOptions: {
       input: {
-        'main': path.resolve(process.cwd(), 'index.html')
+        'en': path.resolve(process.cwd(), 'index.html'),
+        'zh': path.resolve(process.cwd(), 'index.html')
       },
       output: {
-        entryFileNames: (chunkInfo) => {
-          const locale = chunkInfo.facadeModuleId?.includes('/en/') ? 'en' : 
'zh';
-          return `${locale}/theme-builder/app.min.js`;
+        entryFileNames: () => {
+          // 统一放在各自语言目录下的theme-builder目录中
+          return `[name]/theme-builder/app.min.js`
         },
-        chunkFileNames: (chunkInfo) => {
-          const name = chunkInfo.name || '';
-          const locale = name.includes('en') ? 'en' : 'zh';
-          return `${locale}/theme-builder/chunks/[name]-[hash].js`;
+        chunkFileNames: (chunkInfo: any) => {
+          const name = chunkInfo.name || ''
+          // 根据名称推断语言
+          if (name.startsWith('en') || name.includes('en-')) {
+            return `en/theme-builder/chunks/[name]-[hash].js`
+          } else {
+            return `zh/theme-builder/chunks/[name]-[hash].js`
+          }
         },
-        assetFileNames: (assetInfo) => {
-          const info = assetInfo.name || '';
-          
+        assetFileNames: (assetInfo: any) => {
+          const info = assetInfo.name || ''
+
           // For CSS files, put them in shared styles directory
           if (info.endsWith('.css')) {
-            return `styles/main.css`;
+            return `styles/main.css`
           }
-          
+
           // Common assets go to app root, others to language-specific 
directories
           if (info.includes('assets/') || info.includes('images/')) {
-            return `assets/[name]-[hash][extname]`;
+            return `assets/[name]-[hash][extname]`
           }
 
-          return `en/theme-builder/assets/[name]-[hash][extname]`;
+          return `en/theme-builder/assets/[name]-[hash][extname]`
         },
         manualChunks: undefined
       }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to