Skip to content

Commit d7475b1

Browse files
committed
Add patching message
1 parent 6a30511 commit d7475b1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

scripts/patch.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,34 @@ function checkPatch (text, patch) {
1414
/**
1515
* @param {string} text
1616
* @param {Recipe} recipe
17-
* @return {string?}
17+
* @return {?string}
1818
*/
1919
function applyRecipe (text, recipe) {
20-
if (!text || checkPatch(text, recipe.patch)) {
20+
if (!text) {
21+
return text
22+
}
23+
24+
if (checkPatch(text, recipe.patch)) {
25+
debug('already patched, skipped')
2126
return null
2227
}
2328

2429
const matched = text.match(recipe.pattern)
25-
if (matched && matched.length === 1) {
26-
return text.replace(matched[0], `${matched[0]}${recipe.patch}`)
30+
31+
if (!matched) {
32+
debug(`not found ${recipe.pattern}`)
33+
return text
2734
}
2835

29-
return text
36+
return text.replace(matched[0], `${matched[0]}${recipe.patch}`)
3037
}
3138

3239
/**
3340
* @param {string} file
3441
* @param {(Recipe|Recipe[])} recipes
3542
*/
3643
function patch (file, recipes) {
37-
debug(`patching ${file}`)
44+
debug(`patching ${file}...`)
3845

3946
const path = glob.sync(file, {
4047
ignore: ['node_modules/**', '**/build/**']
@@ -43,7 +50,7 @@ function patch (file, recipes) {
4350
const init = fs.readFileSync(path, 'utf8')
4451
const text = recipes.reduce(applyRecipe, init)
4552

46-
if (text) {
53+
if (text != null) {
4754
fs.writeFileSync(path, text)
4855
}
4956
}

0 commit comments

Comments
 (0)