@ivotoby/postgram-cli 1.14.0 → 1.15.0

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/dist/pgm.js CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn, spawnSync } from 'node:child_process';
3
- import { createHash } from 'node:crypto';
4
3
  import { createWriteStream } from 'node:fs';
5
- import { mkdir, readdir, readFile as fsReadFile, stat } from 'node:fs/promises';
4
+ import { mkdir, readFile as fsReadFile, stat } from 'node:fs/promises';
6
5
  import path from 'node:path';
7
6
  import { Command } from 'commander';
8
7
  import { pipeline } from 'node:stream/promises';
9
8
  import { createPgmClient } from './client.js';
10
9
  import { handleCliFailure, isJsonMode, parseCommaList, parseJsonObject, printHuman, printJson, readStdinText, resolvePgmConfig, shortId } from './shared.js';
11
10
  import { AppError, ErrorCode } from './errors.js';
11
+ import { buildSyncManifest } from './sync-walk.js';
12
12
  function formatStoredEntity(entity) {
13
13
  return [
14
14
  `${entity.type} ${shortId(entity.id)}${entity.status ? ` [${entity.status}]` : ''}`,
@@ -540,28 +540,7 @@ program
540
540
  try {
541
541
  const resolvedDir = path.resolve(dir);
542
542
  const repoName = options.repo ?? path.basename(resolvedDir);
543
- const manifest = [];
544
- const SKIP_DIRS = new Set(['.git', 'node_modules', '.obsidian', '.trash']);
545
- async function walk(dirPath, prefix) {
546
- const entries = await readdir(dirPath, { withFileTypes: true });
547
- for (const entry of entries) {
548
- if (entry.isDirectory()) {
549
- if (!SKIP_DIRS.has(entry.name) && !entry.name.startsWith('.')) {
550
- await walk(path.join(dirPath, entry.name), prefix ? `${prefix}/${entry.name}` : entry.name);
551
- }
552
- }
553
- else if (entry.isFile() && entry.name.endsWith('.md')) {
554
- const fullPath = path.join(dirPath, entry.name);
555
- const content = await fsReadFile(fullPath, 'utf8');
556
- const sha = createHash('sha256').update(content).digest('hex');
557
- const relativePath = prefix
558
- ? `${prefix}/${entry.name}`
559
- : entry.name;
560
- manifest.push({ path: relativePath, sha, fullPath });
561
- }
562
- }
563
- }
564
- await walk(resolvedDir, '');
543
+ const manifest = await buildSyncManifest(resolvedDir);
565
544
  const config = await resolvePgmConfig();
566
545
  const client = createPgmClient(config);
567
546
  const manifestForServer = manifest.map(({ path: p, sha }) => ({ path: p, sha }));
package/dist/shared.js CHANGED
@@ -50,7 +50,7 @@ const INSECURE_PGMRC_MODE_MASK = 0o077;
50
50
  function normalizeUrl(url) {
51
51
  return url.replace(/\/+$/, '');
52
52
  }
53
- export async function resolvePgmConfig() {
53
+ export async function resolvePgmConfig(homeDir = os.homedir()) {
54
54
  const envUrl = process.env.PGM_API_URL;
55
55
  const envKey = process.env.PGM_API_KEY;
56
56
  if (envUrl && envKey) {
@@ -59,7 +59,7 @@ export async function resolvePgmConfig() {
59
59
  apiKey: envKey
60
60
  };
61
61
  }
62
- const rcPath = path.join(os.homedir(), '.pgmrc');
62
+ const rcPath = path.join(homeDir, '.pgmrc');
63
63
  try {
64
64
  const raw = await readFile(rcPath, 'utf8');
65
65
  const fileStat = statSync(rcPath);
@@ -0,0 +1,36 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { access, readdir, readFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ const SKIP_DIRS = new Set(['.git', 'node_modules', '.obsidian', '.trash']);
5
+ const IGNORE_MARKERS = ['.pgmignore', '.noindex'];
6
+ export async function buildSyncManifest(rootDir) {
7
+ const manifest = [];
8
+ async function walk(dirPath, prefix) {
9
+ for (const marker of IGNORE_MARKERS) {
10
+ try {
11
+ await access(path.join(dirPath, marker));
12
+ return;
13
+ }
14
+ catch {
15
+ // marker not present
16
+ }
17
+ }
18
+ const entries = await readdir(dirPath, { withFileTypes: true });
19
+ for (const entry of entries) {
20
+ if (entry.isDirectory()) {
21
+ if (!SKIP_DIRS.has(entry.name) && !entry.name.startsWith('.')) {
22
+ await walk(path.join(dirPath, entry.name), prefix ? `${prefix}/${entry.name}` : entry.name);
23
+ }
24
+ }
25
+ else if (entry.isFile() && entry.name.endsWith('.md')) {
26
+ const fullPath = path.join(dirPath, entry.name);
27
+ const content = await readFile(fullPath, 'utf8');
28
+ const sha = createHash('sha256').update(content).digest('hex');
29
+ const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
30
+ manifest.push({ path: relativePath, sha, fullPath });
31
+ }
32
+ }
33
+ }
34
+ await walk(rootDir, '');
35
+ return manifest;
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ivotoby/postgram-cli",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "Postgram CLI — store, search, and manage entities from the command line",
5
5
  "type": "module",
6
6
  "bin": {