Restructured modules, added /lib

This commit is contained in:
Sean Meininger 2022-10-09 21:26:05 -07:00
parent 07a17db7de
commit 3eae507c57
4 changed files with 16 additions and 13 deletions

12
src/lib/fileOperations.ts Normal file
View file

@ -0,0 +1,12 @@
const fs = require("fs");
import { exit } from "process";
// Check for the presence of sentinel.hcl, or else one gets created
export const ensureFileExists = async (filename: string) => {
try {
return await fs.lstatSync(filename).isFile();
} catch(e) {
console.log(`${filename} not present. Are you running this in the right directory?`);
exit();
}
}

View file

@ -1,22 +1,13 @@
#!/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 { exit } from "process";
import {generateHereDoc, functionUrls} from "./configHeredoc";
import {ripGrep} from "./ripGrep";
// Check for the presence of sentinel.hcl, or else one gets created import {generateHereDoc, functionUrls} from "./lib/configHeredoc";
const ensureFileExists = async (filename: string) => { import {ripGrep} from "./lib/ripGrep";
try { import { ensureFileExists } from "lib/fileOperations";
return await fs.lstatSync(filename).isFile();
} catch(e) {
console.log(`${filename} not present. Are you running this in the right directory?`);
exit();
}
}
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
// forEach does funny stuff with Async, like not work
for (const i of functionsArray) { for (const i of functionsArray) {
const exitCode = await ripGrep(i); const exitCode = await ripGrep(i);
// exitCode of 0 indicates a match in ripGrep // exitCode of 0 indicates a match in ripGrep