Skip to content

Commit

Permalink
feat(scripts): update copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdyqin committed Aug 4, 2023
1 parent 8dd25bd commit 5f7c419
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 14 deletions.
92 changes: 85 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-vue": "^9.5.1",
"esm": "^3.2.25",
"flow-remove-types": "^1.2.3",
"fs-extra": "^11.1.1",
"got": "^12.1.0",
"husky": "^7.0.4",
"is-ci": "^2.0.0",
Expand Down
20 changes: 20 additions & 0 deletions packages/hippy-react/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/* !
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed 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.
*/

export * from './focusable';
export * from './image';
export * from './list-view-item';
Expand Down
20 changes: 20 additions & 0 deletions packages/hippy-react/src/dom/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/* !
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed 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.
*/

export * from './view-node';
export { default as DocumentNode } from './document-node';
export { default as ElementNode } from './element-node';
4 changes: 2 additions & 2 deletions packages/hippy-react/src/event/global-listener.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
/* !
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2022 THL A29 Limited, a Tencent company.
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
20 changes: 20 additions & 0 deletions packages/hippy-react/src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/* !
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed 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.
*/

/* eslint-disable */
// // @ts-ignore
declare var global: HippyTypes.HippyGlobal & typeof globalThis;
Expand Down
61 changes: 61 additions & 0 deletions scripts/copyright.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const fs = require('fs-extra');
const chalk = require('chalk');
const yargs = require('yargs');
const glob = require('glob');
const { banner } = require('./utils');

let packages = glob.sync('packages/[!global]*').map(o => o.replace('packages/', ''));

if (yargs.argv._) {
const filters = yargs.argv._.map(o => o.trim());
packages = packages.filter(p => filters.includes(p));
}
const updateList = [];
const updatedList = [];
const needUpdateList = [];
/** update file */
const updateFile = (file, content) => updateList.push(new Promise(r => fs.writeFile(file, `${banner(undefined, undefined, undefined, undefined, false)}\n${content}`, 'utf8', (err) => {
if (err) return console.error(err);
updatedList.push(file);
r();
})));

/**
* @example node scripts/copyright.js hippy-react hippy-react-web
*/
console.log('choise packages', packages);
packages.forEach((pkg) => {
const files = glob.sync(`packages/${pkg}/src/**/*.ts`, {
ignore: ['**/node_modules/**', '**/dist/**'],
});
files.forEach((file) => {
const content = fs.readFileSync(file, 'utf-8');
if (!content.includes('* Copyright (C) 2017-') || !content.includes('THL A29 Limited, a Tencent company')) {
// not found copyright, add it.
updateFile(file, content);
} else if (!content.includes(banner(undefined, undefined, undefined, undefined, false))) {
if (yargs.argv.force) {
updateFile(file, content);
} else {
needUpdateList.push(file);
}
}
});


Promise.all(updateList).then(() => {
if (updatedList.length) {
console.log(chalk.cyan('\nauto add copyright header:'));
console.log(chalk.green(updatedList.join('\n')));
} else {
console.log(chalk.green('all files check copyright is ok.'));
}
})
.catch((e) => {
console.log(chalk.yellow('add copyright found err'), e);
})
.finally(() => {
console.log(chalk.yellow('\nneed to update copyright:'));
console.log(chalk.grey(needUpdateList.join('\n')));
});
});
8 changes: 3 additions & 5 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ const path = require('path');
const fs = require('fs-extra');
const dts = require('rollup-plugin-dts').default;

function banner(name, version, extra = '', startYear = 2017) {
function banner(name, version, extra = '', startYear = 2017, build = true) {
const thisYear = new Date().getFullYear();
let copyRightYears = thisYear;
if (startYear !== thisYear) {
copyRightYears = `${startYear}-${thisYear}`;
}
const buildStr = build ? `\n * ${name} v${version}${extra}\n * Build at: ${new Date()}\n *\n ` : '';

return `/*!
* ${name} v${version}${extra}
* Build at: ${new Date()}
*
return `/* !${buildStr}
* Tencent is pleased to support the open source community by making
* Hippy available.
*
Expand Down

0 comments on commit 5f7c419

Please sign in to comment.