learnhouse 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/dist/bin/learnhouse.js +618 -112
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -97,6 +97,55 @@ learnhouse/
|
|
|
97
97
|
nginx.prod.conf # Reverse proxy (or Caddyfile for auto-SSL)
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
## CI / Non-interactive Mode
|
|
101
|
+
|
|
102
|
+
All commands support non-interactive usage for CI pipelines:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Setup without prompts
|
|
106
|
+
npx learnhouse setup --ci \
|
|
107
|
+
--name production \
|
|
108
|
+
--domain example.com \
|
|
109
|
+
--port 80 \
|
|
110
|
+
--admin-email admin@example.com \
|
|
111
|
+
--admin-password secretpass123
|
|
112
|
+
|
|
113
|
+
# Update with auto-migration
|
|
114
|
+
npx learnhouse update --version 1.2.0 --migrate
|
|
115
|
+
|
|
116
|
+
# Update without migrations
|
|
117
|
+
npx learnhouse update --no-migrate
|
|
118
|
+
|
|
119
|
+
# Setup without starting services
|
|
120
|
+
npx learnhouse setup --ci --admin-password pass123 --no-start
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Testing
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Unit tests (no Docker required)
|
|
127
|
+
bun run test
|
|
128
|
+
|
|
129
|
+
# E2E tests (requires Docker)
|
|
130
|
+
bun run test:e2e
|
|
131
|
+
|
|
132
|
+
# All tests
|
|
133
|
+
bun run test:all
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Unit tests** cover template generation (docker-compose, .env, nginx, caddyfile) and config store operations.
|
|
137
|
+
|
|
138
|
+
**E2E tests** run the full lifecycle with real Docker containers: setup → start → status → health → doctor → stop → restart. They use `--ci` mode to run without prompts.
|
|
139
|
+
|
|
140
|
+
**Not yet tested:**
|
|
141
|
+
- Interactive commands (backup create/restore, env editor, shell, deployments scaling)
|
|
142
|
+
- `update` with actual version swap between two published images
|
|
143
|
+
- `update --migrate` with pending Alembic migrations
|
|
144
|
+
- `logs` (streams indefinitely)
|
|
145
|
+
- `dev` mode (requires full monorepo source)
|
|
146
|
+
- Multi-installation discovery (`findInstallDir` with multiple `~/.learnhouse/*` entries)
|
|
147
|
+
- Error recovery (Docker daemon down, port conflicts, corrupted config)
|
|
148
|
+
|
|
100
149
|
## License
|
|
101
150
|
|
|
102
151
|
GPL-3.0
|
package/dist/bin/learnhouse.js
CHANGED
|
@@ -1202,8 +1202,8 @@ var require_command = __commonJS({
|
|
|
1202
1202
|
"use strict";
|
|
1203
1203
|
var EventEmitter = __require("events").EventEmitter;
|
|
1204
1204
|
var childProcess = __require("child_process");
|
|
1205
|
-
var
|
|
1206
|
-
var
|
|
1205
|
+
var path10 = __require("path");
|
|
1206
|
+
var fs10 = __require("fs");
|
|
1207
1207
|
var process2 = __require("process");
|
|
1208
1208
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1209
1209
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -2197,7 +2197,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2197
2197
|
* @param {string} subcommandName
|
|
2198
2198
|
*/
|
|
2199
2199
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2200
|
-
if (
|
|
2200
|
+
if (fs10.existsSync(executableFile)) return;
|
|
2201
2201
|
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
2202
2202
|
const executableMissing = `'${executableFile}' does not exist
|
|
2203
2203
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
@@ -2215,11 +2215,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2215
2215
|
let launchWithNode = false;
|
|
2216
2216
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2217
2217
|
function findFile(baseDir, baseName) {
|
|
2218
|
-
const localBin =
|
|
2219
|
-
if (
|
|
2220
|
-
if (sourceExt.includes(
|
|
2218
|
+
const localBin = path10.resolve(baseDir, baseName);
|
|
2219
|
+
if (fs10.existsSync(localBin)) return localBin;
|
|
2220
|
+
if (sourceExt.includes(path10.extname(baseName))) return void 0;
|
|
2221
2221
|
const foundExt = sourceExt.find(
|
|
2222
|
-
(ext) =>
|
|
2222
|
+
(ext) => fs10.existsSync(`${localBin}${ext}`)
|
|
2223
2223
|
);
|
|
2224
2224
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
2225
2225
|
return void 0;
|
|
@@ -2231,21 +2231,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2231
2231
|
if (this._scriptPath) {
|
|
2232
2232
|
let resolvedScriptPath;
|
|
2233
2233
|
try {
|
|
2234
|
-
resolvedScriptPath =
|
|
2234
|
+
resolvedScriptPath = fs10.realpathSync(this._scriptPath);
|
|
2235
2235
|
} catch {
|
|
2236
2236
|
resolvedScriptPath = this._scriptPath;
|
|
2237
2237
|
}
|
|
2238
|
-
executableDir =
|
|
2239
|
-
|
|
2238
|
+
executableDir = path10.resolve(
|
|
2239
|
+
path10.dirname(resolvedScriptPath),
|
|
2240
2240
|
executableDir
|
|
2241
2241
|
);
|
|
2242
2242
|
}
|
|
2243
2243
|
if (executableDir) {
|
|
2244
2244
|
let localFile = findFile(executableDir, executableFile);
|
|
2245
2245
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2246
|
-
const legacyName =
|
|
2246
|
+
const legacyName = path10.basename(
|
|
2247
2247
|
this._scriptPath,
|
|
2248
|
-
|
|
2248
|
+
path10.extname(this._scriptPath)
|
|
2249
2249
|
);
|
|
2250
2250
|
if (legacyName !== this._name) {
|
|
2251
2251
|
localFile = findFile(
|
|
@@ -2256,7 +2256,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2256
2256
|
}
|
|
2257
2257
|
executableFile = localFile || executableFile;
|
|
2258
2258
|
}
|
|
2259
|
-
launchWithNode = sourceExt.includes(
|
|
2259
|
+
launchWithNode = sourceExt.includes(path10.extname(executableFile));
|
|
2260
2260
|
let proc;
|
|
2261
2261
|
if (process2.platform !== "win32") {
|
|
2262
2262
|
if (launchWithNode) {
|
|
@@ -3171,7 +3171,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3171
3171
|
* @return {Command}
|
|
3172
3172
|
*/
|
|
3173
3173
|
nameFromFilename(filename) {
|
|
3174
|
-
this._name =
|
|
3174
|
+
this._name = path10.basename(filename, path10.extname(filename));
|
|
3175
3175
|
return this;
|
|
3176
3176
|
}
|
|
3177
3177
|
/**
|
|
@@ -3185,9 +3185,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3185
3185
|
* @param {string} [path]
|
|
3186
3186
|
* @return {(string|null|Command)}
|
|
3187
3187
|
*/
|
|
3188
|
-
executableDir(
|
|
3189
|
-
if (
|
|
3190
|
-
this._executableDir =
|
|
3188
|
+
executableDir(path11) {
|
|
3189
|
+
if (path11 === void 0) return this._executableDir;
|
|
3190
|
+
this._executableDir = path11;
|
|
3191
3191
|
return this;
|
|
3192
3192
|
}
|
|
3193
3193
|
/**
|
|
@@ -3613,13 +3613,13 @@ var {
|
|
|
3613
3613
|
} = import_index.default;
|
|
3614
3614
|
|
|
3615
3615
|
// bin/learnhouse.ts
|
|
3616
|
-
var
|
|
3616
|
+
var import_picocolors23 = __toESM(require_picocolors(), 1);
|
|
3617
3617
|
|
|
3618
3618
|
// src/constants.ts
|
|
3619
|
-
var VERSION = "1.
|
|
3619
|
+
var VERSION = "1.4.0";
|
|
3620
3620
|
var APP_IMAGE = "ghcr.io/learnhouse/app:latest";
|
|
3621
3621
|
var DEV_IMAGE = "ghcr.io/learnhouse/app:dev";
|
|
3622
|
-
var POSTGRES_IMAGE = "
|
|
3622
|
+
var POSTGRES_IMAGE = "pgvector/pgvector:pg16";
|
|
3623
3623
|
var POSTGRES_AI_IMAGE = "pgvector/pgvector:pg16";
|
|
3624
3624
|
var HEALTH_CHECK_TIMEOUT_MS = 18e4;
|
|
3625
3625
|
var HEALTH_CHECK_INTERVAL_MS = 3e3;
|
|
@@ -3723,16 +3723,29 @@ async function resolveAppImage(channel = "stable") {
|
|
|
3723
3723
|
if (channel === "dev") {
|
|
3724
3724
|
return { image: DEV_IMAGE, isLatest: false };
|
|
3725
3725
|
}
|
|
3726
|
-
const versionedTag = `${GHCR_BASE}:${VERSION}`;
|
|
3727
3726
|
try {
|
|
3727
|
+
const releasesResp = await fetch(
|
|
3728
|
+
"https://api.github.com/repos/learnhouse/learnhouse/releases",
|
|
3729
|
+
{
|
|
3730
|
+
signal: AbortSignal.timeout(5e3),
|
|
3731
|
+
headers: { Accept: "application/vnd.github+json" }
|
|
3732
|
+
}
|
|
3733
|
+
);
|
|
3734
|
+
if (!releasesResp.ok) throw new Error("GitHub API failed");
|
|
3735
|
+
const releases = await releasesResp.json();
|
|
3736
|
+
const appRelease = releases.find(
|
|
3737
|
+
(r) => !r.draft && !r.prerelease && !r.tag_name.startsWith("cli-")
|
|
3738
|
+
);
|
|
3739
|
+
if (!appRelease) throw new Error("No app release found");
|
|
3740
|
+
const appVersion = appRelease.tag_name;
|
|
3728
3741
|
const tokenResp = await fetch(
|
|
3729
|
-
|
|
3742
|
+
"https://ghcr.io/token?scope=repository:learnhouse/app:pull",
|
|
3730
3743
|
{ signal: AbortSignal.timeout(5e3) }
|
|
3731
3744
|
);
|
|
3732
|
-
if (!tokenResp.ok) throw new Error("token
|
|
3745
|
+
if (!tokenResp.ok) throw new Error("GHCR token failed");
|
|
3733
3746
|
const { token } = await tokenResp.json();
|
|
3734
3747
|
const manifestResp = await fetch(
|
|
3735
|
-
`https://ghcr.io/v2/learnhouse/app/manifests/${
|
|
3748
|
+
`https://ghcr.io/v2/learnhouse/app/manifests/${appVersion}`,
|
|
3736
3749
|
{
|
|
3737
3750
|
signal: AbortSignal.timeout(5e3),
|
|
3738
3751
|
headers: {
|
|
@@ -3742,7 +3755,7 @@ async function resolveAppImage(channel = "stable") {
|
|
|
3742
3755
|
}
|
|
3743
3756
|
);
|
|
3744
3757
|
if (manifestResp.ok) {
|
|
3745
|
-
return { image:
|
|
3758
|
+
return { image: `${GHCR_BASE}:${appVersion}`, isLatest: false };
|
|
3746
3759
|
}
|
|
3747
3760
|
} catch {
|
|
3748
3761
|
}
|
|
@@ -3752,6 +3765,7 @@ async function resolveAppImage(channel = "stable") {
|
|
|
3752
3765
|
// src/commands/setup.ts
|
|
3753
3766
|
import crypto3 from "crypto";
|
|
3754
3767
|
import fs2 from "fs";
|
|
3768
|
+
import os2 from "os";
|
|
3755
3769
|
import path2 from "path";
|
|
3756
3770
|
|
|
3757
3771
|
// node_modules/@clack/core/dist/index.mjs
|
|
@@ -4840,8 +4854,9 @@ function isDockerRunning() {
|
|
|
4840
4854
|
return false;
|
|
4841
4855
|
}
|
|
4842
4856
|
}
|
|
4843
|
-
function dockerComposeUp(cwd) {
|
|
4844
|
-
|
|
4857
|
+
function dockerComposeUp(cwd, pull = false) {
|
|
4858
|
+
const cmd = pull ? "docker compose up -d --pull always" : "docker compose up -d";
|
|
4859
|
+
execSync(cmd, {
|
|
4845
4860
|
cwd,
|
|
4846
4861
|
stdio: "inherit"
|
|
4847
4862
|
});
|
|
@@ -4852,6 +4867,12 @@ function dockerComposeDown(cwd) {
|
|
|
4852
4867
|
stdio: "inherit"
|
|
4853
4868
|
});
|
|
4854
4869
|
}
|
|
4870
|
+
function dockerComposePs(cwd) {
|
|
4871
|
+
return execSync("docker compose ps", {
|
|
4872
|
+
cwd,
|
|
4873
|
+
stdio: "pipe"
|
|
4874
|
+
}).toString();
|
|
4875
|
+
}
|
|
4855
4876
|
function dockerComposeLogs(cwd) {
|
|
4856
4877
|
const child = spawn("docker", ["compose", "logs", "--tail", "all", "-f"], {
|
|
4857
4878
|
cwd,
|
|
@@ -4917,6 +4938,12 @@ function dockerStatsForContainers(containerNames) {
|
|
|
4917
4938
|
{ stdio: "pipe" }
|
|
4918
4939
|
).toString();
|
|
4919
4940
|
}
|
|
4941
|
+
function dockerExec(containerName, cmd) {
|
|
4942
|
+
return execSync(`docker exec ${containerName} ${cmd}`, {
|
|
4943
|
+
stdio: "pipe",
|
|
4944
|
+
timeout: 1e4
|
|
4945
|
+
}).toString().trim();
|
|
4946
|
+
}
|
|
4920
4947
|
function getContainerLogs(containerName, lines = 50) {
|
|
4921
4948
|
return execSync(`docker logs --tail ${lines} ${containerName}`, {
|
|
4922
4949
|
stdio: "pipe"
|
|
@@ -5898,6 +5925,7 @@ ${config.domain} {
|
|
|
5898
5925
|
|
|
5899
5926
|
// src/services/config-store.ts
|
|
5900
5927
|
import fs from "fs";
|
|
5928
|
+
import os from "os";
|
|
5901
5929
|
import path from "path";
|
|
5902
5930
|
function writeConfig(config) {
|
|
5903
5931
|
const data = {
|
|
@@ -5936,61 +5964,35 @@ function isCompleteInstall(dir) {
|
|
|
5936
5964
|
return false;
|
|
5937
5965
|
}
|
|
5938
5966
|
}
|
|
5939
|
-
function
|
|
5940
|
-
|
|
5941
|
-
if (fs.existsSync(
|
|
5942
|
-
|
|
5943
|
-
}
|
|
5967
|
+
function listInstallations() {
|
|
5968
|
+
const baseDir = path.join(os.homedir(), ".learnhouse");
|
|
5969
|
+
if (!fs.existsSync(baseDir)) return [];
|
|
5970
|
+
const results = [];
|
|
5944
5971
|
try {
|
|
5945
|
-
const entries = fs.readdirSync(
|
|
5972
|
+
const entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
5946
5973
|
for (const entry of entries) {
|
|
5947
|
-
if (!entry.isDirectory()
|
|
5948
|
-
|
|
5974
|
+
if (!entry.isDirectory()) continue;
|
|
5975
|
+
const dir = path.join(baseDir, entry.name);
|
|
5976
|
+
if (isCompleteInstall(dir)) {
|
|
5977
|
+
const config = JSON.parse(fs.readFileSync(path.join(dir, CONFIG_FILENAME), "utf-8"));
|
|
5978
|
+
results.push({ name: entry.name, dir, config });
|
|
5979
|
+
}
|
|
5949
5980
|
}
|
|
5950
5981
|
} catch {
|
|
5951
5982
|
}
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
if (candidates.length === 0) return null;
|
|
5955
|
-
const completeInstalls = candidates.filter(isCompleteInstall);
|
|
5956
|
-
if (completeInstalls.length > 0) {
|
|
5957
|
-
completeInstalls.sort((a, b) => {
|
|
5958
|
-
try {
|
|
5959
|
-
const configA = JSON.parse(fs.readFileSync(path.join(a, CONFIG_FILENAME), "utf-8"));
|
|
5960
|
-
const configB = JSON.parse(fs.readFileSync(path.join(b, CONFIG_FILENAME), "utf-8"));
|
|
5961
|
-
return (configB.createdAt || "").localeCompare(configA.createdAt || "");
|
|
5962
|
-
} catch {
|
|
5963
|
-
return 0;
|
|
5964
|
-
}
|
|
5965
|
-
});
|
|
5966
|
-
return completeInstalls[0];
|
|
5967
|
-
}
|
|
5968
|
-
return candidates[0];
|
|
5983
|
+
results.sort((a, b) => (b.config.createdAt || "").localeCompare(a.config.createdAt || ""));
|
|
5984
|
+
return results;
|
|
5969
5985
|
}
|
|
5970
5986
|
function findInstallDir() {
|
|
5987
|
+
const baseDir = path.join(os.homedir(), ".learnhouse");
|
|
5988
|
+
const defaultDir = path.join(baseDir, "default");
|
|
5989
|
+
const installations = listInstallations();
|
|
5990
|
+
if (installations.length === 1) return installations[0].dir;
|
|
5991
|
+
if (isCompleteInstall(defaultDir)) return defaultDir;
|
|
5992
|
+
if (installations.length > 0) return installations[0].dir;
|
|
5971
5993
|
const cwd = process.cwd();
|
|
5972
5994
|
if (isCompleteInstall(cwd)) return cwd;
|
|
5973
|
-
|
|
5974
|
-
if (isCompleteInstall(subDir)) return subDir;
|
|
5975
|
-
const candidates = [];
|
|
5976
|
-
collectCandidates(cwd, 10, candidates);
|
|
5977
|
-
const best = pickBest(candidates);
|
|
5978
|
-
if (best) return best;
|
|
5979
|
-
let current = cwd;
|
|
5980
|
-
let fallbackDir = null;
|
|
5981
|
-
while (true) {
|
|
5982
|
-
const parent = path.dirname(current);
|
|
5983
|
-
if (parent === current) break;
|
|
5984
|
-
if (isCompleteInstall(parent)) return parent;
|
|
5985
|
-
const parentSub = path.join(parent, "learnhouse");
|
|
5986
|
-
if (isCompleteInstall(parentSub)) return parentSub;
|
|
5987
|
-
if (!fallbackDir && fs.existsSync(path.join(parent, CONFIG_FILENAME))) {
|
|
5988
|
-
fallbackDir = parent;
|
|
5989
|
-
}
|
|
5990
|
-
current = parent;
|
|
5991
|
-
}
|
|
5992
|
-
if (fallbackDir) return fallbackDir;
|
|
5993
|
-
return cwd;
|
|
5995
|
+
return process.cwd();
|
|
5994
5996
|
}
|
|
5995
5997
|
|
|
5996
5998
|
// src/services/health.ts
|
|
@@ -6034,19 +6036,25 @@ async function confirmOrBack(message) {
|
|
|
6034
6036
|
return result === "back" ? BACK : true;
|
|
6035
6037
|
}
|
|
6036
6038
|
async function stepInstallDir() {
|
|
6037
|
-
const
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6039
|
+
const baseDir = path2.join(os2.homedir(), ".learnhouse");
|
|
6040
|
+
R2.info(`All installations are stored in ${import_picocolors8.default.cyan("~/.learnhouse/<name>")}`);
|
|
6041
|
+
const name = await text({
|
|
6042
|
+
message: "Name for this installation:",
|
|
6043
|
+
placeholder: "default",
|
|
6044
|
+
defaultValue: "default",
|
|
6045
|
+
validate: (value) => {
|
|
6046
|
+
if (!value) return "Name is required";
|
|
6047
|
+
if (/[/\\]/.test(value)) return "Name cannot contain slashes";
|
|
6048
|
+
return void 0;
|
|
6049
|
+
}
|
|
6042
6050
|
});
|
|
6043
|
-
if (Ct(
|
|
6051
|
+
if (Ct(name)) {
|
|
6044
6052
|
Ne();
|
|
6045
6053
|
process.exit(0);
|
|
6046
6054
|
}
|
|
6047
|
-
const resolved = path2.
|
|
6055
|
+
const resolved = path2.join(baseDir, name);
|
|
6048
6056
|
if (fs2.existsSync(path2.join(resolved, "learnhouse.config.json"))) {
|
|
6049
|
-
R2.warn(
|
|
6057
|
+
R2.warn(`~/.learnhouse/${name} already contains a LearnHouse installation.`);
|
|
6050
6058
|
const overwrite = await Re({
|
|
6051
6059
|
message: "Overwrite existing installation?",
|
|
6052
6060
|
initialValue: false
|
|
@@ -6056,6 +6064,7 @@ async function stepInstallDir() {
|
|
|
6056
6064
|
process.exit(0);
|
|
6057
6065
|
}
|
|
6058
6066
|
}
|
|
6067
|
+
fs2.mkdirSync(resolved, { recursive: true });
|
|
6059
6068
|
return resolved;
|
|
6060
6069
|
}
|
|
6061
6070
|
async function stepDomain() {
|
|
@@ -6083,7 +6092,70 @@ async function stepFeatures() {
|
|
|
6083
6092
|
R2.step(import_picocolors8.default.cyan(`Step 6/6`) + " Optional Features");
|
|
6084
6093
|
return await promptFeatures();
|
|
6085
6094
|
}
|
|
6086
|
-
async function setupCommand() {
|
|
6095
|
+
async function setupCommand(options) {
|
|
6096
|
+
if (options.ci) {
|
|
6097
|
+
if (!options.adminPassword) {
|
|
6098
|
+
console.error("Error: --admin-password is required in --ci mode");
|
|
6099
|
+
process.exit(1);
|
|
6100
|
+
}
|
|
6101
|
+
await checkPrerequisites();
|
|
6102
|
+
const installName = options.name || "default";
|
|
6103
|
+
const baseDir = path2.join(os2.homedir(), ".learnhouse");
|
|
6104
|
+
const resolvedDir2 = path2.join(baseDir, installName);
|
|
6105
|
+
fs2.mkdirSync(resolvedDir2, { recursive: true });
|
|
6106
|
+
const deploymentId2 = crypto3.randomBytes(4).toString("hex");
|
|
6107
|
+
const channel2 = options.channel === "dev" ? "dev" : "stable";
|
|
6108
|
+
const config2 = {
|
|
6109
|
+
deploymentId: deploymentId2,
|
|
6110
|
+
installDir: resolvedDir2,
|
|
6111
|
+
channel: channel2,
|
|
6112
|
+
domain: options.domain || "localhost",
|
|
6113
|
+
useHttps: false,
|
|
6114
|
+
httpPort: options.port || 80,
|
|
6115
|
+
autoSsl: false,
|
|
6116
|
+
useExternalDb: false,
|
|
6117
|
+
useAiDatabase: false,
|
|
6118
|
+
useExternalRedis: false,
|
|
6119
|
+
orgName: "Default",
|
|
6120
|
+
adminEmail: options.adminEmail || "admin@school.dev",
|
|
6121
|
+
adminPassword: options.adminPassword,
|
|
6122
|
+
aiEnabled: false,
|
|
6123
|
+
emailEnabled: false,
|
|
6124
|
+
s3Enabled: false,
|
|
6125
|
+
googleOAuthEnabled: false,
|
|
6126
|
+
unsplashEnabled: false
|
|
6127
|
+
};
|
|
6128
|
+
console.log(`Setting up LearnHouse in ~/.learnhouse/${installName}`);
|
|
6129
|
+
const { image: appImage2 } = await resolveAppImage(config2.channel);
|
|
6130
|
+
console.log(`Using image: ${appImage2}`);
|
|
6131
|
+
fs2.mkdirSync(resolvedDir2, { recursive: true });
|
|
6132
|
+
fs2.mkdirSync(path2.join(resolvedDir2, "extra"), { recursive: true });
|
|
6133
|
+
fs2.writeFileSync(path2.join(resolvedDir2, "docker-compose.yml"), generateDockerCompose(config2, appImage2));
|
|
6134
|
+
fs2.writeFileSync(path2.join(resolvedDir2, ".env"), generateEnvFile(config2));
|
|
6135
|
+
fs2.writeFileSync(path2.join(resolvedDir2, "extra", "nginx.prod.conf"), generateNginxConf());
|
|
6136
|
+
writeConfig(config2);
|
|
6137
|
+
console.log("Configuration files generated");
|
|
6138
|
+
if (options.start !== false) {
|
|
6139
|
+
console.log("Starting services...");
|
|
6140
|
+
try {
|
|
6141
|
+
dockerComposeUp(resolvedDir2);
|
|
6142
|
+
const healthy = await waitForHealth(`http://localhost:${config2.httpPort}`);
|
|
6143
|
+
if (healthy) {
|
|
6144
|
+
console.log("LearnHouse is ready!");
|
|
6145
|
+
} else {
|
|
6146
|
+
console.log("Health check timed out \u2014 services may still be starting");
|
|
6147
|
+
}
|
|
6148
|
+
} catch {
|
|
6149
|
+
console.error("Failed to start services");
|
|
6150
|
+
process.exit(1);
|
|
6151
|
+
}
|
|
6152
|
+
}
|
|
6153
|
+
const portSuffix2 = config2.httpPort === 80 ? "" : `:${config2.httpPort}`;
|
|
6154
|
+
console.log(`URL: http://${config2.domain}${portSuffix2}`);
|
|
6155
|
+
console.log(`Admin: ${config2.adminEmail}`);
|
|
6156
|
+
console.log(`Install dir: ${resolvedDir2}`);
|
|
6157
|
+
return;
|
|
6158
|
+
}
|
|
6087
6159
|
await printBanner();
|
|
6088
6160
|
We(import_picocolors8.default.cyan("LearnHouse Setup Wizard"));
|
|
6089
6161
|
await checkPrerequisites();
|
|
@@ -6377,8 +6449,7 @@ async function startCommand() {
|
|
|
6377
6449
|
const dir = findInstallDir();
|
|
6378
6450
|
const config = readConfig(dir);
|
|
6379
6451
|
if (!config) {
|
|
6380
|
-
R2.error("No LearnHouse installation found
|
|
6381
|
-
R2.info("Run `npx learnhouse` to set up a new installation.");
|
|
6452
|
+
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6382
6453
|
process.exit(1);
|
|
6383
6454
|
}
|
|
6384
6455
|
We(import_picocolors9.default.cyan("Starting LearnHouse"));
|
|
@@ -6397,7 +6468,7 @@ async function stopCommand() {
|
|
|
6397
6468
|
const dir = findInstallDir();
|
|
6398
6469
|
const config = readConfig(dir);
|
|
6399
6470
|
if (!config) {
|
|
6400
|
-
R2.error("No LearnHouse installation found
|
|
6471
|
+
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6401
6472
|
process.exit(1);
|
|
6402
6473
|
}
|
|
6403
6474
|
We(import_picocolors10.default.cyan("Stopping LearnHouse"));
|
|
@@ -6417,8 +6488,8 @@ async function logsCommand() {
|
|
|
6417
6488
|
R2.info("Streaming logs (Ctrl+C to stop)...");
|
|
6418
6489
|
if (config?.installDir) {
|
|
6419
6490
|
try {
|
|
6420
|
-
const { execSync:
|
|
6421
|
-
const ps =
|
|
6491
|
+
const { execSync: execSync8 } = await import("child_process");
|
|
6492
|
+
const ps = execSync8("docker compose ps -q", { cwd: config.installDir, stdio: "pipe" }).toString().trim();
|
|
6422
6493
|
if (ps) {
|
|
6423
6494
|
dockerComposeLogs(config.installDir);
|
|
6424
6495
|
return;
|
|
@@ -6445,7 +6516,7 @@ async function configCommand() {
|
|
|
6445
6516
|
const dir = findInstallDir();
|
|
6446
6517
|
const config = readConfig(dir);
|
|
6447
6518
|
if (!config) {
|
|
6448
|
-
R2.error("No LearnHouse installation found
|
|
6519
|
+
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6449
6520
|
process.exit(1);
|
|
6450
6521
|
}
|
|
6451
6522
|
We(import_picocolors11.default.cyan("LearnHouse Configuration"));
|
|
@@ -7679,7 +7750,7 @@ async function updateCommand(options) {
|
|
|
7679
7750
|
const dir = findInstallDir();
|
|
7680
7751
|
const config = readConfig(dir);
|
|
7681
7752
|
if (!config) {
|
|
7682
|
-
R2.error("No LearnHouse installation found
|
|
7753
|
+
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
7683
7754
|
process.exit(1);
|
|
7684
7755
|
}
|
|
7685
7756
|
const targetVersion = options.version?.replace(/^v/, "");
|
|
@@ -7724,22 +7795,27 @@ async function updateCommand(options) {
|
|
|
7724
7795
|
dockerComposeDown(config.installDir);
|
|
7725
7796
|
dockerComposeUp(config.installDir);
|
|
7726
7797
|
s.stop("Services restarted");
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
)
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
R2.info("
|
|
7741
|
-
|
|
7742
|
-
|
|
7798
|
+
let shouldMigrate;
|
|
7799
|
+
if (options.migrate === true) {
|
|
7800
|
+
shouldMigrate = true;
|
|
7801
|
+
} else if (options.migrate === false) {
|
|
7802
|
+
shouldMigrate = false;
|
|
7803
|
+
} else {
|
|
7804
|
+
R2.info("");
|
|
7805
|
+
R2.warn(
|
|
7806
|
+
import_picocolors18.default.bold("This update may include database migrations.")
|
|
7807
|
+
);
|
|
7808
|
+
R2.info(
|
|
7809
|
+
`Before proceeding, check the release notes at ${import_picocolors18.default.cyan("https://docs.learnhouse.app")} for migration guides and breaking changes.`
|
|
7810
|
+
);
|
|
7811
|
+
R2.info("");
|
|
7812
|
+
const runMigrations = await Re({
|
|
7813
|
+
message: "Run database migrations now?",
|
|
7814
|
+
initialValue: false
|
|
7815
|
+
});
|
|
7816
|
+
shouldMigrate = !Ct(runMigrations) && !!runMigrations;
|
|
7817
|
+
}
|
|
7818
|
+
if (shouldMigrate) {
|
|
7743
7819
|
s.start("Running database migrations");
|
|
7744
7820
|
try {
|
|
7745
7821
|
const appContainer = getAppContainerName(config.installDir);
|
|
@@ -7810,15 +7886,441 @@ function waitForContainer(containerName, timeoutMs = 6e4) {
|
|
|
7810
7886
|
}
|
|
7811
7887
|
}
|
|
7812
7888
|
|
|
7889
|
+
// src/commands/status.ts
|
|
7890
|
+
var import_picocolors19 = __toESM(require_picocolors(), 1);
|
|
7891
|
+
async function statusCommand() {
|
|
7892
|
+
const dir = findInstallDir();
|
|
7893
|
+
const config = readConfig(dir);
|
|
7894
|
+
if (!config) {
|
|
7895
|
+
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
7896
|
+
process.exit(1);
|
|
7897
|
+
}
|
|
7898
|
+
We(import_picocolors19.default.cyan("LearnHouse Status"));
|
|
7899
|
+
const protocol = config.useHttps ? "https" : "http";
|
|
7900
|
+
const portSuffix = config.useHttps && config.httpPort === 443 || !config.useHttps && config.httpPort === 80 ? "" : `:${config.httpPort}`;
|
|
7901
|
+
R2.info(`URL: ${protocol}://${config.domain}${portSuffix}`);
|
|
7902
|
+
try {
|
|
7903
|
+
const output = dockerComposePs(config.installDir);
|
|
7904
|
+
console.log(output);
|
|
7905
|
+
} catch {
|
|
7906
|
+
R2.error("Failed to get status. Is Docker running?");
|
|
7907
|
+
process.exit(1);
|
|
7908
|
+
}
|
|
7909
|
+
}
|
|
7910
|
+
|
|
7911
|
+
// src/commands/health.ts
|
|
7912
|
+
var import_picocolors20 = __toESM(require_picocolors(), 1);
|
|
7913
|
+
function pass2(msg) {
|
|
7914
|
+
return `${import_picocolors20.default.green("\u25CF")} ${msg}`;
|
|
7915
|
+
}
|
|
7916
|
+
function fail2(msg) {
|
|
7917
|
+
return `${import_picocolors20.default.red("\u25CF")} ${msg}`;
|
|
7918
|
+
}
|
|
7919
|
+
async function healthCommand() {
|
|
7920
|
+
const dir = findInstallDir();
|
|
7921
|
+
const config = readConfig(dir);
|
|
7922
|
+
if (!config) {
|
|
7923
|
+
R2.error("No LearnHouse installation found. Run setup first.");
|
|
7924
|
+
process.exit(1);
|
|
7925
|
+
}
|
|
7926
|
+
We(import_picocolors20.default.cyan("LearnHouse Health Check"));
|
|
7927
|
+
const id = config.deploymentId || autoDetectDeploymentId();
|
|
7928
|
+
if (!id) {
|
|
7929
|
+
R2.error("No deployment found. Start services first.");
|
|
7930
|
+
process.exit(1);
|
|
7931
|
+
}
|
|
7932
|
+
R2.step("Container Status");
|
|
7933
|
+
const containers = listDeploymentContainers(id);
|
|
7934
|
+
if (containers.length === 0) {
|
|
7935
|
+
R2.message(fail2("No containers found. Are services running?"));
|
|
7936
|
+
} else {
|
|
7937
|
+
for (const c of containers) {
|
|
7938
|
+
const isUp = c.status.toLowerCase().startsWith("up");
|
|
7939
|
+
const svcName = c.name.replace(`-${id}`, "");
|
|
7940
|
+
R2.message(isUp ? pass2(`${svcName} \u2014 ${c.status}`) : fail2(`${svcName} \u2014 ${c.status}`));
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7943
|
+
R2.step("Database");
|
|
7944
|
+
const dbContainer = `learnhouse-db-${id}`;
|
|
7945
|
+
if (isContainerRunning(dbContainer)) {
|
|
7946
|
+
try {
|
|
7947
|
+
dockerExec(dbContainer, "pg_isready -U learnhouse");
|
|
7948
|
+
R2.message(pass2("PostgreSQL accepting connections"));
|
|
7949
|
+
} catch {
|
|
7950
|
+
R2.message(fail2("PostgreSQL not ready"));
|
|
7951
|
+
}
|
|
7952
|
+
} else {
|
|
7953
|
+
R2.message(fail2("Database container not running"));
|
|
7954
|
+
}
|
|
7955
|
+
R2.step("Redis");
|
|
7956
|
+
const redisContainer = `learnhouse-redis-${id}`;
|
|
7957
|
+
if (isContainerRunning(redisContainer)) {
|
|
7958
|
+
try {
|
|
7959
|
+
const pong = dockerExec(redisContainer, "redis-cli ping");
|
|
7960
|
+
R2.message(pong === "PONG" ? pass2("Redis responding") : fail2(`Redis returned: ${pong}`));
|
|
7961
|
+
} catch {
|
|
7962
|
+
R2.message(fail2("Redis not responding"));
|
|
7963
|
+
}
|
|
7964
|
+
} else {
|
|
7965
|
+
R2.message(fail2("Redis container not running"));
|
|
7966
|
+
}
|
|
7967
|
+
R2.step("HTTP Endpoint");
|
|
7968
|
+
const protocol = config.useHttps ? "https" : "http";
|
|
7969
|
+
const portSuffix = config.useHttps && config.httpPort === 443 || !config.useHttps && config.httpPort === 80 ? "" : `:${config.httpPort}`;
|
|
7970
|
+
const healthUrl = `${protocol}://${config.domain}${portSuffix}/api/v1/health`;
|
|
7971
|
+
try {
|
|
7972
|
+
const start = Date.now();
|
|
7973
|
+
const resp = await fetch(healthUrl, { signal: AbortSignal.timeout(5e3) });
|
|
7974
|
+
const elapsed = Date.now() - start;
|
|
7975
|
+
if (resp.ok) {
|
|
7976
|
+
R2.message(pass2(`${healthUrl} \u2014 ${resp.status} (${elapsed}ms)`));
|
|
7977
|
+
} else {
|
|
7978
|
+
R2.message(fail2(`${healthUrl} \u2014 ${resp.status} (${elapsed}ms)`));
|
|
7979
|
+
}
|
|
7980
|
+
} catch (err) {
|
|
7981
|
+
R2.message(fail2(`${healthUrl} \u2014 ${err.message || "unreachable"}`));
|
|
7982
|
+
}
|
|
7983
|
+
R2.step("Disk Usage");
|
|
7984
|
+
try {
|
|
7985
|
+
const diskOutput = getDockerDiskUsage();
|
|
7986
|
+
R2.message(import_picocolors20.default.dim(diskOutput.trim()));
|
|
7987
|
+
} catch {
|
|
7988
|
+
R2.message(fail2("Could not retrieve disk usage"));
|
|
7989
|
+
}
|
|
7990
|
+
R2.step("Resource Usage");
|
|
7991
|
+
try {
|
|
7992
|
+
const stats = dockerStats(config.installDir);
|
|
7993
|
+
R2.message(import_picocolors20.default.dim(stats.trim()));
|
|
7994
|
+
} catch {
|
|
7995
|
+
try {
|
|
7996
|
+
const names = containers.filter((c) => c.status.toLowerCase().startsWith("up")).map((c) => c.name);
|
|
7997
|
+
if (names.length > 0) {
|
|
7998
|
+
const stats = dockerStatsForContainers(names);
|
|
7999
|
+
R2.message(import_picocolors20.default.dim(stats.trim()));
|
|
8000
|
+
} else {
|
|
8001
|
+
R2.message(fail2("No running containers to get stats from"));
|
|
8002
|
+
}
|
|
8003
|
+
} catch {
|
|
8004
|
+
R2.message(fail2("Could not retrieve resource stats"));
|
|
8005
|
+
}
|
|
8006
|
+
}
|
|
8007
|
+
Le(import_picocolors20.default.dim("Health check complete"));
|
|
8008
|
+
}
|
|
8009
|
+
|
|
8010
|
+
// src/commands/env.ts
|
|
8011
|
+
import fs8 from "fs";
|
|
8012
|
+
import path8 from "path";
|
|
8013
|
+
var import_picocolors21 = __toESM(require_picocolors(), 1);
|
|
8014
|
+
var SECRET_PATTERNS = ["PASSWORD", "SECRET", "API_KEY", "CLIENT_SECRET"];
|
|
8015
|
+
var CATEGORIES = {
|
|
8016
|
+
domain: {
|
|
8017
|
+
label: "Domain & Hosting",
|
|
8018
|
+
keys: [
|
|
8019
|
+
"LEARNHOUSE_DOMAIN",
|
|
8020
|
+
"HTTP_PORT",
|
|
8021
|
+
"NEXT_PUBLIC_LEARNHOUSE_API_URL",
|
|
8022
|
+
"NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL",
|
|
8023
|
+
"NEXT_PUBLIC_LEARNHOUSE_DOMAIN",
|
|
8024
|
+
"NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN",
|
|
8025
|
+
"NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG",
|
|
8026
|
+
"NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG",
|
|
8027
|
+
"NEXT_PUBLIC_LEARNHOUSE_HTTPS",
|
|
8028
|
+
"NEXTAUTH_URL"
|
|
8029
|
+
]
|
|
8030
|
+
},
|
|
8031
|
+
database: {
|
|
8032
|
+
label: "Database & Redis",
|
|
8033
|
+
keys: [
|
|
8034
|
+
"LEARNHOUSE_SQL_CONNECTION_STRING",
|
|
8035
|
+
"LEARNHOUSE_REDIS_CONNECTION_STRING",
|
|
8036
|
+
"POSTGRES_USER",
|
|
8037
|
+
"POSTGRES_PASSWORD",
|
|
8038
|
+
"POSTGRES_DB"
|
|
8039
|
+
]
|
|
8040
|
+
},
|
|
8041
|
+
security: {
|
|
8042
|
+
label: "Security",
|
|
8043
|
+
keys: [
|
|
8044
|
+
"NEXTAUTH_SECRET",
|
|
8045
|
+
"LEARNHOUSE_AUTH_JWT_SECRET_KEY",
|
|
8046
|
+
"LEARNHOUSE_INITIAL_ADMIN_EMAIL",
|
|
8047
|
+
"LEARNHOUSE_INITIAL_ADMIN_PASSWORD",
|
|
8048
|
+
"LEARNHOUSE_COOKIE_DOMAIN"
|
|
8049
|
+
]
|
|
8050
|
+
},
|
|
8051
|
+
ai: {
|
|
8052
|
+
label: "AI",
|
|
8053
|
+
keys: ["LEARNHOUSE_GEMINI_API_KEY", "LEARNHOUSE_IS_AI_ENABLED"]
|
|
8054
|
+
},
|
|
8055
|
+
email: {
|
|
8056
|
+
label: "Email",
|
|
8057
|
+
keys: ["LEARNHOUSE_RESEND_API_KEY", "LEARNHOUSE_SYSTEM_EMAIL_ADDRESS"]
|
|
8058
|
+
},
|
|
8059
|
+
s3: {
|
|
8060
|
+
label: "S3 Storage",
|
|
8061
|
+
keys: [
|
|
8062
|
+
"LEARNHOUSE_CONTENT_DELIVERY_TYPE",
|
|
8063
|
+
"LEARNHOUSE_S3_API_BUCKET_NAME",
|
|
8064
|
+
"LEARNHOUSE_S3_API_ENDPOINT_URL"
|
|
8065
|
+
]
|
|
8066
|
+
},
|
|
8067
|
+
oauth: {
|
|
8068
|
+
label: "OAuth",
|
|
8069
|
+
keys: [
|
|
8070
|
+
"LEARNHOUSE_GOOGLE_CLIENT_ID",
|
|
8071
|
+
"LEARNHOUSE_GOOGLE_CLIENT_SECRET",
|
|
8072
|
+
"NEXT_PUBLIC_UNSPLASH_ACCESS_KEY"
|
|
8073
|
+
]
|
|
8074
|
+
}
|
|
8075
|
+
};
|
|
8076
|
+
function isSecret(key) {
|
|
8077
|
+
const upper = key.toUpperCase();
|
|
8078
|
+
return SECRET_PATTERNS.some((pat) => upper.includes(pat));
|
|
8079
|
+
}
|
|
8080
|
+
function maskValue(key, value) {
|
|
8081
|
+
if (isSecret(key) && value.length > 0) {
|
|
8082
|
+
return value.slice(0, 4) + "****";
|
|
8083
|
+
}
|
|
8084
|
+
return value;
|
|
8085
|
+
}
|
|
8086
|
+
function parseEnv(content) {
|
|
8087
|
+
const map = /* @__PURE__ */ new Map();
|
|
8088
|
+
for (const line of content.split("\n")) {
|
|
8089
|
+
const trimmed = line.trim();
|
|
8090
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
8091
|
+
const eqIdx = trimmed.indexOf("=");
|
|
8092
|
+
if (eqIdx === -1) continue;
|
|
8093
|
+
map.set(trimmed.slice(0, eqIdx), trimmed.slice(eqIdx + 1));
|
|
8094
|
+
}
|
|
8095
|
+
return map;
|
|
8096
|
+
}
|
|
8097
|
+
function serializeEnv(original, updated) {
|
|
8098
|
+
const lines = original.split("\n");
|
|
8099
|
+
const result = [];
|
|
8100
|
+
const written = /* @__PURE__ */ new Set();
|
|
8101
|
+
for (const line of lines) {
|
|
8102
|
+
const trimmed = line.trim();
|
|
8103
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
8104
|
+
result.push(line);
|
|
8105
|
+
continue;
|
|
8106
|
+
}
|
|
8107
|
+
const eqIdx = trimmed.indexOf("=");
|
|
8108
|
+
if (eqIdx === -1) {
|
|
8109
|
+
result.push(line);
|
|
8110
|
+
continue;
|
|
8111
|
+
}
|
|
8112
|
+
const key = trimmed.slice(0, eqIdx);
|
|
8113
|
+
if (updated.has(key)) {
|
|
8114
|
+
result.push(`${key}=${updated.get(key)}`);
|
|
8115
|
+
written.add(key);
|
|
8116
|
+
} else {
|
|
8117
|
+
result.push(line);
|
|
8118
|
+
}
|
|
8119
|
+
}
|
|
8120
|
+
for (const [key, value] of updated) {
|
|
8121
|
+
if (!written.has(key)) {
|
|
8122
|
+
result.push(`${key}=${value}`);
|
|
8123
|
+
}
|
|
8124
|
+
}
|
|
8125
|
+
return result.join("\n");
|
|
8126
|
+
}
|
|
8127
|
+
async function envCommand() {
|
|
8128
|
+
const dir = findInstallDir();
|
|
8129
|
+
const config = readConfig(dir);
|
|
8130
|
+
if (!config) {
|
|
8131
|
+
R2.error("No LearnHouse installation found. Run setup first.");
|
|
8132
|
+
process.exit(1);
|
|
8133
|
+
}
|
|
8134
|
+
const envPath = path8.join(config.installDir, ".env");
|
|
8135
|
+
if (!fs8.existsSync(envPath)) {
|
|
8136
|
+
R2.error(`No .env file found at ${envPath}`);
|
|
8137
|
+
process.exit(1);
|
|
8138
|
+
}
|
|
8139
|
+
We(import_picocolors21.default.cyan("LearnHouse Environment Editor"));
|
|
8140
|
+
const originalContent = fs8.readFileSync(envPath, "utf-8");
|
|
8141
|
+
const envMap = parseEnv(originalContent);
|
|
8142
|
+
let editing = true;
|
|
8143
|
+
while (editing) {
|
|
8144
|
+
const category = await Je({
|
|
8145
|
+
message: "Select a category to edit",
|
|
8146
|
+
options: [
|
|
8147
|
+
...Object.entries(CATEGORIES).map(([value, { label }]) => ({ value, label })),
|
|
8148
|
+
{ value: "_done", label: import_picocolors21.default.dim("Done editing") }
|
|
8149
|
+
]
|
|
8150
|
+
});
|
|
8151
|
+
if (Ct(category) || category === "_done") {
|
|
8152
|
+
editing = false;
|
|
8153
|
+
break;
|
|
8154
|
+
}
|
|
8155
|
+
const cat = CATEGORIES[category];
|
|
8156
|
+
const presentKeys = cat.keys.filter((k2) => envMap.has(k2));
|
|
8157
|
+
const missingKeys = cat.keys.filter((k2) => !envMap.has(k2));
|
|
8158
|
+
if (presentKeys.length === 0 && missingKeys.length === 0) {
|
|
8159
|
+
R2.info("No variables in this category.");
|
|
8160
|
+
continue;
|
|
8161
|
+
}
|
|
8162
|
+
R2.step(`${cat.label} \u2014 Current Values`);
|
|
8163
|
+
for (const key2 of presentKeys) {
|
|
8164
|
+
R2.message(` ${import_picocolors21.default.dim(key2)} = ${maskValue(key2, envMap.get(key2))}`);
|
|
8165
|
+
}
|
|
8166
|
+
const keyToEdit = await Je({
|
|
8167
|
+
message: "Select a variable to edit",
|
|
8168
|
+
options: [
|
|
8169
|
+
...presentKeys.map((k2) => ({ value: k2, label: `${k2} = ${maskValue(k2, envMap.get(k2))}` })),
|
|
8170
|
+
...missingKeys.map((k2) => ({ value: k2, label: `${k2} ${import_picocolors21.default.dim("(not set)")}` })),
|
|
8171
|
+
{ value: "_back", label: import_picocolors21.default.dim("Back") }
|
|
8172
|
+
]
|
|
8173
|
+
});
|
|
8174
|
+
if (Ct(keyToEdit) || keyToEdit === "_back") continue;
|
|
8175
|
+
const key = keyToEdit;
|
|
8176
|
+
const currentValue = envMap.get(key) || "";
|
|
8177
|
+
const newValue = await text({
|
|
8178
|
+
message: `New value for ${key}`,
|
|
8179
|
+
placeholder: currentValue,
|
|
8180
|
+
defaultValue: currentValue
|
|
8181
|
+
});
|
|
8182
|
+
if (Ct(newValue)) continue;
|
|
8183
|
+
envMap.set(key, newValue);
|
|
8184
|
+
R2.success(`Updated ${key}`);
|
|
8185
|
+
}
|
|
8186
|
+
const newContent = serializeEnv(originalContent, envMap);
|
|
8187
|
+
if (newContent !== originalContent) {
|
|
8188
|
+
fs8.writeFileSync(envPath, newContent);
|
|
8189
|
+
R2.success(".env file updated");
|
|
8190
|
+
const restart = await Re({
|
|
8191
|
+
message: "Restart services to apply changes?",
|
|
8192
|
+
initialValue: false
|
|
8193
|
+
});
|
|
8194
|
+
if (!Ct(restart) && restart) {
|
|
8195
|
+
const s = bt2();
|
|
8196
|
+
s.start("Restarting services");
|
|
8197
|
+
try {
|
|
8198
|
+
dockerComposeDown(config.installDir);
|
|
8199
|
+
dockerComposeUp(config.installDir);
|
|
8200
|
+
s.stop("Services restarted");
|
|
8201
|
+
} catch {
|
|
8202
|
+
s.stop("Restart failed");
|
|
8203
|
+
R2.error("Failed to restart services. Check Docker output above.");
|
|
8204
|
+
}
|
|
8205
|
+
}
|
|
8206
|
+
} else {
|
|
8207
|
+
R2.info("No changes made.");
|
|
8208
|
+
}
|
|
8209
|
+
Le(import_picocolors21.default.dim("Done"));
|
|
8210
|
+
}
|
|
8211
|
+
|
|
8212
|
+
// src/commands/restore.ts
|
|
8213
|
+
import fs9 from "fs";
|
|
8214
|
+
import path9 from "path";
|
|
8215
|
+
import { execSync as execSync7 } from "child_process";
|
|
8216
|
+
var import_picocolors22 = __toESM(require_picocolors(), 1);
|
|
8217
|
+
async function restoreCommand(archivePath) {
|
|
8218
|
+
if (!archivePath) {
|
|
8219
|
+
R2.error("Please provide the path to a backup archive.");
|
|
8220
|
+
R2.info("Usage: npx learnhouse restore <backup-file.tar.gz>");
|
|
8221
|
+
process.exit(1);
|
|
8222
|
+
}
|
|
8223
|
+
if (!fs9.existsSync(archivePath)) {
|
|
8224
|
+
R2.error(`Backup file not found: ${archivePath}`);
|
|
8225
|
+
process.exit(1);
|
|
8226
|
+
}
|
|
8227
|
+
const installDir = findInstallDir();
|
|
8228
|
+
const config = readConfig(installDir);
|
|
8229
|
+
if (!config) {
|
|
8230
|
+
R2.error("No LearnHouse installation found. Run setup first.");
|
|
8231
|
+
process.exit(1);
|
|
8232
|
+
}
|
|
8233
|
+
if (config.useExternalDb) {
|
|
8234
|
+
R2.error("Restore is only supported for local (Docker) databases.");
|
|
8235
|
+
R2.info("For external databases, use your database provider's restore tools.");
|
|
8236
|
+
process.exit(1);
|
|
8237
|
+
}
|
|
8238
|
+
const id = config.deploymentId || autoDetectDeploymentId();
|
|
8239
|
+
if (!id) {
|
|
8240
|
+
R2.error("No deployment found. Start services first.");
|
|
8241
|
+
process.exit(1);
|
|
8242
|
+
}
|
|
8243
|
+
const dbContainer = `learnhouse-db-${id}`;
|
|
8244
|
+
if (!isContainerRunning(dbContainer)) {
|
|
8245
|
+
R2.error("Database container is not running. Start services first.");
|
|
8246
|
+
process.exit(1);
|
|
8247
|
+
}
|
|
8248
|
+
R2.warn(import_picocolors22.default.yellow("This will overwrite the current database with the backup data."));
|
|
8249
|
+
const confirm = await Re({
|
|
8250
|
+
message: "Are you sure you want to restore from this backup?",
|
|
8251
|
+
initialValue: false
|
|
8252
|
+
});
|
|
8253
|
+
if (Ct(confirm) || !confirm) {
|
|
8254
|
+
Ne("Restore cancelled.");
|
|
8255
|
+
process.exit(0);
|
|
8256
|
+
}
|
|
8257
|
+
const tmpDir = path9.join(installDir, ".restore-tmp");
|
|
8258
|
+
fs9.mkdirSync(tmpDir, { recursive: true });
|
|
8259
|
+
const s = bt2();
|
|
8260
|
+
s.start("Extracting backup archive");
|
|
8261
|
+
try {
|
|
8262
|
+
execSync7(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
8263
|
+
s.stop("Archive extracted");
|
|
8264
|
+
} catch {
|
|
8265
|
+
s.stop("Extraction failed");
|
|
8266
|
+
fs9.rmSync(tmpDir, { recursive: true, force: true });
|
|
8267
|
+
R2.error("Failed to extract backup archive.");
|
|
8268
|
+
process.exit(1);
|
|
8269
|
+
}
|
|
8270
|
+
const entries = fs9.readdirSync(tmpDir);
|
|
8271
|
+
const backupFolder = entries.find(
|
|
8272
|
+
(e2) => fs9.existsSync(path9.join(tmpDir, e2, "database.sql"))
|
|
8273
|
+
);
|
|
8274
|
+
if (!backupFolder) {
|
|
8275
|
+
R2.error("No database.sql found in the backup archive.");
|
|
8276
|
+
fs9.rmSync(tmpDir, { recursive: true, force: true });
|
|
8277
|
+
process.exit(1);
|
|
8278
|
+
}
|
|
8279
|
+
const dumpPath = path9.join(tmpDir, backupFolder, "database.sql");
|
|
8280
|
+
const s2 = bt2();
|
|
8281
|
+
s2.start("Restoring database");
|
|
8282
|
+
try {
|
|
8283
|
+
dockerExecFromFile(
|
|
8284
|
+
dbContainer,
|
|
8285
|
+
"psql -U learnhouse -d learnhouse",
|
|
8286
|
+
dumpPath
|
|
8287
|
+
);
|
|
8288
|
+
s2.stop("Database restored");
|
|
8289
|
+
} catch {
|
|
8290
|
+
s2.stop("Database restore failed");
|
|
8291
|
+
fs9.rmSync(tmpDir, { recursive: true, force: true });
|
|
8292
|
+
R2.error("Failed to restore database. The backup file may be corrupted.");
|
|
8293
|
+
process.exit(1);
|
|
8294
|
+
}
|
|
8295
|
+
const envBackup = path9.join(tmpDir, backupFolder, ".env");
|
|
8296
|
+
if (fs9.existsSync(envBackup)) {
|
|
8297
|
+
const restoreEnv = await Re({
|
|
8298
|
+
message: "Backup contains a .env file. Restore it? (overwrites current .env)",
|
|
8299
|
+
initialValue: false
|
|
8300
|
+
});
|
|
8301
|
+
if (!Ct(restoreEnv) && restoreEnv) {
|
|
8302
|
+
fs9.copyFileSync(envBackup, path9.join(installDir, ".env"));
|
|
8303
|
+
R2.info(".env file restored");
|
|
8304
|
+
}
|
|
8305
|
+
}
|
|
8306
|
+
fs9.rmSync(tmpDir, { recursive: true, force: true });
|
|
8307
|
+
R2.success(import_picocolors22.default.green(import_picocolors22.default.bold("Restore complete!")));
|
|
8308
|
+
R2.info("You may want to restart services: npx learnhouse stop && npx learnhouse start");
|
|
8309
|
+
}
|
|
8310
|
+
|
|
7813
8311
|
// bin/learnhouse.ts
|
|
7814
8312
|
var COMMANDS = [
|
|
7815
8313
|
{ name: "setup", desc: "Interactive setup wizard" },
|
|
7816
8314
|
{ name: "start", desc: "Start services" },
|
|
7817
8315
|
{ name: "stop", desc: "Stop services" },
|
|
7818
8316
|
{ name: "update", desc: "Update to latest or specific version" },
|
|
8317
|
+
{ name: "status", desc: "Show service status" },
|
|
8318
|
+
{ name: "health", desc: "Run health checks" },
|
|
7819
8319
|
{ name: "logs", desc: "Stream logs" },
|
|
7820
8320
|
{ name: "config", desc: "Show configuration" },
|
|
7821
|
-
{ name: "
|
|
8321
|
+
{ name: "env", desc: "Edit environment variables" },
|
|
8322
|
+
{ name: "backup", desc: "Backup database" },
|
|
8323
|
+
{ name: "restore", desc: "Restore database from backup" },
|
|
7822
8324
|
{ name: "deployments", desc: "Manage deployments & resources" },
|
|
7823
8325
|
{ name: "doctor", desc: "Diagnose issues" },
|
|
7824
8326
|
{ name: "shell", desc: "Container shell access" },
|
|
@@ -7826,18 +8328,18 @@ var COMMANDS = [
|
|
|
7826
8328
|
];
|
|
7827
8329
|
async function showWelcome() {
|
|
7828
8330
|
await printBanner();
|
|
7829
|
-
console.log(
|
|
8331
|
+
console.log(import_picocolors23.default.bold(import_picocolors23.default.white(" Available commands:\n")));
|
|
7830
8332
|
for (const cmd of COMMANDS) {
|
|
7831
|
-
console.log(` ${
|
|
8333
|
+
console.log(` ${import_picocolors23.default.cyan(cmd.name.padEnd(14))} ${import_picocolors23.default.dim(cmd.desc)}`);
|
|
7832
8334
|
}
|
|
7833
8335
|
console.log();
|
|
7834
|
-
console.log(
|
|
7835
|
-
console.log(
|
|
8336
|
+
console.log(import_picocolors23.default.dim(" Run a command with: npx learnhouse <command>"));
|
|
8337
|
+
console.log(import_picocolors23.default.dim(" Get started with: npx learnhouse setup"));
|
|
7836
8338
|
console.log();
|
|
7837
8339
|
}
|
|
7838
8340
|
var program2 = new Command();
|
|
7839
8341
|
program2.name("learnhouse").description("The official LearnHouse CLI \u2014 deploy, manage, and operate your LearnHouse instance").version(VERSION).action(showWelcome);
|
|
7840
|
-
program2.command("setup").description("Interactive setup wizard for LearnHouse").action(setupCommand);
|
|
8342
|
+
program2.command("setup").description("Interactive setup wizard for LearnHouse").option("--ci", "Non-interactive mode with defaults (for CI/automation)").option("--name <name>", 'Installation name (default: "default")').option("--domain <domain>", 'Domain name (default: "localhost")').option("--port <port>", "HTTP port (default: 80)", parseInt).option("--admin-email <email>", 'Admin email (default: "admin@school.dev")').option("--admin-password <password>", "Admin password (required in --ci mode)").option("--channel <channel>", 'Release channel: stable or dev (default: "stable")').option("--no-start", "Skip starting services after setup").action(setupCommand);
|
|
7841
8343
|
program2.command("start").description("Start LearnHouse services").action(startCommand);
|
|
7842
8344
|
program2.command("stop").description("Stop LearnHouse services").action(stopCommand);
|
|
7843
8345
|
program2.command("logs").description("Stream logs from LearnHouse services").action(logsCommand);
|
|
@@ -7846,7 +8348,11 @@ program2.command("backup").description("Backup & restore LearnHouse database").a
|
|
|
7846
8348
|
program2.command("deployments").description("Manage deployments & resource limits").action(deploymentsCommand);
|
|
7847
8349
|
program2.command("doctor").description("Diagnose common issues with LearnHouse").action(doctorCommand);
|
|
7848
8350
|
program2.command("shell").description("Open a shell in a LearnHouse container").action(shellCommand);
|
|
7849
|
-
program2.command("update").description("Update LearnHouse to latest or a specific version").option("-v, --version <version>", "Target version (e.g. 1.0.0)").action(updateCommand);
|
|
8351
|
+
program2.command("update").description("Update LearnHouse to latest or a specific version").option("-v, --version <version>", "Target version (e.g. 1.0.0)").option("--migrate", "Run database migrations automatically").option("--no-migrate", "Skip database migrations").action(updateCommand);
|
|
8352
|
+
program2.command("status").description("Show service status").action(statusCommand);
|
|
8353
|
+
program2.command("health").description("Run health checks").action(healthCommand);
|
|
8354
|
+
program2.command("env").description("Edit environment variables").action(envCommand);
|
|
8355
|
+
program2.command("restore").description("Restore database from a backup archive").argument("<archive>", "Path to backup archive").action(restoreCommand);
|
|
7850
8356
|
program2.command("dev").description("Start development environment (DB + Redis in Docker, API + Web locally)").option("--ee", "Enable Enterprise Edition features (keeps ee/ folder)").action(devCommand);
|
|
7851
8357
|
var updateCheck = checkForUpdates();
|
|
7852
8358
|
program2.parseAsync().then(() => updateCheck.catch(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "learnhouse",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "The official LearnHouse CLI — deploy, manage, and operate your LearnHouse instance",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"build": "tsup",
|
|
14
14
|
"dev": "tsup --watch",
|
|
15
15
|
"prepublishOnly": "tsup",
|
|
16
|
+
"test": "bun run build && vitest run tests/unit.test.ts",
|
|
17
|
+
"test:e2e": "bun run build && vitest run tests/e2e.test.ts",
|
|
18
|
+
"test:all": "bun run build && vitest run",
|
|
16
19
|
"version:patch": "node scripts/bump-version.js patch",
|
|
17
20
|
"version:minor": "node scripts/bump-version.js minor",
|
|
18
21
|
"version:major": "node scripts/bump-version.js major"
|
|
@@ -39,7 +42,8 @@
|
|
|
39
42
|
"devDependencies": {
|
|
40
43
|
"@types/node": "^25.0.0",
|
|
41
44
|
"tsup": "^8.0.1",
|
|
42
|
-
"typescript": "^5.3.3"
|
|
45
|
+
"typescript": "^5.3.3",
|
|
46
|
+
"vitest": "^4.1.1"
|
|
43
47
|
},
|
|
44
48
|
"dependencies": {
|
|
45
49
|
"@clack/core": "^1.0.1",
|