aboutsummaryrefslogtreecommitdiff
path: root/scripts/apply_vimgrep_updates.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/apply_vimgrep_updates.js')
-rwxr-xr-xscripts/apply_vimgrep_updates.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/apply_vimgrep_updates.js b/scripts/apply_vimgrep_updates.js
new file mode 100755
index 0000000..9707aab
--- /dev/null
+++ b/scripts/apply_vimgrep_updates.js
@@ -0,0 +1,29 @@
+#!/usr/bin/env bun
+
+const main = async () => {
+ let count = 0
+ for await (const line of console) {
+ const [_, filepath, row, _col, text] = line.match(/(.*):(\d+):(\d+):(.*)/) ?? []
+ if (filepath) {
+ const isApplied = await apply_edit(filepath, Number(row), text);
+ if (isApplied) count++
+ }
+ }
+ return count
+}
+
+const apply_edit = async (filepath, row, text) => {
+ if (!Number.isFinite(row) || row <= 0) return false;
+ const file = Bun.file(filepath)
+ const lines = (await file.text()).split('\n')
+ if (lines.length > row) {
+ lines[row - 1] = text
+ await Bun.write(filepath, lines.join('\n'))
+ return true
+ }
+ return false
+}
+
+const changesCount = await main()
+console.log(`Applied ${changesCount} changes`)
+