diff --git a/bin/nef-carbon b/bin/nef-carbon
index 02b47a00..6756f94f 100755
--- a/bin/nef-carbon
+++ b/bin/nef-carbon
@@ -89,6 +89,8 @@ buildCarbon() {
output="$outputPath/$playgroundName"
echo "${normal}Downloading Carbon's snippets for ${green}$playgroundName${reset}"
+
+ checkOutputNotSameInput "$output" "$projectPath"
cleanStructure "$output"
mkdir -pv "$output"
pagesInPlayground "$playgroundPath"
@@ -175,25 +177,8 @@ if [ "$outputPath" == "" ]; then
fi
# Fixes paths
-# 1. fix `projectPath`
-if [ -d "$root/$projectPath" ]; then
- projectPath="$root/$projectPath"
-fi
-
-# 1. fix `outputPath`
-if [ -d "$root/$outputPath" ]; then
- if [ "$outputPath" = "." ]; then
- outputPath="$root/nef-carbon"
- else
- outputPath="$root/$outputPath"
- fi
-else
- mkdir -p "$outputPath"
-
- if [ ${outputPath:0:1} = "." ] || [ -d "$root/$outputPath" ]; then
- outputPath="$root/$outputPath"
- fi
-fi
+projectPath=$(absoluteInputDirectoryPath "$root" "$projectPath")
+outputPath=$(absoluteOutputDirectoryPath "$root" "$outputPath")
# Donwload Carbon code snippets
generateCarbon "$projectPath" "$outputPath" "$background" "$theme" "$size" "$font" "$lines" "$watermark"
diff --git a/bin/nef-common b/bin/nef-common
index b75249b4..8e6ab33c 100755
--- a/bin/nef-common
+++ b/bin/nef-common
@@ -90,6 +90,84 @@ cleanStructure() {
rm -rf $folder 1>/dev/null 2>/dev/null
}
+##
+# absoluteFilePath(String root, String filePath)
+# - Parameter `root`: path to the root directory
+# - Parameter `filePath`: path to file
+# - Return: the absolute file path
+##
+absoluteFilePath() {
+ local root="$1"
+ local filePath="$2"
+
+ if [ -f "$root/$filePath" ]; then # is it 'relative path'?
+ filePath="$root/$filePath"
+ fi
+
+ echo "$filePath"
+}
+
+##
+# absoluteInputDirectoryPath(String root, String folderPath)
+# - Parameter `root`: path to the root directory
+# - Parameter `folderPath`: path to directory
+# - Return: the absolute directory path
+##
+absoluteInputDirectoryPath() {
+ local root="$1"
+ local folderPath="$2"
+
+ if [ -f "$root/$folderPath" ]; then # is it 'relative path'?
+ folderPath="$root/$folderPath"
+ fi
+
+ echo "$folderPath"
+}
+
+##
+# absoluteOutputDirectoryPath(String root, String folderPath)
+# - Parameter `root`: path to the root directory
+# - Parameter `folderPath`: path to directory
+# - Return: the absolute directory path
+##
+absoluteOutputDirectoryPath() {
+ local root="$1"
+ local folderPath="$2"
+
+ if [ -d "$root/$folderPath" ]; then # is it 'relative path'?
+ folderPath="$root/$folderPath"
+ else # in another case
+ mkdir -p "$folderPath"
+
+ if [ ${folderPath:0:1} = "." ] || [ -d "$root/$folderPath" ]; then
+ folderPath="$root/$folderPath"
+ fi
+ fi
+
+ echo "$folderPath"
+}
+
+##
+# checkOutputNotSameInput(String outputPath, String projectPath) throws
+# - Parameter `outputPath`: path to output directory - where to build nef project
+# - Parameter `projectPath`: path to the path directory
+##
+checkOutputNotSameInput() {
+ local outputPath="$1"
+ local projectPath="$2"
+ local root=$(echo "$projectPath" | rev | cut -d'/' -f2- | rev)
+
+ lsOutput=$(ls "$outputPath" 2>&1)
+ lsProject=$(ls "$projectPath" 2>&1)
+
+ if [ "$lsOutput" == "$lsProject" ]; then
+ echo ""
+ echo "${bold}[!] ${normal}${red}error:${reset} 'output' path could not be the same path as 'project'. [${bold}$projectPath${reset}]"
+ echo "${bold}Please, select different directory for 'output'.${reset} ex. $root/output-nef"
+ echo ""
+ exit 1
+ fi
+}
###: - Internal methods
diff --git a/bin/nef-jekyll b/bin/nef-jekyll
index 75d60038..e03a1227 100755
--- a/bin/nef-jekyll
+++ b/bin/nef-jekyll
@@ -81,6 +81,7 @@ buildMicrosite() {
logFile="$LOG_PATH/$playgroundName-$pageName.log"
log="$projectPath/$logFile"
+ checkOutputNotSameInput "$output" "$projectPath"
cleanStructure "$output"
mkdir -p "$output"
nef-jekyll-page --from "$pagePath" --to "$output" --permalink "$permalink" 1> "$log" 2>&1
@@ -171,25 +172,9 @@ if [ "$sitePath" == "" ]; then
fi
# Fixes paths
-# 1. fix `projectPath`
-if [ -d "$root/$projectPath" ]; then
- projectPath="$root/$projectPath"
-fi
-
-# 2. fix `mainPagePath`
-if [ -f "$root/$mainPagePath" ]; then
- mainPagePath="$root/$mainPagePath"
-fi
-
-# 3. fix `sitePath`
-if [ -d "$root/$sitePath" ]; then
- sitePath="$root/$sitePath"
-else
- mkdir -p "$sitePath"
-
- if [ ${sitePath:0:1} = "." ] || [ -d "$root/$sitePath" ]; then
- sitePath="$root/$sitePath"
- fi
-fi
+mainPagePath=$(absoluteFilePath "$root" "$mainPagePath")
+projectPath=$(absoluteInputDirectoryPath "$root" "$projectPath")
+sitePath=$(absoluteOutputDirectoryPath "$root" "$sitePath")
+# MAIN
generateDocumentation "$projectPath" "$sitePath" "$mainPagePath"
diff --git a/bin/nef-markdown b/bin/nef-markdown
index 6570c5b8..d841de08 100755
--- a/bin/nef-markdown
+++ b/bin/nef-markdown
@@ -57,6 +57,7 @@ buildMarkdown() {
echo -ne "${normal}Rendering Markdown files for ${green}$playgroundName${reset}..."
+ checkOutputNotSameInput "$output" "$projectPath"
cleanStructure "$output"
mkdir -p "$output"
pagesInPlayground "$playgroundPath"
@@ -129,25 +130,8 @@ if [ "$outputPath" == "" ]; then
fi
# Fixes paths
-# 1. fix `projectPath`
-if [ -d "$root/$projectPath" ]; then
- projectPath="$root/$projectPath"
-fi
-
-# 1. fix `outputPath`
-if [ -d "$root/$outputPath" ]; then
- if [ "$outputPath" = "." ]; then
- outputPath="$root/nef-markdown"
- else
- outputPath="$root/$outputPath"
- fi
-else
- mkdir -p "$outputPath"
-
- if [ ${outputPath:0:1} = "." ] || [ -d "$root/$outputPath" ]; then
- outputPath="$root/$outputPath"
- fi
-fi
+projectPath=$(absoluteInputDirectoryPath "$root" "$projectPath")
+outputPath=$(absoluteOutputDirectoryPath "$root" "$outputPath")
# Render Markdown
generateMarkdown "$projectPath" "$outputPath"
diff --git a/markdown/Markdown.xcodeproj/xcshareddata/xcschemes/Carbon.xcscheme b/markdown/Markdown.xcodeproj/xcshareddata/xcschemes/Carbon.xcscheme
index 2cac870b..27875237 100644
--- a/markdown/Markdown.xcodeproj/xcshareddata/xcschemes/Carbon.xcscheme
+++ b/markdown/Markdown.xcodeproj/xcshareddata/xcschemes/Carbon.xcscheme
@@ -62,7 +62,7 @@
isEnabled = "YES">