@garyr/pt-cli 0.41.0 → 0.42.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/config.js CHANGED
@@ -109,6 +109,20 @@ export function normalizeVariable(v) {
109
109
  result.required = v.required;
110
110
  return result;
111
111
  }
112
+ export function normalizeFolders(folders) {
113
+ return folders.map(folder => {
114
+ const normalized = { name: folder.name, info: folder.info || '' };
115
+ if (folder.children !== undefined && folder.children.length > 0) {
116
+ normalized.children = normalizeFolders(folder.children);
117
+ }
118
+ else if (folder.children !== undefined) {
119
+ normalized.children = [];
120
+ }
121
+ if (folder.is_file !== undefined)
122
+ normalized.is_file = folder.is_file;
123
+ return normalized;
124
+ });
125
+ }
112
126
  export function saveConfig(config) {
113
127
  ensureConfigDir();
114
128
  // Normalize variable key ordering (forces 'name' to be first in serialized YAML)
@@ -121,6 +135,28 @@ export function saveConfig(config) {
121
135
  if (template.variables && Array.isArray(template.variables)) {
122
136
  template.variables = template.variables.map(normalizeVariable);
123
137
  }
138
+ if (template.folders && Array.isArray(template.folders)) {
139
+ template.folders = normalizeFolders(template.folders);
140
+ }
141
+ // Create a new object with keys in the desired order for consistent YAML output
142
+ const orderedTemplate = {};
143
+ if (template.description !== undefined)
144
+ orderedTemplate.description = template.description;
145
+ if (template.templateRoot !== undefined)
146
+ orderedTemplate.templateRoot = template.templateRoot;
147
+ if (template.variables !== undefined)
148
+ orderedTemplate.variables = template.variables;
149
+ if (template.folders !== undefined)
150
+ orderedTemplate.folders = template.folders;
151
+ if (template.exclude !== undefined)
152
+ orderedTemplate.exclude = template.exclude;
153
+ if (template.copy_files !== undefined)
154
+ orderedTemplate.copy_files = template.copy_files;
155
+ if (template.post_copy !== undefined)
156
+ orderedTemplate.post_copy = template.post_copy;
157
+ if (template.post_config !== undefined)
158
+ orderedTemplate.post_config = template.post_config;
159
+ config.templates[key] = orderedTemplate;
124
160
  }
125
161
  }
126
162
  const content = YAML.stringify(config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@garyr/pt-cli",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "description": "Project Template CLI - Learn structures and initialize projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/config.ts CHANGED
@@ -174,6 +174,19 @@ export function normalizeVariable(v: TemplateVariable): TemplateVariable {
174
174
  return result;
175
175
  }
176
176
 
177
+ export function normalizeFolders(folders: FolderNode[]): FolderNode[] {
178
+ return folders.map(folder => {
179
+ const normalized: FolderNode = { name: folder.name, info: folder.info || '' };
180
+ if (folder.children !== undefined && folder.children.length > 0) {
181
+ normalized.children = normalizeFolders(folder.children);
182
+ } else if (folder.children !== undefined) {
183
+ normalized.children = [];
184
+ }
185
+ if (folder.is_file !== undefined) normalized.is_file = folder.is_file;
186
+ return normalized;
187
+ });
188
+ }
189
+
177
190
  export function saveConfig(config: PtConfig) {
178
191
  ensureConfigDir();
179
192
 
@@ -187,6 +200,20 @@ export function saveConfig(config: PtConfig) {
187
200
  if (template.variables && Array.isArray(template.variables)) {
188
201
  template.variables = template.variables.map(normalizeVariable);
189
202
  }
203
+ if (template.folders && Array.isArray(template.folders)) {
204
+ template.folders = normalizeFolders(template.folders);
205
+ }
206
+ // Create a new object with keys in the desired order for consistent YAML output
207
+ const orderedTemplate: Partial<TemplateConfig> = {};
208
+ if (template.description !== undefined) orderedTemplate.description = template.description;
209
+ if (template.templateRoot !== undefined) orderedTemplate.templateRoot = template.templateRoot;
210
+ if (template.variables !== undefined) orderedTemplate.variables = template.variables;
211
+ if (template.folders !== undefined) orderedTemplate.folders = template.folders;
212
+ if (template.exclude !== undefined) orderedTemplate.exclude = template.exclude;
213
+ if (template.copy_files !== undefined) orderedTemplate.copy_files = template.copy_files;
214
+ if (template.post_copy !== undefined) orderedTemplate.post_copy = template.post_copy;
215
+ if (template.post_config !== undefined) orderedTemplate.post_config = template.post_config;
216
+ config.templates[key] = orderedTemplate as TemplateConfig;
190
217
  }
191
218
  }
192
219