feat: Add the merge to the file. (#2643)

* feat: Add the merge to the file.

* chore: Fix the early escape
This commit is contained in:
Jade
2024-06-10 22:38:12 -06:00
committed by GitHub
parent 4d6cb091cc
commit 5aefb707fa
3 changed files with 26 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import * as matches from "ts-matches"
import * as YAML from "yaml"
import * as TOML from "@iarna/toml"
import _ from "lodash"
import * as T from "../types"
import * as fs from "fs"
@@ -82,6 +83,12 @@ export class FileHelper<A> {
),
)
}
async merge(data: A, effects: T.Effects) {
const fileData = (await this.read(effects).catch(() => ({}))) || {}
const mergeData = _.merge({}, fileData, data)
return await this.write(mergeData, effects)
}
/**
* Create a File Helper for an arbitrary file type.
*