Skip to content

Commit 771c523

Browse files
committed
chore: add license headers and a script of pre-commit
1 parent 8d7f252 commit 771c523

File tree

18 files changed

+363
-61
lines changed

18 files changed

+363
-61
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
npm run lint
55
npm run checktype
6+
npm run checkheader

build/addHeader.js

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,10 @@
1717
* under the License.
1818
*/
1919

20-
2120
const fs = require('fs');
22-
const preamble = require('./preamble');
23-
const pathTool = require('path');
2421
const chalk = require('chalk');
25-
26-
// In the `.headerignore`, each line is a pattern in RegExp.
27-
// all relative path (based on the echarts base directory) is tested.
28-
// The pattern should match the relative path completely.
29-
const excludesPath = pathTool.join(__dirname, '../.headerignore');
30-
const ecBasePath = pathTool.join(__dirname, '../');
22+
const preamble = require('./preamble');
23+
const eachFile = require('./headerUtil').eachFile;
3124

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

@@ -128,56 +121,6 @@ function run() {
128121
console.log('\nDone.');
129122
}
130123

131-
function eachFile(visit) {
132-
133-
const excludePatterns = [];
134-
const extReg = /\.([a-zA-Z0-9_-]+)$/;
135-
136-
prepareExcludePatterns();
137-
travel('./');
138-
139-
function travel(relativePath) {
140-
if (isExclude(relativePath)) {
141-
return;
142-
}
143-
144-
const absolutePath = pathTool.join(ecBasePath, relativePath);
145-
const stat = fs.statSync(absolutePath);
146-
147-
if (stat.isFile()) {
148-
visit(absolutePath, getExt(absolutePath));
149-
}
150-
else if (stat.isDirectory()) {
151-
fs.readdirSync(relativePath).forEach(function (file) {
152-
travel(pathTool.join(relativePath, file));
153-
});
154-
}
155-
}
156-
157-
function prepareExcludePatterns() {
158-
const content = fs.readFileSync(excludesPath, {encoding: 'utf-8'});
159-
content.replace(/\r/g, '\n').split('\n').forEach(function (line) {
160-
line = line.trim();
161-
if (line && line.charAt(0) !== '#') {
162-
excludePatterns.push(new RegExp(line));
163-
}
164-
});
165-
}
166-
167-
function isExclude(relativePath) {
168-
for (let i = 0; i < excludePatterns.length; i++) {
169-
if (excludePatterns[i].test(relativePath)) {
170-
return true;
171-
}
172-
}
173-
}
174124

175-
function getExt(path) {
176-
if (path) {
177-
const mathResult = path.match(extReg);
178-
return mathResult && mathResult[1];
179-
}
180-
}
181-
}
182125

183126
run();

build/checkHeader.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
const fs = require('fs');
21+
const preamble = require('./preamble');
22+
const eachFile = require('./headerUtil').eachFile;
23+
24+
function run() {
25+
const missingFiles = [];
26+
27+
eachFile(function (absolutePath, fileExt) {
28+
const fileStr = fs.readFileSync(absolutePath, 'utf-8');
29+
const existLicense = preamble.extractLicense(fileStr, fileExt);
30+
31+
if (!existLicense && preamble.hasPreamble(fileExt)) {
32+
missingFiles.push(absolutePath);
33+
}
34+
});
35+
36+
if (missingFiles.length) {
37+
console.error('Files missing license header:');
38+
missingFiles.forEach(function (path) {
39+
console.error(path);
40+
});
41+
console.error('\nPlease run `node build/addHeader.js` before commit.');
42+
process.exit(1);
43+
}
44+
}
45+
46+
run();

build/headerUtil.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
const pathTool = require('path');
21+
const fs = require('fs');
22+
23+
// In the `.headerignore`, each line is a pattern in RegExp.
24+
// all relative path (based on the echarts base directory) is tested.
25+
// The pattern should match the relative path completely.
26+
const excludesPath = pathTool.join(__dirname, '../.headerignore');
27+
const ecBasePath = pathTool.join(__dirname, '../');
28+
29+
function eachFile(visit) {
30+
const excludePatterns = [];
31+
const extReg = /\.([a-zA-Z0-9_-]+)$/;
32+
33+
prepareExcludePatterns();
34+
travel('./');
35+
36+
function travel(relativePath) {
37+
if (isExclude(relativePath)) {
38+
return;
39+
}
40+
41+
const absolutePath = pathTool.join(ecBasePath, relativePath);
42+
const stat = fs.statSync(absolutePath);
43+
44+
if (stat.isFile()) {
45+
visit(absolutePath, getExt(absolutePath));
46+
}
47+
else if (stat.isDirectory()) {
48+
fs.readdirSync(relativePath).forEach(function (file) {
49+
travel(pathTool.join(relativePath, file));
50+
});
51+
}
52+
}
53+
54+
function prepareExcludePatterns() {
55+
const content = fs.readFileSync(excludesPath, {encoding: 'utf-8'});
56+
content.replace(/\r/g, '\n').split('\n').forEach(function (line) {
57+
line = line.trim();
58+
if (line && line.charAt(0) !== '#') {
59+
excludePatterns.push(new RegExp(line));
60+
}
61+
});
62+
}
63+
64+
function isExclude(relativePath) {
65+
for (let i = 0; i < excludePatterns.length; i++) {
66+
if (excludePatterns[i].test(relativePath)) {
67+
return true;
68+
}
69+
}
70+
}
71+
72+
function getExt(path) {
73+
if (path) {
74+
const mathResult = path.match(extReg);
75+
return mathResult && mathResult[1];
76+
}
77+
}
78+
}
79+
80+
module.exports = {
81+
eachFile: eachFile
82+
};

build/preamble.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
const cStyleComment = `
21-
/*
20+
const cStyleComment = `/*
2221
* Licensed to the Apache Software Foundation (ASF) under one
2322
* or more contributor license agreements. See the NOTICE file
2423
* distributed with this work for additional information

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"mktest": "node test/build/mktest.js",
6060
"mktest:help": "node test/build/mktest.js -h",
6161
"checktype": "tsc --noEmit",
62+
"checkheader": "node build/checkHeader.js",
6263
"lint": "npx eslint --cache --cache-location node_modules/.cache/eslint src/**/*.ts ssr/client/src/**/*.ts extension-src/**/*.ts",
6364
"lint:fix": "npx eslint --fix src/**/*.ts extension-src/**/*.ts",
6465
"lint:dist": "echo 'It might take a while. Please wait ...' && npx jshint --config .jshintrc-dist dist/echarts.js"

src/chart/chord/ChordEdge.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
import type { PathProps, PathStyleProps } from 'zrender/src/graphic/Path';
221
import type PathProxy from 'zrender/src/core/PathProxy';
322
import { extend, isString } from 'zrender/src/core/util';

src/chart/chord/ChordPiece.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
import { extend, retrieve3 } from 'zrender/src/core/util';
221
import * as graphic from '../../util/graphic';
322
import SeriesData from '../../data/SeriesData';

src/chart/custom/customSeriesRegister.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
import type { CustomSeriesRenderItem } from './CustomSeries';
221

322
const customRenderers: {[type: string]: CustomSeriesRenderItem} = {};

src/chart/scatter/jitterLayout.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
import type GlobalModel from '../../model/Global';
221
import type ScatterSeriesModel from './ScatterSeries';
322
import { needFixJitter, fixJitter } from '../../util/jitter';

0 commit comments

Comments
 (0)