11
11
'''
12
12
13
13
from pathlib import Path
14
+ import sys
14
15
import argparse
15
16
import logging
16
17
import time
@@ -26,7 +27,7 @@ def main():
26
27
27
28
# total number of files, extenion count and total size (in bytes)
28
29
logging .debug ('Counting files...' )
29
- files , types , size = count_files (args .root_dir )
30
+ files , types , size = count_files (find_node_modules ( args .root_dir ) )
30
31
31
32
# Calculate and format data
32
33
total_files = len (files )
@@ -55,6 +56,19 @@ def main():
55
56
print ('Total lines of code' .ljust (20 , '.' ) + f'{ str (total_lines )} ' .rjust (30 , '.' ))
56
57
57
58
59
+ def find_node_modules (root_dir ):
60
+ '''Checks for the presence of a node_modules directory and returns the full
61
+ path to that location based on the input root_dir'''
62
+
63
+ root_dir_abs = os .path .abspath (root_dir )
64
+
65
+ if 'node_modules' not in os .listdir (root_dir_abs ):
66
+ print (f'node_modules not found in { root_dir_abs } ' )
67
+ sys .exit (1 )
68
+
69
+ return os .path .join (root_dir_abs , 'node_modules' )
70
+
71
+
58
72
def top_extensions (types , top = 5 ):
59
73
'''Counts, sorts and returns the 5 highest items in the types dictionary'''
60
74
@@ -118,8 +132,8 @@ def count_files(root_dir):
118
132
for current , dirs , files in os .walk (root_dir ):
119
133
120
134
# ignore files not within a node_modules directory
121
- if 'node_modules' not in current :
122
- continue
135
+ # if 'node_modules' not in current:
136
+ # continue
123
137
124
138
for file in files :
125
139
try :
0 commit comments