Skip to content

Commit

Permalink
Added new command to read file from server
Browse files Browse the repository at this point in the history
  • Loading branch information
jeawhanlee committed Jan 7, 2025
1 parent 313d044 commit 37204c7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,25 @@ export async function updatePostStatus(id: number, status: string): Promise<void
await wp(`post update ${id} --post_status=${status}`);
}

/**
* Read file on the server.
*
* @function
* @name readFile
* @async
* @param {string} path - The path to the file to be read.
* @returns {Promise<string>} - A Promise that resolves after file content is read.
*/
export async function readFile(path: string): Promise<string> {
const cwd = configurations.rootDir;
const command = wrapPrefix(`sudo cat ${path}`);
const result = exec(command, { cwd: cwd, async: false });

if (result.code !== 0) {
return '';
}

return result.stdout;
}

export default wp;

0 comments on commit 37204c7

Please sign in to comment.