@garyr/pt-cli 1.0.0 → 1.0.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.
@@ -1,14 +1,39 @@
1
1
  import fs from 'fs';
2
2
  import { loadConfig, saveConfig } from '../config.js';
3
+ function coercePostConfigTasks(data) {
4
+ if (!Array.isArray(data))
5
+ return [];
6
+ return data.map(item => {
7
+ if (typeof item !== 'object' || item === null)
8
+ return { description: '', command: '' };
9
+ const obj = item;
10
+ const task = {
11
+ description: typeof obj.description === 'string' ? obj.description : '',
12
+ command: typeof obj.command === 'string' ? obj.command : undefined,
13
+ type: typeof obj.type === 'string' ? obj.type : undefined,
14
+ script: typeof obj.script === 'string' ? obj.script : undefined,
15
+ always_prompt: typeof obj.always_prompt === 'boolean' ? obj.always_prompt : undefined,
16
+ cross_platform: typeof obj.cross_platform === 'boolean' ? obj.cross_platform : undefined,
17
+ };
18
+ // Coerce checked: accept boolean, "true"/"false" strings, or omit (defaults to true in getDefaultPostConfig)
19
+ if (typeof obj.checked === 'boolean') {
20
+ task.checked = obj.checked;
21
+ }
22
+ else if (typeof obj.checked === 'string') {
23
+ task.checked = obj.checked.toLowerCase() === 'true';
24
+ }
25
+ return task;
26
+ });
27
+ }
3
28
  export function defaultPostConfigCommand(options = {}) {
4
29
  const config = loadConfig();
5
30
  if (options.set) {
6
31
  if (options.json) {
7
32
  try {
8
- const data = options.json.startsWith('{') || options.json.startsWith('[')
33
+ const rawData = options.json.startsWith('{') || options.json.startsWith('[')
9
34
  ? JSON.parse(options.json)
10
35
  : JSON.parse(fs.readFileSync(options.json, 'utf-8'));
11
- config.default_post_config = Array.isArray(data) ? data : [];
36
+ config.default_post_config = coercePostConfigTasks(rawData);
12
37
  saveConfig(config);
13
38
  console.log('Default post-config updated via JSON.');
14
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@garyr/pt-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Project Template CLI - Learn structures and initialize projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -6,16 +6,39 @@ export interface DefaultPostConfigOptions {
6
6
  json?: string;
7
7
  }
8
8
 
9
+ function coercePostConfigTasks(data: unknown): PostConfigTask[] {
10
+ if (!Array.isArray(data)) return [];
11
+ return data.map(item => {
12
+ if (typeof item !== 'object' || item === null) return { description: '', command: '' };
13
+ const obj = item as Record<string, unknown>;
14
+ const task: PostConfigTask = {
15
+ description: typeof obj.description === 'string' ? obj.description : '',
16
+ command: typeof obj.command === 'string' ? obj.command : undefined,
17
+ type: typeof obj.type === 'string' ? obj.type : undefined,
18
+ script: typeof obj.script === 'string' ? obj.script : undefined,
19
+ always_prompt: typeof obj.always_prompt === 'boolean' ? obj.always_prompt : undefined,
20
+ cross_platform: typeof obj.cross_platform === 'boolean' ? obj.cross_platform : undefined,
21
+ };
22
+ // Coerce checked: accept boolean, "true"/"false" strings, or omit (defaults to true in getDefaultPostConfig)
23
+ if (typeof obj.checked === 'boolean') {
24
+ task.checked = obj.checked;
25
+ } else if (typeof obj.checked === 'string') {
26
+ task.checked = obj.checked.toLowerCase() === 'true';
27
+ }
28
+ return task;
29
+ });
30
+ }
31
+
9
32
  export function defaultPostConfigCommand(options: DefaultPostConfigOptions = {}) {
10
33
  const config = loadConfig();
11
34
 
12
35
  if (options.set) {
13
36
  if (options.json) {
14
37
  try {
15
- const data = options.json.startsWith('{') || options.json.startsWith('[')
38
+ const rawData = options.json.startsWith('{') || options.json.startsWith('[')
16
39
  ? JSON.parse(options.json)
17
40
  : JSON.parse(fs.readFileSync(options.json, 'utf-8'));
18
- config.default_post_config = Array.isArray(data) ? data : [];
41
+ config.default_post_config = coercePostConfigTasks(rawData);
19
42
  saveConfig(config);
20
43
  console.log('Default post-config updated via JSON.');
21
44
  } catch (e) {