Files
Hippy/scripts/copyright.js
T
Tomdy Qin 4e49d4f456 feat(hippy-react): fix declaration and export it (#3414)
* feat(hippy-react): fix declaration and export it;

refactor list-view for extends

* feat(hippy-react): fix style declaration

* feat(hippy-react): add StyleSheet.flatten && fix style declaration

* feat(hippy-react): fix style declaration

* feat(hippy-react-web): fix text-input setStyle error

* feat(scripts): update copyright

* feat(scripts): update copyright force
2023-08-07 17:32:21 +08:00

74 lines
2.4 KiB
JavaScript

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, replace = false) => {
const copyright = banner(undefined, undefined, undefined, undefined, false);
let fileContent;
if (replace) {
fileContent = content.replace(/\/\*(\s|.)*?\*\//, copyright);
} else {
fileContent = `${copyright}\n${content}`;
}
updateList.push(new Promise(r => fs.writeFile(file, fileContent, 'utf8', (err) => {
if (err) return console.error(err);
updatedList.push(file);
r();
})));
};
/**
* @example node scripts/copyright.js hippy-react hippy-react-web
* @example node scripts/copyright.js hippy-react hippy-react-web --force 强制更新
*/
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)) && file === 'packages/hippy-react/src/adapters/animated.ts') {
if (yargs.argv.force) {
updateFile(file, content, true);
} 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(() => {
if (needUpdateList.length) {
console.log(chalk.yellow('\nneed to update copyright:'));
console.log(chalk.grey(needUpdateList.join('\n')));
}
});
});