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 2020/02/21 03:57:27 UTC

[incubator-echarts] branch typescript updated: chalk: optimize progress display in bundling

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/incubator-echarts.git


The following commit(s) were added to refs/heads/typescript by this push:
     new dbcc879  chalk: optimize progress display in bundling
dbcc879 is described below

commit dbcc879efb0d86a2132a07fa3774dd0002c4d5a3
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Feb 21 11:57:11 2020 +0800

    chalk: optimize progress display in bundling
---
 build/config.js         | 14 +++++++++---
 build/progress.js       | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 package.json            |  1 -
 src/stream/Scheduler.ts |  6 ++---
 4 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/build/config.js b/build/config.js
index 8c48351..251fb91 100644
--- a/build/config.js
+++ b/build/config.js
@@ -26,10 +26,13 @@ const nodePath = require('path');
 const preamble = require('./preamble');
 const ecDir = nodePath.resolve(__dirname, '..');
 const typescriptPlugin = require('rollup-plugin-typescript2');
-const progress = require('rollup-plugin-progress');
 const fs = require('fs');
+const progress = require('./progress');
 
-function preparePlugins({min, lang, sourcemap, removeDev, addBundleVersion}, {include, exclude}) {
+function preparePlugins(
+    {min, lang, sourcemap, removeDev, addBundleVersion, totalFiles},
+    {include, exclude}
+) {
     assert(include);
     // In case node_modules/zrender is a symlink
     const zrNodeModulePath = nodePath.resolve(ecDir, 'node_modules/zrender');
@@ -58,7 +61,11 @@ function preparePlugins({min, lang, sourcemap, removeDev, addBundleVersion}, {in
             exclude: exclude || []
         }),
         nodeResolvePlugin(),
-        progress()
+        progress({
+            scope: {
+                total: totalFiles || 0
+            }
+        })
     ];
 
     removeDev && plugins.push(
@@ -105,6 +112,7 @@ function preparePlugins({min, lang, sourcemap, removeDev, addBundleVersion}, {in
  * @param {boolean} [opt.removeDev]
  * @param {string} [opt.format='umd'] If set, `opt.input` is required too, and `opt.type` is ignored.
  * @param {boolean} [opt.addBundleVersion=false] Only for debug in watch, prompt that the two build is different.
+ * @param {Object} [opt.totalFiles] Total files to bundle
  */
 exports.createECharts = function (opt = {}) {
     let min = opt.min;
diff --git a/build/progress.js b/build/progress.js
new file mode 100644
index 0000000..b331400
--- /dev/null
+++ b/build/progress.js
@@ -0,0 +1,60 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+const chalk = require('chalk');
+const path = require('path');
+
+module.exports = function progress(options = {}) {
+    const scope = options.scope || {};
+    scope.finished = scope.finished || 0;
+    scope.total = scope.total || 0;
+
+    return {
+        name: 'progress',
+
+        buildStart() {
+            scope.finished = 0;
+            scope.total = 0;
+        },
+
+        load() {
+            // TODO More accurate total number
+            scope.total++;
+        },
+
+        transform(code, id) {
+            scope.finished++;
+            const filePath = path.relative(process.cwd(), id).split(path.sep).join('/');
+
+            const output = `[${scope.finished}/${scope.total}]: ${chalk.grey(filePath)}`;
+            if (process.stdout.isTTY) {
+                process.stdout.clearLine();
+                process.stdout.cursorTo(0);
+                process.stdout.write(output);
+            }
+            else {
+                console.log(output);
+            }
+        },
+
+        buildEnd() {
+            process.stdout.clearLine();
+            process.stdout.cursorTo(0);
+        }
+    };
+};
diff --git a/package.json b/package.json
index ee1a7dd..10ccec3 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,6 @@
     "rollup": "1.28.0",
     "rollup-plugin-commonjs": "8.4.1",
     "rollup-plugin-node-resolve": "3.0.0",
-    "rollup-plugin-progress": "^1.1.1",
     "rollup-plugin-typescript2": "0.25.3",
     "rollup-plugin-uglify": "6.0.4",
     "seedrandom": "3.0.3",
diff --git a/src/stream/Scheduler.ts b/src/stream/Scheduler.ts
index 287447c..a837bb5 100644
--- a/src/stream/Scheduler.ts
+++ b/src/stream/Scheduler.ts
@@ -27,7 +27,7 @@ import GlobalModel from '../model/Global';
 import ExtensionAPI from '../ExtensionAPI';
 import {normalizeToArray} from '../util/model';
 import {
-    StageHandlerInternal, StageHandlerOverallReset, VisualType, StageHandler,
+    StageHandlerInternal, StageHandlerOverallReset, StageHandler,
     Payload, StageHandlerReset, StageHandlerPlan, StageHandlerProgressExecutor, LarginOptionMixin, SeriesOption
 } from '../util/types';
 import { EChartsType } from '../echarts';
@@ -70,7 +70,7 @@ type TaskRecord = {
 type PerformStageTaskOpt = {
     block?: boolean,
     setDirty?: boolean,
-    visualType?: VisualType,
+    visualType?: StageHandlerInternal['visualType'],
     dirtyMap?: HashMap<any>
 };
 
@@ -550,7 +550,7 @@ class Scheduler {
 
     static wrapStageHandler(
         stageHandler: StageHandler | StageHandlerOverallReset,
-        visualType: VisualType
+        visualType: StageHandlerInternal['visualType']
     ): StageHandlerInternal {
         if (isFunction(stageHandler)) {
             stageHandler = {


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