Remove shelljs
This commit is contained in:
parent
0cbe6a0132
commit
55b0816060
1 changed files with 29 additions and 8 deletions
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const sh = require('shelljs')
|
||||
|
||||
sh.config.fatal = true
|
||||
|
||||
const VERBOSE = process.argv.includes('--verbose')
|
||||
const DRY_RUN = process.argv.includes('--dry') || process.argv.includes('--dry-run')
|
||||
|
|
@ -60,7 +57,29 @@ function walkAsync(directory, excludedDirectories, fileCallback, errback) {
|
|||
|
||||
function replaceRecursively(directory, excludedDirectories, allowedExtensions, original, replacement) {
|
||||
const updateFile = filepath => {
|
||||
if (allowedExtensions.has(path.parse(filepath).ext)) {
|
||||
if (!allowedExtensions.has(path.parse(filepath).ext) && VERBOSE) {
|
||||
console.log(`EXCLUDED: ${filepath}`)
|
||||
return
|
||||
}
|
||||
|
||||
fs.readFile(filepath, 'utf8', (error, originalData) => {
|
||||
if (error) {
|
||||
throw error
|
||||
}
|
||||
|
||||
const newData = originalData.replace(
|
||||
new RegExp(regExpQuote(original), 'g'),
|
||||
regExpQuoteReplacement(replacement)
|
||||
)
|
||||
|
||||
if (originalData === newData) {
|
||||
if (VERBOSE) {
|
||||
console.log(`SKIPPED: ${filepath}`)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (VERBOSE) {
|
||||
console.log(`FILE: ${filepath}`)
|
||||
}
|
||||
|
|
@ -69,10 +88,12 @@ function replaceRecursively(directory, excludedDirectories, allowedExtensions, o
|
|||
return
|
||||
}
|
||||
|
||||
sh.sed('-i', new RegExp(regExpQuote(original), 'g'), regExpQuoteReplacement(replacement), filepath)
|
||||
} else if (VERBOSE) {
|
||||
console.log(`EXCLUDED: ${filepath}`)
|
||||
}
|
||||
fs.writeFile(filepath, newData, 'utf8', err => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
walkAsync(directory, excludedDirectories, updateFile, err => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue