Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: appendFile to declaration + bump #1526

Merged
merged 15 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +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>;
/**
* @param separator 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, separator?: string): 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/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-utils",
"author": "Microsoft Corporation",
"version": "2.0.1",
"version": "2.0.2",
"description": "Common UI tools for developing Azure extensions for VS Code",
"tags": [
"azure",
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, separator: 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 + separator + contents);
}

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