import { ExecutorContextInterface, LifecycleExecutor } from '@qlover/fe-corekit'; import { ScriptPluginProps, ScriptPlugin, ScriptSharedInterface, ScriptContextInterface, ScriptContext, TemplateEngine, RenderFn, ShellInterface } from '@qlover/scripts-context'; export { ScriptPlugin } from '@qlover/scripts-context'; import { CommitField } from 'gitlog'; import { LoggerInterface } from '@qlover/logger'; import { OptionValues } from 'commander'; /** * @module WorkspaceInterface * @description Core data model for a monorepo package in a release run * * Represents one publishable workspace discovered by the {@link Workspaces} * plugin and passed through {@link ChangesetVersion} and {@link Github}. * * Typical lifecycle fields: * - `version` / `newVersion` — before and after `changeset version` * - `lastTag` — git baseline for changelog generation * - `dependencyRelease` — internal dependent bumped only because a dependency changed */ interface WorkspaceInterface { /** * Package name from package.json */ name: string; /** * Current version from package.json before bump */ version: string; /** * Version after `changeset version`, read from package.json on disk. * * - Before bump: usually undefined * - After bump: latest version on disk; may equal `version` if unchanged */ newVersion?: string; /** * The relative path of the workspace */ path: string; /** * The absolute path of the workspace */ root: string; /** * The package.json of the workspace */ packageJson: PackageJson; /** * Release tag name after version bump (for example `pkg@1.0.1`). * * Set by ChangesetVersion.mergeWorkspaces only when `newVersion` differs * from `version`. Not available before `changeset version` completes. */ tagName?: string; /** * Previous release tag used as the git changelog baseline */ lastTag?: string; /** * The changelog of the workspace * */ changelog?: string; /** * Whether this workspace is an internal dependent bumped only because a * dependency was released (not directly changed in git). * * Set by the Workspaces plugin when `includeDependencyReleases` is enabled. * Processing rules depend on `changesetVersion.ignoreNonUpdatedPackages`: * * - `false`: included in changelog template flow and version bump logs * - `true`: tracked for restore only; skipped in changelog generation * * @default false */ dependencyRelease?: boolean; /** * Package name of the direct dependency that caused this `dependencyRelease`. * * Set by Workspaces when appending dependents. ChangesetVersion uses it after * `changeset version` to fill `dependencyReleaseTemplate` with the source's * real `newVersion`. */ dependencyReleaseOf?: string; } /** * Base configuration for Git-related plugins * * Extends ScriptPluginProps with generic options. * * @example * ```typescript * const config: GitBaseProps = { * timeout: 5000 * }; * ``` */ interface GitBaseProps extends ScriptPluginProps { /** * Environment variable name for GitHub API token * @deprecated This property is GitHub-specific, use a subclass if needed. */ tokenRef?: string; /** * Timeout for API requests in milliseconds (generic) */ timeout?: number; } /** * @module ReleaseFormatter * @description Template-based formatting for release branches, commits, and PRs * * Centralizes string formatting for the GitHub release flow. Uses * {@link TemplateEngine} from `@qlover/scripts-context` with ES6-style * `${ path }` placeholders and variables from {@link BranchNameTplVars}. * * Responsibilities: * - **Branch/tag names**: `getReleaseBranch()` from `branchName` / `releaseTagName` templates * - **Commit message**: `getCommitMessage()` with optional `less` / `more` templates when * workspace count exceeds 3 * - **PR content**: `getPRTitle()` and `getPRBody()` with single- vs multi-workspace changelog * formatting via `batchPRBody` * * Defaults are sourced from `releaseJson.github` in {@link defaults}. * {@link Github} constructs an instance and calls `setConfig()` in `onBefore` * with runtime context (`repoName`, `releaseId`, `env`, etc.). * * @example Branch name template variables * ```typescript * // Template: release/${repoName}-${releaseId} * // Variables: repoName, releaseId, timestamp, authorName, env, count, spaces * formatter.getReleaseBranch(workspaces); * ``` * * @example Multi-workspace PR body * ```typescript * formatter.getPRBody(workspaces, releaseBranchResult, templateContext); * ``` */ interface ReleaseFormatterConfig { /** * Repository name */ repoName?: string; /** * Author name */ authorName?: string; /** * Release environment */ env?: string; /** * Unique ID for the current release run */ releaseId?: string; /** * The branch name for batch release * * Template variables: see {@link BranchNameTplVars} * * @default `release/${repoName}-${releaseId}` */ branchName?: string; /** * The tag name for batch release * * Template variables: see {@link BranchNameTplVars} * * @default `release-tag-${count}-patch-${releaseId}` */ releaseTagName?: string; /** * * @default 'Release ${spaces}' */ releaseName?: string; /** * Commit message template used when creating the release branch * * When configured as an object, supports `less` and `more` templates: * - `less`: used when workspace count is 3 or fewer * - `more`: used when workspace count exceeds 3 * * Supports conventional commit structure: subject, body, and footer. * * **Object form is experimental.** * * @example Conventional commit layout * ``` * (): <-- Header/Subject (required) * <-- blank line * <-- detailed description (optional) * <-- blank line *