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/07/27 16:33:42 UTC
[incubator-echarts] branch next-npm-env updated: chore: parallel
build for release.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch next-npm-env
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/next-npm-env by this push:
new 2a667b8 chore: parallel build for release.
2a667b8 is described below
commit 2a667b85ef9ba8846f2c364a9a950915a2fa8ea2
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Jul 28 00:33:02 2020 +0800
chore: parallel build for release.
---
build/build.js | 113 ++++++++++++-----------------------------
build/ec-lang-rollup-plugin.js | 2 +-
build/progress.js | 6 ++-
build/release.js | 77 ++++++++++++++++++++++++++++
package.json | 2 +-
5 files changed, 116 insertions(+), 84 deletions(-)
diff --git a/build/build.js b/build/build.js
index 509be95..341e3f6 100755
--- a/build/build.js
+++ b/build/build.js
@@ -19,7 +19,6 @@
* under the License.
*/
-const fsExtra = require('fs-extra');
const fs = require('fs');
const nodePath = require('path');
const config = require('./config.js');
@@ -32,7 +31,6 @@ const recheckDEV = require('./remove-dev').recheckDEV;
const UglifyJS = require("uglify-js");
const preamble = require('./preamble');
-
async function run() {
/**
@@ -84,10 +82,6 @@ async function run() {
descIndent + '`--lang /my/indexSW.js` will use `/my/indexSW.js`. -o must be specified in this case.'
].join('\n'))
.option(
- '--release',
- 'Build all for release'
- )
- .option(
'--prepublish',
'Build all for release'
)
@@ -148,49 +142,15 @@ async function run() {
validateIO(opt.input, opt.output);
validateLang(opt.lang, opt.output);
- normalizeParams(opt);
-
- // Clear `echarts/dist`
- if (isRelease) {
- fsExtra.removeSync(getPath('./dist'));
- }
-
if (isWatch) {
watch(config.createECharts(opt));
}
else if (isPrePublish) {
await prePublish();
}
- else if (isRelease) {
- let configs = [];
-
- [
- {},
- {lang: 'en'},
- {lang: 'en'}
- ].forEach(function (opt) {
- ['', 'simple', 'common'].forEach(function (type) {
- let singleOpt = Object.assign({type, clean: true}, opt);
- normalizeParams(singleOpt);
- let singleConfig = config.createECharts(singleOpt);
- configs.push(singleConfig);
- });
- });
-
- configs.push(
- config.createBMap(),
- config.createDataTool()
- );
-
- await build(configs);
-
- checkBundleCode();
-
- await prePublish();
- }
else {
let cfg = config.createECharts(opt);
- await build([cfg]);
+ await build([cfg], opt.min);
if (opt.removeDev) {
checkBundleCode(cfg);
@@ -198,15 +158,6 @@ async function run() {
}
}
-function normalizeParams(opt) {
- if (opt.sourcemap == null) {
- opt.sourcemap = !(opt.min || opt.type);
- }
- if (opt.removeDev == null) {
- opt.removeDev = !!opt.min;
- }
-}
-
function checkBundleCode() {
const fullBundleDistPath = path.join(__dirname, '../dist/echarts.min.js');
// Make sure __DEV__ is eliminated.
@@ -242,14 +193,6 @@ function validateLang(lang, output) {
}
/**
- * @param {string} relativePath Based on echarts directory.
- * @return {string} Absolute path.
- */
-function getPath(relativePath) {
- return nodePath.resolve(__dirname, '../', relativePath);
-}
-
-/**
* @param {Array.<Object>} configs A list of rollup configs:
* See: <https://rollupjs.org/#big-list-of-options>
* For example:
@@ -262,13 +205,14 @@ function getPath(relativePath) {
* ...
* ]
*/
-async function build(configs) {
+async function build(configs, min) {
// ensureZRenderCode.prepare();
for (let singleConfig of configs) {
+
console.log(
- chalk.cyan.dim('\nBundles '),
+ chalk.cyan.dim('\Bundling '),
chalk.cyan(singleConfig.input),
chalk.cyan.dim('=>'),
chalk.cyan(singleConfig.output.file),
@@ -281,32 +225,41 @@ async function build(configs) {
await bundle.write(singleConfig.output);
- console.time('Minify');
- const fileMinPath = singleConfig.output.file.replace(/.js$/, '.min.js');
- const code = fs.readFileSync(singleConfig.output.file, 'utf-8');
- const result = UglifyJS.minify(code, {
- output: {
- preamble: preamble.js
- }
- });
- if (result.error) {
- throw new Error(result.error);
- }
- fs.writeFileSync(fileMinPath, result.code, 'utf-8');
-
- console.timeEnd('Minify');
-
console.log(
chalk.green.dim('Created '),
chalk.green(singleConfig.output.file),
chalk.green.dim(' successfully.')
);
- console.log(
- chalk.green.dim('Created '),
- chalk.green(fileMinPath),
- chalk.green.dim(' successfully.')
- );
+ if (min) {
+ const fileMinPath = singleConfig.output.file.replace(/.js$/, '.min.js');
+ console.log(
+ chalk.cyan.dim('Minifying '),
+ chalk.cyan(singleConfig.output.file),
+ chalk.cyan.dim('=>'),
+ chalk.cyan(fileMinPath),
+ chalk.cyan.dim(' ...')
+ )
+ console.time('Minify');
+ const code = fs.readFileSync(singleConfig.output.file, 'utf-8');
+ const result = UglifyJS.minify(code, {
+ output: {
+ preamble: preamble.js
+ }
+ });
+ if (result.error) {
+ throw new Error(result.error);
+ }
+ fs.writeFileSync(fileMinPath, result.code, 'utf-8');
+
+ console.timeEnd('Minify');
+ console.log(
+ chalk.green.dim('Created '),
+ chalk.green(fileMinPath),
+ chalk.green.dim(' successfully.')
+ );
+ }
+
}
// ensureZRenderCode.clear();
diff --git a/build/ec-lang-rollup-plugin.js b/build/ec-lang-rollup-plugin.js
index 2ec8c6d..e05e6b0 100644
--- a/build/ec-lang-rollup-plugin.js
+++ b/build/ec-lang-rollup-plugin.js
@@ -65,7 +65,7 @@ let getLangFileInfo = getPlugin.getLangFileInfo = function (lang) {
if (lang) {
if (/^[a-zA-Z]{2}$/.test(lang)) {
- absolutePath = resolve(__dirname, '../', 'src/lang' + lang.toUpperCase() + '.js');
+ absolutePath = resolve(__dirname, '../', 'src/lang' + lang.toUpperCase() + '.ts');
}
else {
isOuter = true;
diff --git a/build/progress.js b/build/progress.js
index b331400..76a9890 100644
--- a/build/progress.js
+++ b/build/progress.js
@@ -53,8 +53,10 @@ module.exports = function progress(options = {}) {
},
buildEnd() {
- process.stdout.clearLine();
- process.stdout.cursorTo(0);
+ if (process.stdout.isTTY) {
+ process.stdout.clearLine();
+ process.stdout.cursorTo(0);
+ }
}
};
};
diff --git a/build/release.js b/build/release.js
new file mode 100644
index 0000000..36287ca
--- /dev/null
+++ b/build/release.js
@@ -0,0 +1,77 @@
+#!/usr/bin/env node
+
+/*
+* 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 {spawn} = require('child_process');
+const path = require('path');
+const chalk = require('chalk');
+const fsExtra = require('fs-extra');
+
+
+function release() {
+ fsExtra.removeSync(path.resolve(__dirname, '../dist'));
+
+ let idx = 0;
+
+ const logs = [];
+
+ function updateLog() {
+ if (process.stdout.isTTY) {
+ process.stdout.cursorTo(0, 0);
+ process.stdout.clearScreenDown();
+ for (let i = 0; i < logs.length; i++) {
+ process.stdout.write(logs[i] || '');
+ }
+ }
+ }
+ [
+ '', 'en'
+ ].forEach(function (lang) {
+ ['', 'simple', 'common'].forEach(function (type) {
+
+ const args = [
+ `--lang`,
+ lang,
+ `--type`,
+ type,
+ `--clean`,
+ `--sourcemap`,
+ `--min`
+ ];
+
+ const p = spawn(path.join(__dirname, 'build.js'), args);
+
+ const scope = `[${lang || 'zh'}] [${type || 'all'}]`;
+
+ function createOnDataHandler(idx) {
+ return function (data) {
+ logs[idx] = `${chalk.gray(scope)}: ${data}`;
+ updateLog();
+ }
+ }
+
+ p.stdout.on('data', createOnDataHandler(idx));
+
+ idx++;
+ });
+ });
+}
+
+release();
\ No newline at end of file
diff --git a/package.json b/package.json
index f5bc23c..ec05762 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"build:full": "node build/build.js --clean",
"watch": "node build/build.js --watch",
"dev:fast": "node build/dev-fast.js",
- "release": "node build/build.js --release",
+ "release": "node build/release.js",
"help": "node build/build.js --help",
"test:visual": "node test/runTest/server.js",
"test:visual:report": "node test/runTest/genReport.js",
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org