Class: Pindo::Command::Utils::Renewproj

Inherits:
Pindo::Command::Utils show all
Includes:
DeployOptions, XcodeHelper
Defined in:
lib/pindo/command/utils/renewproj.rb

Instance Attribute Summary

Attributes included from DeployOptions

#additional_args, #apple_id, #args_adhoc_flag, #args_appconfig, #args_appconfig_dir, #args_appconfig_fullname, #args_apple_id, #args_appstore_flag, #args_array, #args_bundle_id, #args_dev_flag, #args_macos_flag, #args_repo_name, #argv_temp, #bundle_id, #bundle_id_extension, #bundle_id_extensionad, #bundle_id_extensionporn, #bundle_id_imessage, #bundle_id_keyboard, #bundle_id_pushcontent, #bundle_id_pushservice, #bundle_id_siri, #bundle_id_siriui, #bundle_id_watchapp, #bundle_id_watchapp_extension, #bundle_id_widget, #config_json, #deploy_acount_id, #deploy_group_id, #deploy_icloud_id, #deploy_identifier, #deploy_identifier_extension, #deploy_identifier_extensionad, #deploy_identifier_extensionporn, #deploy_identifier_imessage, #deploy_identifier_keyboard, #deploy_identifier_pushcontent, #deploy_identifier_pushservice, #deploy_identifier_siri, #deploy_identifier_siriui, #deploy_identifier_watchapp, #deploy_identifier_watchapp_extension, #deploy_identifier_widget, #deploy_repo_name, #group_id, #icloud_id, #newconfuse_flag, #oldconfuse_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XcodeHelper

#add_file_to_target, #add_files_proj_with_dir, #config_project_target, #config_target, #copy_to_newproject, #create_project_target, #get_target_by_name, #is_resource_group, #setting_new_project

Methods included from DeployOptions

#check_config_version, #get_build_type_args, #get_bundle_id_map, #get_confuse_type_args, #init_deploy_params, #init_develop_params, #print_params_info

Constructor Details

#initialize(argv) ⇒ Renewproj

Returns a new instance of Renewproj.



56
57
58
59
60
# File 'lib/pindo/command/utils/renewproj.rb', line 56

def initialize(argv)
    @project_name = argv.option('n')
    @args_nocreate_flag = argv.flag?('nocreate')
    super
end

Class Method Details

.optionsObject



49
50
51
52
53
54
# File 'lib/pindo/command/utils/renewproj.rb', line 49

def self.options
    [
        ['--n=', 'input project name'],
        ['--nocreate', 'no create xcode project'],
    ].concat(super)
end

Instance Method Details

#create_project(new_proj_name: nil, new_proj_path: nil, old_proj_name: nil, old_proj_path: nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/pindo/command/utils/renewproj.rb', line 81

def create_project(new_proj_name:nil, new_proj_path:nil, old_proj_name:nil, old_proj_path:nil)
            
    new_proj_fullname = File.join(new_proj_path, new_proj_name) + ".xcodeproj"
    Xcodeproj::Project.new(new_proj_fullname).save
    new_proj_obj = Xcodeproj::Project.open(new_proj_fullname)

    old_proj_fullname = File.join(old_proj_path, old_proj_name) + ".xcodeproj"
    old_proj_obj = Xcodeproj::Project.open(old_proj_fullname)

    copy_to_newproject(new_proj_path:new_proj_path, new_proj_name:new_proj_name, old_proj_path:old_proj_path, old_proj_name:old_proj_name)

    create_project_target(new_proj_name:new_proj_name, new_proj_path:new_proj_path, new_proj_obj:new_proj_obj,  old_proj_name:old_proj_name, old_proj_path:old_proj_path, old_proj_obj:old_proj_obj)
    
    add_file_to_target(new_proj_name:new_proj_name, new_proj_path:new_proj_path, new_proj_obj:new_proj_obj,  old_proj_name:old_proj_name, old_proj_path:old_proj_path, old_proj_obj:old_proj_obj)
    
    config_project_target(new_proj_name:new_proj_name, new_proj_path:new_proj_path, new_proj_obj:new_proj_obj,  old_proj_name:old_proj_name, old_proj_path:old_proj_path, old_proj_obj:old_proj_obj)
    
    setting_new_project(new_proj_name:new_proj_name, new_proj_path:new_proj_path, new_proj_obj:new_proj_obj,  old_proj_name:old_proj_name, old_proj_path:old_proj_path, old_proj_obj:old_proj_obj)
    
end

#get_new_proj_pathObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/pindo/command/utils/renewproj.rb', line 134

def get_new_proj_path

    current_dir = Dir.pwd

    temp_dir_name = @project_name + '_' +Time.now.strftime('%y%m%d_%H%M%S')
    new_project_dir = File.join(File::expand_path(current_dir + "/../") , temp_dir_name)

    if File.exist?(new_project_dir)
        system 'sh rm -rf ' + new_project_dir
        FileUtils.rm_rf(new_project_dir)
    end
    FileUtils.mkdir(new_project_dir)

    return new_project_dir
end

#get_old_proj_name(old_proj_path: nil) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/pindo/command/utils/renewproj.rb', line 150

def get_old_proj_name(old_proj_path:nil)


    old_project_fullname = ""
    Dir.foreach(old_proj_path) do |file|  
        if file =~ /(.*).xcodeproj/
            old_project_fullname = file
            break;
        end
    end 

    old_proj_name = File.basename(old_project_fullname, ".xcodeproj")
    return old_proj_name

end

#runObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pindo/command/utils/renewproj.rb', line 103

def run
    system 'pod deintegrate'
    current_dir = Dir.pwd
    old_project_dir = current_dir
    old_proj_name = get_old_proj_name(old_proj_path:current_dir)

    
    if @args_nocreate_flag
        puts "2=================="
        new_proj_name = old_proj_name
        new_project_dir = old_project_dir
        ENV['pindo_new_project_dir'] = old_project_dir
    else
        new_proj_name = @project_name
        if new_proj_name.nil? 
            puts "Please input a new project name."
            return
        end
        new_project_dir = get_new_proj_path
        ENV['pindo_new_project_dir'] = new_project_dir
        create_project(new_proj_name:new_proj_name, new_proj_path:new_project_dir, old_proj_name:old_proj_name, old_proj_path:old_project_dir)
    end

    if File.exist?(File.join(new_project_dir, 'Podfile.lock'))
        FileUtils.rm_rf(File.join(new_project_dir, 'Podfile.lock'))
    end
    system "open #{new_project_dir}"
    puts "New Project Dir: #{new_project_dir}"
    puts "Done !"
end

#validate!Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pindo/command/utils/renewproj.rb', line 62

def validate!
    super
    if @project_name.nil? || @project_name.empty?
        if @config_json['project_info'] && @config_json['project_info']['project_name']
            @project_name = @config_json['project_info']['project_name']
        end
    end

    if @project_name.nil?
        @project_name = ask('Project Name: ')
    end  

    @project_name = "Example" if @project_name.nil? || @project_name.empty?
    @project_name = @project_name.gsub(/ /, '');
    @project_name = @project_name.gsub(/\'/, '');

    puts "project_name = #{@project_name}"
end