Skip to content

Build your personal knowledge base with Trilium Notes

Add --config, --help, and --version flags to edit-docs

Wael Nasreddinefb4d63b04921
diff --git a/apps/edit-docs/package.json b/apps/edit-docs/package.json
index d627275328..31d7e51ec1 100644
--- a/apps/edit-docs/package.json
+++ b/apps/edit-docs/package.json
@@ -1,6 +1,6 @@
{
"name": "@triliumnext/edit-docs",
- "version": "0.0.1",
+ "version": "0.101.3",
"private": true,
"description": "Desktop version of Trilium which imports the demo database (presented to new users at start-up) or the user guide and other documentation and saves the modifications for committing.",
"dependencies": {
diff --git a/apps/edit-docs/src/edit-docs.ts b/apps/edit-docs/src/edit-docs.ts
index baf56c6f6d..c15a2f0863 100644
--- a/apps/edit-docs/src/edit-docs.ts
+++ b/apps/edit-docs/src/edit-docs.ts
@@ -10,6 +10,7 @@ import fsExtra from "fs-extra";
import yaml from "js-yaml";
import path from "path";
+import packageJson from "../package.json" with { type: "json" };
import { extractZip, importData, initializeDatabase, startElectron } from "./utils.js";
interface NoteMapping {
@@ -25,26 +26,82 @@ interface Config {
noteMappings: NoteMapping[];
}
-// Configuration variables
+// Parse command-line arguments
+function parseArgs() {
+ const args = process.argv.slice(2);
+ let configPath: string | undefined;
+ let showHelp = false;
+ let showVersion = false;
+
+ for (let i = 0; i < args.length; i++) {
+ if (args[i] === '--config' || args[i] === '-c') {
+ configPath = args[i + 1];
+ i++; // Skip the next argument as it's the value
+ } else if (args[i] === '--help' || args[i] === '-h') {
+ showHelp = true;
+ } else if (args[i] === '--version' || args[i] === '-v') {
+ showVersion = true;
+ }
+ }
+
+ return { configPath, showHelp, showVersion };
+}
+
+function getVersion(): string {
+ return packageJson.version;
+}
+
+function printHelp() {
+ const version = getVersion();
+ console.log(`
+Usage: trilium-edit-docs [options]
+
+Options:
+ -c, --config <path> Path to the configuration file (default: edit-docs-config.yaml in the root)
+ -h, --help Display this help message
+ -v, --version Display version information
+
+Version: ${version}
+`);
+}
+
+function printVersion() {
+ const version = getVersion();
+ console.log(version);
+}
+
+const { configPath, showHelp, showVersion } = parseArgs();
+
+if (showHelp) {
+ printHelp();
+ process.exit(0);
+} else if (showVersion) {
+ printVersion();
+ process.exit(0);
+}
+
+// Configuration variables to be initialized
let BASE_URL: string;
let NOTE_MAPPINGS: NoteMapping[];
// Load configuration from edit-docs-config.yaml
async function loadConfig() {
- const CONFIG_PATH = path.join(__dirname, "../../../edit-docs-config.yaml");
+ const CONFIG_PATH = configPath
+ ? path.resolve(configPath)
+ : path.join(__dirname, "../../../edit-docs-config.yaml");
+
const configContent = await fs.readFile(CONFIG_PATH, "utf-8");
const config = yaml.load(configContent) as Config;
BASE_URL = config.baseUrl;
- // Resolve all paths relative to the repository root
- const REPO_ROOT = path.join(__dirname, "../../..");
+ // Resolve all paths relative to the config file's directory (for flexibility with external configs)
+ const CONFIG_DIR = path.dirname(CONFIG_PATH);
NOTE_MAPPINGS = config.noteMappings.map((mapping) => ({
...mapping,
- path: path.join(REPO_ROOT, mapping.path)
+ path: path.resolve(CONFIG_DIR, mapping.path)
}));
}
-
async function main() {
await loadConfig();
const initializedPromise = startElectron(() => {
diff --git a/scripts/electron-start.mts b/scripts/electron-start.mts
index e1ed9df7e0..05277820a1 100644
--- a/scripts/electron-start.mts
+++ b/scripts/electron-start.mts
@@ -3,7 +3,8 @@ import { getElectronPath, isNixOS } from "./utils.mjs";
const LD_LIBRARY_PATH = isNixOS() && execSync("nix eval --raw nixpkgs#gcc.cc.lib").toString("utf-8") + "/lib";
-execSync(`${getElectronPath()} ${process.argv[2]} --no-sandbox`, {
+const args = process.argv.slice(2);
+execSync(`${getElectronPath()} ${args.join(" ")} --no-sandbox`, {
stdio: "inherit",
env: {
...process.env,
diff --git a/scripts/update-version.ts b/scripts/update-version.ts
index fd00ff35d2..d9e52abe45 100644
--- a/scripts/update-version.ts
+++ b/scripts/update-version.ts
@@ -26,7 +26,7 @@ function getVersion(packageJsonPath: string) {
function main() {
const version = getVersion(join(__dirname, "..", "package.json"));
- for (const appName of ["server", "client", "desktop"]) {
+ for (const appName of ["server", "client", "desktop", "edit-docs"]) {
patchPackageJson(join(__dirname, "..", "apps", appName, "package.json"), version);
}