-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathpowerpages-hook-utils.js
More file actions
87 lines (77 loc) · 2.3 KB
/
Copy pathpowerpages-hook-utils.js
File metadata and controls
87 lines (77 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const TRACKED_SKILLS = {
'activate-site': {
validatorScript: 'skills/activate-site/scripts/validate-activation.js',
},
'add-sample-data': {},
'add-seo': {
validatorScript: 'skills/add-seo/scripts/validate-seo.js',
},
'audit-permissions': {
validatorScript: 'skills/audit-permissions/scripts/validate-audit.js',
},
'create-site': {
validatorScript: 'skills/create-site/scripts/validate-site.js',
},
'create-webroles': {
validatorScript: 'skills/create-webroles/scripts/validate-webroles.js',
},
'add-server-logic': {
validatorScript: 'skills/add-server-logic/scripts/validate-serverlogic.js',
},
'integrate-webapi': {
validatorScript: 'skills/integrate-webapi/scripts/validate-webapi-integration.js',
},
'setup-auth': {
validatorScript: 'skills/setup-auth/scripts/validate-auth.js',
},
'setup-datamodel': {
validatorScript: 'skills/setup-datamodel/scripts/validate-datamodel.js',
},
'test-site': {},
};
function detectTrackedSkill(value) {
if (typeof value !== 'string') {
return null;
}
const trimmed = value.trim();
if (TRACKED_SKILLS[trimmed]) {
return trimmed;
}
// Strip leading slash and optional plugin prefix: /create-site, /power-pages:create-site
const normalized = trimmed.replace(/^\/?(?:power-pages:)?/, '').toLowerCase();
if (TRACKED_SKILLS[normalized]) {
return normalized;
}
// Fall back to searching for power-pages:<skill> anywhere in the string
const commandMatch = trimmed.match(/power-pages:([a-z0-9-]+)/i);
if (!commandMatch) {
return null;
}
const skillName = commandMatch[1].toLowerCase();
return TRACKED_SKILLS[skillName] ? skillName : null;
}
function getTrackedSkillFromToolInput(toolInput) {
if (!toolInput || typeof toolInput !== 'object') {
return null;
}
for (const field of ['skill', 'skill_name', 'skillName', 'name', 'commandName', 'command']) {
const skillName = detectTrackedSkill(toolInput[field]);
if (skillName) {
return skillName;
}
}
try {
return detectTrackedSkill(JSON.stringify(toolInput));
} catch {
return null;
}
}
function getValidatorScript(skillName) {
return TRACKED_SKILLS[skillName]?.validatorScript ?? null;
}
module.exports = {
TRACKED_SKILLS,
detectTrackedSkill,
getTrackedSkillFromToolInput,
getValidatorScript,
};