前言

iOS开发,避免不了频繁创建Demo工程,用来开发功能、测试等等。

在我们的组件化方案中,每个业务模块会放到独立的私有git仓库里。

结合这两点,需要一个懒人工具,比如通过脚本一键生成模板工程。

pod lib create

通过pod lib create创建一个基于pod的工程。

当执行pod lib create ProjectName 时,其实是下载了一个pod模板,通过模板内置的脚本修改成自己想要的工程。

pod lib create ProjectName

等于

pod lib create ProjectName –template-url=https://github.com/CocoaPods/pod-template.git

看到这个pod-template 就好办了,把pod-template下载下来,修改成自己想要的,下载地址 https://github.com/CocoaPods/pod-template.git

可以在模板里增加一些自己常用的类、宏等等。

我们将封装好的基础能力库添加到Podfile的引用里。

修改点

使用默认的pod-template模板,脚本会问多个问题。

修改前

# wuxiaoming @ ming-3 in ~ [19:35:35] 
$ pod lib create MyApp       
Cloning `https://github.com/CocoaPods/pod-template.git` into `MyApp`.
Configuring MyApp template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


What platform do you want to use?? [ iOS / macOS ]
 > ios

What language do you want to use?? [ Swift / ObjC ]
 > objc

Would you like to include a demo application with your library? [ Yes / No ]
 > yes

Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > none

Would you like to do view based testing? [ Yes / No ]
 > no


询问工程是基于macos还是ios,语言用objc还是swift,要不要创建一个可执行程序等等。

我只保留了What is your class prefix?这一个问题,可以自定义自己需要的类前缀。

开始修改

-w1004

-w1004

-w1004

-w1004

修改完,推送到自己的仓库里,这样一个模板库就建好了。

执行自定义脚本

$ pod lib create LoginMoudle --template-url=https://github.com/action121/TemplateProject.git
Cloning `https://github.com/action121/TemplateProject.git` into `LoginMoudle`.
Username for 'https://github.com': action121
Password for 'https://action121@github.com': 
Configuring LoginMoudle template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


What is your class prefix?
 >QG    
 
Running pod install on your new library.

Analyzing dependencies
Fetching podspec for `LoginMoudle` from `../`
Downloading dependencies
Installing LoginMoudle (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `LoginMoudle.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'LoginMoudle/Example/LoginMoudle.xcworkspace'

To learn more about the template see `https://github.com/action121/TemplateProject.git`.
To learn more about creating a new pod, see `http://guides.cocoapods.org/making/making-a-cocoapod`.

# wuxiaoming @ ming-3 in ~ [19:02:44] 
$ 

OK,工程建好了。