@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.
- package/README.md +41 -14
- package/dist/commands/completionCommand.js +396 -0
- package/dist/commands/learnCommand.js +28 -7
- package/dist/commands/template-utils.js +17 -7
- package/dist/commands/updateCommand.js +56 -25
- package/dist/config.js +3 -0
- package/dist/index.js +9 -1
- package/doc/usage.md +38 -0
- package/package.json +4 -1
- package/src/commands/completionCommand.ts +404 -0
- package/src/commands/learnCommand.ts +29 -7
- package/src/commands/template-utils.ts +17 -8
- package/src/commands/updateCommand.ts +125 -91
- package/src/config.ts +3 -0
- package/src/index.ts +10 -1
- package/tests/completion.test.ts +210 -0
- package/tests/config-utils.test.ts +1 -1
- package/tests/learn.test.ts +5 -4
- package/tests/update.test.ts +63 -9
package/tests/learn.test.ts
CHANGED
|
@@ -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
|
|
41
|
+
const originalWrite = process.stdout.write;
|
|
42
42
|
let captured = '';
|
|
43
|
-
|
|
44
|
-
captured +=
|
|
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
|
-
|
|
50
|
+
process.stdout.write = originalWrite;
|
|
50
51
|
}
|
|
51
52
|
return captured;
|
|
52
53
|
}
|
package/tests/update.test.ts
CHANGED
|
@@ -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
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
-
|
|
448
|
+
process.stdout.write = originalWrite;
|
|
403
449
|
}
|
|
404
450
|
|
|
405
|
-
//
|
|
406
|
-
|
|
407
|
-
|
|
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);
|