From 7bb17c7e32fa09aa21addb41e3b8350c6fb6004a Mon Sep 17 00:00:00 2001 From: jrhizor Date: Thu, 22 Dec 2022 11:58:20 -0800 Subject: [PATCH 1/6] have cli watch template file for changes --- cli/src/helpers/local/configFileGlobal.ts | 73 ++++++++++++++++++++++- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/cli/src/helpers/local/configFileGlobal.ts b/cli/src/helpers/local/configFileGlobal.ts index b1a7b5c1..0f3a1a28 100644 --- a/cli/src/helpers/local/configFileGlobal.ts +++ b/cli/src/helpers/local/configFileGlobal.ts @@ -1,21 +1,88 @@ import chalk from 'chalk'; -import fs from 'fs'; +import fs, {FSWatcher, readFileSync, WatchEventType} from 'fs'; import { getTypedStoatConfig, readStoatConfig } from '../../../../action/src/configHelpers'; import { StoatConfigSchema } from '../../../../action/src/schemas/stoatConfigSchema'; -import { getTemplate } from '../../../../action/src/templateHelpers'; +import { + getRemoteDefaultTemplate, + getTemplateFormat +} from '../../../../action/src/templateHelpers'; import { Template } from '../../../../action/src/types'; -import { findStoatConfigPath } from '../pathHelpers'; +import {findGitRoot, findStoatConfigPath} from '../pathHelpers'; +import path from "path"; + +// supports reading the local template from a subdirectory +const getLocalTemplate = (commentTemplatePath: string): Template => { + const gitRoot = findGitRoot(process.cwd()); + const fullCommentTemplateFile = path.join(gitRoot, commentTemplatePath); + const template = readFileSync(fullCommentTemplateFile).toString().trim(); + const format = getTemplateFormat(fullCommentTemplateFile); + return { template, format }; +}; + +// supports reading the local template from a subdirectory if necessary +const getTemplate = async ( + ghOwner: string, + ghRepo: string, + stoatConfig: StoatConfigSchema +): Promise