@pgpmjs/core 4.5.1 → 4.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/export/export-migrations.js +20 -7
- package/esm/files/plan/writer.js +4 -16
- package/esm/utils/author.js +11 -0
- package/export/export-migrations.d.ts +5 -1
- package/export/export-migrations.js +20 -7
- package/files/plan/writer.js +4 -16
- package/package.json +2 -2
- package/utils/author.d.ts +5 -0
- package/utils/author.js +14 -0
|
@@ -6,6 +6,7 @@ import { getPgPool } from 'pg-cache';
|
|
|
6
6
|
import { PgpmPackage } from '../core/class/pgpm';
|
|
7
7
|
import { writePgpmFiles, writePgpmPlan } from '../files';
|
|
8
8
|
import { getMissingInstallableModules } from '../modules/modules';
|
|
9
|
+
import { parseAuthor } from '../utils/author';
|
|
9
10
|
import { exportMeta } from './export-meta';
|
|
10
11
|
/**
|
|
11
12
|
* Required extensions for database schema exports.
|
|
@@ -91,7 +92,7 @@ const installMissingModules = async (moduleDir, missingModules) => {
|
|
|
91
92
|
await moduleProject.installModules(...missingNames);
|
|
92
93
|
console.log('Modules installed successfully.');
|
|
93
94
|
};
|
|
94
|
-
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter }) => {
|
|
95
|
+
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username }) => {
|
|
95
96
|
outdir = outdir + '/';
|
|
96
97
|
const pgPool = getPgPool({
|
|
97
98
|
...options.pg,
|
|
@@ -132,7 +133,9 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
132
133
|
name,
|
|
133
134
|
description: dbExtensionDesc,
|
|
134
135
|
extensions: [...DB_REQUIRED_EXTENSIONS],
|
|
135
|
-
prompter
|
|
136
|
+
prompter,
|
|
137
|
+
repoName,
|
|
138
|
+
username
|
|
136
139
|
});
|
|
137
140
|
// Install missing modules if user confirmed (now that module exists)
|
|
138
141
|
if (dbMissingResult.shouldInstall) {
|
|
@@ -158,7 +161,9 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
158
161
|
name: metaExtensionName,
|
|
159
162
|
description: metaDesc,
|
|
160
163
|
extensions: [...SERVICE_REQUIRED_EXTENSIONS],
|
|
161
|
-
prompter
|
|
164
|
+
prompter,
|
|
165
|
+
repoName,
|
|
166
|
+
username
|
|
162
167
|
});
|
|
163
168
|
// Install missing modules if user confirmed (now that module exists)
|
|
164
169
|
if (svcMissingResult.shouldInstall) {
|
|
@@ -211,7 +216,7 @@ SET session_replication_role TO DEFAULT;
|
|
|
211
216
|
}
|
|
212
217
|
pgPool.end();
|
|
213
218
|
};
|
|
214
|
-
export const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter }) => {
|
|
219
|
+
export const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username }) => {
|
|
215
220
|
for (let v = 0; v < dbInfo.database_ids.length; v++) {
|
|
216
221
|
const databaseId = dbInfo.database_ids[v];
|
|
217
222
|
await exportMigrationsToDisk({
|
|
@@ -227,7 +232,9 @@ export const exportMigrations = async ({ project, options, dbInfo, author, outdi
|
|
|
227
232
|
schema_names,
|
|
228
233
|
author,
|
|
229
234
|
outdir,
|
|
230
|
-
prompter
|
|
235
|
+
prompter,
|
|
236
|
+
repoName,
|
|
237
|
+
username
|
|
231
238
|
});
|
|
232
239
|
}
|
|
233
240
|
};
|
|
@@ -237,13 +244,14 @@ export const exportMigrations = async ({ project, options, dbInfo, author, outdi
|
|
|
237
244
|
*
|
|
238
245
|
* @returns The absolute path to the created/prepared module directory
|
|
239
246
|
*/
|
|
240
|
-
const preparePackage = async ({ project, author, outdir, name, description, extensions, prompter }) => {
|
|
247
|
+
const preparePackage = async ({ project, author, outdir, name, description, extensions, prompter, repoName, username }) => {
|
|
241
248
|
const curDir = process.cwd();
|
|
242
249
|
const pgpmDir = path.resolve(path.join(outdir, name));
|
|
243
250
|
mkdirSync(pgpmDir, { recursive: true });
|
|
244
251
|
process.chdir(pgpmDir);
|
|
245
252
|
const plan = glob(path.join(pgpmDir, 'pgpm.plan'));
|
|
246
253
|
if (!plan.length) {
|
|
254
|
+
const { fullName, email } = parseAuthor(author);
|
|
247
255
|
await project.initModule({
|
|
248
256
|
name,
|
|
249
257
|
description,
|
|
@@ -253,7 +261,12 @@ const preparePackage = async ({ project, author, outdir, name, description, exte
|
|
|
253
261
|
moduleName: name,
|
|
254
262
|
moduleDesc: description,
|
|
255
263
|
access: 'restricted',
|
|
256
|
-
license: 'CLOSED'
|
|
264
|
+
license: 'CLOSED',
|
|
265
|
+
fullName,
|
|
266
|
+
...(email && { email }),
|
|
267
|
+
// Use provided values or sensible defaults
|
|
268
|
+
repoName: repoName || name,
|
|
269
|
+
...(username && { username })
|
|
257
270
|
}
|
|
258
271
|
});
|
|
259
272
|
}
|
package/esm/files/plan/writer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { parseAuthor } from '../../utils/author';
|
|
3
4
|
/**
|
|
4
5
|
* Write a PGPM plan file based on the provided rows
|
|
5
6
|
*/
|
|
@@ -7,22 +8,9 @@ export function writePgpmPlan(rows, opts) {
|
|
|
7
8
|
const dir = path.resolve(path.join(opts.outdir, opts.name));
|
|
8
9
|
fs.mkdirSync(dir, { recursive: true });
|
|
9
10
|
const date = () => '2017-08-11T08:11:51Z'; // stubbed timestamp
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
let authorEmail = '';
|
|
14
|
-
// Check if author already contains email in <...> format
|
|
15
|
-
const emailMatch = authorInput.match(/^(.+?)\s*<([^>]+)>\s*$/);
|
|
16
|
-
if (emailMatch) {
|
|
17
|
-
// Author already has email format: "Name <email>"
|
|
18
|
-
authorName = emailMatch[1].trim();
|
|
19
|
-
authorEmail = emailMatch[2].trim();
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
// No email in author, use default format
|
|
23
|
-
authorName = authorInput;
|
|
24
|
-
authorEmail = `${authorName}@5b0c196eeb62`;
|
|
25
|
-
}
|
|
11
|
+
const { fullName, email } = parseAuthor(opts.author || 'constructive');
|
|
12
|
+
const authorName = fullName;
|
|
13
|
+
const authorEmail = email || `${fullName}@5b0c196eeb62`;
|
|
26
14
|
const duplicates = {};
|
|
27
15
|
const plan = opts.replacer(`%syntax-version=1.0.0
|
|
28
16
|
%project=constructive-extension-name
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function parseAuthor(author) {
|
|
2
|
+
const trimmed = (author || '').trim();
|
|
3
|
+
const match = trimmed.match(/^(.+?)\s*<([^>]+)>$/);
|
|
4
|
+
if (match) {
|
|
5
|
+
return {
|
|
6
|
+
fullName: match[1].trim(),
|
|
7
|
+
email: match[2].trim()
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return { fullName: trimmed };
|
|
11
|
+
}
|
|
@@ -23,6 +23,10 @@ interface ExportOptions {
|
|
|
23
23
|
metaExtensionName: string;
|
|
24
24
|
metaExtensionDesc?: string;
|
|
25
25
|
prompter?: Prompter;
|
|
26
|
+
/** Repository name for module scaffolding. Defaults to module name if not provided. */
|
|
27
|
+
repoName?: string;
|
|
28
|
+
/** GitHub username/org for module scaffolding. Required for non-interactive use. */
|
|
29
|
+
username?: string;
|
|
26
30
|
}
|
|
27
|
-
export declare const exportMigrations: ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter }: ExportOptions) => Promise<void>;
|
|
31
|
+
export declare const exportMigrations: ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username }: ExportOptions) => Promise<void>;
|
|
28
32
|
export {};
|
|
@@ -12,6 +12,7 @@ const pg_cache_1 = require("pg-cache");
|
|
|
12
12
|
const pgpm_1 = require("../core/class/pgpm");
|
|
13
13
|
const files_1 = require("../files");
|
|
14
14
|
const modules_1 = require("../modules/modules");
|
|
15
|
+
const author_1 = require("../utils/author");
|
|
15
16
|
const export_meta_1 = require("./export-meta");
|
|
16
17
|
/**
|
|
17
18
|
* Required extensions for database schema exports.
|
|
@@ -97,7 +98,7 @@ const installMissingModules = async (moduleDir, missingModules) => {
|
|
|
97
98
|
await moduleProject.installModules(...missingNames);
|
|
98
99
|
console.log('Modules installed successfully.');
|
|
99
100
|
};
|
|
100
|
-
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter }) => {
|
|
101
|
+
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username }) => {
|
|
101
102
|
outdir = outdir + '/';
|
|
102
103
|
const pgPool = (0, pg_cache_1.getPgPool)({
|
|
103
104
|
...options.pg,
|
|
@@ -138,7 +139,9 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
138
139
|
name,
|
|
139
140
|
description: dbExtensionDesc,
|
|
140
141
|
extensions: [...DB_REQUIRED_EXTENSIONS],
|
|
141
|
-
prompter
|
|
142
|
+
prompter,
|
|
143
|
+
repoName,
|
|
144
|
+
username
|
|
142
145
|
});
|
|
143
146
|
// Install missing modules if user confirmed (now that module exists)
|
|
144
147
|
if (dbMissingResult.shouldInstall) {
|
|
@@ -164,7 +167,9 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
164
167
|
name: metaExtensionName,
|
|
165
168
|
description: metaDesc,
|
|
166
169
|
extensions: [...SERVICE_REQUIRED_EXTENSIONS],
|
|
167
|
-
prompter
|
|
170
|
+
prompter,
|
|
171
|
+
repoName,
|
|
172
|
+
username
|
|
168
173
|
});
|
|
169
174
|
// Install missing modules if user confirmed (now that module exists)
|
|
170
175
|
if (svcMissingResult.shouldInstall) {
|
|
@@ -217,7 +222,7 @@ SET session_replication_role TO DEFAULT;
|
|
|
217
222
|
}
|
|
218
223
|
pgPool.end();
|
|
219
224
|
};
|
|
220
|
-
const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter }) => {
|
|
225
|
+
const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username }) => {
|
|
221
226
|
for (let v = 0; v < dbInfo.database_ids.length; v++) {
|
|
222
227
|
const databaseId = dbInfo.database_ids[v];
|
|
223
228
|
await exportMigrationsToDisk({
|
|
@@ -233,7 +238,9 @@ const exportMigrations = async ({ project, options, dbInfo, author, outdir, sche
|
|
|
233
238
|
schema_names,
|
|
234
239
|
author,
|
|
235
240
|
outdir,
|
|
236
|
-
prompter
|
|
241
|
+
prompter,
|
|
242
|
+
repoName,
|
|
243
|
+
username
|
|
237
244
|
});
|
|
238
245
|
}
|
|
239
246
|
};
|
|
@@ -244,13 +251,14 @@ exports.exportMigrations = exportMigrations;
|
|
|
244
251
|
*
|
|
245
252
|
* @returns The absolute path to the created/prepared module directory
|
|
246
253
|
*/
|
|
247
|
-
const preparePackage = async ({ project, author, outdir, name, description, extensions, prompter }) => {
|
|
254
|
+
const preparePackage = async ({ project, author, outdir, name, description, extensions, prompter, repoName, username }) => {
|
|
248
255
|
const curDir = process.cwd();
|
|
249
256
|
const pgpmDir = path_1.default.resolve(path_1.default.join(outdir, name));
|
|
250
257
|
(0, fs_1.mkdirSync)(pgpmDir, { recursive: true });
|
|
251
258
|
process.chdir(pgpmDir);
|
|
252
259
|
const plan = (0, glob_1.sync)(path_1.default.join(pgpmDir, 'pgpm.plan'));
|
|
253
260
|
if (!plan.length) {
|
|
261
|
+
const { fullName, email } = (0, author_1.parseAuthor)(author);
|
|
254
262
|
await project.initModule({
|
|
255
263
|
name,
|
|
256
264
|
description,
|
|
@@ -260,7 +268,12 @@ const preparePackage = async ({ project, author, outdir, name, description, exte
|
|
|
260
268
|
moduleName: name,
|
|
261
269
|
moduleDesc: description,
|
|
262
270
|
access: 'restricted',
|
|
263
|
-
license: 'CLOSED'
|
|
271
|
+
license: 'CLOSED',
|
|
272
|
+
fullName,
|
|
273
|
+
...(email && { email }),
|
|
274
|
+
// Use provided values or sensible defaults
|
|
275
|
+
repoName: repoName || name,
|
|
276
|
+
...(username && { username })
|
|
264
277
|
}
|
|
265
278
|
});
|
|
266
279
|
}
|
package/files/plan/writer.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.generateChangeLineContent = generateChangeLineContent;
|
|
|
11
11
|
exports.generateTagLineContent = generateTagLineContent;
|
|
12
12
|
const fs_1 = __importDefault(require("fs"));
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const author_1 = require("../../utils/author");
|
|
14
15
|
/**
|
|
15
16
|
* Write a PGPM plan file based on the provided rows
|
|
16
17
|
*/
|
|
@@ -18,22 +19,9 @@ function writePgpmPlan(rows, opts) {
|
|
|
18
19
|
const dir = path_1.default.resolve(path_1.default.join(opts.outdir, opts.name));
|
|
19
20
|
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
20
21
|
const date = () => '2017-08-11T08:11:51Z'; // stubbed timestamp
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
let authorEmail = '';
|
|
25
|
-
// Check if author already contains email in <...> format
|
|
26
|
-
const emailMatch = authorInput.match(/^(.+?)\s*<([^>]+)>\s*$/);
|
|
27
|
-
if (emailMatch) {
|
|
28
|
-
// Author already has email format: "Name <email>"
|
|
29
|
-
authorName = emailMatch[1].trim();
|
|
30
|
-
authorEmail = emailMatch[2].trim();
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
// No email in author, use default format
|
|
34
|
-
authorName = authorInput;
|
|
35
|
-
authorEmail = `${authorName}@5b0c196eeb62`;
|
|
36
|
-
}
|
|
22
|
+
const { fullName, email } = (0, author_1.parseAuthor)(opts.author || 'constructive');
|
|
23
|
+
const authorName = fullName;
|
|
24
|
+
const authorEmail = email || `${fullName}@5b0c196eeb62`;
|
|
37
25
|
const duplicates = {};
|
|
38
26
|
const plan = opts.replacer(`%syntax-version=1.0.0
|
|
39
27
|
%project=constructive-extension-name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.3",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM Package and Migration Tools",
|
|
6
6
|
"main": "index.js",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"pgsql-parser": "^17.9.5",
|
|
65
65
|
"yanse": "^0.1.8"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "b50728f2e33dd0b1da62f574c976737f2d3a41f8"
|
|
68
68
|
}
|
package/utils/author.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAuthor = parseAuthor;
|
|
4
|
+
function parseAuthor(author) {
|
|
5
|
+
const trimmed = (author || '').trim();
|
|
6
|
+
const match = trimmed.match(/^(.+?)\s*<([^>]+)>$/);
|
|
7
|
+
if (match) {
|
|
8
|
+
return {
|
|
9
|
+
fullName: match[1].trim(),
|
|
10
|
+
email: match[2].trim()
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return { fullName: trimmed };
|
|
14
|
+
}
|