bin/nixenvironment in nixenvironment-0.0.57 vs bin/nixenvironment in nixenvironment-0.0.58

- old
+ new

@@ -52,10 +52,18 @@ global_option ('--resigned_bundle_name VALUE') { |value| $resigned_bundle_name = value } global_option ('--resigned_entitlements_path VALUE') { |value| $resigned_entitlements_path = value } global_option ('--resigned_watchkit_extension_entitlements_path VALUE') { |value| $resigned_watchkit_extension_entitlements_path = value } global_option ('--resigned_widget_entitlements_path VALUE') { |value| $resigned_widget_entitlements_path = value } +command :init do |c| + c.syntax = 'nixenvironment init' + c.description = 'Initialize template project of selected type in the destination repository and clone it to current folder' + c.action do |args, options| + init + end +end + command :update do |c| c.syntax = 'nixenvironment update' c.description = 'Install or update ninbas and other environment stuff' c.option '--ninbas NAME', String, 'Select ninbas branch, tag or revision to clone' c.action do |args, options| @@ -198,10 +206,87 @@ c.action do |args, options| clean_working_copy(options.all) end end +def init + template_project_name = nil + template_project_url = nil + template_project_types = [] + + p('Select project type (put index or name):') + TEMPLATES_REPO_LIST.each_with_index do |(key, value), index| + selection_index = index + 1 + selection = "#{selection_index}. #{key}" + template_project_types.push(selection) + p(selection) + end + + loop do + type = ask('> ', template_project_types) + type_index = type.to_i - 1 + + if TEMPLATES_REPO_LIST.has_key?(type) + template_project_url = TEMPLATES_REPO_LIST[type] + break + elsif type_index >= 0 and type_index < TEMPLATES_REPO_LIST.length + template_project_url = TEMPLATES_REPO_LIST.values[type_index] + break + end + end + + dest_url = ask('Destination repository url: ') + local_directory_to_clone = ask('Directory to clone into: ') + + repo_name = File.basename(dest_url, '.git') + template_project_name = File.basename(template_project_url, '.git') + + root_working_directory = Dir.pwd + + begin + # TODO: do we need to rm_rf it every time? + FileUtils.rm_rf(ADJUSTER_WORKING_COPY_PATH) + Dir.mkdir(ADJUSTER_WORKING_COPY_PATH) + Dir.chdir(ADJUSTER_WORKING_COPY_PATH) + + p('Cloning template project ...') + git_clone_success = system("git clone #{template_project_url} --recursive") + abort('Authentication failed for NIX template project! Please check your credentials and try again!') unless git_clone_success + + Dir.chdir(template_project_name) + system('git fetch -t') + tags = %x[ git tag ].lines + abort('Failed to get last tag!') unless tags.length > 0 + + Dir.chdir('..') + FileUtils.rm_rf(ADJUSTER_TEMP_PROJECT_NAME) if Dir.exist?(ADJUSTER_TEMP_PROJECT_NAME) + FileUtils.cp_r(template_project_name, ADJUSTER_TEMP_PROJECT_NAME) + Dir.chdir(ADJUSTER_TEMP_PROJECT_NAME) + + p('Checkout newest template project tag ...') + system("git checkout --orphan #{tags[-1]}") + current_branch = 'HEAD' + + p("Push ... #{dest_url}") + system("git remote add #{repo_name}Remote #{dest_url}") + system("git commit -m 'Initial commit'") + git_push_success = system("git push #{repo_name}Remote #{current_branch}:refs/heads/master --force") + abort("Push failed for #{dest_url} repository! Please check the link and try again!") unless git_push_success + + p("Cloning new created project from #{dest_url} to #{local_directory_to_clone} ...") + Dir.chdir(root_working_directory) + Dir.chdir(root_working_directory) + git_clone_success = system("git clone #{dest_url} --recursive #{local_directory_to_clone}") + abort("Error cloning #{dest_url}!") unless git_clone_success + rescue + p('Project initialization failed!') + raise + end + + p('Project initialization complete!') +end + def update(ninbas) root_working_directory = Dir.pwd target_directory = File.join(Dir.home, NIXENV_ROOT) begin @@ -231,11 +316,11 @@ tags = IO.popen('git tag').readlines tags.map! { |tag| tag.strip! } tags.sort_by!(&:to_i) if tags.size > 0 - p("Checkout newest #{repo_name} tag...") + p("Checkout newest #{repo_name} tag ...") system("git checkout #{tags.last}") else abort("Error checkout #{repo_name}! There is no tags!") end @@ -314,11 +399,11 @@ LAST_REVISION_FILE=\"_last_revision.sh\" source ${LAST_REVISION_FILE} if [ ${WORKING_COPY_IS_CLEAN} -eq 1 ]; then - echo \"Working copy is clean. Continuing...\" + echo \"Working copy is clean. Continuing ...\" else echo \"error: working copy must not have local modifications.\" 1>&2 echo \"You must add following files and folders to .gitignore:\" echo \"$(git status --porcelain)\" exit 1 @@ -564,20 +649,20 @@ restore_info_plist abort('Build error!') end if config == 'Release' - p('IconTagger: configuration is Release. Skipping...') + p('IconTagger: configuration is Release. Skipping ...') else case icon_tagger when 'full' tag_icon(false) when 'short' tag_icon(true) when 'off' - p('IconTagger is disabled. Skipping...') + p('IconTagger is disabled. Skipping ...') else - p("Unknown IconTagger mode: '#{icon_tagger}'. Skipping...") + p("Unknown IconTagger mode: '#{icon_tagger}'. Skipping ...") end end ipa.split.each do |current_ipa| case current_ipa