scripts: fix generate-config-doc, handle usage errors

This commit is contained in:
Zach Bloomquist 2023-12-12 11:34:07 -05:00
parent d1561f8ebc
commit 6603c1a6e6
No known key found for this signature in database
GPG key ID: 6045CC844F942D74
2 changed files with 15 additions and 4 deletions

View file

@ -18,6 +18,7 @@
"coverage": "run-s test:* && nyc --nycrc-path=test/.nycrc-report.json report",
"dev": "cross-env NODE_ENV=development ts-node --project server/tsconfig.json server/index.ts start --dev",
"format:prettier": "prettier --write \"**/*.*\"",
"generate:config:doc": "ts-node scripts/generate-config-doc.js",
"lint:check-eslint": "eslint-config-prettier .eslintrc.cjs",
"lint:eslint": "eslint . --report-unused-disable-directives --color",
"lint:prettier": "prettier --list-different \"**/*.*\"",

View file

@ -1,16 +1,16 @@
"use strict";
// Usage: `node generate-config-doc.js DOC_REPO_PATH`
// Usage: `npm run generate:config:doc DOC_REPO_PATH`
//
// Example:
//
// ```sh
// node scripts/generate-config-doc.js ../thelounge.github.io/
// npm run generate:config:doc ../thelounge.github.io/
// ```
const {readFileSync, writeFileSync} = require("fs");
const colors = require("chalk");
const log = require("../server/log");
const log = require("../server/log").default;
const {join} = require("path");
const {spawnSync} = require("child_process");
@ -20,8 +20,18 @@ function getGitUsername() {
const configContent = readFileSync(join(__dirname, "..", "defaults", "config.js"), "utf8");
const docRoot = process.argv[2];
if (!docRoot) {
log.error("Missing DOC_REPO_PATH. Pass the path to the cloned `thelounge.github.io` repo.");
process.exit(1);
}
const docPath = join(process.argv[2], "_includes", "config.js.md");
/** @type {string[]} */
const acc = [];
const extractedDoc = configContent
.replace(/https:\/\/thelounge\.chat\/docs/g, "/docs") // make links relative
.split("\n")
@ -37,7 +47,7 @@ const extractedDoc = configContent
}
return acc;
}, [])
}, acc)
.join("\n");
const infoBlockHeader = `<!--