fix async for appendFile

This commit is contained in:
Sean Meininger 2022-10-09 21:58:27 -07:00
parent ed7a5afef7
commit 40d46b22bd
2 changed files with 11 additions and 6 deletions

View file

@ -1,4 +1,5 @@
const fs = require("fs");
import { generateHereDoc } from "./configHeredoc";
import { exit } from "process";
// Check for the presence of sentinel.hcl, or else one gets created
@ -9,4 +10,10 @@ export const ensureFileExists = async (filename: string) => {
console.log(`${filename} not present. Are you running this in the right directory?`);
exit();
}
}
}
export const appendHeredocToFile = async (filename:string, textToAppend:string) => {
fs.promises.appendFile(filename, textToAppend);
};
appendHeredocToFile('ok', generateHereDoc('arg'));

View file

@ -1,9 +1,9 @@
#!/usr/bin/env node
// Most of the Typescript essentials are from: https://www.section.io/engineering-education/how-to-use-typescript-with-nodejs/
const fs = require("fs");
import fs from "fs";
import {generateHereDoc, functionUrls} from "./lib/configHeredoc";
import {ripGrep} from "./lib/ripGrep";
import { ensureFileExists } from "lib/fileOperations";
import { ensureFileExists, appendHeredocToFile } from "lib/fileOperations";
const checkForCommonFunctions = async (functionsArray: Array<string>) => {
// iterate over all common functions by name
@ -14,9 +14,7 @@ const checkForCommonFunctions = async (functionsArray: Array<string>) => {
if(exitCode === 0) {
console.log(`found import ${i}, appending to sentinel.hcl`);
// Add heredoc to sentinel.hcl file if a match is found
await fs.appendFile("sentinel.hcl", generateHereDoc(i), (err:any) => {
if(err) throw err;
});
await appendHeredocToFile("sentinel.hcl", generateHereDoc(i));
}
}
}