From f7bf4038dc7fcf3adc09697797da1c68c932eadc Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 06 Jul 2023 23:56:30 +0000
Subject: [PATCH] fix path parsing
---
quartz/bootstrap-cli.mjs | 32 ++++++++++++++++++++------------
1 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/quartz/bootstrap-cli.mjs b/quartz/bootstrap-cli.mjs
index 92f88bf..b1503f2 100755
--- a/quartz/bootstrap-cli.mjs
+++ b/quartz/bootstrap-cli.mjs
@@ -45,6 +45,14 @@
}
}
+function escapePath(fp) {
+ return fp
+ .replace(/\\ /g, " ") // unescape spaces
+ .replace(/^".*"$/, "$1")
+ .replace(/^'.*"$/, "$1")
+ .trim()
+}
+
yargs(hideBin(process.argv))
.scriptName("quartz")
.version(version)
@@ -69,30 +77,29 @@
}
async function rmContentFolder() {
- if (fs.existsSync(contentFolder)) {
- const contentStat = await fs.promises.lstat(contentFolder)
+ const contentStat = await fs.promises.lstat(contentFolder)
+ if (contentStat) {
if (contentStat.isSymbolicLink()) {
await fs.promises.unlink(contentFolder)
} else {
await rimraf(contentFolder)
}
}
-
- await fs.promises.mkdir(contentFolder)
}
if (setupStrategy === 'copy' || setupStrategy === 'symlink') {
- const originalFolder = await text({
+ const originalFolder = escapePath(await text({
message: "Enter the full path to existing content folder",
placeholder: 'On most terminal emulators, you can drag and drop a folder into the window and it will paste the full path',
validate(fp) {
- if (!fs.existsSync(fp)) {
+ const fullPath = escapePath(fp)
+ if (!fs.existsSync(fullPath)) {
return "The given path doesn't exist"
- } else if (!fs.lstatSync(fp).isDirectory()) {
+ } else if (!fs.lstatSync(fullPath).isDirectory()) {
return "The given path is not a folder"
}
}
- })
+ }))
if (isCancel(originalFolder)) {
outro(chalk.red("Exiting"))
@@ -101,14 +108,15 @@
await rmContentFolder()
if (setupStrategy === 'copy') {
- await fs.promises.cp(originalFolder, contentFolder)
+ await fs.promises.cp(originalFolder, contentFolder, { recursive: true })
} else if (setupStrategy === 'symlink') {
- await fs.promises.symlink(originalFolder, contentFolder)
+ await fs.promises.symlink(originalFolder, contentFolder, 'dir')
}
} else if (setupStrategy === 'new') {
await rmContentFolder()
- await fs.promises.writeFile(path.join(contentFolder, "index.md"),
-`---
+ await fs.promises.mkdir(contentFolder)
+ await fs.promises.writeFile(path.join(contentFolder, "index.md"),
+ `---
title: Welcome to Quartz
---
--
Gitblit v1.10.0