mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-20 04:01:42 +01:00
Start again
This commit is contained in:
160
vendors/echarts/build/amd2common.js
vendored
Normal file
160
vendors/echarts/build/amd2common.js
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
var glob = require('glob');
|
||||
var fsExtra = require('fs-extra');
|
||||
var esprima = require('esprima');
|
||||
|
||||
function run(cb) {
|
||||
glob('**/*.js', {
|
||||
cwd: __dirname + '/../src/'
|
||||
}, function (err, files) {
|
||||
files.forEach(function (filePath) {
|
||||
var code = parse(fsExtra.readFileSync(
|
||||
__dirname + '/../src/' + filePath, 'utf-8'));
|
||||
code = code.replace(/require\(([\'"])zrender\//g, 'require($1zrender/lib/');
|
||||
fsExtra.outputFileSync(
|
||||
__dirname + '/../lib/' + filePath,
|
||||
code, 'utf-8');
|
||||
});
|
||||
|
||||
cb && cb();
|
||||
});
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run();
|
||||
}
|
||||
else {
|
||||
module.exports = run;
|
||||
}
|
||||
|
||||
var MAGIC_DEPS = {
|
||||
'exports' : true,
|
||||
'module' : true,
|
||||
'require' : true
|
||||
};
|
||||
|
||||
var SIMPLIFIED_CJS = ['require', 'exports', 'module'];
|
||||
|
||||
// Convert AMD-style JavaScript string into node.js compatible module
|
||||
function parse (raw){
|
||||
var output = '';
|
||||
var ast = esprima.parse(raw, {
|
||||
range: true,
|
||||
raw: true
|
||||
});
|
||||
|
||||
var defines = ast.body.filter(isDefine);
|
||||
|
||||
if ( defines.length > 1 ){
|
||||
throw new Error('Each file can have only a single define call. Found "'+ defines.length +'"');
|
||||
} else if (!defines.length){
|
||||
return raw;
|
||||
}
|
||||
|
||||
var def = defines[0];
|
||||
var args = def.expression['arguments'];
|
||||
var factory = getFactory( args );
|
||||
var useStrict = getUseStrict( factory );
|
||||
|
||||
// do replacements in-place to avoid modifying the code more than needed
|
||||
if (useStrict) {
|
||||
output += useStrict.expression.raw +';\n';
|
||||
}
|
||||
output += raw.substring( 0, def.range[0] ); // anything before define
|
||||
output += getRequires(args, factory); // add requires
|
||||
output += getBody(raw, factory.body, useStrict); // module body
|
||||
|
||||
output += raw.substring( def.range[1], raw.length ); // anything after define
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
function getRequires(args, factory){
|
||||
var requires = [];
|
||||
var deps = getDependenciesNames( args );
|
||||
var params = factory.params.map(function(param, i){
|
||||
return {
|
||||
name : param.name,
|
||||
// simplified cjs doesn't have deps
|
||||
dep : (deps.length)? deps[i] : SIMPLIFIED_CJS[i]
|
||||
};
|
||||
});
|
||||
|
||||
params.forEach(function(param){
|
||||
if ( MAGIC_DEPS[param.dep] && !MAGIC_DEPS[param.name] ) {
|
||||
// if user remaped magic dependency we declare a var
|
||||
requires.push( 'var '+ param.name +' = '+ param.dep +';' );
|
||||
} else if ( param.dep && !MAGIC_DEPS[param.dep] ) {
|
||||
// only do require for params that have a matching dependency also
|
||||
// skip "magic" dependencies
|
||||
requires.push( 'var '+ param.name +' = require(\''+ param.dep +'\');' );
|
||||
}
|
||||
});
|
||||
|
||||
return requires.join('\n');
|
||||
}
|
||||
|
||||
|
||||
function getDependenciesNames(args){
|
||||
var deps = [];
|
||||
var arr = args.filter(function(arg){
|
||||
return arg.type === 'ArrayExpression';
|
||||
})[0];
|
||||
|
||||
if (arr) {
|
||||
deps = arr.elements.map(function(el){
|
||||
return el.value;
|
||||
});
|
||||
}
|
||||
|
||||
return deps;
|
||||
}
|
||||
|
||||
|
||||
function isDefine(node){
|
||||
return node.type === 'ExpressionStatement' &&
|
||||
node.expression.type === 'CallExpression' &&
|
||||
node.expression.callee.type === 'Identifier' &&
|
||||
node.expression.callee.name === 'define';
|
||||
}
|
||||
|
||||
|
||||
function getFactory(args){
|
||||
return args.filter(function(arg){
|
||||
return arg.type === 'FunctionExpression';
|
||||
})[0];
|
||||
}
|
||||
|
||||
|
||||
function getBody(raw, factoryBody, useStrict){
|
||||
var returnStatement = factoryBody.body.filter(function(node){
|
||||
return node.type === 'ReturnStatement';
|
||||
})[0];
|
||||
|
||||
var body = '';
|
||||
var bodyStart = useStrict ? useStrict.expression.range[1] + 1 : factoryBody.range[0] + 1;
|
||||
|
||||
if (returnStatement) {
|
||||
body += raw.substring( bodyStart, returnStatement.range[0] );
|
||||
// "return ".length === 7 so we add "6" to returnStatement start
|
||||
body += 'module.exports ='+ raw.substring( returnStatement.range[0] + 6, factoryBody.range[1] - 1 );
|
||||
} else {
|
||||
// if using exports or module.exports or just a private module we
|
||||
// simply return the factoryBody content
|
||||
body = raw.substring( bodyStart, factoryBody.range[1] - 1 );
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
function getUseStrict(factory){
|
||||
return factory.body.body.filter(isUseStrict)[0];
|
||||
}
|
||||
|
||||
|
||||
function isUseStrict(node){
|
||||
return node.type === 'ExpressionStatement' &&
|
||||
node.expression.type === 'Literal' &&
|
||||
node.expression.value === 'use strict';
|
||||
}
|
||||
15
vendors/echarts/build/build.sh
vendored
Normal file
15
vendors/echarts/build/build.sh
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
basePath=$(cd `dirname $0`; pwd)
|
||||
cd ${basePath}/../
|
||||
rm -r dist
|
||||
|
||||
npm run prepublish
|
||||
|
||||
./node_modules/.bin/webpack
|
||||
./node_modules/.bin/webpack -p
|
||||
./node_modules/.bin/webpack --config extension/webpack.config.js
|
||||
./node_modules/.bin/webpack --config extension/webpack.config.js -p
|
||||
|
||||
|
||||
165
vendors/echarts/build/mangleString.js
vendored
Normal file
165
vendors/echarts/build/mangleString.js
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
var esprima = require('esprima');
|
||||
var escodegen = require('escodegen');
|
||||
var estraverse = require('estraverse');
|
||||
|
||||
var SYNTAX = estraverse.Syntax;
|
||||
|
||||
var STR_MIN_LENGTH = 5;
|
||||
var STR_MIN_DIST = 1000;
|
||||
var STR_MIN_COUNT = 2;
|
||||
|
||||
function createDeclaration(declarations) {
|
||||
return {
|
||||
type: SYNTAX.VariableDeclaration,
|
||||
declarations: declarations,
|
||||
kind: 'var'
|
||||
};
|
||||
}
|
||||
|
||||
function createDeclarator(id, init) {
|
||||
return {
|
||||
type: SYNTAX.VariableDeclarator,
|
||||
id: {
|
||||
type: SYNTAX.Identifier,
|
||||
name: id
|
||||
},
|
||||
init: {
|
||||
type: SYNTAX.Literal,
|
||||
value: init
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function base54Digits() {
|
||||
return 'etnrisouaflchpdvmgybwESxTNCkLAOM_DPHBjFIqRUzWXV$JKQGYZ0516372984';
|
||||
}
|
||||
|
||||
var base54 = (function(){
|
||||
var DIGITS = base54Digits();
|
||||
return function(num) {
|
||||
var ret = '';
|
||||
var base = 54;
|
||||
do {
|
||||
ret += DIGITS.charAt(num % base);
|
||||
num = Math.floor(num / base);
|
||||
base = 64;
|
||||
} while (num > 0);
|
||||
return ret;
|
||||
};
|
||||
})();
|
||||
|
||||
function mangleString(source) {
|
||||
|
||||
var ast = esprima.parse(source, {
|
||||
loc: true
|
||||
});
|
||||
|
||||
var stringVariables = {};
|
||||
|
||||
var stringRelaceCount = 0;
|
||||
|
||||
estraverse.traverse(ast, {
|
||||
enter: function (node, parent) {
|
||||
if (node.type === SYNTAX.Literal
|
||||
&& typeof node.value === 'string'
|
||||
) {
|
||||
// Ignore if string is the key of property
|
||||
if (parent.type === SYNTAX.Property) {
|
||||
return;
|
||||
}
|
||||
var value = node.value;
|
||||
if (value.length > STR_MIN_LENGTH) {
|
||||
if (!stringVariables[value]) {
|
||||
stringVariables[value] = {
|
||||
count: 0,
|
||||
lastLoc: node.loc.start.line,
|
||||
name: '__echartsString__' + base54(stringRelaceCount++)
|
||||
};
|
||||
}
|
||||
var diff = node.loc.start.line - stringVariables[value].lastLoc;
|
||||
// GZIP ?
|
||||
if (diff >= STR_MIN_DIST) {
|
||||
stringVariables[value].lastLoc = node.loc.start.line;
|
||||
stringVariables[value].count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (node.type === SYNTAX.MemberExpression && !node.computed) {
|
||||
if (node.property.type === SYNTAX.Identifier) {
|
||||
var value = node.property.name;
|
||||
if (value.length > STR_MIN_LENGTH) {
|
||||
if (!stringVariables[value]) {
|
||||
stringVariables[value] = {
|
||||
count: 0,
|
||||
lastLoc: node.loc.start.line,
|
||||
name: '__echartsString__' + base54(stringRelaceCount++)
|
||||
};
|
||||
}
|
||||
var diff = node.loc.start.line - stringVariables[value].lastLoc;
|
||||
if (diff >= STR_MIN_DIST) {
|
||||
stringVariables[value].lastLoc = node.loc.start.line;
|
||||
stringVariables[value].count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
estraverse.replace(ast, {
|
||||
enter: function (node, parent) {
|
||||
if ((node.type === SYNTAX.Literal
|
||||
&& typeof node.value === 'string')
|
||||
) {
|
||||
// Ignore if string is the key of property
|
||||
if (parent.type === SYNTAX.Property) {
|
||||
return;
|
||||
}
|
||||
var str = node.value;
|
||||
if (stringVariables[str] && stringVariables[str].count > STR_MIN_COUNT) {
|
||||
return {
|
||||
type: SYNTAX.Identifier,
|
||||
name: stringVariables[str].name
|
||||
};
|
||||
}
|
||||
}
|
||||
if (node.type === SYNTAX.MemberExpression && !node.computed) {
|
||||
if (node.property.type === SYNTAX.Identifier) {
|
||||
var str = node.property.name;
|
||||
if (stringVariables[str] && stringVariables[str].count > STR_MIN_COUNT) {
|
||||
return {
|
||||
type: SYNTAX.MemberExpression,
|
||||
object: node.object,
|
||||
property: {
|
||||
type: SYNTAX.Identifier,
|
||||
name: stringVariables[str].name
|
||||
},
|
||||
computed: true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Add variables in the top
|
||||
for (var str in stringVariables) {
|
||||
// Used more than once
|
||||
if (stringVariables[str].count > STR_MIN_COUNT) {
|
||||
ast.body.unshift(createDeclaration([
|
||||
createDeclarator(stringVariables[str].name, str)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
return escodegen.generate(
|
||||
ast,
|
||||
{
|
||||
format: {escapeless: true},
|
||||
comment: true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports = module.exports = mangleString;
|
||||
40
vendors/echarts/build/optimize.js
vendored
Normal file
40
vendors/echarts/build/optimize.js
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
var UglifyJS = require('uglify-js');
|
||||
var fs = require('fs');
|
||||
var etpl = require('etpl');
|
||||
var argv = require('optimist').argv;
|
||||
|
||||
etpl.config({
|
||||
commandOpen: '/**',
|
||||
commandClose: '*/'
|
||||
});
|
||||
|
||||
var mode = argv.m || 'all';
|
||||
var configPath = mode === 'all' ? 'config/echarts.js' : 'config/echarts.' + mode + '.js';
|
||||
var outPath = mode === 'all' ? '../dist/echarts.js' : '../dist/echarts.' + mode + '.js';
|
||||
|
||||
var config = eval('(' + fs.readFileSync(configPath, 'utf-8') + ')');
|
||||
var mainCode = fs.readFileSync(outPath, 'utf-8');
|
||||
var startCode = fs.readFileSync('wrap/start.js', 'utf-8');
|
||||
var nutCode = fs.readFileSync('wrap/nut.js', 'utf-8');
|
||||
var endCode = fs.readFileSync('wrap/end.js', 'utf-8');
|
||||
|
||||
endCode = etpl.compile(endCode)({
|
||||
parts: config.include
|
||||
});
|
||||
|
||||
// FIXME
|
||||
var sourceCode = [startCode, nutCode, require('./mangleString')(mainCode), endCode].join('\n');
|
||||
|
||||
var ast = UglifyJS.parse(sourceCode);
|
||||
/* jshint camelcase: false */
|
||||
// compressor needs figure_out_scope too
|
||||
ast.figure_out_scope();
|
||||
ast = ast.transform(UglifyJS.Compressor( {} ));
|
||||
|
||||
// need to figure out scope again so mangler works optimally
|
||||
ast.figure_out_scope();
|
||||
ast.compute_char_frequency();
|
||||
ast.mangle_names();
|
||||
|
||||
fs.writeFileSync(outPath, [startCode, nutCode, mainCode, endCode].join('\n'), 'utf-8');
|
||||
fs.writeFileSync(outPath.replace('.js', '.min.js'), ast.print_to_string(), 'utf-8');
|
||||
Reference in New Issue
Block a user