From 9d5d8be47f1c7e326c215396ac166eaf95fe61c5 Mon Sep 17 00:00:00 2001 From: sushuang Date: Tue, 31 Oct 2017 21:34:51 +0800 Subject: [PATCH] tweak build. --- .jshintrc | 1 + build/.jshintrc | 76 ++++++++++++++++++++++++++++++++++++++++++++ build/build.js | 29 +++++++++-------- build/config.js | 29 ++++++++++++----- build/helper.js | 83 +++++++++++++++++++++++++------------------------ 5 files changed, 157 insertions(+), 61 deletions(-) create mode 100644 build/.jshintrc diff --git a/.jshintrc b/.jshintrc index 6b4e82886..8c340b2f5 100644 --- a/.jshintrc +++ b/.jshintrc @@ -26,6 +26,7 @@ "debug": false, "eqnull": true, "esversion": 6, + "module": true, "evil": true, "expr": true, "funcscope": false, diff --git a/build/.jshintrc b/build/.jshintrc new file mode 100644 index 000000000..1e861591e --- /dev/null +++ b/build/.jshintrc @@ -0,0 +1,76 @@ +{ + "bitwise": false, + "camelcase": true, + "curly": true, + "eqeqeq": false, + "forin": false, + "immed": true, + "latedef": false, + "newcap": true, + "noarg": false, + "noempty": true, + "nonew": true, + "plusplus": false, + "quotmark": "single", + "regexp": false, + "undef": true, + "unused": "vars", + "strict": false, + "trailing": false, + "maxparams": 20, + "maxdepth": 6, + "maxlen": 200, + + "asi": false, + "boss": false, + "debug": false, + "eqnull": true, + "esversion": 6, + "evil": true, + "expr": true, + "funcscope": false, + "globalstrict": false, + "iterator": false, + "lastsemic": false, + "laxbreak": true, + "laxcomma": false, + "loopfunc": false, + "multistr": false, + "onecase": false, + "proto": false, + "regexdash": false, + "scripturl": false, + "smarttabs": false, + "shadow": true, + "sub": true, + "supernew": false, + "validthis": true, + + "browser": true, + "couch": false, + "devel": true, + "dojo": false, + "jquery": true, + "mootools": false, + "node": false, + "nonstandard": false, + "prototypejs": false, + "rhino": false, + "wsh": false, + + "nomen": false, + "onevar": false, + "passfail": false, + "white": false, + + "varstmt": true, + + "predef": [ + "__DEV__", + "global", + "require", + "exports", + "Buffer", + "__dirname" + ] +} \ No newline at end of file diff --git a/build/build.js b/build/build.js index 4ba431d14..e46d984b9 100755 --- a/build/build.js +++ b/build/build.js @@ -1,10 +1,10 @@ #!/usr/bin/env node -let fsExtra = require('fs-extra'); -let {resolve} = require('path'); -let config = require('./config.js'); -let commander = require('commander'); -let {build, watch} = require('./helper'); +const fsExtra = require('fs-extra'); +const {resolve} = require('path'); +const config = require('./config.js'); +const commander = require('commander'); +const {build, watch} = require('./helper'); function run() { @@ -60,11 +60,11 @@ function run() { let configs = []; if (isWatch) { - watch(config.createEChartsBuild(opt)); + watch(config.createECharts(opt)); } else { if (!buildAll) { - configs = [config.createEChartsBuild(opt)]; + configs = [config.createECharts(opt)]; } else { configs = []; @@ -76,15 +76,15 @@ function run() { {min: true, lang: 'en'} ].forEach(function (opt) { ['', 'simple', 'common'].forEach(function (type) { - configs.push(config.createEChartsBuild(Object.assign({type}, opt))); + configs.push(config.createECharts(Object.assign({type}, opt))); }); }); configs.push( - config.createBMapBuild(false), - config.createBMapBuild(true), - config.createDataToolBuild(false), - config.createDataToolBuild(true) + config.createBMap(false), + config.createBMap(true), + config.createDataTool(false), + config.createDataTool(true) ); } @@ -96,7 +96,10 @@ function run() { } } -// Based on echarts dir/ +/** + * @param {string} relativePath Based on echarts directory. + * @return {string} Absolute path. + */ function getPath(relativePath) { return resolve(__dirname, '../', relativePath); } diff --git a/build/config.js b/build/config.js index 4a4e9ab88..85d633123 100644 --- a/build/config.js +++ b/build/config.js @@ -1,8 +1,6 @@ -/* global require, __dirname, exports */ - -let nodeResolvePlugin = require('rollup-plugin-node-resolve'); -let uglifyPlugin = require('rollup-plugin-uglify'); -let {dirname, resolve} = require('path'); +const nodeResolvePlugin = require('rollup-plugin-node-resolve'); +const uglifyPlugin = require('rollup-plugin-uglify'); +const {dirname, resolve} = require('path'); // Based on echarts/ function getPath(relativePath) { @@ -49,7 +47,7 @@ function getPlugins(min, lang) { * @param {boolean} [opt.min=false] * @param {string} [opt.lang=undefined] null/undefined/'' or 'en' or 'fi' or ... */ -exports.createEChartsBuild = function (opt) { +exports.createECharts = function (opt) { opt = opt || {}; let postfixType = opt.type ? '.' + opt.type : ''; let postfixMin = opt.min ? '.min' : ''; @@ -74,7 +72,7 @@ exports.createEChartsBuild = function (opt) { /** * @param {boolean} [min=false] */ -exports.createBMapBuild = function (min) { +exports.createBMap = function (min) { let postfix = min ? '.min' : ''; return { @@ -101,7 +99,7 @@ exports.createBMapBuild = function (min) { /** * @param {boolean} [min=false] */ -exports.createDataToolBuild = function (min) { +exports.createDataTool = function (min) { let postfix = min ? '.min' : ''; return { plugins: getPlugins(min), @@ -123,3 +121,18 @@ exports.createDataToolBuild = function (min) { } }; }; + +/** + * @param {string} [absolutePath] + */ +exports.createSingleModule = function (absolutePath) { + return { + plugins: getPlugins(), + input: absolutePath, + legacy: true, // Support IE8- + output: { + name: 'echarts', + format: 'amd' + } + }; +}; diff --git a/build/helper.js b/build/helper.js index 50efde2f2..0efd88a61 100644 --- a/build/helper.js +++ b/build/helper.js @@ -1,6 +1,4 @@ -/* global require, exports */ - -let rollup = require('rollup'); +const rollup = require('rollup'); /** * @param {Array.} configs A list of rollup configs: @@ -14,45 +12,50 @@ let rollup = require('rollup'); * }, * ... * ] + * @return {Promise} */ exports.build = function (configs) { - let index = 0; + return new Promise(function (promiseResolve, promiseReject) { + let index = 0; - buildSingle(); + buildSingle(); - function buildSingle() { - let singleConfig = configs[index++]; + function buildSingle() { + let singleConfig = configs[index++]; - if (!singleConfig) { - return; - } + if (!singleConfig) { + promiseResolve(); + return; + } - console.log( - color('fgCyan', 'dim')('\nBundles '), - color('fgCyan')(singleConfig.input), - color('fgCyan', 'dim')('=>'), - color('fgCyan')(singleConfig.output.file), - color('fgCyan', 'dim')(' ...') - ); + console.log( + color('fgCyan', 'dim')('\nBundles '), + color('fgCyan')(singleConfig.input), + color('fgCyan', 'dim')('=>'), + color('fgCyan')(singleConfig.output.file), + color('fgCyan', 'dim')(' ...') + ); - rollup - .rollup(singleConfig) - .then(function (bundle) { - return bundle.write(singleConfig.output); - }) - .then(function () { - console.log( - color('fgGreen', 'dim')('Created '), - color('fgGreen')(singleConfig.output.file), - color('fgGreen', 'dim')(' successfully.') - ); - buildSingle(); - }) - .catch(function (err) { - console.log(color('fgRed')(err)); - }); - } -} + rollup + .rollup(singleConfig) + .then(function (bundle) { + return bundle.write(singleConfig.output); + }) + .then(function () { + console.log( + color('fgGreen', 'dim')('Created '), + color('fgGreen')(singleConfig.output.file), + color('fgGreen', 'dim')(' successfully.') + ); + buildSingle(); + }) + .catch(function (err) { + console.log(color('fgRed')(err)); + promiseReject(); + }); + } + }); +}; /** * @param {Object} singleConfig A single rollup config: @@ -65,7 +68,7 @@ exports.build = function (configs) { * } */ exports.watch = function (singleConfig) { - var watcher = rollup.watch(singleConfig); + let watcher = rollup.watch(singleConfig); watcher.on('event', function (event) { // event.code can be one of: @@ -89,7 +92,7 @@ exports.watch = function (singleConfig) { printWatchResult(event); } }); -} +}; function printWatchResult(event) { console.log( @@ -155,12 +158,12 @@ const COLOR_MAP = { * Print colored text with `console.log`. * * Usage: - * var color = require('colorConsole'); + * let color = require('colorConsole'); * color('fgCyan')('some text'); // cyan text. * color('fgCyan', 'bright')('some text'); // bright cyan text. * color('fgCyan', 'bgRed')('some text') // cyan text and red background. */ -function color() { +let color = exports.color = function () { let prefix = []; for (let i = 0; i < arguments.length; i++) { let color = COLOR_MAP[arguments[i]]; @@ -171,4 +174,4 @@ function color() { return function (text) { return prefix + text + COLOR_RESET; }; -} +}; -- GitLab