Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
376f2412
Commit
376f2412
authored
Jun 09, 2013
by
Ian Ynda-Hummel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Base init implementation for generating from an xcode project.
parent
9eab5cb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
3 deletions
+55
-3
init.rb
lib/cocoapods/command/init.rb
+55
-3
No files found.
lib/cocoapods/command/init.rb
View file @
376f2412
require
'xcodeproj'
module
Pod
class
Command
class
Init
<
Command
self
.
summary
=
'Create a Podfile'
self
.
summary
=
'Generate a Podfile for the current directory.'
self
.
description
=
<<-
DESC
Creates a Podfile for the current directory if none currently exists.
Creates a Podfile for the current directory if none currently exists. If
an Xcode project file is specified or if there is only a single project
file in the current directory, targets will be automatically generated
based on targets defined in the project.
DESC
self
.
arguments
=
'[XCODEPROJ]'
def
initialize
(
argv
)
@podfile_path
=
Pathname
.
pwd
+
"Podfile"
@project_path
=
argv
.
shift_argument
@project_paths
=
Pathname
.
pwd
.
children
.
select
{
|
pn
|
pn
.
extname
==
'.xcodeproj'
}
super
end
def
validate!
super
help!
"Existing Podfile found in directory"
if
File
.
file?
@podfile_path
unless
@project_path
help!
"No xcode project found, please specify one"
unless
@project_paths
.
length
>
0
help!
"Multiple xcode projects found, please specify one"
unless
@project_paths
.
length
==
1
@project_path
=
@project_paths
.
first
end
help!
"Xcode project at
#{
@project_path
}
does not exist"
unless
File
.
exist?
@project_path
@xcode_project
=
Xcodeproj
::
Project
.
new
(
@project_path
)
end
def
run
(
Pathname
.
pwd
+
"Podfile"
).
open
(
'w'
)
{
|
f
|
f
<<
''
}
@podfile_path
.
open
(
'w'
)
{
|
f
|
f
<<
podfile_template
(
@xcode_project
)
}
end
def
podfile_template
(
project
)
platforms
=
project
.
targets
.
map
{
|
t
|
t
.
platform_name
}.
uniq
if
platforms
.
length
==
1
podfile
=
<<-
PLATFORM
platform
#{
platforms
.
first
}
PLATFORM
else
podfile
=
<<-
PLATFORM
# Uncomment this line to define the platform for your project
platform :ios, "6.0"
PLATFORM
end
for
target
in
project
.
targets
podfile
<<
target_module
(
target
)
end
podfile
end
def
target_module
(
target
,
define_platform
=
true
)
platform
=
"platform
#{
target
.
platform_name
}
"
if
define_platform
return
<<-
TARGET
target :
#{
target
.
name
}
do
#{
platform
}
end
TARGET
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment