@garyr/pt-cli 0.25.1 → 0.26.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/README.md CHANGED
@@ -55,12 +55,12 @@ graph LR
55
55
  ### Installation
56
56
 
57
57
  ```bash
58
- # Clone this repository
58
+ npm i @garyr/pt-cli
59
+
60
+ # ...or clone this repository, then:
59
61
  cd pt-cli
60
62
  npm install
61
63
  npm run build
62
-
63
- # Link for global use
64
64
  npm link
65
65
  ```
66
66
 
@@ -0,0 +1,26 @@
1
+ import fs from 'fs';
2
+ import { loadConfig, saveConfig } from '../config.js';
3
+ export function defaultPostConfigCommand(options = {}) {
4
+ const config = loadConfig();
5
+ if (options.set) {
6
+ if (options.json) {
7
+ try {
8
+ const data = options.json.startsWith('{') || options.json.startsWith('[')
9
+ ? JSON.parse(options.json)
10
+ : JSON.parse(fs.readFileSync(options.json, 'utf-8'));
11
+ config.default_post_config = Array.isArray(data) ? data : [];
12
+ saveConfig(config);
13
+ console.log('Default post-config updated via JSON.');
14
+ }
15
+ catch (e) {
16
+ const error = e;
17
+ console.error('Failed to parse JSON for default post-config:', error.message);
18
+ }
19
+ return;
20
+ }
21
+ console.error('You must provide --json <data> to set the default post-config array.');
22
+ }
23
+ else {
24
+ console.log('Current default post-config tasks:', config.default_post_config || []);
25
+ }
26
+ }
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import inquirer from 'inquirer';
4
- import { loadConfig } from '../config.js';
4
+ import { loadConfig, sanitizePath } from '../config.js';
5
5
  import chalk from 'chalk';
6
6
  import { processCopyFiles } from '../substitute.js';
7
7
  import { execSync } from 'child_process';
