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
7 changes: 6 additions & 1 deletion pgpm/core/src/export/export-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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,
Expand All @@ -425,7 +428,9 @@ const preparePackage = async ({
moduleName: name,
moduleDesc: description,
access: 'restricted',
license: 'CLOSED'
license: 'CLOSED',
fullName,
...(email && { email })
}
});
} else {
Expand Down
20 changes: 4 additions & 16 deletions pgpm/core/src/files/plan/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <email>"
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 <email>"
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<string, boolean> = {};

Expand Down
16 changes: 16 additions & 0 deletions pgpm/core/src/utils/author.ts
Original file line number Diff line number Diff line change
@@ -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 };
}