Created
June 4, 2023 04:27
-
-
Save d1y/821fe5ce3c88b3bdd5a7c4ddfedaf300 to your computer and use it in GitHub Desktop.
删除copyright
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path' | |
import fs from 'fs' | |
const __dirname = path.resolve() | |
const kRuleFolder = [ | |
'lib', | |
] | |
const kMatchRule = /^\/\/ Copyright \(C\)[\s\S]*s\/>\./ | |
function removeCopyRight(path) { | |
if (fs.lstatSync(path).isDirectory() ) { | |
return readDirRemoveCP(path) | |
} | |
const ctx = fs.readFileSync(path).toString('utf-8') | |
const newCtx = ctx.replace(kMatchRule, '').trimStart() | |
fs.writeFileSync(path, newCtx) | |
} | |
function readDirRemoveCP(fullpath) { | |
const files = fs.readdirSync(fullpath) | |
files.map(item=> path.join(fullpath, item)).map(currentFile=> { | |
console.log(currentFile) | |
removeCopyRight(currentFile) | |
}) | |
} | |
;(()=> { | |
kRuleFolder.map(item=> path.join(__dirname, item)).forEach(fullpath=> { | |
const files = fs.readdirSync(fullpath) | |
files.map(item=> path.join(fullpath, item)).map(currentFile=> { | |
console.log(currentFile) | |
removeCopyRight(currentFile) | |
}) | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment