diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index fcca4628..00000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -( - cd action - npx lint-staged -) - -( - cd cli - npx lint-staged -) diff --git a/action/.husky/pre-commit b/action/.husky/pre-commit new file mode 100755 index 00000000..f195bec7 --- /dev/null +++ b/action/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +cd action +npx lint-staged diff --git a/cli/.husky/pre-commit b/cli/.husky/pre-commit new file mode 100755 index 00000000..e4220545 --- /dev/null +++ b/cli/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +cd cli +npx lint-staged diff --git a/cli/package.json b/cli/package.json index 931e4fb9..ffc8a781 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "stoat", - "version": "0.0.7", + "version": "0.0.8", "description": "Stoat CLI", "main": "src/index.ts", "bin": { @@ -15,7 +15,7 @@ "build": "ncc build --source-map --license licenses.txt", "local": "yarn build && npm i -g", "test": "jest --coverage", - "prepare": "cd .. && husky install action/.husky" + "prepare": "cd .. && husky install cli/.husky" }, "repository": { "type": "git", diff --git a/cli/src/helpers/local/configFileGlobal.ts b/cli/src/helpers/local/configFileGlobal.ts index b1a7b5c1..b114fad3 100644 --- a/cli/src/helpers/local/configFileGlobal.ts +++ b/cli/src/helpers/local/configFileGlobal.ts @@ -1,21 +1,84 @@ 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