Skip to content

Instantly share code, notes, and snippets.

@nnsnodnb
Last active April 16, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnsnodnb/7b94ca49f0130c13125d7fc719b7d9c7 to your computer and use it in GitHub Desktop.
Save nnsnodnb/7b94ca49f0130c13125d7fc719b7d9c7 to your computer and use it in GitHub Desktop.
External library automatic input script to ResouceKit.
#!/usr/bin/env python
# coding: utf-8
"""
This script file automatically inserts the import of the libraries used for 'ResourceKit'.
Insert new 'Run Script' before 'Compile Sources' in Build Phases.
And fill this code.
python $SRCROOT/script/generated_resource.py LIBRARY_1 LIBRARY_2 LIBRARY_3 ...
"""
import os.path
import sys
generated_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'Resource.generated.swift')
output = ''
if len(sys.argv) == 1:
sys.exit(0)
libraries = sys.argv[1:]
with open(generated_file, 'r') as f:
for line in f.readlines():
if line.startswith('import'):
if line == 'import UIKit\n':
output += line + '\n'.join(map(lambda item: 'import {}'.format(item), libraries)) + '\n'
elif line.replace('import ', '').replace('\n', '') in libraries:
continue
else:
output += line
with open(generated_file, 'w') as f:
f.write(output)
#!/usr/bin/env python
# coding: utf-8
"""
This script file automatically inserts the import of the libraries used for 'ResourceKit'.
Insert new 'Run Script' before 'Compile Sources' in Build Phases.
And fill this code.
python $SRCROOT/script/generated_resource.py
"""
import os.path
# Fill your using libraries
libraries = []
generated_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'Resource.generated.swift')
output = ''
with open(generated_file, 'r') as f:
for line in f.readlines():
if line.startswith('import'):
if line == 'import UIKit\n':
output += line + '\n'.join(map(lambda item: 'import {}'.format(item), libraries)) + '\n'
elif line.replace('import ', '').replace('\n', '') in libraries:
continue
else:
output += line
with open(generated_file, 'w') as f:
f.write(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment