Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Supported-File-Managers.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ export default defineConfig({
});
```

> [See `IFileManager` interface to see the required methods and properties for a custom file manager.](../src/files/file-manager.ts)
> [See `IFileManager` interface to see the required methods and properties for a custom file manager.](../src/services/file-manager.ts)
2 changes: 1 addition & 1 deletion examples/custom-file-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ You can define a custom file manager either by implementing the `IFileManager` i
- [custom-file-manager-function.ts](./custom-file-manager-function.ts) - defines a custom file manager using the `defineFileManager` function.

> [!NOTE]
> Have a look at the [files folder](../../src/files) within the fork-version source code for example on how to work with different file types.
> Have a look at the [file-managers folder](../../src/file-managers) within the fork-version source code for example on how to work with different file types.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ZodError } from "zod";
import { getCliArguments } from "./config/cli-arguments";
import { getUserConfig } from "./config/user-config";
import { Logger } from "./services/logger";
import { FileManager } from "./files/file-manager";
import { FileManager } from "./services/file-manager";
import { Git } from "./services/git";

import { validateConfig } from "./commands/validate-config";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/__tests__/inspect.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setupTest } from "../../../tests/setup-tests";
import { FileManager } from "../../files/file-manager";
import { FileManager } from "../../services/file-manager";
import { inspect } from "../inspect";

describe("inspect", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getCurrentVersion } from "../process/get-current-version";

import type { ForkConfig } from "../config/types";
import type { Logger } from "../services/logger";
import type { FileManager } from "../files/file-manager";
import type { FileManager } from "../services/file-manager";
import type { Git } from "../services/git";

export async function inspect(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { tagChanges } from "../process/tag";

import type { ForkConfig } from "../config/types";
import type { Logger } from "../services/logger";
import type { FileManager } from "../files/file-manager";
import type { FileManager } from "../services/file-manager";
import type { Git } from "../services/git";

export async function main(config: ForkConfig, logger: Logger, fileManager: FileManager, git: Git) {
Expand Down
23 changes: 23 additions & 0 deletions src/config/__tests__/define-file-manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineFileManager } from "../define-file-manager";
import type { IFileManager } from "../../services/file-manager";

describe("define-file-manager", () => {
it("should return the given file manager", () => {
const TEST_FILE_MANAGER: IFileManager = {
read: async (filePath) => {
return {
path: filePath,
version: "1.2.3",
};
},
write: async (_fileState, _newVersion) => {
// no-op
},
isSupportedFile: (filePath) => {
return filePath.endsWith(".test");
},
};

expect(defineFileManager(TEST_FILE_MANAGER)).toStrictEqual(TEST_FILE_MANAGER);
});
});
17 changes: 16 additions & 1 deletion src/config/define-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import type { Config } from "./types";

/**
* [Fork-Version - Config Properties](https://github.com/eglavin/fork-version/blob/main/README.md#config-properties)
* Optional helper function to enable intellisense and type checking when defining a Fork-Version configuration object.
*
* [Fork-Version - Config Options](https://github.com/eglavin/fork-version/blob/main/docs/Configuration.md#config-options)
*
* @example
* ```ts
* // File: fork.config.ts
* import { defineConfig } from "fork-version";
*
* export default defineConfig({
* header: "# Changelog\n\nMy Custom Changelog Header",
* });
* ```
*
* @param config The configuration object to be defined.
* @returns The same configuration object that was passed in.
*/
export function defineConfig(config: Config): Config {
return config;
Expand Down
41 changes: 41 additions & 0 deletions src/config/define-file-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { IFileManager } from "../services/file-manager";

/**
* Optional helper function to enable intellisense and type checking when defining a custom file manager.
*
* [Fork-Version - Custom File Managers](https://github.com/eglavin/fork-version/blob/main/docs/Supported-File-Managers.md#custom-file-updaters)
*
*
* @example
* ```ts
* // File: fork.config.ts
* import { defineFileManager } from "fork-version";
*
* const myFileManager = defineFileManager({
* async read(filePath) {
* // Logic to read the file and extract the version.
* return {
* path: "/path/to/file",
* version: "1.2.3",
* };
* },
* async write(fileState, newVersion) {
* // Logic to write the updated version.
* },
* isSupportedFile(fileName) {
* // Logic to determine if the file is supported by this file manager.
* return fileName.endsWith(".custom");
* },
* });
*
* export default {
* customFileManagers: [myFileManager],
* }
* ```
*
* @param fileManager The custom file manager to be defined.
* @returns The same file manager object that was passed in.
*/
export function defineFileManager(fileManager: IFileManager): IFileManager {
return fileManager;
}
2 changes: 1 addition & 1 deletion src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { getCliArguments } from "./cli-arguments";
import type { ParserOptions } from "../commit-parser/options";
import type { IFileManager } from "../files/file-manager";
import type { IFileManager } from "../services/file-manager";

export interface ChangelogPresetConfigType {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";

import { setupTest } from "../../../tests/setup-tests";
import { MissingPropertyException } from "../file-manager";
import { MissingPropertyException } from "../../services/file-manager";
import { ARMBicep } from "../arm-bicep";

describe("files arm-bicep", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setupTest } from "../../../tests/setup-tests";
import { MissingPropertyException } from "../file-manager";
import { MissingPropertyException } from "../../services/file-manager";
import { InstallShieldISM } from "../install-shield-ism";

describe("files install-shield-ism", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";

import { setupTest } from "../../../tests/setup-tests";
import { MissingPropertyException } from "../file-manager";
import { MissingPropertyException } from "../../services/file-manager";
import { JSONPackage } from "../json-package";

describe("files json-package", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";

import { setupTest } from "../../../tests/setup-tests";
import { MissingPropertyException } from "../file-manager";
import { MissingPropertyException } from "../../services/file-manager";
import { MSBuildProject } from "../ms-build-project";

describe("files ms-build-project", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";

import { setupTest } from "../../../tests/setup-tests";
import { MissingPropertyException } from "../file-manager";
import { MissingPropertyException } from "../../services/file-manager";
import { PlainText } from "../plain-text";

describe("files plain-text", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setupTest } from "../../../tests/setup-tests";
import { MissingPropertyException } from "../file-manager";
import { MissingPropertyException } from "../../services/file-manager";
import { YAMLPackage } from "../yaml-package";

describe("files yaml-package", () => {
Expand Down
6 changes: 5 additions & 1 deletion src/files/arm-bicep.ts → src/file-managers/arm-bicep.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { readFile, writeFile } from "node:fs/promises";

import { MissingPropertyException, type FileState, type IFileManager } from "./file-manager";
import {
MissingPropertyException,
type FileState,
type IFileManager,
} from "../services/file-manager";

/**
* An ARM bicep file with metadata and variable called contentVersion.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { readFile, writeFile } from "node:fs/promises";
import * as cheerio from "cheerio/slim";

import { MissingPropertyException, type FileState, type IFileManager } from "./file-manager";
import {
MissingPropertyException,
type FileState,
type IFileManager,
} from "../services/file-manager";

/**
* An InstallShield ISM file can be either XML or binary, only the XML format is supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
type ParseOptions,
} from "jsonc-parser";

import { MissingPropertyException, type FileState, type IFileManager } from "./file-manager";
import {
MissingPropertyException,
type FileState,
type IFileManager,
} from "../services/file-manager";

/** The things we are interested in, in package.json-like files. */
interface PackageJsonish {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { readFile, writeFile } from "node:fs/promises";
import * as cheerio from "cheerio/slim";

import { MissingPropertyException, type FileState, type IFileManager } from "./file-manager";
import {
MissingPropertyException,
type FileState,
type IFileManager,
} from "../services/file-manager";

/**
* A ms-build file is an xml file with a version property under the Project > PropertyGroup node.
Expand Down
6 changes: 5 additions & 1 deletion src/files/plain-text.ts → src/file-managers/plain-text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { readFile, writeFile } from "node:fs/promises";

import { MissingPropertyException, type FileState, type IFileManager } from "./file-manager";
import {
MissingPropertyException,
type FileState,
type IFileManager,
} from "../services/file-manager";

/**
* A plain text file will have just the version as the content.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { readFile, writeFile } from "node:fs/promises";
import { parse, parseDocument } from "yaml";

import { MissingPropertyException, type FileState, type IFileManager } from "./file-manager";
import {
MissingPropertyException,
type FileState,
type IFileManager,
} from "../services/file-manager";

/**
* A yaml package file should have a version property on the top level, like what can be seen
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type {
Config,
} from "./config/types";
export { defineConfig } from "./config/define-config";
export { defineFileManager } from "./config/define-file-manager";
export { getUserConfig } from "./config/user-config";

export { getCommitsSinceTag, type CommitsSinceTag } from "./process/get-commits";
Expand All @@ -31,12 +32,10 @@ export { commitChanges } from "./process/commit";
export { tagChanges } from "./process/tag";

export {
defineFileManager,
FileManager,
MissingPropertyException,
type FileState,
type IFileManager,
} from "./files/file-manager";

} from "./services/file-manager";
export { Logger } from "./services/logger";
export { Git } from "./services/git";
2 changes: 1 addition & 1 deletion src/process/__tests__/get-current-version.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setupTest } from "../../../tests/setup-tests";
import { getCommitsSinceTag } from "../get-commits";
import { getCurrentVersion } from "../get-current-version";
import { FileManager } from "../../files/file-manager";
import { FileManager } from "../../services/file-manager";

describe("getCurrentVersion", () => {
it("should be able to read package.json", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/process/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from "node:path";
import { formatCommitMessage } from "../utils/format-commit-message";
import { fileExists } from "../utils/file-state";
import type { ForkConfig } from "../config/types";
import type { FileState } from "../files/file-manager";
import type { FileState } from "../services/file-manager";
import type { Logger } from "../services/logger";
import type { Git } from "../services/git";

Expand Down
2 changes: 1 addition & 1 deletion src/process/get-current-version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import semver from "semver";

import type { ForkConfig } from "../config/types";
import type { FileManager, FileState } from "../files/file-manager";
import type { FileManager, FileState } from "../services/file-manager";
import type { Logger } from "../services/logger";
import type { Git } from "../services/git";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { readFileSync } from "node:fs";

import { setupTest } from "../../../tests/setup-tests";
import {
defineFileManager,
FileManager,
MissingPropertyException,
type FileState,
type IFileManager,
} from "../file-manager";
} from "../../services/file-manager";
import { defineFileManager } from "../../config/define-file-manager";

describe("files file-manager", () => {
describe("json file", () => {
Expand Down
23 changes: 7 additions & 16 deletions src/files/file-manager.ts → src/services/file-manager.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { isAbsolute, relative, resolve } from "node:path";

import { fileExists } from "../utils/file-state";
import { JSONPackage } from "./json-package";
import { YAMLPackage } from "./yaml-package";
import { PlainText } from "./plain-text";
import { MSBuildProject } from "./ms-build-project";
import { ARMBicep } from "./arm-bicep";
import { InstallShieldISM } from "./install-shield-ism";
import { JSONPackage } from "../file-managers/json-package";
import { YAMLPackage } from "../file-managers/yaml-package";
import { PlainText } from "../file-managers/plain-text";
import { MSBuildProject } from "../file-managers/ms-build-project";
import { ARMBicep } from "../file-managers/arm-bicep";
import { InstallShieldISM } from "../file-managers/install-shield-ism";

import { extractBuildMetadata } from "../utils/extract-build-metadata";
import type { ForkConfig } from "../config/types";
import type { Logger } from "../services/logger";
import type { Logger } from "./logger";

/**
* Exception thrown if a file manager encounters a file missing a required property,
Expand Down Expand Up @@ -79,15 +79,6 @@ export interface IFileManager {
isSupportedFile(filePath: string): boolean;
}

/**
* Helper function to define a custom file manager with proper typing.
*
* [Fork-Version - Custom File Managers](https://github.com/eglavin/fork-version#custom-file-updaters)
*/
export function defineFileManager(fileManager: IFileManager): IFileManager {
return fileManager;
}

export class FileManager {
#config: ForkConfig;
#logger: Logger;
Expand Down
Loading