toxic 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6c56348e42d597019f3576c5ee3329f12cca67e5ac6af4a46f5a35b8f7b567d
4
- data.tar.gz: 598ed0ab773ba5320ed28b05c7258150e4272c09ed6dc105f9d25492669f062d
3
+ metadata.gz: 73b4b9e5f5e2fa21357aa55a9818585c6e90fe531d4b71835894a1fb9ffe177f
4
+ data.tar.gz: 69ebc1c3382ae9ec65255de322bc462ac5d90e892e570c6e9c7726c07be81bc3
5
5
  SHA512:
6
- metadata.gz: 31fbe3e77b6398e32689c06b69bc54b02b7c8fdd9d95808e7c75c06cac682c0851a5d678e9ac203dcdb5d3f4fb932616d2694e58f7ac7fe15190a693e846a8b4
7
- data.tar.gz: c665b7f5012f7e37edeb5ea67d218b40c3ea3e229a0fdaa5b0bab066cf1b1f2692d8e03b76ff63d77d9597d19d7c61b62a82f07d5aa170cf5633d100b972995b
6
+ metadata.gz: 8adc97ca1e9751d74c8b5ceb9ef1ee9e8d5e45b2144379df3e5d8cfcaa29a7d74c534d65bba419cbedae001a0873fb232f62285a6d16f141366f15cf627b452c
7
+ data.tar.gz: b23a6319ddc0365952982470769cc0c73112b62abad097f3999d9328bb508aca4e4a7c7c9471d5c2d4c2dc528380221828d7e9ff9dd14f4b48e6c83f5f0048c5
data/README.md CHANGED
@@ -4,21 +4,8 @@
4
4
  create xcode project from template
5
5
 
6
6
  ## Installation
7
-
8
- Add this line to your application's Gemfile:
9
-
10
- ```ruby
11
- gem Toxic
12
- ```
13
-
14
- And then execute:
15
-
16
- $ bundle
17
-
18
- Or install it yourself as:
19
-
20
7
  $ gem install Toxic
21
-
8
+
22
9
  ## Usage
23
10
 
24
11
  using default template
@@ -30,21 +17,6 @@ using your own template
30
17
  $ toxic project create <name> --template-url=<repository address>
31
18
 
32
19
 
33
-
34
- ## Development
35
-
36
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
-
38
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
-
40
- ## Contributing
41
-
42
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Toxic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
43
-
44
20
  ## License
45
21
 
46
22
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
47
-
48
- ## Code of Conduct
49
-
50
- Everyone interacting in the Toxic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/Toxic/blob/master/CODE_OF_CONDUCT.md).
@@ -4,7 +4,7 @@ desc 'Project'
4
4
  command :project, :p do |c|
5
5
  c.desc 'template url'
6
6
  c.arg_name 'template-url'
7
- c.default_value 'https://github.com/srv7/project-template.git'
7
+ c.default_value 'https://github.com/srv7/ios-template-project.git'
8
8
  c.flag :'template-url'
9
9
 
10
10
  c.desc 'create xcode project'
@@ -8,6 +8,7 @@ module Toxic
8
8
 
9
9
  attr_accessor :name, :template_url, :author, :organization, :repository_address
10
10
  attr_accessor :template_name, :template_author, :template_organization
11
+ attr_accessor :template_name_other
11
12
 
12
13
  def initialize(name, template_url)
13
14
  @name = name
@@ -23,13 +24,16 @@ module Toxic
23
24
  configure_template
24
25
  set_bundle_identifiers
25
26
  add_git_repository
27
+ pod_install
28
+ add_fastlane
29
+ open_project
26
30
  end
27
31
 
28
32
  def validate!
29
33
  raise "A name for the project is required." unless name
30
34
  raise "The project name cannot contain spaces." if name =~ /\s/
31
35
  raise "The project name cannot begin with a '.'" if name[0, 1] == '.'
32
- puts CLI::UI.fmt("{{green: validate! pass")
36
+ raise "" if name =~ /[^a-zA-Z0-9]/
33
37
  end
34
38
 
35
39
  def clone_template
@@ -44,15 +48,13 @@ module Toxic
44
48
  end
45
49
  end
46
50
  system "git clone #{@template_url} #{name}"
47
-
48
- puts CLI::UI.fmt("{{green: clone_template pass")
49
51
  end
50
52
 
51
53
  def get_template_info
52
54
  template_path = Dir.glob("./#{name}/**/**/*.xcodeproj").first
53
55
  @template_name = File.basename(template_path, '.xcodeproj')
56
+ @template_name_other = template_name.gsub(/[^a-zA-Z0-9]/, '_')
54
57
  @template_author, @template_organization = template_author_organization
55
- puts CLI::UI.fmt("{{green: get_template_info pass")
56
58
  end
57
59
 
58
60
  def ask_info_for_new
@@ -60,9 +62,6 @@ module Toxic
60
62
 
61
63
  @author = CLI::UI.ask('author for the project:')
62
64
  @organization = CLI::UI.ask('organization for the project:')
63
- @repository_address = CLI::UI.ask('repository address for the project:')
64
-
65
- puts CLI::UI.fmt("{{green: ask_info_for_new pass")
66
65
  end
