forked from SigmaWe/SmartCommand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugInCommands.py
More file actions
64 lines (48 loc) · 2.28 KB
/
plugInCommands.py
File metadata and controls
64 lines (48 loc) · 2.28 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
import json
import glob
import os
def get_extension_folder():
if os.name == 'nt':
return os.path.join(os.getenv('USERPROFILE'), '.vscode', 'extensions')
else:
return os.path.join(os.path.expanduser('~'), '.vscode', 'extensions')
def get_default_keybindings_file():
return 'package.json'
def main():
extension_folder = get_extension_folder()
extension_json_files = glob.glob(f'{extension_folder}/**/package.json', recursive=True)
all_extensions = {}
for file in extension_json_files:
with open(file, 'r', encoding='utf-8') as f:
package = json.load(f)
extension_name = package['name']
extension_version = package['version'] # Read the version from package.json
if 'contributes' in package and 'commands' in package['contributes']:
commands = package['contributes']['commands']
# Group commands by extension name and version
key = f"{extension_name}@{extension_version}"
if key not in all_extensions:
all_extensions[key] = {
"source": extension_name,
"version": extension_version,
"commands": []
}
for command in commands:
all_extensions[key]['commands'].append(command)
# Add default commands
default_keybindings_file = get_default_keybindings_file()
with open(default_keybindings_file, 'r', encoding='utf-8') as f:
package = json.load(f)
if 'contributes' in package and 'commands' in package['contributes']:
commands = package['contributes']['commands']
for command in commands:
command['source'] = 'default'
all_extensions['default'] = {
"source": "default",
"commands": commands
}
output_file = "plugInCommandsOutput.json"
print("Commands and titles have been successfully extracted and saved to plugInCommandsOutput.json.")
with open(output_file, 'w', encoding='utf-8') as outfile:
json.dump(list(all_extensions.values()), outfile, indent=2)
return list(all_extensions.values())