diff --git a/pgpm/core/src/export/export-migrations.ts b/pgpm/core/src/export/export-migrations.ts index 0bdf2777f..b39482a31 100644 --- a/pgpm/core/src/export/export-migrations.ts +++ b/pgpm/core/src/export/export-migrations.ts @@ -8,6 +8,7 @@ import { getPgPool } from 'pg-cache'; import { PgpmPackage } from '../core/class/pgpm'; import { PgpmRow, SqlWriteOptions, writePgpmFiles, writePgpmPlan } from '../files'; import { getMissingInstallableModules } from '../modules/modules'; +import { parseAuthor } from '../utils/author'; import { exportMeta } from './export-meta'; /** @@ -416,6 +417,8 @@ const preparePackage = async ({ const plan = glob(path.join(pgpmDir, 'pgpm.plan')); if (!plan.length) { + const { fullName, email } = parseAuthor(author); + await project.initModule({ name, description, @@ -425,7 +428,9 @@ const preparePackage = async ({ moduleName: name, moduleDesc: description, access: 'restricted', - license: 'CLOSED' + license: 'CLOSED', + fullName, + ...(email && { email }) } }); } else { diff --git a/pgpm/core/src/files/plan/writer.ts b/pgpm/core/src/files/plan/writer.ts index db8255acf..61d8d8d70 100644 --- a/pgpm/core/src/files/plan/writer.ts +++ b/pgpm/core/src/files/plan/writer.ts @@ -2,6 +2,7 @@ import fs from 'fs'; import path from 'path'; import { Change, PlanFile, PgpmRow, Tag, ExtendedPlanFile } from '../types'; +import { parseAuthor } from '../../utils/author'; export interface PlanWriteOptions { outdir: string; @@ -19,22 +20,9 @@ export function writePgpmPlan(rows: PgpmRow[], opts: PlanWriteOptions): void { const date = (): string => '2017-08-11T08:11:51Z'; // stubbed timestamp - // Parse author string - it might contain email in format "Name " - const authorInput = (opts.author || 'constructive').trim(); - let authorName = authorInput; - let authorEmail = ''; - - // Check if author already contains email in <...> format - const emailMatch = authorInput.match(/^(.+?)\s*<([^>]+)>\s*$/); - if (emailMatch) { - // Author already has email format: "Name " - authorName = emailMatch[1].trim(); - authorEmail = emailMatch[2].trim(); - } else { - // No email in author, use default format - authorName = authorInput; - authorEmail = `${authorName}@5b0c196eeb62`; - } + const { fullName, email } = parseAuthor(opts.author || 'constructive'); + const authorName = fullName; + const authorEmail = email || `${fullName}@5b0c196eeb62`; const duplicates: Record = {}; diff --git a/pgpm/core/src/utils/author.ts b/pgpm/core/src/utils/author.ts new file mode 100644 index 000000000..db39f83fc --- /dev/null +++ b/pgpm/core/src/utils/author.ts @@ -0,0 +1,16 @@ +export interface ParsedAuthor { + fullName: string; + email?: string; +} + +export function parseAuthor(author: string): ParsedAuthor { + const trimmed = (author || '').trim(); + const match = trimmed.match(/^(.+?)\s*<([^>]+)>$/); + if (match) { + return { + fullName: match[1].trim(), + email: match[2].trim() + }; + } + return { fullName: trimmed }; +}