Skip to content

Commit

Permalink
修改说明文档,增加打包之后的产物,方便后续拉取
Browse files Browse the repository at this point in the history
  • Loading branch information
chengmingrui committed Apr 27, 2023
1 parent 278781f commit 5e82b5c
Show file tree
Hide file tree
Showing 49 changed files with 91,107 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
build
.idea
*.DS_Store*
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ Steps:

(For reference follow: https://thoughtbot.com/blog/how-to-make-a-chrome-extension)

5. 如果你想获取打包之后的产物
```bash
npm run pack
```
6. 如果不能访问谷歌应用商店,可以直接使用项目目录中的 `span-tree-gitlab`

## 💳 Credits

SpanTree uses the following open-source packages:
Expand Down
183 changes: 183 additions & 0 deletions build/addHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* 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 fs = require('fs');
const preamble = require('./preamble');
const pathTool = require('path');
const chalk = require('chalk');

// In the `.headerignore`, each line is a pattern in RegExp.
// all relative path (based on the echarts base directory) is tested.
// The pattern should match the relative path completely.
const excludesPath = pathTool.join(__dirname, '../.headerignore');
const ecBasePath = pathTool.join(__dirname, '../');

const isVerbose = process.argv[2] === '--verbose';

// const lists = [
// '../src/**/*.js',
// '../build/*.js',
// '../benchmark/src/*.js',
// '../benchmark/src/gulpfile.js',
// '../extension-src/**/*.js',
// '../extension/**/*.js',
// '../map/js/**/*.js',
// '../test/build/**/*.js',
// '../test/node/**/*.js',
// '../test/ut/core/*.js',
// '../test/ut/spe/*.js',
// '../test/ut/ut.js',
// '../test/*.js',
// '../theme/*.js',
// '../theme/tool/**/*.js',
// '../echarts.all.js',
// '../echarts.blank.js',
// '../echarts.common.js',
// '../echarts.simple.js',
// '../index.js',
// '../index.common.js',
// '../index.simple.js'
// ];

function run() {
const updatedFiles = [];
const passFiles = [];
const pendingFiles = [];

eachFile(function (absolutePath, fileExt) {
const fileStr = fs.readFileSync(absolutePath, 'utf-8');

const existLicense = preamble.extractLicense(fileStr, fileExt);

if (existLicense) {
passFiles.push(absolutePath);
return;
}

// Conside binary files, only add for files with known ext.
if (!preamble.hasPreamble(fileExt)) {
pendingFiles.push(absolutePath);
return;
}

fs.writeFileSync(absolutePath, preamble.addPreamble(fileStr, fileExt), 'utf-8');
updatedFiles.push(absolutePath);
});

console.log('\n');
console.log('----------------------------');
console.log(' Files that exists license: ');
console.log('----------------------------');
if (passFiles.length) {
if (isVerbose) {
passFiles.forEach(function (path) {
console.log(chalk.green(path));
});
}
else {
console.log(chalk.green(passFiles.length + ' files. (use argument "--verbose" see details)'));
}
}
else {
console.log('Nothing.');
}

console.log('\n');
console.log('--------------------');
console.log(' License added for: ');
console.log('--------------------');
if (updatedFiles.length) {
updatedFiles.forEach(function (path) {
console.log(chalk.green(path));
});
}
else {
console.log('Nothing.');
}

console.log('\n');
console.log('----------------');
console.log(' Pending files: ');
console.log('----------------');
if (pendingFiles.length) {
pendingFiles.forEach(function (path) {
console.log(chalk.red(path));
});
}
else {
console.log('Nothing.');
}

console.log('\nDone.');
}

function eachFile(visit) {

const excludePatterns = [];
const extReg = /\.([a-zA-Z0-9_-]+)$/;

prepareExcludePatterns();
travel('./');

function travel(relativePath) {
if (isExclude(relativePath)) {
return;
}

const absolutePath = pathTool.join(ecBasePath, relativePath);
const stat = fs.statSync(absolutePath);

if (stat.isFile()) {
visit(absolutePath, getExt(absolutePath));
}
else if (stat.isDirectory()) {
fs.readdirSync(relativePath).forEach(function (file) {
travel(pathTool.join(relativePath, file));
});
}
}

function prepareExcludePatterns() {
const content = fs.readFileSync(excludesPath, {encoding: 'utf-8'});
content.replace(/\r/g, '\n').split('\n').forEach(function (line) {
line = line.trim();
if (line && line.charAt(0) !== '#') {
excludePatterns.push(new RegExp(line));
}
});
}

function isExclude(relativePath) {
for (let i = 0; i < excludePatterns.length; i++) {
if (excludePatterns[i].test(relativePath)) {
return true;
}
}
}

function getExt(path) {
if (path) {
const mathResult = path.match(extReg);
return mathResult && mathResult[1];
}
}
}

run();
114 changes: 114 additions & 0 deletions build/build-i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

/*
* 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 fs = require('fs');
const preamble = require('./preamble');
const ts = require('typescript');
const path = require('path');
const fsExtra = require('fs-extra');

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/lib/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]*?)\*\//, '');

fsExtra.ensureDirSync(targetDir);

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
};
Loading

0 comments on commit 5e82b5c

Please sign in to comment.