diff --git a/src/configHeredoc.ts b/src/lib/configHeredoc.ts similarity index 100% rename from src/configHeredoc.ts rename to src/lib/configHeredoc.ts diff --git a/src/lib/fileOperations.ts b/src/lib/fileOperations.ts new file mode 100644 index 0000000..ffa19a2 --- /dev/null +++ b/src/lib/fileOperations.ts @@ -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(); + } +} \ No newline at end of file diff --git a/src/ripGrep.ts b/src/lib/ripGrep.ts similarity index 100% rename from src/ripGrep.ts rename to src/lib/ripGrep.ts diff --git a/src/main.ts b/src/main.ts index 55b676a..af95c56 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,22 +1,13 @@ #!/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 { exit } from "process"; -import {generateHereDoc, functionUrls} from "./configHeredoc"; -import {ripGrep} from "./ripGrep"; -// Check for the presence of sentinel.hcl, or else one gets created -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(); - } -} +import {generateHereDoc, functionUrls} from "./lib/configHeredoc"; +import {ripGrep} from "./lib/ripGrep"; +import { ensureFileExists } from "lib/fileOperations"; const checkForCommonFunctions = async (functionsArray: Array) => { // iterate over all common functions by name + // forEach does funny stuff with Async, like not work for (const i of functionsArray) { const exitCode = await ripGrep(i); // exitCode of 0 indicates a match in ripGrep