fix async for appendFile
This commit is contained in:
parent
ed7a5afef7
commit
40d46b22bd
|
@ -1,4 +1,5 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
import { generateHereDoc } from "./configHeredoc";
|
||||||
import { exit } from "process";
|
import { exit } from "process";
|
||||||
|
|
||||||
// Check for the presence of sentinel.hcl, or else one gets created
|
// Check for the presence of sentinel.hcl, or else one gets created
|
||||||
|
@ -10,3 +11,9 @@ export const ensureFileExists = async (filename: string) => {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const appendHeredocToFile = async (filename:string, textToAppend:string) => {
|
||||||
|
fs.promises.appendFile(filename, textToAppend);
|
||||||
|
};
|
||||||
|
|
||||||
|
appendHeredocToFile('ok', generateHereDoc('arg'));
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// Most of the Typescript essentials are from: https://www.section.io/engineering-education/how-to-use-typescript-with-nodejs/
|
// 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 {generateHereDoc, functionUrls} from "./lib/configHeredoc";
|
||||||
import {ripGrep} from "./lib/ripGrep";
|
import {ripGrep} from "./lib/ripGrep";
|
||||||
import { ensureFileExists } from "lib/fileOperations";
|
import { ensureFileExists, appendHeredocToFile } from "lib/fileOperations";
|
||||||
|
|
||||||
const checkForCommonFunctions = async (functionsArray: Array<string>) => {
|
const checkForCommonFunctions = async (functionsArray: Array<string>) => {
|
||||||
// iterate over all common functions by name
|
// iterate over all common functions by name
|
||||||
|
@ -14,9 +14,7 @@ const checkForCommonFunctions = async (functionsArray: Array<string>) => {
|
||||||
if(exitCode === 0) {
|
if(exitCode === 0) {
|
||||||
console.log(`found import ${i}, appending to sentinel.hcl`);
|
console.log(`found import ${i}, appending to sentinel.hcl`);
|
||||||
// Add heredoc to sentinel.hcl file if a match is found
|
// Add heredoc to sentinel.hcl file if a match is found
|
||||||
await fs.appendFile("sentinel.hcl", generateHereDoc(i), (err:any) => {
|
await appendHeredocToFile("sentinel.hcl", generateHereDoc(i));
|
||||||
if(err) throw err;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue