8
8
playgrounds () {
9
9
local root=" $1 " # parameter `folder`
10
10
11
- workspacesForProjectPath " $1 "
12
- checkIsWorkspaceValid " $workspacesForProjectPath "
13
- local workspacePath=$( echo " $workspacesForProjectPath " | rev | cut -d' /' -f 2- | rev)
14
- local content=" $workspacesForProjectPath /contents.xcworkspacedata"
11
+ local workspacePath=$( getWorkspace " $1 " )
12
+ local content=" $workspacePath /contents.xcworkspacedata"
15
13
16
14
local dependencies=" awk -F'location = \" group:' '{print \$ 2}'"
17
15
local cleanUp=" rev | cut -d'\" ' -f 2- | rev | grep playground"
@@ -23,9 +21,9 @@ playgrounds() {
23
21
# build playground path
24
22
playgroundsPaths=()
25
23
for playground in " ${playgrounds[@]} " ; do
26
- if [ -d " $workspacePath /$playground " ]; then # is it relative path?
27
- playgroundsPaths+=(" $workspacePath /$playground " )
28
- elif [ -d " $playground " ]; then # is it a absolute path?
24
+ if [ -d " $workspacePath /../ $playground " ]; then # is it relative path?
25
+ playgroundsPaths+=(" $workspacePath /../ $playground " )
26
+ elif [ -d " $playground " ]; then # is it a absolute path?
29
27
playgroundsPaths+=(" $playground " )
30
28
else
31
29
echo " ❌"
@@ -83,10 +81,10 @@ pagesInPlayground() {
83
81
}
84
82
85
83
# #
86
- # cleanStructure (String folder)
84
+ # resetStructure (String folder)
87
85
# - Parameter `folder`: path to the folder to clean up.
88
86
# #
89
- cleanStructure () {
87
+ resetStructure () {
90
88
set +e
91
89
local folder=" $1 " # parameter `folder`
92
90
rm -rf $folder 1> /dev/null 2> /dev/null
@@ -178,15 +176,50 @@ checkOutputNotSameInput() {
178
176
fi
179
177
}
180
178
179
+ # #
180
+ # getWorkspace(String folder, String projectPath) throws : String
181
+ # - Parameter `folder`: path to the project folder.
182
+ # - Return an valid `workspace` path given a project path
183
+ # #
184
+ getWorkspace () {
185
+ _workspacesForProjectPath " $1 "
186
+ for workspacePath in " ${workspacesForProjectPath[@]} " ; do
187
+ isDependency=$( isPathFromDependencies " $workspacePath " )
188
+ [ $isDependency -eq 1 ] && continue
189
+ echo " $workspacePath "
190
+ return
191
+ done
192
+
193
+ echo " [!] error: not found any valid workspace in root project '$1 '"
194
+ exit 1
195
+ }
196
+
197
+ # #
198
+ # _isPathFromDependencies(String path): Bool
199
+ # - Parameter `path`: path to check if it is in dependencies folder
200
+ # - Return `isDependency` 1 - is a dependency; 0 - another case
201
+ # #
202
+ isPathFromDependencies () {
203
+ podProject=$( eval echo " \" $1 \" | grep '/Pods/' | awk '{ print length; }'" )
204
+ carthageProject=$( eval echo " \" $1 \" | grep '/Carthage/' | awk '{ print length; }'" )
205
+
206
+ if [ " $podProject " != " " ] || [ " $carthageProject " != " " ]; then
207
+ echo 1
208
+ else
209
+ echo 0
210
+ fi
211
+ }
212
+
213
+
181
214
# ##: - Internal methods
182
215
183
216
# #
184
- # workspacesForProjectPath(String folder, String projectPath ): String
217
+ # workspacesForProjectPath(String folder): String
185
218
# - Parameter `folder`: path to the project folder.
186
219
# - Parameter `projectPath`: path to the *.pbxproj file.
187
220
# - Return `workspaces` path given a project path
188
221
# #
189
- workspacesForProjectPath () {
222
+ _workspacesForProjectPath () {
190
223
local path=" $1 " # parameter `folder`
191
224
local log=" $1 /$LOG_PATH /workspace.log"
192
225
cd " $path "
@@ -195,7 +228,7 @@ workspacesForProjectPath() {
195
228
while read -r -d $' \0' project; do
196
229
projectPath=$( echo " $path /$project " | rev | cut -d' /' -f3- | rev)
197
230
projectName=$( echo " $project " | rev | cut -d' /' -f 2 | rev)
198
- workspacePath=$( workspaceForProjectPath " $projectPath " " $projectName " )
231
+ workspacePath=$( _workspaceForProjectPath " $projectPath " " $projectName " )
199
232
workspaceExtension=$( echo " $workspacePath " | rev | cut -d' .' -f1 | rev)
200
233
workspaceContent=" $workspacePath /contents.xcworkspacedata"
201
234
(! [ " $workspaceExtension " = " xcworkspace" ] || ! [ -f " $workspaceContent " ]) && continue
@@ -206,35 +239,19 @@ workspacesForProjectPath() {
206
239
declare -p workspacesForProjectPath 1> /dev/null 2> /dev/null
207
240
}
208
241
209
- checkIsWorkspaceValid () {
210
- local workspacesPaths=" $1 "
211
- local numberOfWorkspaces=${# workspacesPaths[@]}
212
-
213
- if [ " $numberOfWorkspaces " -gt 1 ]; then
214
- echo " [!] error: found more than 1 workspace (total:$numberOfWorkspaces ): '$workspacesPaths '" > " $log "
215
- exit 1
216
- elif [ " $numberOfWorkspaces " -eq 0 ] || ! [ -d $workspacesPaths ]; then
217
- echo " [!] error: not found any workspace in root project '$workspacesPaths '" > " $log "
218
- exit 1
219
- fi
220
- }
221
-
222
242
# #
223
- # workspacePathForProjectPath (String projectPath, String projectName): String
243
+ # _workspaceForProjectPath (String projectPath, String projectName): String
224
244
# - Parameter `projectPath`: path to the project folder.
225
245
# - Parameter `projectName`: *.pbxproj filename.
226
246
# - Return `workspaceName`
227
247
# #
228
- workspaceForProjectPath () {
248
+ _workspaceForProjectPath () {
229
249
cd " $1 "
230
250
local xcprojectNoExtension=$( echo " $2 " | rev | cut -d' .' -f 2- | rev )
231
- local nefWorkspace=" ` pwd` /nef.xcworkspace"
232
251
local xcprojectWorkspace=" ` pwd` /$xcprojectNoExtension .xcworkspace"
233
252
local xcproject=" ` pwd` /$xcprojectNoExtension .xcodeproj"
234
253
235
- if [ -d " $nefWorkspace " ]; then
236
- echo " $nefWorkspace "
237
- elif [ -d " $xcprojectWorkspace " ]; then
254
+ if [ -d " $xcprojectWorkspace " ]; then
238
255
echo " $xcprojectWorkspace "
239
256
else
240
257
echo " $xcproject "
0 commit comments