67
66
 
68
67
  def remove_useless
@@ -70,17 +69,14 @@ module Toxic
70
69
  system "rm -rf ./#{name}/**/xcuserdata/"
71
70
  system "rm -rf ./#{name}/**/**/xcuserdata/"
72
71
  system "rm -rf ./#{name}/**/**/xcshareddata"
73
- puts CLI::UI.fmt("{{green: remove_useless pass")
74
72
  end
75
73
 
76
74
  def configure_template
77
75
  traverse_dir(Pathname("./#{name}"))
78
- puts CLI::UI.fmt("{{green: configure_template pass")
79
76
  end
80
77
 
81
78
  def set_bundle_identifiers
82
79
  puts CLI::UI.fmt("{{cyan: Let's setup your bundle identifiers}}")
83
-
84
80
  project_path = Dir.glob("./#{name}/**/**/#{name}.xcodeproj").first
85
81
  project = Xcodeproj::Project.open(project_path)
86
82
  project.targets.each do |target|
@@ -96,18 +92,45 @@ module Toxic
96
92
 
97
93
  def add_git_repository
98
94
  Dir.chdir("#{name}") do |_|
99
- puts CLI::UI.fmt("{{green: initializing git}}")
100
- system "git init"
95
+ system "git init > /dev/null"
96
+ puts CLI::UI.fmt("{{green: Initialized empty Git repository}}")
97
+ @repository_address = CLI::UI.ask('repository address for the project:(enter to skip)')
101
98
  system "git remote add origin #{repository_address}" unless repository_address.empty?
102
- project = Dir.glob("./#{name}/**/**/#{name}.xcworkspace").first
103
- project = Dir.glob("./#{name}/**/**/#{name}.xcodeproj") unless Dir.glob(project).any?
104
- system "open #{project}"
105
99
  end
106
100
  end
107
101
 
102
+ def pod_install
103
+ Dir.chdir("#{name}") do |_|
104
+ if File.exists?('Podfile')
105
+ decision = CLI::UI.ask("Podfile detected, do you want to exec 'pod install' ?", options: %w(install later))
106
+ case decision
107
+ when 'install'
108
+ system "pod install"
109
+ else break
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ def add_fastlane
116
+ return nil unless system "which fastlane > /dev/null"
117
+ decision = CLI::UI.ask("do you want to add fastlane to your project? (y/n)", default: 'y')
118
+ return nil unless decision == 'y'
119
+ Dir.chdir("#{name}") do |_|
120
+ system "fastlane init"
121
+ end
122
+ end
123
+
124
+ def open_project
125
+ project = Dir.glob("./**/**/#{name}.xcworkspace").first
126
+ project = Dir.glob("./**/**/#{name}.xcodeproj") unless Dir.glob(project).any?
127
+ system "open #{project}"
128
+ end
129
+
108
130
  def traverse_dir(file_path)
131
+ puts "updating #{file_path}"
132
+ file_path = rename(file_path)
109
133
  if File.directory?(file_path)
110
- file_path = rename(file_path)
111
134
  Dir.each_child(file_path) do |file|
112
135
  traverse_dir(file_path + file)
113
136
  end
@@ -144,13 +167,12 @@ module Toxic
144
167
 
145
168
  def rename(original_name)
146
169
  name_new = original_name.sub(Regexp.new(Regexp.escape(template_name), Regexp::IGNORECASE), name)
170
+ name_new = name_new.sub(Regexp.new(Regexp.escape(template_name_other), Regexp::IGNORECASE), name)
147
171
  File.rename(original_name, name_new)
148
172
  name_new
149
173
  end
150
174
 
151
175
  def update_content(file_path)
152
- puts "updating #{file_path}"
153
-
154
176
  begin
155
177
 
156
178
  file = File.new("#{file_path}_new", "w+")
@@ -159,6 +181,7 @@ module Toxic
159
181
  line = "// Created by #{author} on #{Date.today}." if /^\/\/ {2}Created by/ =~ line
160
182
  line = "// Copyright © 2018 #{organization}. All rights reserved." if /^\/\/ {2}Copyright ©/ =~ line
161
183
  line.gsub!(Regexp.new(Regexp.escape(template_name), Regexp::IGNORECASE), name)
184
+ line.gsub!(Regexp.new(Regexp.escape(template_name_other), Regexp::IGNORECASE), name)
162
185
  line.gsub!(Regexp.new(Regexp.escape(template_organization), Regexp::IGNORECASE), organization)
163
186
  line.gsub!(Regexp.new(Regexp.escape(template_author), Regexp::IGNORECASE), author)
164
187
  file.puts line
@@ -167,11 +190,9 @@ module Toxic
167
190
  file.close
168
191
  File.delete(origin)
169
192
  File.rename("#{file_path}_new", file_path)
170
-
171
193
  rescue Exception
172
- # ignored
194
+ # ignored
173
195
  end
174
- rename(file_path)
175
196
  end
176
197
  end
177
198
  end
data/lib/toxic/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toxic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toxic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - liubo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-04 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler