class GoNative::Plugins::IOS::Create
Constants
- TEMPLATE_DIRECTORY_PATH
Attributes
plugin_name[R]
Public Class Methods
new(plugin_name)
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 17 def initialize(plugin_name) @plugin_name = plugin_name end
Public Instance Methods
assert_not_exists!()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 31 def assert_not_exists! return unless File.directory?(plugin_name) raise Error, "Directory #{plugin_name} already exists" end
call()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 21 def call assert_not_exists! set_working_dir! cp_template_files! inflate_templates! chmod_frameworks_script! create_framework_proj! run_pod_install! end
chmod_frameworks_script!()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 58 def chmod_frameworks_script! FileUtils.chmod 0755, 'create-framework.sh' end
contents(file)
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 91 def contents(file) Utils::TemplateInflator.new(File.read(file)).call(PLUGIN_NAME: plugin_name) end
cp_template_files!()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 42 def cp_template_files! FileUtils.cp_r("#{TEMPLATE_DIRECTORY_PATH}/.", '.') end
create_framework_proj!()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 62 def create_framework_proj! proj = Xcodeproj::Project.new(FileUtils.pwd) target = proj.new_target(:framework, "#{plugin_name}Framework", :ios, '10.0') main_group = proj.new_group(plugin_name, plugin_name) classes_group = main_group.new_group('Classes', 'Classes') references = Dir.glob("#{plugin_name}/Classes/**").map{ |file| classes_group.new_file(file.split('/').last) } main_group.new_file('Info.plist') target.add_file_references(references) target.build_configurations.each do |config| config.build_settings['INFOPLIST_FILE'] = "$(SRCROOT)/#{plugin_name}/Info.plist" end proj.save("#{plugin_name}.xcodeproj") end
inflate_files()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 80 def inflate_files Dir.glob("*#{TEMPLATE_FILES_EXTENSION}").each do |file| File.write(normalized_name(file), contents(file)) FileUtils.rm(file) end end
inflate_templates!()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 46 def inflate_templates! Dir.glob('*/').each do |dir| FileUtils.cd(dir) inflate_templates! FileUtils.cd('..') dir_name = dir.delete_suffix('/') normalized_name = normalized_name(dir_name) FileUtils.mv(dir_name, normalized_name) if dir_name != normalized_name end inflate_files end
normalized_name(file)
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 87 def normalized_name(file) file.gsub('PLUGIN_NAME', plugin_name).delete_suffix(TEMPLATE_FILES_EXTENSION) end
run_pod_install!()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 76 def run_pod_install! system 'pod install' end
set_working_dir!()
click to toggle source
# File lib/gonative/plugins/ios/create.rb, line 37 def set_working_dir! FileUtils.mkdir(plugin_name) FileUtils.cd(plugin_name) end