WIP
This commit is contained in:
@@ -44,20 +44,49 @@ function findJJSource {
|
|||||||
|
|
||||||
export JJ_SOURCE_DIR=$(findJJSource)
|
export JJ_SOURCE_DIR=$(findJJSource)
|
||||||
|
|
||||||
if ! JJ_DATA_DIR=$(bun -e '
|
readJJDataDir() {
|
||||||
const fs = require("fs");
|
local line value
|
||||||
const YAML = require(`${process.env.JJ_SOURCE_DIR}/node_modules/js-yaml`);
|
local keyPattern='^dataFolder:[[:space:]]*(.*)$'
|
||||||
try {
|
local doubleQuotedPattern='^"([^"\\]*)"[[:space:]]*(#.*)?$'
|
||||||
const config = YAML.load(fs.readFileSync("jj.yaml", "utf8"));
|
local singleQuotedPattern="^'([^']*)'[[:space:]]*(#.*)?$"
|
||||||
if (typeof config?.dataFolder !== "string" || !config.dataFolder.trim()) {
|
|
||||||
throw new Error("jj.yaml must contain a non-empty dataFolder string");
|
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
|
||||||
}
|
}
|
||||||
process.stdout.write(config.dataFolder);
|
|
||||||
} catch (error) {
|
if ! JJ_DATA_DIR=$(readJJDataDir); then
|
||||||
console.error(`[jj] ${error.message}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
'); then
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [[ "$JJ_DATA_DIR" == "~" ]]; then
|
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",
|
"description": "jj cli",
|
||||||
"version": "2.1.1",
|
"version": "2.1.7",
|
||||||
"author": "Jason Jafari",
|
"author": "Jason Jafari",
|
||||||
"bin": {
|
"bin": {
|
||||||
"jj": "./jj.sh"
|
"jj": "./jj.sh"
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"folder-hash": "^4.0.4",
|
"folder-hash": "^4.0.4",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"inquirer": "^12.0.1",
|
"inquirer": "^12.0.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^5.4.3",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"pino": "^9.5.0",
|
"pino": "^9.5.0",
|
||||||
@@ -41,14 +41,14 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"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": [
|
"keywords": [
|
||||||
"oclif"
|
"oclif"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"repository": "https://github.com/jafarijason/jj/jj",
|
"repository": "https://gitea.root.sarava.dev/jason/jj-command-line",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": " ",
|
"build": " ",
|
||||||
"lint": "eslint . --ext .ts",
|
"lint": "eslint . --ext .ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user