forked from PacktPublishing/Angular-Cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_correct_project_names.py
29 lines (24 loc) · 1.08 KB
/
check_correct_project_names.py
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
import os
import json
def find_package_names(start_dir):
for root, dirs, files in os.walk(start_dir):
# Exclude specific folders
if "node_modules" in dirs:
dirs.remove("node_modules")
if ".git" in dirs:
dirs.remove(".git")
for file_name in files:
if file_name == "package.json":
file_path = os.path.join(root, file_name)
project_dir_name = os.path.basename(root)
with open(file_path, "r") as json_file:
try:
package_data = json.load(json_file)
package_name = package_data.get("name")
if package_name and package_name != project_dir_name:
print(f"{root}: {package_name}")
except json.JSONDecodeError:
print(f"Error decoding JSON in {file_path}")
# Start walking from the script's directory
script_directory = os.path.dirname(os.path.abspath(__file__))
find_package_names(script_directory)