Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.