Skip to content

Commit 8e11849

Browse files
committed
Adding 'annotations' to component typing for actions
1 parent 61d0151 commit 8e11849

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

scripts/tool-annotations/apply-annotations.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class AnnotationApplier {
3030
processed: 0,
3131
modified: 0,
3232
errors: 0,
33-
skipped: 0
33+
skipped: 0,
34+
modifiedFiles: []
3435
};
3536
}
3637

@@ -186,9 +187,10 @@ class AnnotationApplier {
186187
}
187188

188189
isActionFile(fileName, fullPath) {
190+
const normalizedPath = fullPath.replace(/\\/g, '/');
189191
return (fileName.endsWith('.mjs') || fileName.endsWith('.ts')) &&
190-
fullPath.includes('/actions/') &&
191-
!fullPath.includes('/common/');
192+
normalizedPath.includes('/actions/') &&
193+
!normalizedPath.includes('/common/');
192194
}
193195

194196
extractActionKey(fileContent) {
@@ -221,8 +223,15 @@ class AnnotationApplier {
221223
}
222224

223225
applyAnnotations(fileContent, annotations) {
224-
// Find and replace version
225-
const versionMatch = fileContent.match(/(.*version:\s*["'])([^"']+)(["'],?\s*\n)/s);
226+
// Find and replace version - handle both orders: type before version OR version before type
227+
// Try lookahead first (version comes before type: "action")
228+
let versionMatch = fileContent.match(/(.*version:\s*["'])([^"']+)(["'],?\s*\n)(?=[\s\S]*?type:\s*["']action["'])/s);
229+
230+
// If not found, try lookbehind (type: "action" comes before version)
231+
if (!versionMatch) {
232+
versionMatch = fileContent.match(/(?<=type:\s*["']action["'][\s\S]{0,1000}?)(.*version:\s*["'])([^"']+)(["'],?\s*\n)/s);
233+
}
234+
226235
if (!versionMatch) {
227236
throw new Error('Could not find version field in file');
228237
}
@@ -270,7 +279,7 @@ class AnnotationApplier {
270279
const modifiedContent = this.applyAnnotations(fileContent, annotations);
271280
fs.writeFileSync(filePath, modifiedContent, 'utf8');
272281

273-
this.recordModification(fileContent, actionKey);
282+
this.recordModification(fileContent, actionKey, filePath);
274283
return true;
275284

276285
} catch (error) {
@@ -290,8 +299,9 @@ class AnnotationApplier {
290299
this.log(`Error processing ${filePath}: ${error.message}`, 'error');
291300
}
292301

293-
recordModification(fileContent, actionKey) {
302+
recordModification(fileContent, actionKey, filePath) {
294303
this.stats.modified++;
304+
this.stats.modifiedFiles.push(filePath);
295305

296306
const currentVersionMatch = fileContent.match(/version:\s*["']([^"']+)["']/);
297307
const currentVersion = currentVersionMatch ? currentVersionMatch[1] : 'unknown';
@@ -341,6 +351,12 @@ class AnnotationApplier {
341351
this.log('\n=== ERRORS ===');
342352
this.errors.forEach(error => this.log(error, 'error'));
343353
}
354+
355+
// Output modified files as JSON
356+
if (this.stats.modifiedFiles.length > 0) {
357+
this.log('\n=== MODIFIED FILES (JSON) ===');
358+
console.log(JSON.stringify(this.stats.modifiedFiles, null, 2));
359+
}
344360
}
345361

346362
async run() {

types/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ export interface Action<
384384
type: "action";
385385
methods?: Methods & ThisType<PropThis<ActionPropDefinitions> & Methods>;
386386
props?: ActionPropDefinitions;
387+
annotations?: {
388+
destructiveHint?: boolean;
389+
openWorldHint?: boolean;
390+
readOnlyHint?: boolean;
391+
}
387392
additionalProps?: (
388393
previousPropDefs: ActionPropDefinitions
389394
) => Promise<ActionPropDefinitions>;

0 commit comments

Comments
 (0)