WIP
This commit is contained in:
@@ -44,20 +44,49 @@ function findJJSource {
|
||||
|
||||
export JJ_SOURCE_DIR=$(findJJSource)
|
||||
|
||||
if ! JJ_DATA_DIR=$(bun -e '
|
||||
const fs = require("fs");
|
||||
const YAML = require(`${process.env.JJ_SOURCE_DIR}/node_modules/js-yaml`);
|
||||
try {
|
||||
const config = YAML.load(fs.readFileSync("jj.yaml", "utf8"));
|
||||
if (typeof config?.dataFolder !== "string" || !config.dataFolder.trim()) {
|
||||
throw new Error("jj.yaml must contain a non-empty dataFolder string");
|
||||
}
|
||||
process.stdout.write(config.dataFolder);
|
||||
} catch (error) {
|
||||
console.error(`[jj] ${error.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
'); then
|
||||
readJJDataDir() {
|
||||
local line value
|
||||
local keyPattern='^dataFolder:[[:space:]]*(.*)$'
|
||||
local doubleQuotedPattern='^"([^"\\]*)"[[:space:]]*(#.*)?$'
|
||||
local singleQuotedPattern="^'([^']*)'[[:space:]]*(#.*)?$"
|
||||
|
||||
if [[ ! -r jj.yaml ]]; then
|
||||
echo "[jj] Cannot read jj.yaml in the current directory" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
if [[ ! "$line" =~ $keyPattern ]]; then
|
||||
continue
|
||||
fi
|
||||
value="${BASH_REMATCH[1]}"
|
||||
if [[ "$value" =~ $doubleQuotedPattern || "$value" =~ $singleQuotedPattern ]]; then
|
||||
value="${BASH_REMATCH[1]}"
|
||||
elif [[ "$value" == \"* || "$value" == \'* ]]; then
|
||||
break
|
||||
else
|
||||
# YAML comments start at a # preceded by whitespace.
|
||||
value="${value%%[[:space:]]#*}"
|
||||
value="${value%"${value##*[![:space:]]}"}"
|
||||
case "$value" in
|
||||
\#*|\[*|\{*|\|*|\>*|\&*|\**|\!*|null|Null|NULL|~|true|True|TRUE|false|False|FALSE) break ;;
|
||||
esac
|
||||
if [[ "$value" =~ ^[-+]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][-+]?[0-9]+)?$ ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
if [[ -n "${value//[[:space:]]/}" ]]; then
|
||||
printf '%s' "$value"
|
||||
return 0
|
||||
fi
|
||||
break
|
||||
done < jj.yaml
|
||||
|
||||
echo "[jj] jj.yaml must contain a non-empty dataFolder path (plain or quoted, without YAML escapes)" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
if ! JJ_DATA_DIR=$(readJJDataDir); then
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$JJ_DATA_DIR" == "~" ]]; then
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jj-command-line",
|
||||
"name": "@sarava-npm-packages/jj-command-line",
|
||||
"description": "jj cli",
|
||||
"version": "2.1.1",
|
||||
"version": "2.1.7",
|
||||
"author": "Jason Jafari",
|
||||
"bin": {
|
||||
"jj": "./jj.sh"
|
||||
@@ -14,7 +14,7 @@
|
||||
"folder-hash": "^4.0.4",
|
||||
"fs-extra": "^11.2.0",
|
||||
"inquirer": "^12.0.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"js-yaml": "^5.4.3",
|
||||
"lodash": "^4.17.21",
|
||||
"moment": "^2.30.1",
|
||||
"pino": "^9.5.0",
|
||||
@@ -41,14 +41,14 @@
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/https://github.com/jafarijason/jj/jj",
|
||||
"homepage": "https://gitea.root.sarava.dev/jason/jj-command-line",
|
||||
"keywords": [
|
||||
"oclif"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "src/index.ts",
|
||||
"type": "commonjs",
|
||||
"repository": "https://github.com/jafarijason/jj/jj",
|
||||
"repository": "https://gitea.root.sarava.dev/jason/jj-command-line",
|
||||
"scripts": {
|
||||
"build": " ",
|
||||
"lint": "eslint . --ext .ts",
|
||||
|
||||
Reference in New Issue
Block a user