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

sushuang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git

commit 1c0a17c4e4b67098addc4ad4f500c1e2a7f3865c
Author: 100pah <sushuang0...@gmail.com>
AuthorDate: Tue Jul 1 19:01:25 2025 +0800

    (infra): (1) Support compile:example only a single file. (2) Tweak README 
doc.
---
 README.md               | 11 ++++---
 tool/compile-example.js | 85 +++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 83 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index e3a4e662..f546291f 100644
--- a/README.md
+++ b/README.md
@@ -64,17 +64,20 @@ Use this code to enable controller panel for a example:
 
 ```js
 app.config = {
-  aNameForTheSelectWidget: 'This is the initial value'
+  aNameForTheSelectionWidget: 'This is the initial value'
   aNameForTheRangeWidget: 45,
   aNameForTheButtonWidget: function () {
-    // Do something.
+    // Do something on button click.
   },
   onChange: function () {
-    // Do something.
+    // Do something on SelectionWidget or RangeWidget changed.
+    // Read the current value.
+    console.log(app.config.aNameForTheRangeWidget)
+    console.log(app.config.aNameForTheSelectionWidget)
   }
 };
 app.configParameters = {
-  aNameForTheSelectWidget: {
+  aNameForTheSelectionWidget: {
     options: [
       'This is the initial value',
       'This is another value',
diff --git a/tool/compile-example.js b/tool/compile-example.js
index a367208e..7ce63fec 100644
--- a/tool/compile-example.js
+++ b/tool/compile-example.js
@@ -3,18 +3,85 @@ const fs = require('fs');
 const path = require('path');
 const shell = require('shelljs');
 
+/**
+ * @usage
+ *  ```shell
+ *  # compile all
+ *  npm run compile:example
+ *
+ *  # compile single
+ *  npm run compile:example -- area-basic.ts
+ *  ```
+ */
+
 const exampleDir = path.join(__dirname, '../public/examples');
 
+// Get the file argument (relative to exampleDir, e.g. 'area-basic.ts')
+const fileArg = process.argv[2];
+
 async function run() {
-  const hasError =
-    shell.exec(`tsc --project "${path.join(exampleDir, 'tsconfig.json')}"`)
-      .code !== 0;
-  shell.exec(`prettier --write "${path.join(exampleDir, 'js')}"`);
-
-  const files = await globby('js/**/*.js', {
-    cwd: exampleDir,
-    absolute: true
-  });
+  const tsConfigPath = path.join(exampleDir, 'tsconfig.json');
+
+  let singleSrcFilePath;
+  let intermediaJSFilePath;
+  let retCode;
+
+  if (fileArg) {
+    singleSrcFilePath = path.join('ts', fileArg); // relative to exampleDir
+    console.log(`Compile single file "${singleSrcFilePath}" ...`);
+    intermediaJSFilePath = path
+      .join(exampleDir, singleSrcFilePath)
+      .replace(/\.ts$/, '.js')
+      .replace(/\/ts\//, '/js/');
+
+    // Create a temporary tsconfig.single.json
+    const tempConfigPath = path.join(exampleDir, 'tsconfig.single.json');
+    const tempConfig = {
+      extends: './tsconfig.json',
+      include: [singleSrcFilePath]
+    };
+    fs.writeFileSync(
+      tempConfigPath,
+      JSON.stringify(tempConfig, null, 2),
+      'utf-8'
+    );
+
+    // Compile using the temp config
+    retCode = shell.exec(`tsc --project "${tempConfigPath}"`).code;
+
+    // Remove the temp config
+    fs.unlinkSync(tempConfigPath);
+  } else {
+    retCode = shell.exec(`tsc --project "${tsConfigPath}"`).code;
+  }
+
+  // There might be TS error, but probably no need to handle them immediately,
+  // thus do not block the subsequent process.
+  // if (retCode !== 0) {
+  //   process.exit(retCode);
+  // }
+
+  // Prettier for the corresponding JS file
+  if (fileArg) {
+    if (fs.existsSync(intermediaJSFilePath)) {
+      shell.exec(`prettier --write "${intermediaJSFilePath}"`);
+    } else {
+      console.error(`prettier JS file not found: ${intermediaJSFilePath}`);
+      process.exit(1);
+    }
+  } else {
+    shell.exec(`prettier --write "${path.join(exampleDir, 'js')}"`);
+  }
+
+  let files;
+  if (fileArg) {
+    files = [intermediaJSFilePath];
+  } else {
+    files = await globby('js/**/*.js', {
+      cwd: exampleDir,
+      absolute: true
+    });
+  }
 
   for (const file of files) {
     const content =


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to