Last active
April 16, 2018 10:27
-
-
Save nnsnodnb/7b94ca49f0130c13125d7fc719b7d9c7 to your computer and use it in GitHub Desktop.
External library automatic input script to ResouceKit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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