You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/09/07 08:05:08 UTC

[echarts-examples] branch typescript updated (85dfdaf -> bfb64a2)

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

shenyi pushed a change to branch typescript
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git.


    from 85dfdaf  feat: add ts and js switch. add prettier
     new 91a9f36  add language switch confirm
     new bfb64a2  fix build example

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 package.json                  |  8 ++++----
 public/examples/tsconfig.json | 24 ++++++++++++------------
 src/common/i18n.js            | 14 ++++++++++++--
 src/common/store.js           |  1 +
 src/editor/Editor.vue         | 24 ++++++++++++++++++++----
 src/editor/Preview.vue        |  8 ++++----
 tool/build-example.js         | 33 +++++++++++++++++++--------------
 tool/compile-example.js       | 35 +++++++++++++++++++++++++++++++++++
 tool/screenshot.html          |  5 +++--
 9 files changed, 110 insertions(+), 42 deletions(-)
 create mode 100644 tool/compile-example.js

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


[echarts-examples] 02/02: fix build example

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bfb64a2da816b160843720ecb6742ba00d9a5897
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Sep 7 16:04:17 2021 +0800

    fix build example
---
 package.json                  |  8 ++++----
 public/examples/tsconfig.json | 24 ++++++++++++------------
 src/common/store.js           |  1 +
 tool/build-example.js         | 33 +++++++++++++++++++--------------
 tool/compile-example.js       | 35 +++++++++++++++++++++++++++++++++++
 tool/screenshot.html          |  5 +++--
 6 files changed, 74 insertions(+), 32 deletions(-)

diff --git a/package.json b/package.json
index cbc49e1..90c55fe 100644
--- a/package.json
+++ b/package.json
@@ -5,11 +5,11 @@
   "scripts": {
     "build": "npx webpack --config build/webpack.config.js --mode production",
     "watch": "npx webpack --config build/webpack.config.js --mode development --devtool source-map --watch",
-    "localsite": "npm run build && node build/copyResource.js --env localsite",
-    "release": "npm run build && node build/copyResource.js --env asf",
+    "localsite": "npm run compile:example || npm run build && node build/copyResource.js --env localsite",
+    "release": "npm run compile:example || npm run build && node build/copyResource.js --env asf",
     "dev": "npx concurrently --kill-others \"npm:watch\" \"npm:server\"",
-    "build:example": "node tool/build-example.js && node tool/build-example.js --source data-gl",
-    "compile:example": "tsc --project public/examples/tsconfig.json || prettier --write public/examples/js",
+    "build:example": "npm run compile:example || node tool/build-example.js && node tool/build-example.js --gl",
+    "compile:example": "node tool/compile-example.js",
     "test:e2e": "node e2e/main.js --bundler webpack -m",
     "test:e2e:local": "node e2e/main.js --bundler webpack -m --local",
     "test:e2e:esbuild": "node e2e/main.js --bundler esbuild -m",
diff --git a/public/examples/tsconfig.json b/public/examples/tsconfig.json
index b689d9a..f47c85b 100644
--- a/public/examples/tsconfig.json
+++ b/public/examples/tsconfig.json
@@ -1,13 +1,13 @@
 {
-    "compilerOptions": {
-        "target": "ES6",
-        "strict": true,
-        "moduleResolution": "node",
-        "allowJs": true,
-        "checkJs": false,
-        "pretty": true,
-        "outDir": "./js/",
-        "baseUrl": "./"
-    },
-    "include": ["./ts/**/*.ts", "./ts/**/*.js", "./types/**/*.d.ts"]
-}
\ No newline at end of file
+  "compilerOptions": {
+    "target": "ES6",
+    "strict": true,
+    "moduleResolution": "node",
+    "allowJs": true,
+    "checkJs": false,
+    "pretty": true,
+    "outDir": "./js/",
+    "baseUrl": "./"
+  },
+  "include": ["./ts/**/*.ts", "./ts/**/*.js", "./types/**/*.d.ts"]
+}
diff --git a/src/common/store.js b/src/common/store.js
index f6a56df..af35246 100644
--- a/src/common/store.js
+++ b/src/common/store.js
@@ -49,6 +49,7 @@ export function parseSourceCode(code) {
       .replace(/\/\*[\w\W]*?\*\//, '')
       .trim()
       // ts code needs add `export {}` to be a module. remove it.
+      // FIXME
       .replace(/export\s+\{\s*\}\s*;?$/g, '')
   );
 }
