diff --git a/src/main.ts b/src/main.ts index 406c67f..70615c5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { cwd, readConfig, readFile, writeFile } from "./utils/filesystem"; +import { cwd, readFile, writeFile } from "./utils/filesystem"; import { context, getOctokit } from "@actions/github"; import { parse } from "./utils/inputs"; import { info } from "@actions/core"; @@ -8,6 +8,7 @@ import { setPreview } from "./utils/preview"; import { setOutputs } from "./utils/outputs"; import { getPackageManager } from "./utils/packageManagers"; import { titleCase } from "./utils/strings"; +import { readConfig } from './utils/config' const previewUpdater = async () => { // Inputs diff --git a/src/utils/config.ts b/src/utils/config.ts new file mode 100644 index 0000000..f5f01e6 --- /dev/null +++ b/src/utils/config.ts @@ -0,0 +1,16 @@ +import { Config, defaultConfig } from '../types/config' +import { deepmerge } from 'deepmerge-ts' +import * as yaml from 'js-yaml' +import { readFile } from './filesystem' + +export const readConfig = (config: Config, userConfigPath: string): Config => { + const content: string = readFile(config, userConfigPath); + + if (content === "") { + return deepmerge(defaultConfig, config); + } + + const userConfig = yaml.load(content); + + return deepmerge(defaultConfig, userConfig, config); +}; diff --git a/src/utils/filesystem.ts b/src/utils/filesystem.ts index 956b1a5..1b9fee0 100644 --- a/src/utils/filesystem.ts +++ b/src/utils/filesystem.ts @@ -37,18 +37,6 @@ export const writeFile = ( fs.writeFileSync(filePath(config, filename), content); }; -export const readConfig = (config: Config, userConfigPath: string): Config => { - const content: string = readFile(config, userConfigPath); - - if (content === "") { - return deepmerge(defaultConfig, config); - } - - const userConfig = yaml.load(content); - - return deepmerge(defaultConfig, userConfig, config); -}; - export const exec = async (command: string): Promise => { const execAsync = promisify(nodeExec); diff --git a/tests/unit/filesystem.test.ts b/tests/unit/filesystem.test.ts index 6e0d5e1..72d21eb 100644 --- a/tests/unit/filesystem.test.ts +++ b/tests/unit/filesystem.test.ts @@ -1,7 +1,7 @@ import { rawTestConfig } from "../helpers/config"; import { type Config, defaultConfig } from "../../src/types/config"; -import { readConfig } from "../../src/utils/filesystem"; import { CONFIG_PATH } from "../../src/utils/inputs"; +import { readConfig } from '../../src/utils/config' test("read config", () => { const data: Config = readConfig(rawTestConfig, CONFIG_PATH.defaultValue);