Skip to content

Commit b53279a

Browse files
committed
fix(cli): ensure target dir
1 parent 4fac613 commit b53279a

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

bin/server.sh

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ environment
5656
'
5757
}
5858

59-
# todo - make this phase 2!
60-
#echo '----------------------'
61-
#echo "${npm_package_config_initCommand:-dev}"
62-
#echo '----------------------'
63-
6459
function main {
6560
if [[ "$@" =~ '-h' ]]; then
6661
info
@@ -75,18 +70,18 @@ function main {
7570
function start {
7671
local temp_dir
7772
local expect_file
78-
# todo - is this default working properly in all cases? test it
7973
local target_dir="${1:-${SOURCE_DIR}/out}"
8074
local target_project_name="${2:-awesome-vue-app}"
8175

76+
# we have to ensure the directory exists first, as abs_path() will fail on non-existing directories
77+
ensure_dir "$target_dir"
78+
8279
target_dir="$(abs_path "$target_dir")"
8380
temp_dir="$(create_temp_dir)"
8481
expect_file="${temp_dir}/vue-init.exp"
8582

8683
set_traps "$temp_dir"
8784

88-
# todo - cleanup output dir before everything
89-
9085
log 'hi :)'
9186

9287
log 'starting vue init survey...'
@@ -126,10 +121,11 @@ function start_auto_survey {
126121
# create a directory to force vue-init to ask about overwriting the directory on the first time
127122
ensure_dir "${work_dir}/$target_project_name"
128123

129-
pushd ${work_dir} >/dev/null 2>&1
130-
# this will generate an expect file, all filled with answers to the vue-init survey questions
131-
autoexpect -quiet -f ${expect_file} vue init ${source_dir} "${target_project_name}"
132-
popd >/dev/null 2>&1
124+
(
125+
cd ${work_dir} >/dev/null 2>&1
126+
# this will generate an expect file, all filled with answers to the vue-init survey questions
127+
autoexpect -quiet -f ${expect_file} vue init ${source_dir} "${target_project_name}"
128+
)
133129

134130
search_line ${expect_file} 'expect -exact.*'
135131
if (( $? == 1 )); then
@@ -148,8 +144,12 @@ function initialize_target_project {
148144
local project_dir="$1"
149145
local init_command="$2"
150146

151-
if is_npm_repo "$project_dir"; then
152-
pushd ${project_dir} >/dev/null 2>&1
147+
if ! is_npm_repo "$project_dir"; then
148+
return 0
149+
fi
150+
151+
(
152+
cd ${project_dir} >/dev/null 2>&1
153153

154154
# install dependencies
155155
npm i >/dev/null 2>&1
@@ -164,18 +164,17 @@ function initialize_target_project {
164164
quit "the output project's initialize command execution failed"
165165
fi
166166
fi
167-
168-
popd >/dev/null 2>&1
169-
fi
167+
)
170168
}
171169

172170
function start_survey {
173171
local work_dir="$1"
174172
local expect_file="$2"
175173

176-
pushd ${work_dir} >/dev/null 2>&1
177-
${expect_file} >/dev/null 2>&1
178-
popd >/dev/null 2>&1
174+
(
175+
cd ${work_dir} >/dev/null 2>&1
176+
${expect_file} >/dev/null 2>&1
177+
)
179178
}
180179

181180
function validate_source_dir {
@@ -224,6 +223,9 @@ function is_npm_command_available {
224223

225224
function abs_path {
226225
local path="$1"
226+
if ! path_exist "$path"; then
227+
return 1
228+
fi
227229
printf "%s" "$(cd "$(dirname "$path")"; pwd)/$(basename "$path")"
228230
}
229231

@@ -244,6 +246,11 @@ function is_dir {
244246
[[ -n "$path" && -d "$path" ]]
245247
}
246248

249+
function path_exist {
250+
local path="$1"
251+
[[ -n "$path" && -e "$path" ]]
252+
}
253+
247254
function remove_dir {
248255
rm -rf "$@" >/dev/null 2>&1
249256
}

0 commit comments

Comments
 (0)