1
+ #!/usr/bin/env node
2
+
3
+ /*---------------------------------------------------------------------------------------------
4
+ * Copyright (c) Microsoft Corporation. All rights reserved.
5
+ * Licensed under the MIT License. See License.txt in the project root for license information.
6
+ *--------------------------------------------------------------------------------------------*/
7
+
8
+ const fs = require ( 'fs' ) ;
9
+ const path = require ( 'path' ) ;
10
+
11
+ const extensionRoot = __dirname ;
12
+
13
+ function validateExtension ( ) {
14
+ console . log ( '🔍 Validating Hello World Extension...\n' ) ;
15
+
16
+ // Check package.json
17
+ const packageJsonPath = path . join ( extensionRoot , 'package.json' ) ;
18
+ if ( ! fs . existsSync ( packageJsonPath ) ) {
19
+ console . error ( '❌ package.json not found' ) ;
20
+ return false ;
21
+ }
22
+
23
+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
24
+ console . log ( '✅ package.json found' ) ;
25
+ console . log ( ` - Name: ${ packageJson . name } ` ) ;
26
+ console . log ( ` - Display Name: ${ packageJson . displayName } ` ) ;
27
+ console . log ( ` - Version: ${ packageJson . version } ` ) ;
28
+
29
+ // Check activation events
30
+ if ( packageJson . activationEvents && packageJson . activationEvents . includes ( 'onCommand:helloWorld.hello' ) ) {
31
+ console . log ( '✅ Activation event configured' ) ;
32
+ } else {
33
+ console . error ( '❌ Missing activation event' ) ;
34
+ return false ;
35
+ }
36
+
37
+ // Check commands
38
+ if ( packageJson . contributes && packageJson . contributes . commands ) {
39
+ const helloCommand = packageJson . contributes . commands . find ( cmd => cmd . command === 'helloWorld.hello' ) ;
40
+ if ( helloCommand ) {
41
+ console . log ( '✅ Hello World command configured' ) ;
42
+ console . log ( ` - Command: ${ helloCommand . command } ` ) ;
43
+ console . log ( ` - Title: ${ helloCommand . title } ` ) ;
44
+ } else {
45
+ console . error ( '❌ Hello World command not found' ) ;
46
+ return false ;
47
+ }
48
+ } else {
49
+ console . error ( '❌ No commands configured' ) ;
50
+ return false ;
51
+ }
52
+
53
+ // Check source file
54
+ const mainSrcPath = path . join ( extensionRoot , 'src' , 'extension.ts' ) ;
55
+ if ( ! fs . existsSync ( mainSrcPath ) ) {
56
+ console . error ( '❌ src/extension.ts not found' ) ;
57
+ return false ;
58
+ }
59
+ console . log ( '✅ Source file exists' ) ;
60
+
61
+ // Check compiled output
62
+ const mainOutPath = path . join ( extensionRoot , 'out' , 'extension.js' ) ;
63
+ if ( ! fs . existsSync ( mainOutPath ) ) {
64
+ console . error ( '❌ Compiled output not found (run: npx tsc)' ) ;
65
+ return false ;
66
+ }
67
+ console . log ( '✅ Compiled output exists' ) ;
68
+
69
+ // Check that compiled output contains the expected function
70
+ const compiledContent = fs . readFileSync ( mainOutPath , 'utf8' ) ;
71
+ if ( compiledContent . includes ( 'helloWorld.hello' ) && compiledContent . includes ( 'Hello World from VS Code!' ) ) {
72
+ console . log ( '✅ Compiled extension contains expected command and message' ) ;
73
+ } else {
74
+ console . error ( '❌ Compiled extension missing expected content' ) ;
75
+ return false ;
76
+ }
77
+
78
+ console . log ( '\n🎉 Hello World Extension validation passed!' ) ;
79
+ console . log ( '\nTo test the extension:' ) ;
80
+ console . log ( '1. Open VS Code development host' ) ;
81
+ console . log ( '2. Open Command Palette (Ctrl+Shift+P)' ) ;
82
+ console . log ( '3. Type "Hello World" and execute the command' ) ;
83
+ console . log ( '4. You should see: "Hello World from VS Code!" message' ) ;
84
+
85
+ return true ;
86
+ }
87
+
88
+ if ( require . main === module ) {
89
+ const success = validateExtension ( ) ;
90
+ process . exit ( success ? 0 : 1 ) ;
91
+ }
92
+
93
+ module . exports = validateExtension ;
0 commit comments