@garyr/pt-cli 0.28.0 → 0.30.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.
|
@@ -155,12 +155,32 @@ export async function learn(sourcePath, updateTemplate = null, options = {}) {
|
|
|
155
155
|
console.log(chalk.cyan(`Auto-detected ${detectedVars.length} variable(s): ${detectedVars.join(', ')}`));
|
|
156
156
|
}
|
|
157
157
|
let variables = [];
|
|
158
|
-
//
|
|
159
|
-
if (isUpdate
|
|
160
|
-
|
|
158
|
+
// During updates, merge existing template variables with JSON file variables
|
|
159
|
+
if (isUpdate) {
|
|
160
|
+
// Start with existing template variables
|
|
161
|
+
if (config.templates[updateTemplate].variables) {
|
|
162
|
+
variables = [...config.templates[updateTemplate].variables];
|
|
163
|
+
}
|
|
164
|
+
// Then add JSON variables (overwrite/update existing ones with same name)
|
|
165
|
+
if (fileTemplateConfig.variables && Array.isArray(fileTemplateConfig.variables)) {
|
|
166
|
+
for (const v of fileTemplateConfig.variables) {
|
|
167
|
+
const existingIndex = variables.findIndex(existing => existing.name === v.name);
|
|
168
|
+
if (existingIndex !== -1) {
|
|
169
|
+
// Update existing variable with JSON values (but preserve other fields)
|
|
170
|
+
variables[existingIndex] = { ...variables[existingIndex], ...v };
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Add new variable
|
|
174
|
+
variables.push({ ...v });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
161
178
|
}
|
|
162
|
-
else
|
|
163
|
-
variables
|
|
179
|
+
else {
|
|
180
|
+
// For new templates, use JSON variables if available
|
|
181
|
+
if (fileTemplateConfig.variables && Array.isArray(fileTemplateConfig.variables)) {
|
|
182
|
+
variables = [...fileTemplateConfig.variables];
|
|
183
|
+
}
|
|
164
184
|
}
|
|
165
185
|
// Add detected variables if not already present
|
|
166
186
|
for (const varName of detectedVars) {
|
|
@@ -369,7 +389,8 @@ export async function learn(sourcePath, updateTemplate = null, options = {}) {
|
|
|
369
389
|
loop: false,
|
|
370
390
|
theme: {
|
|
371
391
|
icon: {
|
|
372
|
-
|
|
392
|
+
checked: chalk.green('[x] '),
|
|
393
|
+
unchecked: '[ ] ',
|
|
373
394
|
}
|
|
374
395
|
},
|
|
375
396
|
choices
|
package/dist/remote.js
CHANGED
|
@@ -8,12 +8,14 @@ import { extract } from 'tar'; // You'll need: npm install tar
|
|
|
8
8
|
export async function downloadAndExtract(url) {
|
|
9
9
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pt-template-'));
|
|
10
10
|
let downloadUrl = url;
|
|
11
|
+
// Strip trailing slash and .git suffix before converting to archive URL
|
|
12
|
+
let cleanUrl = url.replace(/\/$/, '').replace(/\.git$/, '');
|
|
11
13
|
// Convert GitHub/Gitea URLs to Zip/Tarball endpoints
|
|
12
14
|
if (url.includes('github.com')) {
|
|
13
|
-
downloadUrl =
|
|
15
|
+
downloadUrl = cleanUrl + '/archive/refs/heads/main.tar.gz';
|
|
14
16
|
}
|
|
15
17
|
else if (url.includes('gitea')) {
|
|
16
|
-
downloadUrl =
|
|
18
|
+
downloadUrl = cleanUrl + '/archive/main.tar.gz';
|
|
17
19
|
}
|
|
18
20
|
const response = await fetch(downloadUrl);
|
|
19
21
|
if (!response.ok)
|
package/package.json
CHANGED
|
@@ -158,11 +158,30 @@ export async function learn(sourcePath: string, updateTemplate: string | null =
|
|
|
158
158
|
|
|
159
159
|
let variables: TemplateVariable[] = [];
|
|
160
160
|
|
|
161
|
-
//
|
|
162
|
-
if (isUpdate
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
// During updates, merge existing template variables with JSON file variables
|
|
162
|
+
if (isUpdate) {
|
|
163
|
+
// Start with existing template variables
|
|
164
|
+
if (config.templates[updateTemplate].variables) {
|
|
165
|
+
variables = [...config.templates[updateTemplate].variables];
|
|
166
|
+
}
|
|
167
|
+
// Then add JSON variables (overwrite/update existing ones with same name)
|
|
168
|
+
if (fileTemplateConfig.variables && Array.isArray(fileTemplateConfig.variables)) {
|
|
169
|
+
for (const v of fileTemplateConfig.variables) {
|
|
170
|
+
const existingIndex = variables.findIndex(existing => existing.name === v.name);
|
|
171
|
+
if (existingIndex !== -1) {
|
|
172
|
+
// Update existing variable with JSON values (but preserve other fields)
|
|
173
|
+
variables[existingIndex] = { ...variables[existingIndex], ...v };
|
|
174
|
+
} else {
|
|
175
|
+
// Add new variable
|
|
176
|
+
variables.push({ ...v });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
// For new templates, use JSON variables if available
|
|
182
|
+
if (fileTemplateConfig.variables && Array.isArray(fileTemplateConfig.variables)) {
|
|
183
|
+
variables = [...fileTemplateConfig.variables];
|
|
184
|
+
}
|
|
166
185
|
}
|
|
167
186
|
|
|
168
187
|
// Add detected variables if not already present
|
|
@@ -380,7 +399,8 @@ export async function learn(sourcePath: string, updateTemplate: string | null =
|
|
|
380
399
|
loop: false,
|
|
381
400
|
theme: {
|
|
382
401
|
icon: {
|
|
383
|
-
|
|
402
|
+
checked: chalk.green('[x] '),
|
|
403
|
+
unchecked: '[ ] ',
|
|
384
404
|
}
|
|
385
405
|
},
|
|
386
406
|
choices
|
package/src/remote.ts
CHANGED
|
@@ -10,11 +10,14 @@ export async function downloadAndExtract(url: string): Promise<string> {
|
|
|
10
10
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pt-template-'));
|
|
11
11
|
let downloadUrl = url;
|
|
12
12
|
|
|
13
|
+
// Strip trailing slash and .git suffix before converting to archive URL
|
|
14
|
+
let cleanUrl = url.replace(/\/$/, '').replace(/\.git$/, '');
|
|
15
|
+
|
|
13
16
|
// Convert GitHub/Gitea URLs to Zip/Tarball endpoints
|
|
14
17
|
if (url.includes('github.com')) {
|
|
15
|
-
downloadUrl =
|
|
18
|
+
downloadUrl = cleanUrl + '/archive/refs/heads/main.tar.gz';
|
|
16
19
|
} else if (url.includes('gitea')) {
|
|
17
|
-
downloadUrl =
|
|
20
|
+
downloadUrl = cleanUrl + '/archive/main.tar.gz';
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
const response = await fetch(downloadUrl);
|