Skip to content

Commit

Permalink
Add a seperator option for appendFile
Browse files Browse the repository at this point in the history
  • Loading branch information
nturinski authored Jul 20, 2023
1 parent 84f8a66 commit d25f161
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,10 @@ export declare namespace AzExtFsExtra {
export function ensureDir(resource: Uri | string): Promise<void>;
export function ensureFile(resource: Uri | string): Promise<void>;
export function readFile(resource: Uri | string): Promise<string>;
export function writeFile(resource: Uri | string, contents: string): Promise<void>;
export function appendFile(resource: Uri | string, contents: string): Promise<void>;
/**
* @param seperator By default, will append "\r\n\r\n" between existing content and new content to be appended
*/
export function appendFile(resource: Uri | string, contents: string, seperator: string = '\r\n\r\n'): Promise<void>;
export function pathExists(resource: Uri | string): Promise<boolean>;
export function readJSON<T>(resource: Uri | string): Promise<T>
/**
Expand Down
4 changes: 2 additions & 2 deletions utils/src/utils/AzExtFsExtra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export namespace AzExtFsExtra {
await workspace.fs.writeFile(uri, Buffer.from(contents));
}

export async function appendFile(resource: Uri | string, contents: string): Promise<void> {
export async function appendFile(resource: Uri | string, contents: string, seperator: string = '\r\n\r\n'): Promise<void> {
const uri = convertToUri(resource);
const existingContent = await AzExtFsExtra.readFile(uri);
await AzExtFsExtra.writeFile(uri, existingContent + '\r\n\r\n' + contents);
await AzExtFsExtra.writeFile(uri, existingContent + seperator + contents);
}

export async function pathExists(resource: Uri | string): Promise<boolean> {
Expand Down

0 comments on commit d25f161

Please sign in to comment.