Skip to content

Commit 433ea30

Browse files
Merge pull request #100 from bow-swift/fix_nef_launcher
create xcworkspace using playground name
2 parents eae0354 + 9bb3711 commit 433ea30

File tree

8 files changed

+151
-159
lines changed

8 files changed

+151
-159
lines changed

bin/nef-carbon

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ buildCarbon() {
9191
echo "${normal}Downloading Carbon's snippets for ${green}$playgroundName${reset}"
9292

9393
checkOutputNotSameInput "$output" "$projectPath"
94-
cleanStructure "$output"
94+
resetStructure "$output"
9595
mkdir -pv "$output"
9696
pagesInPlayground "$playgroundPath"
9797

@@ -125,7 +125,7 @@ makeStructure() {
125125
local logPath="$1/$LOG_PATH" # parameter `project`
126126
local outputPath="$2" # parameter `outputPath`
127127

128-
cleanStructure "$outputPath/*/*.png"
128+
resetStructure "$outputPath/*/*.png"
129129
mkdir -p "$logPath"
130130
mkdir -p "$outputPath"
131131
}

bin/nef-common

+48-31
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
playgrounds() {
99
local root="$1" # parameter `folder`
1010

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"
1513

1614
local dependencies="awk -F'location = \"group:' '{print \$2}'"
1715
local cleanUp="rev | cut -d'\"' -f 2- | rev | grep playground"
@@ -23,9 +21,9 @@ playgrounds() {
2321
# build playground path
2422
playgroundsPaths=()
2523
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?
2927
playgroundsPaths+=("$playground")
3028
else
3129
echo ""
@@ -83,10 +81,10 @@ pagesInPlayground() {
8381
}
8482

8583
##
86-
# cleanStructure(String folder)
84+
# resetStructure(String folder)
8785
# - Parameter `folder`: path to the folder to clean up.
8886
##
89-
cleanStructure() {
87+
resetStructure() {
9088
set +e
9189
local folder="$1" # parameter `folder`
9290
rm -rf $folder 1>/dev/null 2>/dev/null
@@ -178,15 +176,50 @@ checkOutputNotSameInput() {
178176
fi
179177
}
180178

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+
181214
###: - Internal methods
182215

183216
##
184-
# workspacesForProjectPath(String folder, String projectPath): String
217+
# workspacesForProjectPath(String folder): String
185218
# - Parameter `folder`: path to the project folder.
186219
# - Parameter `projectPath`: path to the *.pbxproj file.
187220
# - Return `workspaces` path given a project path
188221
##
189-
workspacesForProjectPath() {
222+
_workspacesForProjectPath() {
190223
local path="$1" # parameter `folder`
191224
local log="$1/$LOG_PATH/workspace.log"
192225
cd "$path"
@@ -195,7 +228,7 @@ workspacesForProjectPath() {
195228
while read -r -d $'\0' project; do
196229
projectPath=$(echo "$path/$project" | rev | cut -d'/' -f3- | rev)
197230
projectName=$(echo "$project" | rev | cut -d'/' -f 2 | rev)
198-
workspacePath=$(workspaceForProjectPath "$projectPath" "$projectName")
231+
workspacePath=$(_workspaceForProjectPath "$projectPath" "$projectName")
199232
workspaceExtension=$(echo "$workspacePath" | rev | cut -d'.' -f1 | rev)
200233
workspaceContent="$workspacePath/contents.xcworkspacedata"
201234
(! [ "$workspaceExtension" = "xcworkspace" ] || ! [ -f "$workspaceContent" ]) && continue
@@ -206,35 +239,19 @@ workspacesForProjectPath() {
206239
declare -p workspacesForProjectPath 1>/dev/null 2>/dev/null
207240
}
208241

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-
222242
##
223-
# workspacePathForProjectPath(String projectPath, String projectName): String
243+
# _workspaceForProjectPath(String projectPath, String projectName): String
224244
# - Parameter `projectPath`: path to the project folder.
225245
# - Parameter `projectName`: *.pbxproj filename.
226246
# - Return `workspaceName`
227247
##
228-
workspaceForProjectPath() {
248+
_workspaceForProjectPath() {
229249
cd "$1"
230250
local xcprojectNoExtension=$(echo "$2" | rev | cut -d'.' -f 2- | rev )
231-
local nefWorkspace="`pwd`/nef.xcworkspace"
232251
local xcprojectWorkspace="`pwd`/$xcprojectNoExtension.xcworkspace"
233252
local xcproject="`pwd`/$xcprojectNoExtension.xcodeproj"
234253

235-
if [ -d "$nefWorkspace" ]; then
236-
echo "$nefWorkspace"
237-
elif [ -d "$xcprojectWorkspace" ]; then
254+
if [ -d "$xcprojectWorkspace" ]; then
238255
echo "$xcprojectWorkspace"
239256
else
240257
echo "$xcproject"

bin/nef-jekyll

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ buildMicrosite() {
8282
log="$1/$logFile"
8383

8484
checkOutputNotSameInput "$output" "$projectPath"
85-
cleanStructure "$output"
85+
resetStructure "$output"
8686
mkdir -p "$output"
8787
nef-jekyll-page --from "$pagePath" --to "$output" --permalink "$permalink" 1> "$log" 2>&1
8888
echo -e " - title: $pageName\n url: $permalink\n" >> "$sidebarFilePath" # sidebar page
@@ -127,8 +127,8 @@ makeStructure() {
127127
local sidebarFolderPath="$sitePath/$BASE_SIDEBAR"
128128
local baseJekyllPath="$sitePath/$BASE_JEKYLL"
129129

130-
cleanStructure "$logPath"
131-
cleanStructure "$baseJekyllPath"
130+
resetStructure "$logPath"
131+
resetStructure "$baseJekyllPath"
132132

133133
mkdir -p "$logPath"
134134
mkdir -p "$sidebarFolderPath"

bin/nef-markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ buildMarkdown() {
5858
echo -ne "${normal}Rendering Markdown files for ${green}$playgroundName${reset}..."
5959

6060
checkOutputNotSameInput "$output" "$projectPath"
61-
cleanStructure "$output"
61+
resetStructure "$output"
6262
mkdir -p "$output"
6363
pagesInPlayground "$playgroundPath"
6464

@@ -91,7 +91,7 @@ makeStructure() {
9191
local logPath="$1/$LOG_PATH" # parameter `project`
9292
local outputPath="$2" # parameter `outputPath`
9393

94-
cleanStructure "$outputPath/*/*.md"
94+
resetStructure "$outputPath/*/*.md"
9595
mkdir -p "$logPath"
9696
mkdir -p "$outputPath"
9797
}

bin/nef-playground

+23-12
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ setDependency() {
6161
checkCocoaPods
6262
setPlaygroundPlatform "$projectFolder" "$projectName" "$platform" "cocoapods"
6363
setCocoaPodsDependency "$projectFolder" "$projectName" "$platform" "$podfile"
64-
setDefaultWorkspace "$projectFolder"
6564
elif [ "$cartfile" != "" ] && [ -f "$cartfile" ]; then
6665
checkCarthage
6766
setPlaygroundPlatform "$projectFolder" "$projectName" "$platform" "carthage"
@@ -70,13 +69,13 @@ setDependency() {
7069
checkCocoaPods
7170
setPlaygroundPlatform "$projectFolder" "$projectName" "$platform" "cocoapods"
7271
setBowBranchDependency "$projectFolder" "$projectName" "$platform" "$branch"
73-
setDefaultWorkspace "$projectFolder"
7472
else # version
7573
checkCocoaPods
7674
setPlaygroundPlatform "$projectFolder" "$projectName" "$platform" "cocoapods"
7775
setBowVersionDependency "$projectFolder" "$projectName" "$platform" "$version"
78-
setDefaultWorkspace "$projectFolder"
7976
fi
77+
78+
configureLauncher "$projectFolder" "$projectName"
8079
}
8180

8281
setCarthageDependency() {
@@ -157,15 +156,19 @@ setBowVersionDependency() {
157156
fi
158157
}
159158

160-
setDefaultWorkspace() {
161-
local projectFolder="$1" # parameter `projectFolder`
162-
podfilePath="$projectFolder/Podfile"
159+
configureLauncher() {
160+
cd "$1"
161+
local projectName="$2" # parameter `projectName`
163162

164-
! [ -f "$podfilePath" ] && continue
163+
launcherName="launcher"
164+
launcher=""
165165

166-
echo -ne "${normal}Updating podfile with ${green}default workspace${reset}..."
167-
echo "workspace 'nef'" >> $podfilePath
168-
echo ""
166+
while read -r -d $'\0' path; do
167+
launcher="`pwd`/$path"
168+
done < <(find . -name $launcherName -print0)
169+
170+
[ "$launcher" = "" ] && return
171+
sed -i '' "1,/{{nef}}/s/{{nef}}/$projectName/" "$launcher"
169172
}
170173

171174
##
@@ -334,6 +337,12 @@ clean() {
334337
#: - MAIN
335338
set -e
336339

340+
# Load common nef library
341+
commonNefLibName="nef-common"
342+
commonNefLibPath=$(which "$commonNefLibName")
343+
source "$commonNefLibPath"
344+
345+
# Menu
337346
root=`pwd`
338347
projectName="$DEFAULT_PLAYGROUND"
339348
version=$(lastestBowVersion)
@@ -359,11 +368,13 @@ while [ "$1" != "" ]; do
359368
shift
360369
done
361370

371+
# Fixes paths
362372
projectName="$projectName"
363373
project="$root/$projectName.app"
364374
projectFolder="$project/Contents/MacOS"
365-
cartfilePath="$root/$cartfile"
366-
podfilePath="$root/$podfile"
375+
cartfilePath=$(absoluteFilePath "$root" "$cartfile")
376+
podfilePath=$(absoluteFilePath "$root" "$podfile")
367377

378+
# MAIN
368379
playground "$project" "$projectFolder" "$projectName"
369380
setDependency "$projectFolder" "$projectName" "$platform" "$version" "$branch" "$cartfilePath" "$podfilePath"

0 commit comments

Comments
 (0)