@garyr/pt-cli 1.0.1 → 1.1.1

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.
@@ -38,15 +38,16 @@ function cleanConfig() {
38
38
 
39
39
  /** Capture console.log output during an async callback. */
40
40
  async function captureStdout(fn: () => Promise<void>): Promise<string> {
41
- const original = console.log;
41
+ const originalWrite = process.stdout.write;
42
42
  let captured = '';
43
- console.log = (...args: unknown[]) => {
44
- captured += args.map(a => (typeof a === 'string' ? a : JSON.stringify(a))).join(' ') + '\n';
43
+ process.stdout.write = (chunk: any) => {
44
+ captured += chunk.toString();
45
+ return true;
45
46
  };
46
47
  try {
47
48
  await fn();
48
49
  } finally {
49
- console.log = original;
50
+ process.stdout.write = originalWrite;
50
51
  }
51
52
  return captured;
52
53
  }
@@ -366,6 +366,51 @@ test('update: handles post_copy executables additively', async () => {
366
366
  }
367
367
  });
368
368
 
369
+ test('update: does not add post_config.sh/.bat to post_copy when unchecked', async () => {
370
+ const srcDir = createSourceDir('.test-update-postconfig-exclude');
371
+ cleanup(testHome);
372
+
373
+ try {
374
+ const initialConfig: PtConfig = {
375
+ version: '3.0',
376
+ templates: {
377
+ 'update-test-pc-exclude': {
378
+ description: 'Test',
379
+ templateRoot: '/old/path',
380
+ folders: [],
381
+ copy_files: [],
382
+ variables: [],
383
+ post_copy: []
384
+ }
385
+ }
386
+ };
387
+ saveConfig(initialConfig);
388
+
389
+ // Create post_config scripts - these should be excluded by shouldExcludeFile
390
+ fs.writeFileSync(path.join(srcDir, 'post_config.sh'), '#!/bin/bash\necho "Running: Build"\nnpm run build\n');
391
+ fs.writeFileSync(path.join(srcDir, 'post_config.bat'), '@echo off\necho Running: Build\nnpm run build\n');
392
+ fs.chmodSync(path.join(srcDir, 'post_config.sh'), 0o755);
393
+ fs.chmodSync(path.join(srcDir, 'post_config.bat'), 0o755);
394
+
395
+ await update(srcDir, 'update-test-pc-exclude', { yes: true });
396
+
397
+ const config = loadConfig();
398
+ const tpl = config.templates['update-test-pc-exclude'];
399
+
400
+ // post_config.sh and post_config.bat should NOT be in post_copy
401
+ const postCopySrcs = (tpl.post_copy || []).map(pc => pc.src);
402
+ assert.ok(!postCopySrcs.includes('post_config.sh'), 'post_config.sh should not be in post_copy');
403
+ assert.ok(!postCopySrcs.includes('post_config.bat'), 'post_config.bat should not be in post_copy');
404
+
405
+ // They should also not be in copy_files
406
+ const copySrcs = (tpl.copy_files || []).map(cf => cf.src);
407
+ assert.ok(!copySrcs.includes('post_config.sh'), 'post_config.sh should not be in copy_files');
408
+ assert.ok(!copySrcs.includes('post_config.bat'), 'post_config.bat should not be in copy_files');
409
+ } finally {
410
+ cleanup(srcDir, testHome);
411
+ }
412
+ });
413
+
369
414
  test('update: JSON mode outputs template config', async () => {
370
415
  const srcDir = createSourceDir('.test-update-json');
371
416
  cleanup(testHome);
@@ -390,21 +435,30 @@ test('update: JSON mode outputs template config', async () => {
390
435
  fs.writeFileSync(path.join(srcDir, 'template.txt'), '{{ var }}');
391
436
 
392
437
  // Capture stdout using a proper approach
393
- const output: string[] = [];
394
- const originalLog = console.log;
395
- console.log = (...args: any[]) => {
396
- output.push(args.join(' '));
438
+ const originalWrite = process.stdout.write;
439
+ let stdoutOutput = '';
440
+ process.stdout.write = (chunk: any) => {
441
+ stdoutOutput += chunk.toString();
442
+ return true;
397
443
  };
398
-
444
+
399
445
  try {
400
446
  await update(srcDir, 'update-test-json', { yes: true, json: true });
401
447
  } finally {
402
- console.log = originalLog;
448
+ process.stdout.write = originalWrite;
403
449
  }
404
450
 
405
- // Find the JSON line (last line that starts with {)
406
- const jsonLine = output.reverse().find(line => line.trim().startsWith('{'));
407
- const parsed = JSON.parse(jsonLine!);
451
+ // Debug output
452
+ // console.error('stdoutOutput:', JSON.stringify(stdoutOutput));
453
+
454
+ // Find the JSON (starts with { and goes to end)
455
+ const firstBrace = stdoutOutput.indexOf('{');
456
+ if (firstBrace === -1) {
457
+ console.error('No JSON found. Full output:', stdoutOutput);
458
+ assert.fail('No JSON output found');
459
+ }
460
+ const jsonString = stdoutOutput.substring(firstBrace);
461
+ const parsed = JSON.parse(jsonString);
408
462
  assert.strictEqual(parsed.name, 'update-test-json');
409
463
  assert.ok(parsed.folders);
410
464
  assert.ok(parsed.copy_files);