diff --git a/tool/build-example.js b/tool/build-example.js
index ac763da..b23290b 100644
--- a/tool/build-example.js
+++ b/tool/build-example.js
@@ -36,8 +36,8 @@ function codeSize(code) {
 const parser = new argparse.ArgumentParser({
   addHelp: true
 });
-parser.addArgument(['-s', '--source'], {
-  help: 'Source folder'
+parser.addArgument(['--gl'], {
+  help: 'If generating gl'
 });
 parser.addArgument(['-t', '--theme'], {
   help: 'Theme list, default to be all'
@@ -51,7 +51,7 @@ parser.addArgument(['--no-thumb'], {
 });
 
 const args = parser.parseArgs();
-const sourceFolder = args.source || 'data';
+const isGL = args.gl;
 let themeList = args.theme || 'default,dark';
 let matchPattern = args.pattern;
 if (matchPattern) {
@@ -107,7 +107,8 @@ async function takeScreenshot(
 ) {
   const thumbFolder = theme !== 'default' ? 'thumb-' + theme : 'thumb';
   const page = await browser.newPage();
-  const thumbDir = `${rootDir}public/${sourceFolder}/${thumbFolder}`;
+  const dataDir = isGL ? 'data-gl' : 'data';
+  const thumbDir = `${rootDir}public/${dataDir}/${thumbFolder}`;
   const fileBase = `${thumbDir}/${basename}`;
   const webmFile = `${fileBase}.webm`;
 
@@ -138,7 +139,9 @@ async function takeScreenshot(
     width: shotWidth || DEFAULT_PAGE_WIDTH,
     height: (shotWidth || DEFAULT_PAGE_WIDTH) * DEFAULT_PAGE_RATIO
   });
-  let url = `${SCREENSHOT_PAGE_URL}?c=${basename}&t=${theme}&s=${sourceFolder}`;
+  let url = `${SCREENSHOT_PAGE_URL}?c=${basename}&t=${theme}${
+    isGL ? '&gl' : ''
+  }`;
 
   if (hasVideo) {
     url += `&start=${videoStart}&end=${videoEnd}`;
@@ -193,9 +196,9 @@ async function takeScreenshot(
         return _$getEChartsOption();
       });
       const optionStr = optionToJson(option);
-      fse.ensureDirSync(`${rootDir}public/${sourceFolder}/option/`);
+      fse.ensureDirSync(`${rootDir}public/${dataDir}/option/`);
       fs.writeFileSync(
-        `${rootDir}public/${sourceFolder}/option/${basename}.json`,
+        `${rootDir}public/${dataDir}/option/${basename}.json`,
         optionStr,
         'utf-8'
       );
@@ -261,7 +264,9 @@ async function takeScreenshot(
   // TODO puppeteer will have Navigation Timeout Exceeded: 30000ms exceeded error in these examples.
   const screenshotBlackList = [];
 
-  const files = await globby(`${rootDir}public/${sourceFolder}/*.js`);
+  const files = await globby(
+    `${rootDir}public/examples/js/${isGL ? 'gl/' : ''}*.js`
+  );
 
   const exampleList = [];
 
@@ -286,10 +291,7 @@ async function takeScreenshot(
 
       let fmResult;
       try {
-        const code = fs.readFileSync(
-          `${rootDir}public/${sourceFolder}/${basename}.js`,
-          'utf-8'
-        );
+        const code = fs.readFileSync(fileName, 'utf-8');
         fmResult = matter(code, {
           delimiters: ['/*', '*/']
         });
@@ -355,7 +357,10 @@ export default ${JSON.stringify(exampleList, null, 2)}`;
 
   if (!matchPattern) {
     fs.writeFileSync(
-      path.join(__dirname, `../src/data/chart-list-${sourceFolder}.js`),
+      path.join(
+        __dirname,
+        `../src/data/chart-list-data${isGL ? '-gl' : ''}.js`
+      ),
       code,
       'utf-8'
     );
@@ -420,7 +425,7 @@ export default ${JSON.stringify(exampleList, null, 2)}`;
             }
           );
         },
-        sourceFolder === 'data-gl' ? 2 : 16
+        isGL ? 2 : 16
       );
 
       await runTasks(
diff --git a/tool/compile-example.js b/tool/compile-example.js
new file mode 100644
index 0000000..321bf4c
--- /dev/null
+++ b/tool/compile-example.js
@@ -0,0 +1,35 @@
+const globby = require('globby');
+const fs = require('fs');
+const path = require('path');
+const shell = require('shelljs');
+
+const exampleDir = path.join(__dirname, '../public/examples');
+
+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(path.join(exampleDir, `js/**/*.js`));
+
+  for (let file of files) {
+    const content =
+      fs
+        .readFileSync(file, 'utf-8')
+        .trim()
+        // ts code needs add `export {}` to be a module. remove it.
+        // FIXME
+        .replace(/export\s+\{\s*\}\s*;?$/g, '')
+        .replace(/^'use strict';/, '')
+        .trim() + '\n';
+
+    fs.writeFileSync(file, content, 'utf-8');
+  }
+
+  if (hasError) {
+    shell.exit(1);
+  }
+}
+
+run();
diff --git a/tool/screenshot.html b/tool/screenshot.html
index ebab89e..271e8cc 100644
--- a/tool/screenshot.html
+++ b/tool/screenshot.html
@@ -141,10 +141,11 @@
           console.error('No ROOT_PATH specified. Use default ROOT_PATH "."');
           window.ROOT_PATH = '.';
         }
-        const sourceFolder = params.s || 'data';
         const scriptTag = document.createElement('script');
         scriptTag.async = false;
-        scriptTag.src = `../public/${sourceFolder}/${params.c}.js`;
+        scriptTag.src = `../public/examples/js${'gl' in params ? '/gl' : ''}/${
+          params.c
+        }.js`;
         document.body.appendChild(scriptTag);
 
         let videoRecorder;

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


[echarts-examples] 01/02: add language switch confirm

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 91a9f36c6b8c9137b9912923f4d61816aef26400
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Sep 7 15:39:47 2021 +0800

    add language switch confirm
---
 src/common/i18n.js     | 14 ++++++++++++--
 src/editor/Editor.vue  | 24 ++++++++++++++++++++----
 src/editor/Preview.vue |  8 ++++----
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/src/common/i18n.js b/src/common/i18n.js
index 206515a..8bb0e56 100644
--- a/src/common/i18n.js
+++ b/src/common/i18n.js
@@ -26,7 +26,12 @@ export default {
       tooltip: {
         jsMode: 'JavaScript',
         tsMode: 'TypeScript. Provides Better Intelligent'
-      }
+      },
+
+      codeChangedConfirm:
+        "Modified code will be lost. Do you wan't to continue?",
+      confirmButtonText: 'Yes',
+      cancelButtonText: 'No'
     },
 
     chartTypes: {
@@ -98,7 +103,12 @@ export default {
       tooltip: {
         jsMode: 'JavaScript 代码编辑',
         tsMode: 'TypeScript 代码编辑,提供更好的代码补全和类型检查。'
-      }
+      },
+
+      codeChangedConfirm: '已经修改过的代码将会丢失,是否确认继续?',
+
+      confirmButtonText: '确认',
+      cancelButtonText: '取消'
     },
 
     chartTypes: {
diff --git a/src/editor/Editor.vue b/src/editor/Editor.vue
index f0f8abd..2070a26 100644
--- a/src/editor/Editor.vue
+++ b/src/editor/Editor.vue
@@ -292,11 +292,27 @@ export default {
     },
     changeLang(lang) {
       if ((URL_PARAMS.lang || 'js').toLowerCase() !== lang) {
-        goto(
-          Object.assign({}, URL_PARAMS, {
-            lang
+        if (!this.initialCode || store.sourceCode === this.initialCode) {
+          goto(
+            Object.assign({}, URL_PARAMS, {
+              lang
+            })
+          );
+        } else {
+          this.$confirm(this.$t('editor.codeChangedConfirm'), '', {
+            confirmButtonText: this.$t('editor.confirmButtonText'),
+            cancelButtonText: this.$t('editor.cancelButtonText'),
+            type: 'warning'
           })
-        );
+            .then(() => {
+              goto(
+                Object.assign({}, URL_PARAMS, {
+                  lang
+                })
+              );
+            })
+            .catch(() => {});
+        }
       }
     },
     format() {
diff --git a/src/editor/Preview.vue b/src/editor/Preview.vue
index dd573d5..89518da 100644
--- a/src/editor/Preview.vue
+++ b/src/editor/Preview.vue
@@ -57,10 +57,10 @@
               </el-col>
             </el-row>
           </div>
-          <span class="render-config-trigger" slot="reference"
-            ><i class="el-icon-setting el-icon--left"></i
-            >{{ $t('editor.renderCfgTitle') }}</span
-          >
+          <span class="render-config-trigger" slot="reference">
+            <i class="el-icon-setting el-icon--left"></i
+            >{{ $t('editor.renderCfgTitle') }}
+          </span>
         </el-popover>
       </div>
       <template v-if="inEditor">

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