Guest User

Untitled

a guest
Apr 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. """
  5. This script file automatically inserts the import of the libraries used for 'ResourceKit'.
  6.  
  7. Insert new 'Run Script' before 'Compile Sources' in Build Phases.
  8. And fill this code.
  9.  
  10. python $SRCROOT/script/generated_resource.py LIBRARY_1 LIBRARY_2 LIBRARY_3 ...
  11. """
  12.  
  13. import os.path
  14. import sys
  15.  
  16. generated_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'Resource.generated.swift')
  17. output = ''
  18.  
  19. if len(sys.argv) == 1:
  20. sys.exit(0)
  21.  
  22. libraries = sys.argv[1:]
  23.  
  24. with open(generated_file, 'r') as f:
  25. for line in f.readlines():
  26. if line.startswith('import'):
  27. if line == 'import UIKit\n':
  28. output += line + '\n'.join(map(lambda item: 'import {}'.format(item), libraries)) + '\n'
  29. elif line.replace('import ', '').replace('\n', '') in libraries:
  30. continue
  31. else:
  32. output += line
  33.  
  34. with open(generated_file, 'w') as f:
  35. f.write(output)
Add Comment
Please, Sign In to add comment