csa 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/gem-push.yml +32 -0
- data/.gitignore +58 -0
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +53 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/csa.gemspec +36 -0
- data/exe/csa +3 -0
- data/lib/csa/app.rb +285 -0
- data/lib/csa/ext/string.rb +8 -0
- data/lib/csa/parser.rb +26 -0
- data/lib/csa/version.rb +5 -0
- data/lib/csa.rb +9 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e37dbac84cb56eb915d24fe7866e1b5c1dc520c547930eae10544bc9a0c7d691
|
4
|
+
data.tar.gz: 59da24e1e2ab3e43fdaba581f3859081362f1285b477b4e277f1eadc4188b744
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01f60cfc0389a49ddc9d63d363aa40c90a4617c142a34b479c9519abf79cf3df002d552f2956094443b348288db389c63c572045ae1e6cf9b32564ed2b68bf27
|
7
|
+
data.tar.gz: 161dec7c7ddb99ee9609afed61bee7e3218d995f083d0822c633e3d214c8bf2ecf3c580c02e7a0885bb7773ad14aba68baa303461a55349df1919b65169cbfdf
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: macos-latest
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- name: Checkout
|
16
|
+
uses: actions/checkout@v2
|
17
|
+
|
18
|
+
- name: Set up Ruby 2.7
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 2.7.x
|
22
|
+
|
23
|
+
- name: Publish to RubyGems
|
24
|
+
run: |
|
25
|
+
mkdir -p $HOME/.gem
|
26
|
+
touch $HOME/.gem/credentials
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
28
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
+
gem build *.gemspec
|
30
|
+
gem push *.gem
|
31
|
+
env:
|
32
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
.DS_Store
|
2
|
+
**/Demo/
|
3
|
+
|
4
|
+
*.gem
|
5
|
+
*.rbc
|
6
|
+
/.config
|
7
|
+
/coverage/
|
8
|
+
/InstalledFiles
|
9
|
+
/pkg/
|
10
|
+
/spec/reports/
|
11
|
+
/spec/examples.txt
|
12
|
+
/test/tmp/
|
13
|
+
/test/version_tmp/
|
14
|
+
/tmp/
|
15
|
+
# Used by dotenv library to load environment variables.
|
16
|
+
# .env
|
17
|
+
|
18
|
+
# Ignore Byebug command history file.
|
19
|
+
.byebug_history
|
20
|
+
|
21
|
+
## Specific to RubyMotion:
|
22
|
+
.dat*
|
23
|
+
.repl_history
|
24
|
+
build/
|
25
|
+
*.bridgesupport
|
26
|
+
build-iPhoneOS/
|
27
|
+
build-iPhoneSimulator/
|
28
|
+
|
29
|
+
## Specific to RubyMotion (use of CocoaPods):
|
30
|
+
#
|
31
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
32
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
33
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
34
|
+
#
|
35
|
+
# vendor/Pods/
|
36
|
+
|
37
|
+
## Documentation cache and generated files:
|
38
|
+
/.yardoc/
|
39
|
+
/_yardoc/
|
40
|
+
/doc/
|
41
|
+
/rdoc/
|
42
|
+
|
43
|
+
## Environment normalization:
|
44
|
+
/.bundle/
|
45
|
+
/vendor/bundle
|
46
|
+
/lib/bundler/man/
|
47
|
+
|
48
|
+
# for a library or gem, you might want to ignore these files since the code is
|
49
|
+
# intended to run in multiple environments; otherwise, check them in:
|
50
|
+
# Gemfile.lock
|
51
|
+
# .ruby-version
|
52
|
+
# .ruby-gemset
|
53
|
+
|
54
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
55
|
+
.rvmrc
|
56
|
+
|
57
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
58
|
+
# .rubocop-https?--*
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
csa (0.1.0)
|
5
|
+
cli-ui (~> 1.3)
|
6
|
+
gli (~> 2.19)
|
7
|
+
xcodeproj (~> 1.18)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
CFPropertyList (3.0.2)
|
13
|
+
atomos (0.1.3)
|
14
|
+
claide (1.0.3)
|
15
|
+
cli-ui (1.3.0)
|
16
|
+
colored2 (3.1.2)
|
17
|
+
diff-lcs (1.4.4)
|
18
|
+
gli (2.19.2)
|
19
|
+
nanaimo (0.3.0)
|
20
|
+
rake (12.3.3)
|
21
|
+
rspec (3.9.0)
|
22
|
+
rspec-core (~> 3.9.0)
|
23
|
+
rspec-expectations (~> 3.9.0)
|
24
|
+
rspec-mocks (~> 3.9.0)
|
25
|
+
rspec-core (3.9.2)
|
26
|
+
rspec-support (~> 3.9.3)
|
27
|
+
rspec-expectations (3.9.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-mocks (3.9.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-support (3.9.3)
|
34
|
+
xcodeproj (1.18.0)
|
35
|
+
CFPropertyList (>= 2.3.3, < 4.0)
|
36
|
+
atomos (~> 0.1.3)
|
37
|
+
claide (>= 1.0.2, < 2.0)
|
38
|
+
colored2 (~> 3.1)
|
39
|
+
nanaimo (~> 0.3.0)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
cli-ui (~> 1.3)
|
46
|
+
csa!
|
47
|
+
gli (~> 2.19)
|
48
|
+
rake (~> 12.0)
|
49
|
+
rspec (~> 3.9.0)
|
50
|
+
xcodeproj (~> 1.18)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
2.2.30
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# [Create Swift App](https://rubygems.org/gems/csa)
|
2
|
+
|
3
|
+
a command line tool helps you create a swift app from a template
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
install it yourself as:
|
8
|
+
|
9
|
+
$ gem install csa
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```shell
|
14
|
+
csa [Project Name] [default template URL]
|
15
|
+
```
|
16
|
+
|
17
|
+
or
|
18
|
+
|
19
|
+
```shell
|
20
|
+
Usage: csa [options]
|
21
|
+
-n, --name NAME The Name of the project
|
22
|
+
-u, --url URL The URL of the template
|
23
|
+
-h, --help Prints help
|
24
|
+
-y, --yes Use default settings
|
25
|
+
-v, --version Prints Version
|
26
|
+
```
|
27
|
+
|
28
|
+
e.g.
|
29
|
+
|
30
|
+
1. `csa`
|
31
|
+
1. `csa MyApp`
|
32
|
+
1. `csa MyApp -y`
|
33
|
+
1. `csa MyApp -u https:...`
|
34
|
+
|
35
|
+
## Testing
|
36
|
+
|
37
|
+
run `rspec --format doc`
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "csa"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/csa.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "csa/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "csa"
|
9
|
+
spec.version = Csa::VERSION
|
10
|
+
spec.authors = ["dianyi j"]
|
11
|
+
spec.email = ["lastobject@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{create swift app}
|
14
|
+
spec.description = %q{a command line tool helps you create a swift app from a template}
|
15
|
+
spec.homepage = "https://rubygems.org/gems/csa"
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/djiangnz/csa"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/djiangnz/csa/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^#{spec.bindir}/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency "gli", "~> 2.19"
|
33
|
+
spec.add_dependency "xcodeproj", "~> 1.18"
|
34
|
+
spec.add_dependency "cli-ui", "~> 1.3"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
36
|
+
end
|
data/exe/csa
ADDED
data/lib/csa/app.rb
ADDED
@@ -0,0 +1,285 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "csa/version"
|
4
|
+
require "gli"
|
5
|
+
require "xcodeproj"
|
6
|
+
require "cli/ui"
|
7
|
+
require "date"
|
8
|
+
require "csa/ext/string"
|
9
|
+
|
10
|
+
class App
|
11
|
+
def initialize(options)
|
12
|
+
@name = options[:project_name].capitalize_first
|
13
|
+
@template_url = options[:template_url]
|
14
|
+
@use_default = options[:use_default]
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
validate_project_name
|
19
|
+
setup_template
|
20
|
+
setup_project
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_project_name
|
24
|
+
raise "Name is required" unless @name
|
25
|
+
raise "Project name cannot contain spaces" if @name =~ /\s/
|
26
|
+
raise "Project name cannot begin with a '.'" if @name[0, 1] == "."
|
27
|
+
raise "Project name should only contain numbers and letters" if @name =~ /[^a-zA-Z0-9]/
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup_template
|
31
|
+
clone_template
|
32
|
+
get_template_info
|
33
|
+
end
|
34
|
+
|
35
|
+
def clone_template
|
36
|
+
if Dir.exist?(Pathname("./#{@name}"))
|
37
|
+
question = CLI::UI.fmt("{{green:Folder #{@name} already exists, overwrite? (y/n)}}")
|
38
|
+
override = CLI::UI.ask(question, default: "n")
|
39
|
+
if override.downcase == "y"
|
40
|
+
delete_file(@name)
|
41
|
+
else
|
42
|
+
exit(0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
unless @template_url.empty?
|
47
|
+
puts CLI::UI.fmt("{{green:git clone #{@template_url} #{@name}}}")
|
48
|
+
system "git clone #{@template_url} #{@name}"
|
49
|
+
else
|
50
|
+
exit(0)
|
51
|
+
end
|
52
|
+
remove_userdata
|
53
|
+
end
|
54
|
+
|
55
|
+
def remove_userdata
|
56
|
+
Dir.chdir("#{@name}") do |_|
|
57
|
+
delete_file("Pods")
|
58
|
+
delete_file(".git")
|
59
|
+
delete_file(".DS_Store")
|
60
|
+
delete_file("xcuserdata")
|
61
|
+
delete_file("xcshareddata")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_file(name)
|
66
|
+
puts CLI::UI.fmt("{{green:deleting #{name}}}")
|
67
|
+
system "find . -name #{name} -depth -exec rm -rf {} \\;"
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_template_info
|
71
|
+
template_path = Dir.glob("./#{@name}/**/**/*.xcodeproj").first
|
72
|
+
@template_name = File.basename(template_path, ".xcodeproj")
|
73
|
+
@template_name_other = @template_name.gsub(/[^a-zA-Z0-9]/, "_")
|
74
|
+
get_template_author_organization
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_template_author_organization
|
78
|
+
app_delegate_path = Dir.glob("./#{@name}/**/**/*AppDelegate*.swift").last
|
79
|
+
raise "Can't find your AppDelegate file" if app_delegate_path.nil?
|
80
|
+
|
81
|
+
@template_author = File.open(app_delegate_path) do |file|
|
82
|
+
file.each_line do |line|
|
83
|
+
break line if /^\/\/ {2}Created by/ =~ line
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
begin
|
88
|
+
index1 = @template_author.index("by") + 2
|
89
|
+
index2 = @template_author.index("on")
|
90
|
+
@template_author = @template_author[0, index2]
|
91
|
+
@template_author = @template_author[index1, index2]
|
92
|
+
@template_author.strip!
|
93
|
+
rescue
|
94
|
+
@template_author = "DEFAULT_AUTHOR"
|
95
|
+
end
|
96
|
+
|
97
|
+
@template_organization = File.open(app_delegate_path) do |file|
|
98
|
+
file.each_line do |line|
|
99
|
+
break line if /^\/\/ {2}Copyright ©/ =~ line
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
begin
|
104
|
+
index1 = @template_organization.index("©") + 1
|
105
|
+
index2 = @template_organization.index(".")
|
106
|
+
@template_organization = @template_organization[0, index2]
|
107
|
+
@template_organization = @template_organization[index1, index2]
|
108
|
+
@template_organization.strip!
|
109
|
+
rescue
|
110
|
+
@template_organization = "DEFAULT_ORG"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def setup_project
|
115
|
+
get_project_info
|
116
|
+
rename_files
|
117
|
+
set_bundle_identifiers
|
118
|
+
add_git
|
119
|
+
install_pods
|
120
|
+
add_fastlane
|
121
|
+
open_project
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_project_info
|
125
|
+
if @use_default
|
126
|
+
@author = "DEFAULT_AUTHOR"
|
127
|
+
@organization = "DEFAULT_ORG"
|
128
|
+
return
|
129
|
+
end
|
130
|
+
|
131
|
+
# get author and org name
|
132
|
+
question_author = CLI::UI.fmt("{{green:Author for the project:}}")
|
133
|
+
question_organization = CLI::UI.fmt("{{green:Organization Name for the project:}}")
|
134
|
+
@author = CLI::UI.ask(question_author)
|
135
|
+
@organization = CLI::UI.ask(question_organization)
|
136
|
+
@author.strip!
|
137
|
+
@author.gsub!(/[^a-zA-Z0-9]/, "")
|
138
|
+
@organization.strip!
|
139
|
+
@author = "DEFAULT_AUTHOR" if @author.empty?
|
140
|
+
@organization = "DEFAULT_ORG" if @organization.empty?
|
141
|
+
puts @author
|
142
|
+
puts @organization
|
143
|
+
end
|
144
|
+
|
145
|
+
def rename_files(path = Pathname("./#{@name}"))
|
146
|
+
puts "updating #{path}"
|
147
|
+
path = rename(path)
|
148
|
+
if File.directory?(path)
|
149
|
+
Dir.each_child(path) do |file|
|
150
|
+
rename_files(path + file)
|
151
|
+
end
|
152
|
+
else
|
153
|
+
update_content(path)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def rename(original_name)
|
158
|
+
name_new = original_name.sub(Regexp.new(Regexp.escape(@template_name), Regexp::IGNORECASE), @name)
|
159
|
+
name_new = name_new.sub(Regexp.new(Regexp.escape(@template_name_other), Regexp::IGNORECASE), @name)
|
160
|
+
File.rename(original_name, name_new) if original_name != name_new
|
161
|
+
name_new
|
162
|
+
end
|
163
|
+
|
164
|
+
def update_content(path)
|
165
|
+
begin
|
166
|
+
file = File.new("#{path}_new", "w+")
|
167
|
+
origin = File.open(path, "r:UTF-8")
|
168
|
+
today = Date.today.strftime("%d/%m/%y")
|
169
|
+
origin.each do |line|
|
170
|
+
line = "// Created by #{@author} on #{today}." if /^\/\/ {2}Created by/ =~ line
|
171
|
+
line = "// Copyright © #{Time.new.strftime("%Y")} #{@organization}. All rights reserved." if /^\/\/ {2}Copyright ©/ =~ line
|
172
|
+
line.gsub!(Regexp.new(Regexp.escape(@template_name), Regexp::IGNORECASE), @name)
|
173
|
+
line.gsub!(Regexp.new(Regexp.escape(@template_name_other), Regexp::IGNORECASE), @name)
|
174
|
+
line.gsub!(Regexp.new(Regexp.escape(@template_organization), Regexp::IGNORECASE), @organization)
|
175
|
+
line.gsub!(Regexp.new(Regexp.escape(@template_author), Regexp::IGNORECASE), @author)
|
176
|
+
file.puts line
|
177
|
+
end
|
178
|
+
origin.close
|
179
|
+
file.close
|
180
|
+
File.delete(origin)
|
181
|
+
File.rename("#{path}_new", path)
|
182
|
+
rescue Exception
|
183
|
+
# ignored
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def set_bundle_identifiers
|
188
|
+
project_path = Dir.glob("./#{@name}/**/**/#{@name}.xcodeproj").first
|
189
|
+
project = Xcodeproj::Project.open(project_path)
|
190
|
+
project.root_object.attributes["ORGANIZATIONNAME"] = @organization
|
191
|
+
project.targets.each do |target|
|
192
|
+
target.build_configurations.each do |config|
|
193
|
+
config.build_settings["PRODUCT_BUNDLE_IDENTIFIER"] = "com.#{@organization.downcase.gsub(/[^a-zA-Z0-9]/, "-")}.#{@name.downcase}.#{target}.#{config}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
project.save
|
197
|
+
return if @use_default
|
198
|
+
|
199
|
+
# change bundle identifier
|
200
|
+
puts CLI::UI.fmt("{{cyan:Let's setup your bundle identifiers}}")
|
201
|
+
project.targets.each do |target|
|
202
|
+
target.build_configurations.each do |config|
|
203
|
+
original_bundle_identifier = config.build_settings["PRODUCT_BUNDLE_IDENTIFIER"]
|
204
|
+
question = CLI::UI.fmt("Bundle Identifier of Target {{green:#{target}}} for {{green:#{config}}}")
|
205
|
+
answer = CLI::UI.ask(question, default: original_bundle_identifier)
|
206
|
+
config.build_settings["PRODUCT_BUNDLE_IDENTIFIER"] = answer if answer != original_bundle_identifier
|
207
|
+
end
|
208
|
+
end
|
209
|
+
project.save
|
210
|
+
end
|
211
|
+
|
212
|
+
def add_git
|
213
|
+
return if Dir.exist?(Pathname("./#{@name}/.git"))
|
214
|
+
|
215
|
+
if @use_default
|
216
|
+
Dir.chdir("#{@name}") do |_|
|
217
|
+
system "git init > /dev/null"
|
218
|
+
puts "Initialized empty Git repository in ./#{@name}/.git/"
|
219
|
+
end
|
220
|
+
return
|
221
|
+
end
|
222
|
+
|
223
|
+
question = CLI::UI.fmt("{{green:Do you want to use git?}} (y/n)")
|
224
|
+
answer = CLI::UI.ask(question, default: "y")
|
225
|
+
if answer.downcase == "y"
|
226
|
+
Dir.chdir("#{@name}") do |_|
|
227
|
+
system "git init > /dev/null"
|
228
|
+
puts "Initialized empty Git repository in ./#{@name}/.git/"
|
229
|
+
question = CLI::UI.fmt("{{green:Repository url for the project: (enter to skip)?}}")
|
230
|
+
@repo_url = CLI::UI.ask(question)
|
231
|
+
@repo_url.strip!
|
232
|
+
unless @repo_url.empty?
|
233
|
+
system "git remote add origin #{@repo_url}"
|
234
|
+
system "git push --set-upstream origin master"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def install_pods
|
241
|
+
return unless system "which pod > /dev/null"
|
242
|
+
Dir.chdir("#{@name}") do |_|
|
243
|
+
if File.exists?("Podfile")
|
244
|
+
if @use_default
|
245
|
+
system "pod deintegrate"
|
246
|
+
system "pod install"
|
247
|
+
return
|
248
|
+
end
|
249
|
+
|
250
|
+
question = CLI::UI.fmt("{{green:Podfile detected, do you want to install pods now?}}")
|
251
|
+
answer = CLI::UI.ask(question, options: %w(install skip))
|
252
|
+
case answer
|
253
|
+
when "install"
|
254
|
+
system "pod deintegrate"
|
255
|
+
system "pod install"
|
256
|
+
else break
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def add_fastlane
|
263
|
+
return unless system "which fastlane > /dev/null"
|
264
|
+
return if @use_default
|
265
|
+
question = CLI::UI.fmt("{{green:Do you want to add fastlane to your project?}} (y/n)")
|
266
|
+
answer = CLI::UI.ask(question, default: "n")
|
267
|
+
return unless answer == "y"
|
268
|
+
Dir.chdir("#{@name}") do |_|
|
269
|
+
system "fastlane init"
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def open_project
|
274
|
+
begin
|
275
|
+
Dir.chdir("#{@name}") do |_|
|
276
|
+
system "open ."
|
277
|
+
end
|
278
|
+
project = Dir.glob("./**/**/#{@name}.xcworkspace").first
|
279
|
+
project = Dir.glob("./**/**/#{@name}.xcodeproj").first if project.nil?
|
280
|
+
system "open #{project}"
|
281
|
+
rescue Exception
|
282
|
+
# ignore
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
data/lib/csa/parser.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "csa/version"
|
5
|
+
|
6
|
+
class Parser
|
7
|
+
def Parser.getParams
|
8
|
+
default_project_name = "Demo"
|
9
|
+
default_url = "https://github.com/djiangnz/swift-template.git"
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
OptionParser.new do |opt|
|
13
|
+
opt.on_tail("-h", "--help", "Prints help") { puts opt; exit }
|
14
|
+
opt.on_tail("-y", "--yes", "Use default settings") { |o| options[:use_default] = true }
|
15
|
+
opt.on_tail("-v", "--version", "Prints Version") { puts Csa::VERSION; exit }
|
16
|
+
opt.on("-n", "--name NAME", "The Name of the project") { |o| options[:name] = o }
|
17
|
+
opt.on("-u", "--url URL", "The URL of the template") { |o| raise "Git is required" unless system "which git > /dev/null"; options[:url] = o }
|
18
|
+
end.parse!
|
19
|
+
|
20
|
+
params = {}
|
21
|
+
params[:project_name] = options[:name] ||= ARGV[0] ||= default_project_name
|
22
|
+
params[:template_url] = options[:url] ||= ARGV[1] ||= default_url
|
23
|
+
params[:use_default] = options[:use_default] == true
|
24
|
+
params
|
25
|
+
end
|
26
|
+
end
|
data/lib/csa/version.rb
ADDED
data/lib/csa.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dianyi j
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gli
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.19'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: xcodeproj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.18'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.18'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cli-ui
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
description: a command line tool helps you create a swift app from a template
|
70
|
+
email:
|
71
|
+
- lastobject@gmail.com
|
72
|
+
executables:
|
73
|
+
- csa
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".github/workflows/gem-push.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- csa.gemspec
|
87
|
+
- exe/csa
|
88
|
+
- lib/csa.rb
|
89
|
+
- lib/csa/app.rb
|
90
|
+
- lib/csa/ext/string.rb
|
91
|
+
- lib/csa/parser.rb
|
92
|
+
- lib/csa/version.rb
|
93
|
+
homepage: https://rubygems.org/gems/csa
|
94
|
+
licenses: []
|
95
|
+
metadata:
|
96
|
+
homepage_uri: https://rubygems.org/gems/csa
|
97
|
+
source_code_uri: https://github.com/djiangnz/csa
|
98
|
+
changelog_uri: https://github.com/djiangnz/csa/CHANGELOG.md
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 2.3.0
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubygems_version: 3.1.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: create swift app
|
118
|
+
test_files: []
|