myskillshub 1.0.6 → 1.0.7
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/package.json +1 -1
- package/src/commands/publish.js +43 -11
package/package.json
CHANGED
package/src/commands/publish.js
CHANGED
|
@@ -12,6 +12,7 @@ const FormData = require('form-data');
|
|
|
12
12
|
const { createWriteStream } = require('fs');
|
|
13
13
|
|
|
14
14
|
const program = new Command();
|
|
15
|
+
const DEFAULT_CATEGORY_SLUG = 'dev-tools';
|
|
15
16
|
|
|
16
17
|
program
|
|
17
18
|
.name('publish')
|
|
@@ -73,7 +74,7 @@ program
|
|
|
73
74
|
console.log(chalk.cyan(`Skill URL: ${options.apiUrl}/skills/${result.slug}`));
|
|
74
75
|
|
|
75
76
|
} catch (error) {
|
|
76
|
-
spinner.fail(chalk.red(`Publish failed: ${error
|
|
77
|
+
spinner.fail(chalk.red(`Publish failed: ${formatErrorMessage(error)}`));
|
|
77
78
|
if (options.verbose) {
|
|
78
79
|
console.error(error);
|
|
79
80
|
}
|
|
@@ -229,18 +230,25 @@ async function resolveCategoryId(apiUrl, options, frontmatter) {
|
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
232
|
|
|
232
|
-
const slugCandidate = options.categorySlug
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
const slugCandidate = options.categorySlug
|
|
234
|
+
|| frontmatter.category_slug
|
|
235
|
+
|| frontmatter.category
|
|
236
|
+
|| DEFAULT_CATEGORY_SLUG;
|
|
236
237
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
try {
|
|
239
|
+
const response = await axios.get(`${apiUrl}/api/categories/${encodeURIComponent(String(slugCandidate).trim())}`);
|
|
240
|
+
const category = response.data?.data?.category;
|
|
241
|
+
if (!response.data?.success || !category?.id) {
|
|
242
|
+
throw new Error(`Failed to resolve category slug: ${slugCandidate}`);
|
|
243
|
+
}
|
|
242
244
|
|
|
243
|
-
|
|
245
|
+
return category.id;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
if (error.response?.status === 404 && slugCandidate === DEFAULT_CATEGORY_SLUG) {
|
|
248
|
+
throw new Error(`Default category "${DEFAULT_CATEGORY_SLUG}" not found. Use --category-id or --category-slug.`);
|
|
249
|
+
}
|
|
250
|
+
throw new Error(`Failed to resolve category slug: ${slugCandidate}. ${formatErrorMessage(error)}`);
|
|
251
|
+
}
|
|
244
252
|
}
|
|
245
253
|
|
|
246
254
|
async function getAuthCookie(apiUrl, options, spinner) {
|
|
@@ -493,4 +501,28 @@ async function uploadSkill(zipPath, skillData, categoryId, apiUrl, authCookie) {
|
|
|
493
501
|
}
|
|
494
502
|
}
|
|
495
503
|
|
|
504
|
+
function formatErrorMessage(error) {
|
|
505
|
+
if (!error) {
|
|
506
|
+
return 'Unknown error';
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const status = error.response?.status;
|
|
510
|
+
const apiError = error.response?.data?.error;
|
|
511
|
+
const directMessage = error.response?.data?.message;
|
|
512
|
+
|
|
513
|
+
if (apiError?.message) {
|
|
514
|
+
return status ? `HTTP ${status}: ${apiError.message}` : apiError.message;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (directMessage) {
|
|
518
|
+
return status ? `HTTP ${status}: ${directMessage}` : directMessage;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (status) {
|
|
522
|
+
return `HTTP ${status}: ${error.message}`;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return error.message || 'Unknown error';
|
|
526
|
+
}
|
|
527
|
+
|
|
496
528
|
module.exports = program;
|