AshSimmonds
07/03/2022, 9:40 AMconst arrayOfFiles = ['./docs/testefile01.md', './docs/testefile02.md'];
// read files in arrayOfFiles and return the contents as a string in a JSON object
export const getFiles = async (): Promise<string> => {
const files = await Promise.all(arrayOfFiles.map(file => readFile(file, 'utf8')));
return JSON.stringify(files);
}
// read file and return the contents as a string
export const getFile = async (file: string): Promise<string> => {
const content = await readFile(file, 'utf8');
return content;
}
// write file and return the contents as a string
export const writeFile = async (file: string, content: string): Promise<string> => {
await writeFile(file, content);
return content;
}
// delete file and return the contents as a string
export const deleteFile = async (file: string): Promise<string> => {
await unlink(file);
return file;
}
// rename file and return the contents as a string
export const renameFile = async (file: string, newFile: string): Promise<string> => {
await rename(file, newFile);
return newFile;
}
// copy file and return the contents as a string
export const copyFile = async (file: string, newFile: string): Promise<string> => {
await copyFile(file, newFile);
return newFile;
}
// move file and return the contents as a string
export const moveFile = async (file: string, newFile: string): Promise<string> => {
await move(file, newFile);
return newFile;
}
// read directory and return the contents as a string
export const getDirectory = async (dir: string): Promise<string> => {
const content = await readdir(dir);
return JSON.stringify(content);
}
// create directory and return the contents as a string
export const createDirectory = async (dir: string): Promise<string> => {
await mkdir(dir);
return dir;
}
// delete directory and return the contents as a string
export const deleteDirectory = async (dir: string): Promise<string> => {
await rmdir(
const arrayOfFiles = ['./docs/testefile01.md', './docs/testefile02.md'];
// read files in arrayOfFiles and return the contents as a string in a JSON object
export const getFiles = async (): Promise<string> => {
const files = await Promise.all(arrayOfFiles.map(file => Deno.readTextFile(file)));
return JSON.stringify(files);
}
export const handler = async (theRequest: Request): Promise<Response> => {
const theFilesOutput = getFiles();
return new Response(await theFilesOutput);
};
["# it's a copilot teste \r\n \r\nCan this thing actually do stuff?\r\n\r\n## Dunno\r\n","# still testing \r\n \r\nare we getting somewhere?\r\n\r\n## maybe\r\n"]
promise
in the wrong spot or something.
Anyhoo, I'm suddenly more optimistic - and as they say, it all comes down to giving good very specific instructions, and let Copilot suss out the syntax.kfischer_okarin
07/04/2022, 10:03 AMAshSimmonds
07/05/2022, 5:04 AM// add '.md' to all files in arrayOfFiles that don't end in '.md'
arrayOfFiles = arrayOfFiles.map(file => {
if (!file.endsWith(".md")) {
return file + ".md";
}
return file;
}).sort();