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

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

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

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

Attributes inherited from Pindo::Command

#args_help_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

Methods inherited from Pindo::Command

run

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Renewproj

Returns a new instance of Renewproj.

[View source]

33
34
35
36
37
# File 'lib/pindo/command/utils/renewproj.rb', line 33

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

Class Method Details

.optionsObject

[View source]

26
27
28
29
30
31
# File 'lib/pindo/command/utils/renewproj.rb', line 26

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

[View source]

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

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

[View source]

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/pindo/command/utils/renewproj.rb', line 111

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

[View source]

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/pindo/command/utils/renewproj.rb', line 127

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

[View source]

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pindo/command/utils/renewproj.rb', line 80

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

[View source]

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pindo/command/utils/renewproj.rb', line 39

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