-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcleanjs_cmdline.py
44 lines (36 loc) · 1.27 KB
/
cleanjs_cmdline.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
This is the command line tool for cleanjs.
Usage example:
python cmdline.py /my/source/file.js /path/to/myReport.html
Note that it's simple to integrate cleanjs in any other type of
python 2.7 enabled system. See the source code below to understand
how easy it is to review a file using the fileparser, reviewer and
reporter
"""
# This tool works on the command line, so needs to use commant line arguments
import sys
if len(sys.argv) != 3:
print ""
print "This command line tool requires 2 arguments:"
print " - the javascript file path to be checked"
print " - the path and filename of the report HTML file that will be created"
print ""
print "Usage example: $ python cleanjs_cmdline.py path/to/myFile.js path/to/myFileReport.html"
print ""
exit()
file_name = sys.argv[1]
report_name = sys.argv[2]
# Gather data about the file to be reviewed
from parsers import fileparser
try:
file_data = fileparser.get_file_data_from_file(file_name)
except Exception as error:
print error
exit()
# Review the file
from reviewers import reviewer
result = reviewer.review(file_data)
# Displaying the messages to an output
from reporters import htmlwithcode
htmlwithcode.output_messages(result, file_data, report_name)
print "Your file has been cleanjs'd! Check the report here " + report_name