@@ -128,7 +128,7 @@ export async function init(targetName, destPath, options = {}) {
128
128
  console.log(chalk.cyan("Processing post_copy..."));
129
129
  for (const file of template.post_copy) {
130
130
  const srcPath = path.join(template.templateRoot, file.src);
131
- const destPath = path.join(resolvedDest, file.dest || file.src);
131
+ const destPath = path.join(resolvedDest, sanitizePath(file.dest || file.src));
132
132
  if (fs.existsSync(srcPath)) {
133
133
  if (options.dryRun) {
134
134
  console.log(chalk.gray(` [DRY RUN] Would copy ${file.src} → ${file.dest || file.src}`));
@@ -269,7 +269,7 @@ export async function init(targetName, destPath, options = {}) {
269
269
  }
270
270
  function createStructure(dirPath, folders, dryRun = false) {
271
271
  for (const folder of folders) {
272
- const fullDirPath = path.join(dirPath, folder.name);
272
+ const fullDirPath = path.join(dirPath, sanitizePath(folder.name));
273
273
  if (dryRun) {
274
274
  console.log(chalk.gray(` [DRY RUN] Would create directory: ${fullDirPath}`));
275
275
  }
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { ignoreCommand } from './commands/ignoreCommand.js';
8
8
  import { variablesCommand } from './commands/variablesCommand.js';
9
9
  import { addCommand } from './commands/addCommand.js';
10
10
  import { removeCommand } from './commands/removeCommand.js';
11
+ import { defaultPostConfigCommand } from './commands/defaultPostConfigCommand.js';
11
12
  import pkg from '../package.json' with { type: 'json' };
12
13
  const program = new Command();
13
14
  program
@@ -61,6 +62,12 @@ program
61
62
  .option('--json <data>', 'Set variables via JSON string or file')
62
63
  .option('--delete <key>', 'Delete a specific global variable')
63
64
  .action(variablesCommand);
65
+ program
66
+ .command('default-post-config')
67
+ .description('View or set default post-config tasks')
68
+ .option('--set', 'Set the default post-config tasks via JSON')
69
+ .option('--json <data>', 'JSON string or file containing tasks array')
70
+ .action(defaultPostConfigCommand);
64
71
  program
65
72
  .command('add <name> [json]')
66
73
  .description('Import/add a template from a JSON string or file')
@@ -146,9 +146,14 @@ Each default task supports the same fields as template post-config:
146
146
  - **`pt learn --yes`**: all applicable default tasks are added automatically to the new template's `post_config`.
147
147
  - **Interactive mode (`pt learn`)**: applicable default tasks are shown in a checkbox group. Default tasks default to checked; `checked: false` overrides this.
148
148
 
149
- ### Viewing
149
+ ### Management
150
150
 
151
- Default tasks cannot be added via `pt add` or `pt learn` — they must be edited directly in `~/.pt/config.yaml` or viewed with `pt config`.
151
+ You can view current default tasks using `pt config` or `pt default-post-config`.
152
+ To update default tasks programmatically or via CLI, use the `pt default-post-config` command:
153
+ - `pt default-post-config`: List current default post-config tasks.
154
+ - `pt default-post-config --set --json '...'`: Replace the default post-config tasks list via a JSON string or file.
155
+
156
+ Alternatively, you can edit `~/.pt/config.yaml` directly.
152
157
 
153
158
  ## Global Variables
154
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@garyr/pt-cli",
3
- "version": "0.25.1",
3
+ "version": "0.26.0",
4
4
  "description": "Project Template CLI - Learn structures and initialize projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -42,7 +42,7 @@ Default post-config tasks are stored in `~/.pt/config.yaml` under `default_post_
42
42
 
43
43
  Tasks with `checked: false` stay unchecked by default in interactive mode. In `pt learn --yes` mode, **all applicable** default tasks are included.
44
44
 
45
- Use `pt config` to view currently configured default tasks. To add default tasks, edit `~/.pt/config.yaml` directly or use `pt add` for template management (config is YAML-only at this time).
45
+ Use `pt config` to view currently configured default tasks. To update default tasks, you can use `pt default-post-config --set --json '...'` to apply a new JSON array of tasks. Alternatively, you can edit `~/.pt/config.yaml` directly.
46
46
 
47
47
  ## Global Variables
48
48
 
@@ -0,0 +1,32 @@
1
+ import fs from 'fs';
2
+ import { loadConfig, saveConfig, PostConfigTask } from '../config.js';
3
+
4
+ export interface DefaultPostConfigOptions {
5
+ set?: boolean;
6
+ json?: string;
7
+ }
8
+
9
+ export function defaultPostConfigCommand(options: DefaultPostConfigOptions = {}) {
10
+ const config = loadConfig();
11
+
12
+ if (options.set) {
13
+ if (options.json) {
14
+ try {
15
+ const data = options.json.startsWith('{') || options.json.startsWith('[')
16
+ ? JSON.parse(options.json)
17
+ : JSON.parse(fs.readFileSync(options.json, 'utf-8'));
18
+ config.default_post_config = Array.isArray(data) ? data : [];
19
+ saveConfig(config);
20
+ console.log('Default post-config updated via JSON.');
21
+ } catch (e) {
22
+ const error = e as Error;
23
+ console.error('Failed to parse JSON for default post-config:', error.message);
24
+ }
25
+ return;
26
+ }
27
+
28
+ console.error('You must provide --json <data> to set the default post-config array.');
29
+ } else {
30
+ console.log('Current default post-config tasks:', config.default_post_config || []);
31
+ }
32
+ }
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import inquirer from 'inquirer';
4
- import { loadConfig, FolderNode } from '../config.js';
4
+ import { loadConfig, FolderNode, sanitizePath } from '../config.js';
5
5
  import chalk from 'chalk';
6
6
  import { processCopyFiles } from '../substitute.js';
7
7
  import { execSync } from 'child_process';
@@ -145,7 +145,7 @@ export async function init(targetName: string | undefined, destPath: string | un
145
145
 
146
146
  for (const file of template.post_copy) {
147
147
  const srcPath = path.join(template.templateRoot!, file.src);
148
- const destPath = path.join(resolvedDest, file.dest || file.src);
148
+ const destPath = path.join(resolvedDest, sanitizePath(file.dest || file.src));
149
149
 
150
150
  if (fs.existsSync(srcPath)) {
151
151
  if (options.dryRun) {
@@ -285,7 +285,7 @@ export async function init(targetName: string | undefined, destPath: string | un
285
285
 
286
286
  function createStructure(dirPath: string, folders: FolderNode[], dryRun: boolean = false) {
287
287
  for (const folder of folders) {
288
- const fullDirPath = path.join(dirPath, folder.name);
288
+ const fullDirPath = path.join(dirPath, sanitizePath(folder.name));
289
289
 
290
290
  if (dryRun) {
291
291
  console.log(chalk.gray(` [DRY RUN] Would create directory: ${fullDirPath}`));
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ import { ignoreCommand } from './commands/ignoreCommand.js';
13
13
  import { variablesCommand } from './commands/variablesCommand.js';
14
14
  import { addCommand } from './commands/addCommand.js';
15
15
  import { removeCommand } from './commands/removeCommand.js';
16
+ import { defaultPostConfigCommand } from './commands/defaultPostConfigCommand.js';
16
17
 
17
18
  import pkg from '../package.json' with { type: 'json' };
18
19
 
@@ -76,6 +77,13 @@ program
76
77
  .option('--delete <key>', 'Delete a specific global variable')
77
78
  .action(variablesCommand);
78
79
 
80
+ program
81
+ .command('default-post-config')
82
+ .description('View or set default post-config tasks')
83
+ .option('--set', 'Set the default post-config tasks via JSON')
84
+ .option('--json <data>', 'JSON string or file containing tasks array')
85
+ .action(defaultPostConfigCommand);
86
+
79
87
  program
80
88
  .command('add <name> [json]')
81
89
  .description('Import/add a template from a JSON string or file')