├── LICENSE ├── MANIFEST.in ├── README.md ├── cocoapods-graph-runner.py ├── cocoapodsgraph ├── __init__.py ├── __main__.py └── executor.py ├── docs └── wordpress_example.gif └── setup.py /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Erick Jung 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.md -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cocoapods-graph 2 | ================ 3 | 4 | This tool generates a dependencies graph report, printing on console or saving on a json or creating a html with a interactive disc to navigate through it. 5 | 6 | ## Example for Wordpress iOS app dependencies link ## 7 | 8 | 9 | ![the dependency wheel for wordpress iOS app](https://github.com/erickjung/cocoapods-graph/blob/master/docs/wordpress_example.gif) 10 | 11 | ## Installing ## 12 | ```shell 13 | [sudo] pip install cocoapods-graph 14 | ``` 15 | 16 | ## How to use ## 17 | ```shell 18 | cocoapods-graph -f Podfile.lock --html 19 | ``` 20 | 21 | ## Thanks ## 22 | 23 | All html rendering is done with: 24 | * d3.js 25 | * Dependency Wheel 26 | 27 | -------------------------------------------------------------------------------- /cocoapods-graph-runner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from cocoapodsgraph.executor import main 4 | 5 | if __name__ == '__main__': 6 | main() 7 | -------------------------------------------------------------------------------- /cocoapodsgraph/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erickjung/cocoapods-graph/fa337d6cd497f4735128835cda4106661e7ecf65/cocoapodsgraph/__init__.py -------------------------------------------------------------------------------- /cocoapodsgraph/__main__.py: -------------------------------------------------------------------------------- 1 | from .executor import main 2 | main() 3 | -------------------------------------------------------------------------------- /cocoapodsgraph/executor.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Erick Jung 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | import os 22 | import sys 23 | import json 24 | from optparse import OptionParser 25 | 26 | __version__ = "0.1.2" 27 | 28 | PROJECT_NAME = "cocoapods-graph" 29 | PROJECT_DESCRIPTION = "cocoapods dependencies graph generator" 30 | PROJECT_AUTHOR = "erick jung (erickjung@gmail.com)" 31 | 32 | class PodClass: 33 | name = '' 34 | version = '' 35 | dependencies = [] 36 | 37 | def __init__(self, name, version, dependencies): 38 | self.name = name 39 | self.version = version 40 | self.dependencies = dependencies 41 | 42 | def printObject(self): 43 | print(self.name + " " + self.version) 44 | for dep in self.dependencies: 45 | print(" " + dep.name + " " + dep.version) 46 | 47 | # --------- 48 | 49 | def parse_lock_file(fileName): 50 | def parse_lock_pods_line(line): 51 | try: 52 | name = line[line.index("-")+1:line.index("(")].strip() 53 | except Exception: 54 | name = line[line.index("-")+1:].strip() 55 | 56 | try: 57 | version = line[line.index("(")+1:line.index(")")].strip() 58 | except Exception: 59 | version = "" 60 | 61 | return PodClass(name, version, []) 62 | 63 | with open(fileName, 'r+') as inFile: 64 | contentFile = [x.replace('\n', '').replace('"', '') for x in inFile.readlines()] 65 | 66 | resultList = [] 67 | pod = PodClass("", "", []) 68 | for line in contentFile: 69 | if line.startswith(' -'): 70 | if len(pod.name) > 0: 71 | resultList.append(pod) 72 | pod = parse_lock_pods_line(line) 73 | elif line.startswith(' -'): 74 | pod.dependencies.append(parse_lock_pods_line(line)) 75 | elif line.startswith('DEPENDENCIES'): 76 | if len(pod.name) > 0: 77 | resultList.append(pod) 78 | break 79 | 80 | return resultList 81 | 82 | 83 | def generate_json(resultList): 84 | def generate_json_deps(resultList): 85 | data = '{' 86 | for result in resultList: 87 | data += '"%s":"%s",' % (result.name, result.version) 88 | 89 | data = data[:len(data)-1] 90 | return data + '}' 91 | 92 | json = '{"packages": [' 93 | deps = generate_json_deps(resultList) 94 | json += '{"name":"app","require":%s},' % deps 95 | 96 | for pod in resultList: 97 | if len(pod.dependencies) > 0: 98 | podDeps = generate_json_deps(pod.dependencies) 99 | json += '{"name":"%s","require":%s},' % (pod.name, podDeps) 100 | else: 101 | json += '{"name":"%s","require":{}},' % pod.name 102 | 103 | return json[:len(json)-1] + ']}' 104 | 105 | def save_json_file(data, fileName): 106 | with open(fileName + '.json', 'w') as outfile: 107 | outfile.write(generate_json(data)) 108 | 109 | def save_html_wheel_file(data, fileName): 110 | P_TEMPLATE = ' deps
' 111 | P_DATA_JSON = "'%s'" % generate_json(data) 112 | P_DATA_WIDTH = "960" 113 | P_DATA_MARGIN = "200" 114 | P_DATA_PADDING = ".02" 115 | 116 | html_out = P_TEMPLATE.replace("P_DATA_JSON", P_DATA_JSON).replace("P_DATA_WIDTH", P_DATA_WIDTH).replace("P_DATA_MARGIN", P_DATA_MARGIN).replace("P_DATA_PADDING", P_DATA_PADDING) 117 | 118 | with open(fileName + '.html', 'w') as outfile: 119 | outfile.write(html_out) 120 | 121 | def main(): 122 | if len(sys.argv) == 1: 123 | print("%s - %s (%s)\nby %s\n" % (PROJECT_NAME, __version__, PROJECT_DESCRIPTION, PROJECT_AUTHOR)) 124 | print("type: -h to see more information") 125 | sys.exit(1) 126 | 127 | parser = OptionParser("usage: %prog [options] filename") 128 | parser.add_option("-f", "--file", dest="file", default="", type="string", help="specify file path") 129 | parser.add_option("--show", action='store_true', dest="show", help="print dependencies on console") 130 | parser.add_option("--json", action='store_true', dest="json", help="save dependencies to json file") 131 | parser.add_option("--html", action='store_true', dest="html", help="save dependencies to wheel graph html file") 132 | (options, args) = parser.parse_args() 133 | 134 | if len(options.file) != 0: 135 | 136 | if options.show != True and options.json != True and options.html != True: 137 | print("you must select an output option (show | json | html)\n") 138 | sys.exit(1) 139 | 140 | if ".lock" not in options.file: 141 | options.file += ".lock" 142 | 143 | result = parse_lock_file(options.file) 144 | 145 | if options.show: 146 | print("Printing dependencies...") 147 | for pod in result: 148 | pod.printObject() 149 | 150 | if options.json: 151 | print("Saving json file...") 152 | save_json_file(result, options.file) 153 | 154 | if options.html: 155 | print("Saving html file...") 156 | save_html_wheel_file(result, options.file) 157 | 158 | print("done") 159 | -------------------------------------------------------------------------------- /docs/wordpress_example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erickjung/cocoapods-graph/fa337d6cd497f4735128835cda4106661e7ecf65/docs/wordpress_example.gif -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import re 2 | from setuptools import setup 3 | 4 | version = re.search( 5 | '^__version__\s*=\s*"(.*)"', 6 | open('cocoapodsgraph/executor.py').read(), 7 | re.M 8 | ).group(1) 9 | 10 | 11 | with open("README.md", "rb") as f: 12 | long_descr = f.read().decode("utf-8") 13 | 14 | 15 | setup( 16 | name = "cocoapods-graph", 17 | packages = ["cocoapodsgraph"], 18 | entry_points = { 19 | "console_scripts": ['cocoapods-graph = cocoapodsgraph.executor:main'] 20 | }, 21 | version = version, 22 | author="Erick Jung", 23 | author_email="erickjung@gmail.com", 24 | description="Cocoapods dependencies graph generator", 25 | long_description = long_descr, 26 | long_description_content_type='text/markdown', 27 | url="https://github.com/erickjung/cocoapods-graph", 28 | classifiers=( 29 | "Programming Language :: Python :: 2", 30 | "License :: OSI Approved :: MIT License", 31 | "Operating System :: MacOS", 32 | ), 33 | ) --------------------------------------------------------------------------------