Skip to content

Commit 52104f7

Browse files
authored
Merge pull request #21132 from apache/release-dev
chore: add license headers and a script of pre-commit
2 parents 8d7f252 + 5e02596 commit 52104f7

26 files changed

+423
-64
lines changed

.headerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
node_modules
66
.*\.git
77
.*\.github
8+
.*\.husky
89
.*\.editorconfig
910
.*\.gitignore
1011
.*\.jshintrc

.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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 chalk = require('chalk');
22+
const preamble = require('./preamble');
23+
const eachFile = require('./headerUtil').eachFile;
24+
25+
function run() {
26+
const missingFiles = [];
27+
28+
eachFile(function (absolutePath, fileExt) {
29+
const fileStr = fs.readFileSync(absolutePath, 'utf-8');
30+
const existLicense = preamble.extractLicense(fileStr, fileExt);
31+
32+
if (!existLicense && preamble.hasPreamble(fileExt)) {
33+
missingFiles.push(absolutePath);
34+
}
35+
});
36+
37+
if (missingFiles.length) {
38+
console.error(chalk.red('Files missing license header:'));
39+
missingFiles.forEach(function (path) {
40+
console.error(chalk.red(path));
41+
});
42+
console.error(chalk.red('\nPlease run `node build/addHeader.js` before commit.'));
43+
process.exit(1);
44+
}
45+
}
46+
47+
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+
};

dist/echarts.common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/echarts.esm.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27597,6 +27597,24 @@ function getImpl(name) {
2759727597
* AUTO-GENERATED FILE. DO NOT MODIFY.
2759827598
*/
2759927599

27600+
/*
27601+
* Licensed to the Apache Software Foundation (ASF) under one
27602+
* or more contributor license agreements. See the NOTICE file
27603+
* distributed with this work for additional information
27604+
* regarding copyright ownership. The ASF licenses this file
27605+
* to you under the Apache License, Version 2.0 (the
27606+
* "License"); you may not use this file except in compliance
27607+
* with the License. You may obtain a copy of the License at
27608+
*
27609+
* http://www.apache.org/licenses/LICENSE-2.0
27610+
*
27611+
* Unless required by applicable law or agreed to in writing,
27612+
* software distributed under the License is distributed on an
27613+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27614+
* KIND, either express or implied. See the License for the
27615+
* specific language governing permissions and limitations
27616+
* under the License.
27617+
*/
2760027618
var customRenderers = {};
2760127619
function registerCustomSeries(type, renderItem) {
2760227620
customRenderers[type] = renderItem;

dist/echarts.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/echarts.esm.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27597,6 +27597,24 @@ function getImpl(name) {
2759727597
* AUTO-GENERATED FILE. DO NOT MODIFY.
2759827598
*/
2759927599

27600+
/*
27601+
* Licensed to the Apache Software Foundation (ASF) under one
27602+
* or more contributor license agreements. See the NOTICE file
27603+
* distributed with this work for additional information
27604+
* regarding copyright ownership. The ASF licenses this file
27605+
* to you under the Apache License, Version 2.0 (the
27606+
* "License"); you may not use this file except in compliance
27607+
* with the License. You may obtain a copy of the License at
27608+
*
27609+
* http://www.apache.org/licenses/LICENSE-2.0
27610+
*
27611+
* Unless required by applicable law or agreed to in writing,
27612+
* software distributed under the License is distributed on an
27613+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27614+
* KIND, either express or implied. See the License for the
27615+
* specific language governing permissions and limitations
27616+
* under the License.
27617+
*/
2760027618
var customRenderers = {};
2760127619
function registerCustomSeries(type, renderItem) {
2760227620
customRenderers[type] = renderItem;

dist/echarts.esm.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)