Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/dist
/node_modules
/build
/i18n
/extension-esm
/extension
/lib
Expand All @@ -12,4 +13,4 @@
/echarts.all.js
/echarts.blank.js
/echarts.common.js
/echarts.simple.js
/echarts.simple.js
91 changes: 91 additions & 0 deletions build/build-i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const fs = require('fs');
const preamble = require('./preamble');
const ts = require('typescript');
const path = require('path');

const umdWrapperHead = `
${preamble.js}
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports'], factory);
} else if (
typeof exports === 'object' &&
typeof exports.nodeName !== 'string'
) {
// CommonJS
factory(exports);
} else {
// Browser globals
factory({});
}
})(this, function(exports) {
`;

const umdWrapperHeadWithEcharts = `
${preamble.js}
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'echarts'], factory);
} else if (
typeof exports === 'object' &&
typeof exports.nodeName !== 'string'
) {
// CommonJS
factory(exports, require('echarts'));
} else {
// Browser globals
factory({}, root.echarts);
}
})(this, function(exports, echarts) {
`;

const umdWrapperTail = `
});`;

async function buildI18nWrap() {
const targetDir = path.join(__dirname, '../i18n');
const sourceDir = path.join(__dirname, '../src/i18n');
const files = fs.readdirSync(sourceDir);
files.forEach(t => {
if(!t.startsWith('lang')) {
return;
}
const fileName = t.replace(/\.ts$/, '');
const type = fileName.replace(/^lang/, '');
const echartsRegister = `
echarts.registerLocale('${type}', localeObj);
`;
const pureExports = `
for (var key in localeObj) {
if (localeObj.hasOwnProperty(key)) {
exports[key] = localeObj[key];
}
}
`;
const code = fs.readFileSync(path.join(sourceDir, t), 'utf-8');
// const outputText = ts.transpileModule(code, {
// module: ts.ModuleKind.CommonJS,
// }).outputText;
// Simple regexp replace is enough
const outputCode = code.replace(/export\s+?default/, 'var localeObj =')
.replace(/\/\*([\w\W]*?)\*\//, '');

fs.writeFileSync(path.join(targetDir, fileName + '.js'), umdWrapperHeadWithEcharts + outputCode + echartsRegister + umdWrapperTail, 'utf-8');
fs.writeFileSync(path.join(targetDir, fileName + '-obj.js'), umdWrapperHead + outputCode + pureExports + umdWrapperTail, 'utf-8');
})
console.log('i18n build completed');
}

buildI18nWrap();

module.exports = {
buildI18n: buildI18nWrap
};
33 changes: 5 additions & 28 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const config = require('./config.js');
const commander = require('commander');
const chalk = require('chalk');
const rollup = require('rollup');
const ecLangPlugin = require('./ec-lang-rollup-plugin');
const prePublish = require('./pre-publish');
const transformDEV = require('./transform-dev');
const UglifyJS = require("uglify-js");
const preamble = require('./preamble');
const {buildI18n} = require('./build-i18n')

async function run() {

Expand Down Expand Up @@ -60,24 +60,16 @@ async function run() {
+ '\n' + descIndent + '# Only generate `dist/echarts.js`.',
egIndent + 'node build/build.js --type common --min'
+ '\n' + descIndent + '# Only generate `dist/echarts.common.min.js`.',
egIndent + 'node build/build.js --type simple --min --lang en'
egIndent + 'node build/build.js --type simple --min'
+ '\n' + descIndent + '# Only generate `dist/echarts-en.simple.min.js`.',
egIndent + 'node build/build.js --lang "my/lang.js" -i "my/index.js" -o "my/bundle.js"'
egIndent + 'node build/build.js -i "my/index.js" -o "my/bundle.js"'
+ '\n' + descIndent + '# Take `<cwd>/my/index.js` as input and generate `<cwd>/my/bundle.js`,'
+ '\n' + descIndent + 'where `<cwd>/my/lang.js` is used as language file.',
].join('\n'))
.option(
'-w, --watch', [
'Watch modifications of files and auto-compile to dist file. For example,',
descIndent + '`echarts/dist/echarts.js`.'
].join('\n'))
.option(
'--lang <language file path or shortcut>', [
'Use the specified file instead of `echarts/src/lang.js`. For example:',
descIndent + '`--lang en` will use `echarts/src/langEN.js`.',
descIndent + '`--lang my/langDE.js` will use `<cwd>/my/langDE.js`. -o must be specified in this case.',
descIndent + '`--lang /my/indexSW.js` will use `/my/indexSW.js`. -o must be specified in this case.'
].join('\n'))
.option(
'--prepublish',
'Build all for release'
Expand Down Expand Up @@ -118,7 +110,6 @@ async function run() {
let isPrePublish = !!commander.prepublish;

let opt = {
lang: commander.lang,
min: commander.min,
type: commander.type || '',
input: commander.input,
Expand All @@ -132,7 +123,6 @@ async function run() {
};

validateIO(opt.input, opt.output);
validateLang(opt.lang, opt.output);

if (isWatch) {
watch(config.createECharts(opt));
Expand Down Expand Up @@ -172,21 +162,6 @@ function validateIO(input, output) {
}
}

function validateLang(lang, output) {
if (!lang) {
return;
}

let langInfo = ecLangPlugin.getLangFileInfo(lang);

if (langInfo.isOuter && !output) {
throw new Error('`-o` or `--output` must be specified if using a file path in `--lang`.');
}
if (!langInfo.absolutePath || !fs.statSync(langInfo.absolutePath).isFile()) {
throw new Error(`File ${langInfo.absolutePath} does not exist yet. Contribution is welcome!`);
}
}

/**
* @param {Array.<Object>} configs A list of rollup configs:
* See: <https://rollupjs.org/#big-list-of-options>
Expand All @@ -201,6 +176,8 @@ function validateLang(lang, output) {
* ]
*/
async function build(configs, min, sourcemap) {
// buildI18n JSON before build when build
buildI18n();

// ensureZRenderCode.prepare();

Expand Down
7 changes: 1 addition & 6 deletions build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@

const assert = require('assert');
const nodeResolvePlugin = require('rollup-plugin-node-resolve');
const ecLangPlugin = require('./ec-lang-rollup-plugin');
const nodePath = require('path');
const ecDir = nodePath.resolve(__dirname, '..');
const typescriptPlugin = require('rollup-plugin-typescript2');
const fs = require('fs');
const progress = require('./progress');

function preparePlugins(
{lang, sourcemap, addBundleVersion, totalFiles, clean},
{sourcemap, addBundleVersion, totalFiles, clean},
{include, exclude}
) {
assert(include);
Expand Down Expand Up @@ -71,10 +70,6 @@ function preparePlugins(
})
];

lang && plugins.push(
ecLangPlugin({lang})
);

addBundleVersion && plugins.push({
outro: function () {
return 'exports.bundleVersion = \'' + (+new Date()) + '\';';
Expand Down
80 changes: 0 additions & 80 deletions build/ec-lang-rollup-plugin.js

This file was deleted.

43 changes: 17 additions & 26 deletions build/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,31 @@ function release() {
}
}
}
[
'', 'en'
].forEach(function (lang) {
['', 'simple', 'common', 'extension'].forEach(function (type) {

const args = [
`--lang`,
lang,
`--type`,
type,
`--clean`,
`--sourcemap`,
`--min`
];
['', 'simple', 'common', 'extension'].forEach(function (type) {

if (lang === 'en' && type === 'extension') {
return;
}
const args = [
`--type`,
type,
`--clean`,
`--sourcemap`,
`--min`
];

const p = spawn(path.join(__dirname, 'build.js'), args);
const p = spawn(path.join(__dirname, 'build.js'), args);

const scope = `[${lang || 'zh'}] [${type || 'all'}]`;
const scope = `[${type || 'all'}]`;

function createOnDataHandler(idx) {
return function (data) {
logs[idx] = `${chalk.gray(scope)}: ${data}`;
updateLog();
}
function createOnDataHandler(idx) {
return function (data) {
logs[idx] = `${chalk.gray(scope)}: ${data}`;
updateLog();
}
}

p.stdout.on('data', createOnDataHandler(idx));
p.stdout.on('data', createOnDataHandler(idx));

idx++;
});
idx++;
});
}

Expand Down
Loading