learnhouse 1.4.4 → 1.4.6
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/dist/bin/learnhouse.js +670 -360
- package/package.json +1 -1
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 path11 = __require("path");
|
|
1206
|
+
var fs11 = __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 (fs11.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 = path11.resolve(baseDir, baseName);
|
|
2219
|
+
if (fs11.existsSync(localBin)) return localBin;
|
|
2220
|
+
if (sourceExt.includes(path11.extname(baseName))) return void 0;
|
|
2221
2221
|
const foundExt = sourceExt.find(
|
|
2222
|
-
(ext) =>
|
|
2222
|
+
(ext) => fs11.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 = fs11.realpathSync(this._scriptPath);
|
|
2235
2235
|
} catch {
|
|
2236
2236
|
resolvedScriptPath = this._scriptPath;
|
|
2237
2237
|
}
|
|
2238
|
-
executableDir =
|
|
2239
|
-
|
|
2238
|
+
executableDir = path11.resolve(
|
|
2239
|
+
path11.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 = path11.basename(
|
|
2247
2247
|
this._scriptPath,
|
|
2248
|
-
|
|
2248
|
+
path11.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(path11.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 = path11.basename(filename, path11.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(path12) {
|
|
3189
|
+
if (path12 === void 0) return this._executableDir;
|
|
3190
|
+
this._executableDir = path12;
|
|
3191
3191
|
return this;
|
|
3192
3192
|
}
|
|
3193
3193
|
/**
|
|
@@ -3613,10 +3613,10 @@ var {
|
|
|
3613
3613
|
} = import_index.default;
|
|
3614
3614
|
|
|
3615
3615
|
// bin/learnhouse.ts
|
|
3616
|
-
var
|
|
3616
|
+
var import_picocolors24 = __toESM(require_picocolors(), 1);
|
|
3617
3617
|
|
|
3618
3618
|
// src/constants.ts
|
|
3619
|
-
var VERSION = "1.4.
|
|
3619
|
+
var VERSION = "1.4.6";
|
|
3620
3620
|
var APP_IMAGE = "ghcr.io/learnhouse/app:latest";
|
|
3621
3621
|
var DEV_IMAGE = "ghcr.io/learnhouse/app:dev";
|
|
3622
3622
|
var POSTGRES_IMAGE = "pgvector/pgvector:pg16";
|
|
@@ -4831,7 +4831,7 @@ ${barEnd}
|
|
|
4831
4831
|
}
|
|
4832
4832
|
|
|
4833
4833
|
// src/commands/setup.ts
|
|
4834
|
-
var
|
|
4834
|
+
var import_picocolors9 = __toESM(require_picocolors(), 1);
|
|
4835
4835
|
|
|
4836
4836
|
// src/prompts/prerequisites.ts
|
|
4837
4837
|
var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
@@ -5047,11 +5047,26 @@ async function checkPrerequisites() {
|
|
|
5047
5047
|
s.stop("All prerequisites met");
|
|
5048
5048
|
}
|
|
5049
5049
|
|
|
5050
|
+
// src/prompts/domain.ts
|
|
5051
|
+
var import_picocolors7 = __toESM(require_picocolors(), 1);
|
|
5052
|
+
|
|
5050
5053
|
// src/utils/validators.ts
|
|
5054
|
+
var RESERVED_TLDS = /* @__PURE__ */ new Set([
|
|
5055
|
+
"local",
|
|
5056
|
+
"localhost",
|
|
5057
|
+
"test",
|
|
5058
|
+
"invalid",
|
|
5059
|
+
"example"
|
|
5060
|
+
]);
|
|
5051
5061
|
function validateEmail(value) {
|
|
5052
5062
|
if (!value) return "Email is required";
|
|
5053
5063
|
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
5054
5064
|
if (!re.test(value)) return "Please enter a valid email address";
|
|
5065
|
+
const domain = value.slice(value.lastIndexOf("@") + 1).toLowerCase();
|
|
5066
|
+
const tld = domain.includes(".") ? domain.slice(domain.lastIndexOf(".") + 1) : domain;
|
|
5067
|
+
if (RESERVED_TLDS.has(tld)) {
|
|
5068
|
+
return `Reserved TLD ".${tld}" is not accepted. Use a real domain (e.g. admin@yourdomain.com).`;
|
|
5069
|
+
}
|
|
5055
5070
|
return void 0;
|
|
5056
5071
|
}
|
|
5057
5072
|
function validatePassword(value) {
|
|
@@ -5076,6 +5091,61 @@ function validateRequired(value) {
|
|
|
5076
5091
|
return void 0;
|
|
5077
5092
|
}
|
|
5078
5093
|
|
|
5094
|
+
// src/utils/network.ts
|
|
5095
|
+
import net from "net";
|
|
5096
|
+
function checkPort(port) {
|
|
5097
|
+
return new Promise((resolve) => {
|
|
5098
|
+
const server = net.createServer();
|
|
5099
|
+
server.once("error", () => resolve(false));
|
|
5100
|
+
server.once("listening", () => {
|
|
5101
|
+
server.close(() => resolve(true));
|
|
5102
|
+
});
|
|
5103
|
+
server.listen(port);
|
|
5104
|
+
});
|
|
5105
|
+
}
|
|
5106
|
+
async function findAvailablePort(preferred, candidates = [8080, 8e3, 9090, 3030, 5050]) {
|
|
5107
|
+
if (await checkPort(preferred)) return preferred;
|
|
5108
|
+
for (const port of candidates) {
|
|
5109
|
+
if (port === preferred) continue;
|
|
5110
|
+
if (await checkPort(port)) return port;
|
|
5111
|
+
}
|
|
5112
|
+
return null;
|
|
5113
|
+
}
|
|
5114
|
+
function checkTcpConnection(host, port, timeoutMs = 5e3) {
|
|
5115
|
+
return new Promise((resolve) => {
|
|
5116
|
+
const socket = net.createConnection({ host, port });
|
|
5117
|
+
const timer = setTimeout(() => {
|
|
5118
|
+
socket.destroy();
|
|
5119
|
+
resolve(false);
|
|
5120
|
+
}, timeoutMs);
|
|
5121
|
+
socket.once("connect", () => {
|
|
5122
|
+
clearTimeout(timer);
|
|
5123
|
+
socket.destroy();
|
|
5124
|
+
resolve(true);
|
|
5125
|
+
});
|
|
5126
|
+
socket.once("error", () => {
|
|
5127
|
+
clearTimeout(timer);
|
|
5128
|
+
resolve(false);
|
|
5129
|
+
});
|
|
5130
|
+
});
|
|
5131
|
+
}
|
|
5132
|
+
function parsePostgresUrl(connString) {
|
|
5133
|
+
try {
|
|
5134
|
+
const url = new URL(connString);
|
|
5135
|
+
return { host: url.hostname, port: url.port ? parseInt(url.port, 10) : 5432 };
|
|
5136
|
+
} catch {
|
|
5137
|
+
return null;
|
|
5138
|
+
}
|
|
5139
|
+
}
|
|
5140
|
+
function parseRedisUrl(connString) {
|
|
5141
|
+
try {
|
|
5142
|
+
const url = new URL(connString);
|
|
5143
|
+
return { host: url.hostname, port: url.port ? parseInt(url.port, 10) : 6379 };
|
|
5144
|
+
} catch {
|
|
5145
|
+
return null;
|
|
5146
|
+
}
|
|
5147
|
+
}
|
|
5148
|
+
|
|
5079
5149
|
// src/prompts/domain.ts
|
|
5080
5150
|
async function promptDomain() {
|
|
5081
5151
|
const domain = await text({
|
|
@@ -5121,22 +5191,41 @@ async function promptDomain() {
|
|
|
5121
5191
|
useHttps = true;
|
|
5122
5192
|
}
|
|
5123
5193
|
}
|
|
5124
|
-
const
|
|
5194
|
+
const canonicalDefault = autoSsl ? 443 : 80;
|
|
5195
|
+
let defaultPort = canonicalDefault;
|
|
5196
|
+
if (!autoSsl) {
|
|
5197
|
+
const available = await findAvailablePort(canonicalDefault);
|
|
5198
|
+
if (available && available !== canonicalDefault) {
|
|
5199
|
+
R2.warn(`Port ${canonicalDefault} is already in use. Suggesting ${import_picocolors7.default.cyan(String(available))} instead.`);
|
|
5200
|
+
defaultPort = available;
|
|
5201
|
+
} else if (!available) {
|
|
5202
|
+
R2.warn("Could not find a free common port. You will need to enter one manually.");
|
|
5203
|
+
}
|
|
5204
|
+
}
|
|
5125
5205
|
const portMessage = autoSsl ? "HTTPS port? (Caddy needs 443 for auto SSL, and will also listen on 80 for redirect)" : "HTTP port for the web server?";
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5206
|
+
let httpPort = 0;
|
|
5207
|
+
while (httpPort === 0) {
|
|
5208
|
+
const port = await text({
|
|
5209
|
+
message: portMessage,
|
|
5210
|
+
placeholder: String(defaultPort),
|
|
5211
|
+
defaultValue: String(defaultPort),
|
|
5212
|
+
validate: validatePort
|
|
5213
|
+
});
|
|
5214
|
+
if (Ct(port)) {
|
|
5215
|
+
Ne();
|
|
5216
|
+
process.exit(0);
|
|
5217
|
+
}
|
|
5218
|
+
const parsed = parseInt(port, 10);
|
|
5219
|
+
if (parsed > 1024 && !await checkPort(parsed)) {
|
|
5220
|
+
R2.warn(`Port ${parsed} is already in use. Pick another.`);
|
|
5221
|
+
continue;
|
|
5222
|
+
}
|
|
5223
|
+
httpPort = parsed;
|
|
5135
5224
|
}
|
|
5136
5225
|
return {
|
|
5137
5226
|
domain,
|
|
5138
5227
|
useHttps,
|
|
5139
|
-
httpPort
|
|
5228
|
+
httpPort,
|
|
5140
5229
|
autoSsl,
|
|
5141
5230
|
sslEmail
|
|
5142
5231
|
};
|
|
@@ -5144,56 +5233,7 @@ async function promptDomain() {
|
|
|
5144
5233
|
|
|
5145
5234
|
// src/prompts/database.ts
|
|
5146
5235
|
import crypto from "crypto";
|
|
5147
|
-
var
|
|
5148
|
-
|
|
5149
|
-
// src/utils/network.ts
|
|
5150
|
-
import net from "net";
|
|
5151
|
-
function checkPort(port) {
|
|
5152
|
-
return new Promise((resolve) => {
|
|
5153
|
-
const server = net.createServer();
|
|
5154
|
-
server.once("error", () => resolve(false));
|
|
5155
|
-
server.once("listening", () => {
|
|
5156
|
-
server.close(() => resolve(true));
|
|
5157
|
-
});
|
|
5158
|
-
server.listen(port);
|
|
5159
|
-
});
|
|
5160
|
-
}
|
|
5161
|
-
function checkTcpConnection(host, port, timeoutMs = 5e3) {
|
|
5162
|
-
return new Promise((resolve) => {
|
|
5163
|
-
const socket = net.createConnection({ host, port });
|
|
5164
|
-
const timer = setTimeout(() => {
|
|
5165
|
-
socket.destroy();
|
|
5166
|
-
resolve(false);
|
|
5167
|
-
}, timeoutMs);
|
|
5168
|
-
socket.once("connect", () => {
|
|
5169
|
-
clearTimeout(timer);
|
|
5170
|
-
socket.destroy();
|
|
5171
|
-
resolve(true);
|
|
5172
|
-
});
|
|
5173
|
-
socket.once("error", () => {
|
|
5174
|
-
clearTimeout(timer);
|
|
5175
|
-
resolve(false);
|
|
5176
|
-
});
|
|
5177
|
-
});
|
|
5178
|
-
}
|
|
5179
|
-
function parsePostgresUrl(connString) {
|
|
5180
|
-
try {
|
|
5181
|
-
const url = new URL(connString);
|
|
5182
|
-
return { host: url.hostname, port: url.port ? parseInt(url.port, 10) : 5432 };
|
|
5183
|
-
} catch {
|
|
5184
|
-
return null;
|
|
5185
|
-
}
|
|
5186
|
-
}
|
|
5187
|
-
function parseRedisUrl(connString) {
|
|
5188
|
-
try {
|
|
5189
|
-
const url = new URL(connString);
|
|
5190
|
-
return { host: url.hostname, port: url.port ? parseInt(url.port, 10) : 6379 };
|
|
5191
|
-
} catch {
|
|
5192
|
-
return null;
|
|
5193
|
-
}
|
|
5194
|
-
}
|
|
5195
|
-
|
|
5196
|
-
// src/prompts/database.ts
|
|
5236
|
+
var import_picocolors8 = __toESM(require_picocolors(), 1);
|
|
5197
5237
|
async function promptAndVerifyPostgres() {
|
|
5198
5238
|
while (true) {
|
|
5199
5239
|
const connString = await text({
|
|
@@ -5221,10 +5261,10 @@ async function promptAndVerifyPostgres() {
|
|
|
5221
5261
|
s.start(`Checking connection to ${parsed.host}:${parsed.port}`);
|
|
5222
5262
|
const reachable = await checkTcpConnection(parsed.host, parsed.port);
|
|
5223
5263
|
if (reachable) {
|
|
5224
|
-
s.stop(`${
|
|
5264
|
+
s.stop(`${import_picocolors8.default.green("Connected")} to ${parsed.host}:${parsed.port}`);
|
|
5225
5265
|
return connString;
|
|
5226
5266
|
}
|
|
5227
|
-
s.stop(`${
|
|
5267
|
+
s.stop(`${import_picocolors8.default.red("Connection failed")} to ${parsed.host}:${parsed.port}`);
|
|
5228
5268
|
const retry = await Re({
|
|
5229
5269
|
message: "Could not reach the database. Try a different connection string?",
|
|
5230
5270
|
initialValue: true
|
|
@@ -5262,10 +5302,10 @@ async function promptAndVerifyRedis() {
|
|
|
5262
5302
|
s.start(`Checking connection to ${parsed.host}:${parsed.port}`);
|
|
5263
5303
|
const reachable = await checkTcpConnection(parsed.host, parsed.port);
|
|
5264
5304
|
if (reachable) {
|
|
5265
|
-
s.stop(`${
|
|
5305
|
+
s.stop(`${import_picocolors8.default.green("Connected")} to ${parsed.host}:${parsed.port}`);
|
|
5266
5306
|
return connString;
|
|
5267
5307
|
}
|
|
5268
|
-
s.stop(`${
|
|
5308
|
+
s.stop(`${import_picocolors8.default.red("Connection failed")} to ${parsed.host}:${parsed.port}`);
|
|
5269
5309
|
const retry = await Re({
|
|
5270
5310
|
message: "Could not reach Redis. Try a different connection string?",
|
|
5271
5311
|
initialValue: true
|
|
@@ -5310,15 +5350,15 @@ async function promptDatabase() {
|
|
|
5310
5350
|
useAiDatabase = dbImageChoice === "ai";
|
|
5311
5351
|
dbPassword = crypto.randomBytes(24).toString("base64url");
|
|
5312
5352
|
R2.message("");
|
|
5313
|
-
R2.info(
|
|
5353
|
+
R2.info(import_picocolors8.default.bold("Database credentials generated:"));
|
|
5314
5354
|
R2.message([
|
|
5315
5355
|
"",
|
|
5316
|
-
` ${
|
|
5317
|
-
` ${
|
|
5318
|
-
` ${
|
|
5319
|
-
` ${
|
|
5356
|
+
` ${import_picocolors8.default.dim("User:")} learnhouse`,
|
|
5357
|
+
` ${import_picocolors8.default.dim("Password:")} ${import_picocolors8.default.cyan(dbPassword)}`,
|
|
5358
|
+
` ${import_picocolors8.default.dim("Database:")} learnhouse`,
|
|
5359
|
+
` ${import_picocolors8.default.dim("Host:")} db:5432 (internal)`,
|
|
5320
5360
|
"",
|
|
5321
|
-
` ${
|
|
5361
|
+
` ${import_picocolors8.default.yellow("Copy the password now if needed \u2014 it will be saved in .env")}`,
|
|
5322
5362
|
""
|
|
5323
5363
|
].join("\n"));
|
|
5324
5364
|
const ack = await Re({ message: "Continue?", initialValue: true });
|
|
@@ -5366,8 +5406,25 @@ async function promptOrganization() {
|
|
|
5366
5406
|
Ne();
|
|
5367
5407
|
process.exit(0);
|
|
5368
5408
|
}
|
|
5409
|
+
const orgSlug = await text({
|
|
5410
|
+
message: 'Organization slug? (used in URLs like /orgs/<slug> \u2014 keep "default" unless you know you need to change it)',
|
|
5411
|
+
placeholder: "default",
|
|
5412
|
+
defaultValue: "default",
|
|
5413
|
+
validate: (value) => {
|
|
5414
|
+
if (!value) return "Slug is required";
|
|
5415
|
+
if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]?$/.test(value)) {
|
|
5416
|
+
return "Lowercase letters, numbers and hyphens only";
|
|
5417
|
+
}
|
|
5418
|
+
return void 0;
|
|
5419
|
+
}
|
|
5420
|
+
});
|
|
5421
|
+
if (Ct(orgSlug)) {
|
|
5422
|
+
Ne();
|
|
5423
|
+
process.exit(0);
|
|
5424
|
+
}
|
|
5369
5425
|
return {
|
|
5370
|
-
orgName
|
|
5426
|
+
orgName,
|
|
5427
|
+
orgSlug: orgSlug.toLowerCase()
|
|
5371
5428
|
};
|
|
5372
5429
|
}
|
|
5373
5430
|
|
|
@@ -5606,7 +5663,8 @@ ${deps.join("\n")}` : "";
|
|
|
5606
5663
|
networks:
|
|
5607
5664
|
- learnhouse-network-${id}
|
|
5608
5665
|
healthcheck:
|
|
5609
|
-
|
|
5666
|
+
# Use 127.0.0.1 \u2014 alpine's wget tries IPv6 first and Caddy only binds v4 by default
|
|
5667
|
+
test: ["CMD-SHELL", "wget --quiet --tries=1 --spider http://127.0.0.1:80/ || exit 1"]
|
|
5610
5668
|
interval: 30s
|
|
5611
5669
|
timeout: 10s
|
|
5612
5670
|
retries: 3
|
|
@@ -5625,7 +5683,8 @@ ${deps.join("\n")}` : "";
|
|
|
5625
5683
|
networks:
|
|
5626
5684
|
- learnhouse-network-${id}
|
|
5627
5685
|
healthcheck:
|
|
5628
|
-
|
|
5686
|
+
# Use 127.0.0.1 \u2014 alpine's wget resolves localhost to IPv6 first, but nginx only listens on v4 by default
|
|
5687
|
+
test: ["CMD-SHELL", "wget --quiet --tries=1 --spider http://127.0.0.1/ || exit 1"]
|
|
5629
5688
|
interval: 30s
|
|
5630
5689
|
timeout: 10s
|
|
5631
5690
|
retries: 3
|
|
@@ -5679,6 +5738,10 @@ ${deps.join("\n")}` : "";
|
|
|
5679
5738
|
interval: 5s
|
|
5680
5739
|
timeout: 4s
|
|
5681
5740
|
retries: 5
|
|
5741
|
+
` : "";
|
|
5742
|
+
const useLocalContent = !config.s3Enabled;
|
|
5743
|
+
const appVolumes = useLocalContent ? ` volumes:
|
|
5744
|
+
- learnhouse_content_${id}:/app/api/content
|
|
5682
5745
|
` : "";
|
|
5683
5746
|
const volumeEntries = [];
|
|
5684
5747
|
if (config.autoSsl) {
|
|
@@ -5687,6 +5750,7 @@ ${deps.join("\n")}` : "";
|
|
|
5687
5750
|
}
|
|
5688
5751
|
if (useLocalDb) volumeEntries.push(` learnhouse_db_data_${id}:`);
|
|
5689
5752
|
if (useLocalRedis) volumeEntries.push(` learnhouse_redis_data_${id}:`);
|
|
5753
|
+
if (useLocalContent) volumeEntries.push(` learnhouse_content_${id}:`);
|
|
5690
5754
|
const volumesSection = volumeEntries.length > 0 ? `volumes:
|
|
5691
5755
|
${volumeEntries.join("\n")}` : "";
|
|
5692
5756
|
return `name: learnhouse-${id}
|
|
@@ -5702,7 +5766,7 @@ services:
|
|
|
5702
5766
|
# HOSTNAME needs to be set explicitly for the container
|
|
5703
5767
|
- HOSTNAME=0.0.0.0
|
|
5704
5768
|
- LEARNHOUSE_API_URL=http://localhost:9000
|
|
5705
|
-
${appDependsOn}
|
|
5769
|
+
${appVolumes}${appDependsOn}
|
|
5706
5770
|
networks:
|
|
5707
5771
|
- learnhouse-network-${id}
|
|
5708
5772
|
healthcheck:
|
|
@@ -5761,7 +5825,7 @@ function generateEnvFile(config) {
|
|
|
5761
5825
|
`NEXT_PUBLIC_LEARNHOUSE_DOMAIN=${domainWithPort}`,
|
|
5762
5826
|
`NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN=${topDomain}`,
|
|
5763
5827
|
"NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG=False",
|
|
5764
|
-
"
|
|
5828
|
+
`NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG=${config.orgSlug || "default"}`,
|
|
5765
5829
|
`NEXT_PUBLIC_LEARNHOUSE_HTTPS=${config.useHttps ? "True" : "False"}`
|
|
5766
5830
|
];
|
|
5767
5831
|
if (config.unsplashEnabled && config.unsplashAccessKey) {
|
|
@@ -5800,6 +5864,8 @@ function generateEnvFile(config) {
|
|
|
5800
5864
|
`LEARNHOUSE_AUTH_JWT_SECRET_KEY=${jwtSecret}`,
|
|
5801
5865
|
`LEARNHOUSE_INITIAL_ADMIN_EMAIL=${quoteEnvValue(config.adminEmail)}`,
|
|
5802
5866
|
`LEARNHOUSE_INITIAL_ADMIN_PASSWORD=${quoteEnvValue(config.adminPassword)}`,
|
|
5867
|
+
`LEARNHOUSE_INITIAL_ORG_NAME=${quoteEnvValue(config.orgName || "Default Organization")}`,
|
|
5868
|
+
`LEARNHOUSE_INITIAL_ORG_SLUG=${quoteEnvValue(config.orgSlug || "default")}`,
|
|
5803
5869
|
"",
|
|
5804
5870
|
"# =============================================================================",
|
|
5805
5871
|
"# Collaboration Server",
|
|
@@ -5904,6 +5970,7 @@ function generateNginxConf() {
|
|
|
5904
5970
|
return `
|
|
5905
5971
|
server {
|
|
5906
5972
|
listen 80;
|
|
5973
|
+
listen [::]:80;
|
|
5907
5974
|
server_name _;
|
|
5908
5975
|
client_max_body_size 500M;
|
|
5909
5976
|
|
|
@@ -5970,7 +6037,7 @@ function writeConfig(config) {
|
|
|
5970
6037
|
useHttps: config.useHttps,
|
|
5971
6038
|
autoSsl: config.autoSsl,
|
|
5972
6039
|
useExternalDb: config.useExternalDb,
|
|
5973
|
-
orgSlug: "default"
|
|
6040
|
+
orgSlug: config.orgSlug || "default"
|
|
5974
6041
|
};
|
|
5975
6042
|
fs.writeFileSync(
|
|
5976
6043
|
path.join(config.installDir, CONFIG_FILENAME),
|
|
@@ -6022,8 +6089,7 @@ function findInstallDir() {
|
|
|
6022
6089
|
const running = installations.find(
|
|
6023
6090
|
(i) => isContainerRunning(`learnhouse-app-${i.config.deploymentId}`)
|
|
6024
6091
|
);
|
|
6025
|
-
|
|
6026
|
-
return installations[0].dir;
|
|
6092
|
+
return (running ?? installations[0]).dir;
|
|
6027
6093
|
}
|
|
6028
6094
|
const cwd = process.cwd();
|
|
6029
6095
|
if (isCompleteInstall(cwd)) return cwd;
|
|
@@ -6044,6 +6110,19 @@ async function waitForHealth(baseUrl) {
|
|
|
6044
6110
|
}
|
|
6045
6111
|
return false;
|
|
6046
6112
|
}
|
|
6113
|
+
async function waitForOrgSeed(baseUrl, orgSlug) {
|
|
6114
|
+
const url = `${baseUrl}/api/v1/orgs/slug/${encodeURIComponent(orgSlug)}`;
|
|
6115
|
+
const deadline = Date.now() + 3e4;
|
|
6116
|
+
while (Date.now() < deadline) {
|
|
6117
|
+
try {
|
|
6118
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(5e3) });
|
|
6119
|
+
if (res.ok) return true;
|
|
6120
|
+
} catch {
|
|
6121
|
+
}
|
|
6122
|
+
await new Promise((r) => setTimeout(r, HEALTH_CHECK_INTERVAL_MS));
|
|
6123
|
+
}
|
|
6124
|
+
return false;
|
|
6125
|
+
}
|
|
6047
6126
|
|
|
6048
6127
|
// src/commands/setup.ts
|
|
6049
6128
|
var STEP_NAMES = [
|
|
@@ -6061,7 +6140,7 @@ async function confirmOrBack(message) {
|
|
|
6061
6140
|
message,
|
|
6062
6141
|
options: [
|
|
6063
6142
|
{ value: "continue", label: "Continue" },
|
|
6064
|
-
{ value: "back", label:
|
|
6143
|
+
{ value: "back", label: import_picocolors9.default.dim("Go back to previous step") }
|
|
6065
6144
|
]
|
|
6066
6145
|
});
|
|
6067
6146
|
if (Ct(result)) {
|
|
@@ -6072,7 +6151,7 @@ async function confirmOrBack(message) {
|
|
|
6072
6151
|
}
|
|
6073
6152
|
async function stepInstallDir() {
|
|
6074
6153
|
const baseDir = path2.join(os2.homedir(), ".learnhouse");
|
|
6075
|
-
R2.info(`All installations are stored in ${
|
|
6154
|
+
R2.info(`All installations are stored in ${import_picocolors9.default.cyan("~/.learnhouse/<name>")}`);
|
|
6076
6155
|
const name = await text({
|
|
6077
6156
|
message: "Name for this installation:",
|
|
6078
6157
|
placeholder: "default",
|
|
@@ -6103,28 +6182,23 @@ async function stepInstallDir() {
|
|
|
6103
6182
|
return resolved;
|
|
6104
6183
|
}
|
|
6105
6184
|
async function stepDomain() {
|
|
6106
|
-
R2.step(
|
|
6107
|
-
|
|
6108
|
-
const portAvailable = await checkPort(config.httpPort);
|
|
6109
|
-
if (!portAvailable) {
|
|
6110
|
-
R2.warn(`Port ${config.httpPort} is already in use. You may need to free it before starting.`);
|
|
6111
|
-
}
|
|
6112
|
-
return config;
|
|
6185
|
+
R2.step(import_picocolors9.default.cyan(`Step 2/6`) + " Domain Configuration");
|
|
6186
|
+
return await promptDomain();
|
|
6113
6187
|
}
|
|
6114
6188
|
async function stepDatabase() {
|
|
6115
|
-
R2.step(
|
|
6189
|
+
R2.step(import_picocolors9.default.cyan(`Step 3/6`) + " Database & Redis");
|
|
6116
6190
|
return await promptDatabase();
|
|
6117
6191
|
}
|
|
6118
6192
|
async function stepOrganization() {
|
|
6119
|
-
R2.step(
|
|
6193
|
+
R2.step(import_picocolors9.default.cyan(`Step 4/6`) + " Organization Setup");
|
|
6120
6194
|
return await promptOrganization();
|
|
6121
6195
|
}
|
|
6122
6196
|
async function stepAdmin() {
|
|
6123
|
-
R2.step(
|
|
6197
|
+
R2.step(import_picocolors9.default.cyan(`Step 5/6`) + " Admin Account");
|
|
6124
6198
|
return await promptAdmin();
|
|
6125
6199
|
}
|
|
6126
6200
|
async function stepFeatures() {
|
|
6127
|
-
R2.step(
|
|
6201
|
+
R2.step(import_picocolors9.default.cyan(`Step 6/6`) + " Optional Features");
|
|
6128
6202
|
return await promptFeatures();
|
|
6129
6203
|
}
|
|
6130
6204
|
async function setupCommand(options) {
|
|
@@ -6133,6 +6207,13 @@ async function setupCommand(options) {
|
|
|
6133
6207
|
console.error("Error: --admin-password is required in --ci mode");
|
|
6134
6208
|
process.exit(1);
|
|
6135
6209
|
}
|
|
6210
|
+
if (options.adminEmail) {
|
|
6211
|
+
const emailErr = validateEmail(options.adminEmail);
|
|
6212
|
+
if (emailErr) {
|
|
6213
|
+
console.error(`Error: --admin-email "${options.adminEmail}" \u2014 ${emailErr}`);
|
|
6214
|
+
process.exit(1);
|
|
6215
|
+
}
|
|
6216
|
+
}
|
|
6136
6217
|
await checkPrerequisites();
|
|
6137
6218
|
const installName = options.name || "default";
|
|
6138
6219
|
const baseDir = path2.join(os2.homedir(), ".learnhouse");
|
|
@@ -6141,19 +6222,34 @@ async function setupCommand(options) {
|
|
|
6141
6222
|
const deploymentId2 = crypto3.randomBytes(4).toString("hex");
|
|
6142
6223
|
const channel2 = options.channel === "dev" ? "dev" : "stable";
|
|
6143
6224
|
const dbPassword = crypto3.randomBytes(24).toString("base64url");
|
|
6225
|
+
let httpPort = options.port || 80;
|
|
6226
|
+
if (!options.port) {
|
|
6227
|
+
const available = await findAvailablePort(httpPort);
|
|
6228
|
+
if (available && available !== httpPort) {
|
|
6229
|
+
console.log(`Port ${httpPort} is in use \u2014 falling back to ${available}.`);
|
|
6230
|
+
httpPort = available;
|
|
6231
|
+
} else if (!available) {
|
|
6232
|
+
console.error("No common port is available. Pass --port=<port> explicitly.");
|
|
6233
|
+
process.exit(1);
|
|
6234
|
+
}
|
|
6235
|
+
} else if (!await checkPort(httpPort)) {
|
|
6236
|
+
console.error(`Port ${httpPort} is already in use. Free it or pass a different --port.`);
|
|
6237
|
+
process.exit(1);
|
|
6238
|
+
}
|
|
6144
6239
|
const config2 = {
|
|
6145
6240
|
deploymentId: deploymentId2,
|
|
6146
6241
|
installDir: resolvedDir2,
|
|
6147
6242
|
channel: channel2,
|
|
6148
6243
|
domain: options.domain || "localhost",
|
|
6149
6244
|
useHttps: false,
|
|
6150
|
-
httpPort
|
|
6245
|
+
httpPort,
|
|
6151
6246
|
autoSsl: false,
|
|
6152
6247
|
useExternalDb: false,
|
|
6153
6248
|
dbPassword,
|
|
6154
6249
|
useAiDatabase: false,
|
|
6155
6250
|
useExternalRedis: false,
|
|
6156
|
-
orgName: "Default",
|
|
6251
|
+
orgName: options.orgName || "Default Organization",
|
|
6252
|
+
orgSlug: (options.orgSlug || "default").toLowerCase(),
|
|
6157
6253
|
adminEmail: options.adminEmail || "admin@school.dev",
|
|
6158
6254
|
adminPassword: options.adminPassword,
|
|
6159
6255
|
aiEnabled: false,
|
|
@@ -6178,12 +6274,27 @@ async function setupCommand(options) {
|
|
|
6178
6274
|
dockerComposeUp(resolvedDir2);
|
|
6179
6275
|
const healthy = await waitForHealth(`http://localhost:${config2.httpPort}`);
|
|
6180
6276
|
if (healthy) {
|
|
6181
|
-
|
|
6277
|
+
const seeded = await waitForOrgSeed(`http://localhost:${config2.httpPort}`, "default");
|
|
6278
|
+
if (seeded) {
|
|
6279
|
+
console.log("LearnHouse is ready!");
|
|
6280
|
+
} else {
|
|
6281
|
+
console.error("");
|
|
6282
|
+
console.error("API is healthy but the default organization was not seeded.");
|
|
6283
|
+
console.error("Run `npx learnhouse logs` to inspect; pin a different image tag and re-run.");
|
|
6284
|
+
console.error("");
|
|
6285
|
+
process.exit(1);
|
|
6286
|
+
}
|
|
6182
6287
|
} else {
|
|
6183
6288
|
console.log("Health check timed out \u2014 services may still be starting");
|
|
6184
6289
|
}
|
|
6185
|
-
} catch {
|
|
6186
|
-
|
|
6290
|
+
} catch (err) {
|
|
6291
|
+
const stderr = err?.stderr?.toString?.() ?? "";
|
|
6292
|
+
const message = err?.message ?? "";
|
|
6293
|
+
if (/port is already allocated/i.test(stderr) || /address already in use/i.test(stderr) || /port is already allocated/i.test(message)) {
|
|
6294
|
+
console.error(`Port ${config2.httpPort} is already bound \u2014 pass --port=<other> and re-run.`);
|
|
6295
|
+
} else {
|
|
6296
|
+
console.error("Failed to start services");
|
|
6297
|
+
}
|
|
6187
6298
|
process.exit(1);
|
|
6188
6299
|
}
|
|
6189
6300
|
}
|
|
@@ -6194,7 +6305,7 @@ async function setupCommand(options) {
|
|
|
6194
6305
|
return;
|
|
6195
6306
|
}
|
|
6196
6307
|
await printBanner();
|
|
6197
|
-
We(
|
|
6308
|
+
We(import_picocolors9.default.cyan("LearnHouse Setup Wizard"));
|
|
6198
6309
|
await checkPrerequisites();
|
|
6199
6310
|
const channelChoice = await Je({
|
|
6200
6311
|
message: "Which release channel do you want to use?",
|
|
@@ -6227,7 +6338,7 @@ async function setupCommand(options) {
|
|
|
6227
6338
|
while (step < totalSteps) {
|
|
6228
6339
|
switch (step) {
|
|
6229
6340
|
case 0: {
|
|
6230
|
-
R2.step(
|
|
6341
|
+
R2.step(import_picocolors9.default.cyan(`Step 1/${totalSteps}`) + " Install Directory");
|
|
6231
6342
|
const result = await stepInstallDir();
|
|
6232
6343
|
if (result === BACK) {
|
|
6233
6344
|
step = Math.max(0, step - 1);
|
|
@@ -6300,19 +6411,19 @@ async function setupCommand(options) {
|
|
|
6300
6411
|
const url = `${protocol}://${config.domain}${portSuffix}`;
|
|
6301
6412
|
R2.step("Configuration Summary");
|
|
6302
6413
|
R2.message([
|
|
6303
|
-
` ${
|
|
6304
|
-
` ${
|
|
6305
|
-
` ${
|
|
6306
|
-
` ${
|
|
6307
|
-
` ${
|
|
6308
|
-
` ${
|
|
6309
|
-
` ${
|
|
6310
|
-
` ${
|
|
6311
|
-
` ${
|
|
6312
|
-
` ${
|
|
6313
|
-
` ${
|
|
6314
|
-
` ${
|
|
6315
|
-
` ${
|
|
6414
|
+
` ${import_picocolors9.default.dim("Directory:")} ${resolvedDir}`,
|
|
6415
|
+
` ${import_picocolors9.default.dim("Channel:")} ${config.channel === "dev" ? import_picocolors9.default.yellow("Dev (:dev)") : import_picocolors9.default.green("Stable")}`,
|
|
6416
|
+
` ${import_picocolors9.default.dim("URL:")} ${url}`,
|
|
6417
|
+
` ${import_picocolors9.default.dim("HTTPS:")} ${config.autoSsl ? "Auto SSL (Caddy)" : config.useHttps ? "Manual" : "Disabled"}`,
|
|
6418
|
+
` ${import_picocolors9.default.dim("Database:")} ${config.useExternalDb ? "External" : config.useAiDatabase ? "Local (Docker, AI-enabled)" : "Local (Docker)"}`,
|
|
6419
|
+
` ${import_picocolors9.default.dim("Redis:")} ${config.useExternalRedis ? "External" : "Local (Docker)"}`,
|
|
6420
|
+
` ${import_picocolors9.default.dim("Organization:")} ${config.orgName}`,
|
|
6421
|
+
` ${import_picocolors9.default.dim("Admin:")} ${config.adminEmail}`,
|
|
6422
|
+
` ${import_picocolors9.default.dim("AI:")} ${config.aiEnabled ? "Enabled" : "Disabled"}`,
|
|
6423
|
+
` ${import_picocolors9.default.dim("Email:")} ${config.emailEnabled ? "Enabled" : "Disabled"}`,
|
|
6424
|
+
` ${import_picocolors9.default.dim("S3 Storage:")} ${config.s3Enabled ? "Enabled" : "Disabled"}`,
|
|
6425
|
+
` ${import_picocolors9.default.dim("Google OAuth:")} ${config.googleOAuthEnabled ? "Enabled" : "Disabled"}`,
|
|
6426
|
+
` ${import_picocolors9.default.dim("Unsplash:")} ${config.unsplashEnabled ? "Enabled" : "Disabled"}`
|
|
6316
6427
|
].join("\n"));
|
|
6317
6428
|
let confirmed = false;
|
|
6318
6429
|
while (!confirmed) {
|
|
@@ -6320,8 +6431,8 @@ async function setupCommand(options) {
|
|
|
6320
6431
|
message: "What would you like to do?",
|
|
6321
6432
|
options: [
|
|
6322
6433
|
{ value: "confirm", label: "Proceed with this configuration" },
|
|
6323
|
-
{ value: "edit", label:
|
|
6324
|
-
{ value: "cancel", label:
|
|
6434
|
+
{ value: "edit", label: import_picocolors9.default.dim("Go back and edit a step") },
|
|
6435
|
+
{ value: "cancel", label: import_picocolors9.default.dim("Cancel setup") }
|
|
6325
6436
|
]
|
|
6326
6437
|
});
|
|
6327
6438
|
if (Ct(action) || action === "cancel") {
|
|
@@ -6337,7 +6448,7 @@ async function setupCommand(options) {
|
|
|
6337
6448
|
const idx = stepChoice;
|
|
6338
6449
|
switch (idx) {
|
|
6339
6450
|
case 0: {
|
|
6340
|
-
R2.step(
|
|
6451
|
+
R2.step(import_picocolors9.default.cyan(`Step 1/${totalSteps}`) + " Install Directory");
|
|
6341
6452
|
const result = await stepInstallDir();
|
|
6342
6453
|
if (result !== BACK) {
|
|
6343
6454
|
resolvedDir = result;
|
|
@@ -6376,19 +6487,19 @@ async function setupCommand(options) {
|
|
|
6376
6487
|
const url2 = `${p2}://${config.domain}${ps2}`;
|
|
6377
6488
|
R2.step("Updated Configuration Summary");
|
|
6378
6489
|
R2.message([
|
|
6379
|
-
` ${
|
|
6380
|
-
` ${
|
|
6381
|
-
` ${
|
|
6382
|
-
` ${
|
|
6383
|
-
` ${
|
|
6384
|
-
` ${
|
|
6385
|
-
` ${
|
|
6386
|
-
` ${
|
|
6387
|
-
` ${
|
|
6388
|
-
` ${
|
|
6389
|
-
` ${
|
|
6390
|
-
` ${
|
|
6391
|
-
` ${
|
|
6490
|
+
` ${import_picocolors9.default.dim("Directory:")} ${config.installDir}`,
|
|
6491
|
+
` ${import_picocolors9.default.dim("Channel:")} ${config.channel === "dev" ? import_picocolors9.default.yellow("Dev (:dev)") : import_picocolors9.default.green("Stable")}`,
|
|
6492
|
+
` ${import_picocolors9.default.dim("URL:")} ${url2}`,
|
|
6493
|
+
` ${import_picocolors9.default.dim("HTTPS:")} ${config.autoSsl ? "Auto SSL (Caddy)" : config.useHttps ? "Manual" : "Disabled"}`,
|
|
6494
|
+
` ${import_picocolors9.default.dim("Database:")} ${config.useExternalDb ? "External" : config.useAiDatabase ? "Local (Docker, AI-enabled)" : "Local (Docker)"}`,
|
|
6495
|
+
` ${import_picocolors9.default.dim("Redis:")} ${config.useExternalRedis ? "External" : "Local (Docker)"}`,
|
|
6496
|
+
` ${import_picocolors9.default.dim("Organization:")} ${config.orgName}`,
|
|
6497
|
+
` ${import_picocolors9.default.dim("Admin:")} ${config.adminEmail}`,
|
|
6498
|
+
` ${import_picocolors9.default.dim("AI:")} ${config.aiEnabled ? "Enabled" : "Disabled"}`,
|
|
6499
|
+
` ${import_picocolors9.default.dim("Email:")} ${config.emailEnabled ? "Enabled" : "Disabled"}`,
|
|
6500
|
+
` ${import_picocolors9.default.dim("S3 Storage:")} ${config.s3Enabled ? "Enabled" : "Disabled"}`,
|
|
6501
|
+
` ${import_picocolors9.default.dim("Google OAuth:")} ${config.googleOAuthEnabled ? "Enabled" : "Disabled"}`,
|
|
6502
|
+
` ${import_picocolors9.default.dim("Unsplash:")} ${config.unsplashEnabled ? "Enabled" : "Disabled"}`
|
|
6392
6503
|
].join("\n"));
|
|
6393
6504
|
} else {
|
|
6394
6505
|
confirmed = true;
|
|
@@ -6441,47 +6552,202 @@ async function setupCommand(options) {
|
|
|
6441
6552
|
s2.stop("Services started");
|
|
6442
6553
|
} catch (err) {
|
|
6443
6554
|
s2.stop("Failed to start services");
|
|
6444
|
-
|
|
6445
|
-
|
|
6555
|
+
const stderr = err?.stderr?.toString?.() ?? "";
|
|
6556
|
+
const message = err?.message ?? "";
|
|
6557
|
+
const portAllocated = /port is already allocated/i.test(stderr) || /port is already allocated/i.test(message) || /bind:.*address already in use/i.test(stderr);
|
|
6558
|
+
if (portAllocated) {
|
|
6559
|
+
R2.error(
|
|
6560
|
+
`Port ${config.httpPort} is already bound by another process or container \u2014 Docker couldn't publish to it.`
|
|
6561
|
+
);
|
|
6562
|
+
R2.info(
|
|
6563
|
+
`Fix one of these and re-run \`learnhouse start\` (your config is already saved):
|
|
6564
|
+
\u2022 Stop whatever is using port ${config.httpPort}, or
|
|
6565
|
+
\u2022 Re-run \`learnhouse setup\` and pick a different port, or
|
|
6566
|
+
\u2022 Edit HTTP_PORT in ${finalDir}/.env and run \`docker compose up -d\` from there.`
|
|
6567
|
+
);
|
|
6568
|
+
} else {
|
|
6569
|
+
R2.error("Docker Compose failed. Check the output above for details.");
|
|
6570
|
+
R2.info(`You can manually start with: cd ${finalDir} && docker compose up -d`);
|
|
6571
|
+
}
|
|
6446
6572
|
process.exit(1);
|
|
6447
6573
|
}
|
|
6448
6574
|
const s3 = bt2();
|
|
6449
6575
|
s3.start("Waiting for LearnHouse to be ready (up to 3 minutes)");
|
|
6450
6576
|
const healthy = await waitForHealth(`http://localhost:${config.httpPort}`);
|
|
6451
6577
|
if (healthy) {
|
|
6452
|
-
|
|
6578
|
+
const seeded = await waitForOrgSeed(`http://localhost:${config.httpPort}`, "default");
|
|
6579
|
+
if (seeded) {
|
|
6580
|
+
s3.stop("LearnHouse is ready!");
|
|
6581
|
+
} else {
|
|
6582
|
+
s3.stop("API is healthy but the default organization was not seeded");
|
|
6583
|
+
R2.error(
|
|
6584
|
+
"`/api/v1/orgs/slug/default` returns no org. Run `learnhouse logs` to inspect, pin a different image tag, and re-run setup."
|
|
6585
|
+
);
|
|
6586
|
+
process.exit(1);
|
|
6587
|
+
}
|
|
6453
6588
|
} else {
|
|
6454
6589
|
s3.stop("Health check timed out");
|
|
6455
6590
|
R2.warn("LearnHouse may still be starting. Check status with:");
|
|
6456
6591
|
R2.message(` cd ${finalDir} && docker compose ps`);
|
|
6457
6592
|
}
|
|
6458
|
-
R2.success(
|
|
6593
|
+
R2.success(import_picocolors9.default.green(import_picocolors9.default.bold("LearnHouse is installed!")));
|
|
6459
6594
|
R2.message([
|
|
6460
6595
|
"",
|
|
6461
|
-
` ${
|
|
6462
|
-
` ${
|
|
6463
|
-
` ${
|
|
6596
|
+
` ${import_picocolors9.default.cyan("URL:")} ${finalUrl}`,
|
|
6597
|
+
` ${import_picocolors9.default.cyan("Admin:")} ${config.adminEmail}`,
|
|
6598
|
+
` ${import_picocolors9.default.cyan("Password:")} ${config.adminPassword}`,
|
|
6464
6599
|
"",
|
|
6465
|
-
` ${
|
|
6466
|
-
` ${
|
|
6467
|
-
` ${
|
|
6468
|
-
` ${
|
|
6469
|
-
` ${
|
|
6470
|
-
` ${
|
|
6471
|
-
` ${
|
|
6472
|
-
` ${
|
|
6473
|
-
` ${
|
|
6600
|
+
` ${import_picocolors9.default.dim("Management commands:")}`,
|
|
6601
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse start ${import_picocolors9.default.dim("Start services")}`,
|
|
6602
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse stop ${import_picocolors9.default.dim("Stop services")}`,
|
|
6603
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse logs ${import_picocolors9.default.dim("View logs")}`,
|
|
6604
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse config ${import_picocolors9.default.dim("Show configuration")}`,
|
|
6605
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse backup ${import_picocolors9.default.dim("Backup & restore")}`,
|
|
6606
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse deployments ${import_picocolors9.default.dim("Manage deployments")}`,
|
|
6607
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse doctor ${import_picocolors9.default.dim("Diagnose issues")}`,
|
|
6608
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse shell ${import_picocolors9.default.dim("Container shell")}`,
|
|
6474
6609
|
""
|
|
6475
6610
|
].join("\n"));
|
|
6476
6611
|
} else {
|
|
6477
6612
|
R2.info(`Files have been generated in ${finalDir}`);
|
|
6478
6613
|
R2.message(` Start later with: cd ${finalDir} && docker compose up -d`);
|
|
6479
6614
|
}
|
|
6480
|
-
Le(
|
|
6615
|
+
Le(import_picocolors9.default.dim("Happy teaching!"));
|
|
6616
|
+
}
|
|
6617
|
+
|
|
6618
|
+
// src/commands/start.ts
|
|
6619
|
+
var import_picocolors10 = __toESM(require_picocolors(), 1);
|
|
6620
|
+
|
|
6621
|
+
// src/services/content-volume-migration.ts
|
|
6622
|
+
import { execFileSync } from "child_process";
|
|
6623
|
+
import fs3 from "fs";
|
|
6624
|
+
import os3 from "os";
|
|
6625
|
+
import path3 from "path";
|
|
6626
|
+
var CONTENT_PATH = "/app/api/content";
|
|
6627
|
+
function migrateContentVolume(installDir, deploymentId) {
|
|
6628
|
+
const composePath = path3.join(installDir, "docker-compose.yml");
|
|
6629
|
+
if (!fs3.existsSync(composePath)) return { status: "no_compose" };
|
|
6630
|
+
let compose = fs3.readFileSync(composePath, "utf-8");
|
|
6631
|
+
if (compose.includes(CONTENT_PATH)) return { status: "already_mounted" };
|
|
6632
|
+
const envPath = path3.join(installDir, ".env");
|
|
6633
|
+
if (fs3.existsSync(envPath)) {
|
|
6634
|
+
const env = fs3.readFileSync(envPath, "utf-8");
|
|
6635
|
+
if (/^LEARNHOUSE_CONTENT_DELIVERY_TYPE\s*=\s*s3api\s*$/m.test(env)) {
|
|
6636
|
+
return { status: "skipped_s3" };
|
|
6637
|
+
}
|
|
6638
|
+
}
|
|
6639
|
+
const projectName = compose.match(/^name:\s*(\S+)/m)?.[1] ?? `learnhouse-${deploymentId}`;
|
|
6640
|
+
const volumeFull = `${projectName}_learnhouse_content_${deploymentId}`;
|
|
6641
|
+
const containerName = `learnhouse-app-${deploymentId}`;
|
|
6642
|
+
let copiedBytes = 0;
|
|
6643
|
+
const hasContainer = dockerContainerExists(containerName);
|
|
6644
|
+
if (hasContainer) {
|
|
6645
|
+
copiedBytes = copyContainerContentIntoVolume(containerName, volumeFull);
|
|
6646
|
+
}
|
|
6647
|
+
compose = patchComposeAddContentVolume(compose, deploymentId);
|
|
6648
|
+
fs3.writeFileSync(composePath, compose);
|
|
6649
|
+
return hasContainer ? { status: "migrated", copiedBytes } : { status: "patched_no_data" };
|
|
6650
|
+
}
|
|
6651
|
+
function dockerContainerExists(name) {
|
|
6652
|
+
try {
|
|
6653
|
+
execFileSync("docker", ["inspect", name], { stdio: "pipe" });
|
|
6654
|
+
return true;
|
|
6655
|
+
} catch {
|
|
6656
|
+
return false;
|
|
6657
|
+
}
|
|
6658
|
+
}
|
|
6659
|
+
function copyContainerContentIntoVolume(containerName, volumeFull) {
|
|
6660
|
+
const tmpDir = fs3.mkdtempSync(path3.join(os3.tmpdir(), "lh-content-"));
|
|
6661
|
+
const helperName = `lh-content-migrate-${Date.now()}`;
|
|
6662
|
+
try {
|
|
6663
|
+
execFileSync(
|
|
6664
|
+
"docker",
|
|
6665
|
+
["cp", `${containerName}:${CONTENT_PATH}/.`, `${tmpDir}/`],
|
|
6666
|
+
{ stdio: "pipe" }
|
|
6667
|
+
);
|
|
6668
|
+
execFileSync(
|
|
6669
|
+
"docker",
|
|
6670
|
+
[
|
|
6671
|
+
"run",
|
|
6672
|
+
"--name",
|
|
6673
|
+
helperName,
|
|
6674
|
+
"-d",
|
|
6675
|
+
"-v",
|
|
6676
|
+
`${volumeFull}:/dst`,
|
|
6677
|
+
"alpine",
|
|
6678
|
+
"sh",
|
|
6679
|
+
"-c",
|
|
6680
|
+
"sleep 60"
|
|
6681
|
+
],
|
|
6682
|
+
{ stdio: "pipe" }
|
|
6683
|
+
);
|
|
6684
|
+
try {
|
|
6685
|
+
execFileSync(
|
|
6686
|
+
"docker",
|
|
6687
|
+
["cp", `${tmpDir}/.`, `${helperName}:/dst/`],
|
|
6688
|
+
{ stdio: "pipe" }
|
|
6689
|
+
);
|
|
6690
|
+
} finally {
|
|
6691
|
+
try {
|
|
6692
|
+
execFileSync("docker", ["rm", "-f", helperName], { stdio: "pipe" });
|
|
6693
|
+
} catch {
|
|
6694
|
+
}
|
|
6695
|
+
}
|
|
6696
|
+
return directorySize(tmpDir);
|
|
6697
|
+
} finally {
|
|
6698
|
+
fs3.rmSync(tmpDir, { recursive: true, force: true });
|
|
6699
|
+
}
|
|
6700
|
+
}
|
|
6701
|
+
function patchComposeAddContentVolume(compose, deploymentId) {
|
|
6702
|
+
const mountLine = ` - learnhouse_content_${deploymentId}:${CONTENT_PATH}`;
|
|
6703
|
+
const appStart = compose.indexOf("learnhouse-app:");
|
|
6704
|
+
if (appStart === -1) {
|
|
6705
|
+
throw new Error("learnhouse-app service not found in docker-compose.yml");
|
|
6706
|
+
}
|
|
6707
|
+
const networksIdx = compose.indexOf("\n networks:", appStart);
|
|
6708
|
+
if (networksIdx === -1) {
|
|
6709
|
+
throw new Error("No service-level networks: block under learnhouse-app");
|
|
6710
|
+
}
|
|
6711
|
+
const appBody = compose.slice(appStart, networksIdx);
|
|
6712
|
+
if (/\n volumes:/.test(appBody)) {
|
|
6713
|
+
const volumesIdx = compose.indexOf("\n volumes:", appStart);
|
|
6714
|
+
const insertAt = volumesIdx + "\n volumes:".length;
|
|
6715
|
+
if (!compose.slice(insertAt, networksIdx).includes(mountLine)) {
|
|
6716
|
+
compose = compose.slice(0, insertAt) + "\n" + mountLine + compose.slice(insertAt);
|
|
6717
|
+
}
|
|
6718
|
+
} else {
|
|
6719
|
+
const block = ` volumes:
|
|
6720
|
+
${mountLine}
|
|
6721
|
+
`;
|
|
6722
|
+
compose = compose.slice(0, networksIdx + 1) + block + compose.slice(networksIdx + 1);
|
|
6723
|
+
}
|
|
6724
|
+
const volumeEntry = ` learnhouse_content_${deploymentId}:`;
|
|
6725
|
+
if (/^volumes:\s*$/m.test(compose) || /^volumes:\s*\n/m.test(compose)) {
|
|
6726
|
+
if (!compose.includes(volumeEntry)) {
|
|
6727
|
+
compose = compose.replace(/\s*$/, "") + `
|
|
6728
|
+
${volumeEntry}
|
|
6729
|
+
`;
|
|
6730
|
+
}
|
|
6731
|
+
} else {
|
|
6732
|
+
compose = compose.replace(/\s*$/, "") + `
|
|
6733
|
+
|
|
6734
|
+
volumes:
|
|
6735
|
+
${volumeEntry}
|
|
6736
|
+
`;
|
|
6737
|
+
}
|
|
6738
|
+
return compose;
|
|
6739
|
+
}
|
|
6740
|
+
function directorySize(dir) {
|
|
6741
|
+
let total = 0;
|
|
6742
|
+
for (const entry of fs3.readdirSync(dir, { withFileTypes: true })) {
|
|
6743
|
+
const full = path3.join(dir, entry.name);
|
|
6744
|
+
if (entry.isDirectory()) total += directorySize(full);
|
|
6745
|
+
else if (entry.isFile()) total += fs3.statSync(full).size;
|
|
6746
|
+
}
|
|
6747
|
+
return total;
|
|
6481
6748
|
}
|
|
6482
6749
|
|
|
6483
6750
|
// src/commands/start.ts
|
|
6484
|
-
var import_picocolors9 = __toESM(require_picocolors(), 1);
|
|
6485
6751
|
async function startCommand() {
|
|
6486
6752
|
const dir = findInstallDir();
|
|
6487
6753
|
const config = readConfig(dir);
|
|
@@ -6489,7 +6755,18 @@ async function startCommand() {
|
|
|
6489
6755
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6490
6756
|
process.exit(1);
|
|
6491
6757
|
}
|
|
6492
|
-
We(
|
|
6758
|
+
We(import_picocolors10.default.cyan("Starting LearnHouse"));
|
|
6759
|
+
try {
|
|
6760
|
+
const result = migrateContentVolume(config.installDir, config.deploymentId);
|
|
6761
|
+
if (result.status === "migrated") {
|
|
6762
|
+
R2.success("Preserved existing uploaded content into a persistent volume.");
|
|
6763
|
+
} else if (result.status === "patched_no_data") {
|
|
6764
|
+
R2.info("Added persistent content volume to docker-compose.yml.");
|
|
6765
|
+
}
|
|
6766
|
+
} catch (err) {
|
|
6767
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6768
|
+
R2.warn(`Could not migrate content volume: ${msg}`);
|
|
6769
|
+
}
|
|
6493
6770
|
try {
|
|
6494
6771
|
dockerComposeUp(config.installDir);
|
|
6495
6772
|
R2.success("LearnHouse is running!");
|
|
@@ -6500,7 +6777,7 @@ async function startCommand() {
|
|
|
6500
6777
|
}
|
|
6501
6778
|
|
|
6502
6779
|
// src/commands/stop.ts
|
|
6503
|
-
var
|
|
6780
|
+
var import_picocolors11 = __toESM(require_picocolors(), 1);
|
|
6504
6781
|
async function stopCommand() {
|
|
6505
6782
|
const dir = findInstallDir();
|
|
6506
6783
|
const config = readConfig(dir);
|
|
@@ -6508,7 +6785,7 @@ async function stopCommand() {
|
|
|
6508
6785
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6509
6786
|
process.exit(1);
|
|
6510
6787
|
}
|
|
6511
|
-
We(
|
|
6788
|
+
We(import_picocolors11.default.cyan("Stopping LearnHouse"));
|
|
6512
6789
|
try {
|
|
6513
6790
|
dockerComposeDown(config.installDir);
|
|
6514
6791
|
R2.success("LearnHouse stopped.");
|
|
@@ -6548,7 +6825,7 @@ async function logsCommand() {
|
|
|
6548
6825
|
}
|
|
6549
6826
|
|
|
6550
6827
|
// src/commands/config.ts
|
|
6551
|
-
var
|
|
6828
|
+
var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
6552
6829
|
async function configCommand() {
|
|
6553
6830
|
const dir = findInstallDir();
|
|
6554
6831
|
const config = readConfig(dir);
|
|
@@ -6556,25 +6833,25 @@ async function configCommand() {
|
|
|
6556
6833
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6557
6834
|
process.exit(1);
|
|
6558
6835
|
}
|
|
6559
|
-
We(
|
|
6836
|
+
We(import_picocolors12.default.cyan("LearnHouse Configuration"));
|
|
6560
6837
|
const protocol = config.useHttps ? "https" : "http";
|
|
6561
6838
|
const portSuffix = config.useHttps && config.httpPort === 443 || !config.useHttps && config.httpPort === 80 ? "" : `:${config.httpPort}`;
|
|
6562
6839
|
R2.message([
|
|
6563
|
-
` ${
|
|
6564
|
-
` ${
|
|
6565
|
-
` ${
|
|
6566
|
-
` ${
|
|
6567
|
-
` ${
|
|
6840
|
+
` ${import_picocolors12.default.dim("Version:")} ${config.version}`,
|
|
6841
|
+
` ${import_picocolors12.default.dim("Created:")} ${config.createdAt}`,
|
|
6842
|
+
` ${import_picocolors12.default.dim("Directory:")} ${config.installDir}`,
|
|
6843
|
+
` ${import_picocolors12.default.dim("URL:")} ${protocol}://${config.domain}${portSuffix}`,
|
|
6844
|
+
` ${import_picocolors12.default.dim("Org slug:")} ${config.orgSlug}`
|
|
6568
6845
|
].join("\n"));
|
|
6569
|
-
R2.info(
|
|
6570
|
-
R2.info(
|
|
6846
|
+
R2.info(import_picocolors12.default.dim(`Full config: ${dir}/learnhouse.config.json`));
|
|
6847
|
+
R2.info(import_picocolors12.default.dim(`Environment: ${config.installDir}/.env (contains secrets)`));
|
|
6571
6848
|
}
|
|
6572
6849
|
|
|
6573
6850
|
// src/commands/backup.ts
|
|
6574
|
-
import
|
|
6575
|
-
import
|
|
6851
|
+
import fs4 from "fs";
|
|
6852
|
+
import path4 from "path";
|
|
6576
6853
|
import { execSync as execSync2 } from "child_process";
|
|
6577
|
-
var
|
|
6854
|
+
var import_picocolors13 = __toESM(require_picocolors(), 1);
|
|
6578
6855
|
function resolveDbContainer(config) {
|
|
6579
6856
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
6580
6857
|
if (!id) return null;
|
|
@@ -6598,15 +6875,15 @@ async function createBackup() {
|
|
|
6598
6875
|
process.exit(1);
|
|
6599
6876
|
}
|
|
6600
6877
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
6601
|
-
const backupDir =
|
|
6878
|
+
const backupDir = path4.join(installDir, "backups");
|
|
6602
6879
|
const backupName = `learnhouse-backup-${timestamp}`;
|
|
6603
|
-
const tmpDir =
|
|
6604
|
-
const archivePath =
|
|
6605
|
-
|
|
6880
|
+
const tmpDir = path4.join(backupDir, backupName);
|
|
6881
|
+
const archivePath = path4.join(backupDir, `${backupName}.tar.gz`);
|
|
6882
|
+
fs4.mkdirSync(tmpDir, { recursive: true });
|
|
6606
6883
|
const s = bt2();
|
|
6607
6884
|
s.start("Creating database dump");
|
|
6608
6885
|
try {
|
|
6609
|
-
const dumpPath =
|
|
6886
|
+
const dumpPath = path4.join(tmpDir, "database.sql");
|
|
6610
6887
|
dockerExecToFile(
|
|
6611
6888
|
dbContainer,
|
|
6612
6889
|
"pg_dump -U learnhouse learnhouse",
|
|
@@ -6616,12 +6893,12 @@ async function createBackup() {
|
|
|
6616
6893
|
} catch (err) {
|
|
6617
6894
|
s.stop("Database dump failed");
|
|
6618
6895
|
R2.error("Failed to create database dump. Check that the database is running.");
|
|
6619
|
-
|
|
6896
|
+
fs4.rmSync(tmpDir, { recursive: true, force: true });
|
|
6620
6897
|
process.exit(1);
|
|
6621
6898
|
}
|
|
6622
|
-
const envPath =
|
|
6623
|
-
if (
|
|
6624
|
-
|
|
6899
|
+
const envPath = path4.join(installDir, ".env");
|
|
6900
|
+
if (fs4.existsSync(envPath)) {
|
|
6901
|
+
fs4.copyFileSync(envPath, path4.join(tmpDir, ".env"));
|
|
6625
6902
|
}
|
|
6626
6903
|
const s2 = bt2();
|
|
6627
6904
|
s2.start("Creating archive");
|
|
@@ -6635,21 +6912,21 @@ async function createBackup() {
|
|
|
6635
6912
|
R2.error("Failed to create archive.");
|
|
6636
6913
|
process.exit(1);
|
|
6637
6914
|
}
|
|
6638
|
-
|
|
6639
|
-
const stats =
|
|
6915
|
+
fs4.rmSync(tmpDir, { recursive: true, force: true });
|
|
6916
|
+
const stats = fs4.statSync(archivePath);
|
|
6640
6917
|
const sizeMb = (stats.size / (1024 * 1024)).toFixed(1);
|
|
6641
|
-
R2.success(
|
|
6918
|
+
R2.success(import_picocolors13.default.green(import_picocolors13.default.bold("Backup complete!")));
|
|
6642
6919
|
R2.message([
|
|
6643
6920
|
"",
|
|
6644
|
-
` ${
|
|
6645
|
-
` ${
|
|
6921
|
+
` ${import_picocolors13.default.dim("File:")} ${archivePath}`,
|
|
6922
|
+
` ${import_picocolors13.default.dim("Size:")} ${sizeMb} MB`,
|
|
6646
6923
|
"",
|
|
6647
|
-
` ${
|
|
6924
|
+
` ${import_picocolors13.default.dim("Restore with:")} npx learnhouse backup --restore ${archivePath}`,
|
|
6648
6925
|
""
|
|
6649
6926
|
].join("\n"));
|
|
6650
6927
|
}
|
|
6651
6928
|
async function restoreBackup(archivePath) {
|
|
6652
|
-
if (!
|
|
6929
|
+
if (!fs4.existsSync(archivePath)) {
|
|
6653
6930
|
R2.error(`Backup file not found: ${archivePath}`);
|
|
6654
6931
|
process.exit(1);
|
|
6655
6932
|
}
|
|
@@ -6669,7 +6946,7 @@ async function restoreBackup(archivePath) {
|
|
|
6669
6946
|
R2.error("Database container is not running. Start services first.");
|
|
6670
6947
|
process.exit(1);
|
|
6671
6948
|
}
|
|
6672
|
-
R2.warn(
|
|
6949
|
+
R2.warn(import_picocolors13.default.yellow("This will overwrite the current database with the backup data."));
|
|
6673
6950
|
const confirm = await Re({
|
|
6674
6951
|
message: "Are you sure you want to restore from this backup?",
|
|
6675
6952
|
initialValue: false
|
|
@@ -6678,8 +6955,8 @@ async function restoreBackup(archivePath) {
|
|
|
6678
6955
|
Ne("Restore cancelled.");
|
|
6679
6956
|
process.exit(0);
|
|
6680
6957
|
}
|
|
6681
|
-
const tmpDir =
|
|
6682
|
-
|
|
6958
|
+
const tmpDir = path4.join(installDir, ".restore-tmp");
|
|
6959
|
+
fs4.mkdirSync(tmpDir, { recursive: true });
|
|
6683
6960
|
const s = bt2();
|
|
6684
6961
|
s.start("Extracting backup archive");
|
|
6685
6962
|
try {
|
|
@@ -6687,20 +6964,20 @@ async function restoreBackup(archivePath) {
|
|
|
6687
6964
|
s.stop("Archive extracted");
|
|
6688
6965
|
} catch {
|
|
6689
6966
|
s.stop("Extraction failed");
|
|
6690
|
-
|
|
6967
|
+
fs4.rmSync(tmpDir, { recursive: true, force: true });
|
|
6691
6968
|
R2.error("Failed to extract backup archive.");
|
|
6692
6969
|
process.exit(1);
|
|
6693
6970
|
}
|
|
6694
|
-
const entries =
|
|
6971
|
+
const entries = fs4.readdirSync(tmpDir);
|
|
6695
6972
|
const backupFolder = entries.find(
|
|
6696
|
-
(e2) =>
|
|
6973
|
+
(e2) => fs4.existsSync(path4.join(tmpDir, e2, "database.sql"))
|
|
6697
6974
|
);
|
|
6698
6975
|
if (!backupFolder) {
|
|
6699
6976
|
R2.error("No database.sql found in the backup archive.");
|
|
6700
|
-
|
|
6977
|
+
fs4.rmSync(tmpDir, { recursive: true, force: true });
|
|
6701
6978
|
process.exit(1);
|
|
6702
6979
|
}
|
|
6703
|
-
const dumpPath =
|
|
6980
|
+
const dumpPath = path4.join(tmpDir, backupFolder, "database.sql");
|
|
6704
6981
|
const s2 = bt2();
|
|
6705
6982
|
s2.start("Restoring database");
|
|
6706
6983
|
try {
|
|
@@ -6712,32 +6989,32 @@ async function restoreBackup(archivePath) {
|
|
|
6712
6989
|
s2.stop("Database restored");
|
|
6713
6990
|
} catch {
|
|
6714
6991
|
s2.stop("Database restore failed");
|
|
6715
|
-
|
|
6992
|
+
fs4.rmSync(tmpDir, { recursive: true, force: true });
|
|
6716
6993
|
R2.error("Failed to restore database. The backup file may be corrupted.");
|
|
6717
6994
|
process.exit(1);
|
|
6718
6995
|
}
|
|
6719
|
-
const envBackup =
|
|
6720
|
-
if (
|
|
6996
|
+
const envBackup = path4.join(tmpDir, backupFolder, ".env");
|
|
6997
|
+
if (fs4.existsSync(envBackup)) {
|
|
6721
6998
|
const restoreEnv = await Re({
|
|
6722
6999
|
message: "Backup contains a .env file. Restore it? (overwrites current .env)",
|
|
6723
7000
|
initialValue: false
|
|
6724
7001
|
});
|
|
6725
7002
|
if (!Ct(restoreEnv) && restoreEnv) {
|
|
6726
|
-
|
|
7003
|
+
fs4.copyFileSync(envBackup, path4.join(installDir, ".env"));
|
|
6727
7004
|
R2.info(".env file restored");
|
|
6728
7005
|
}
|
|
6729
7006
|
}
|
|
6730
|
-
|
|
6731
|
-
R2.success(
|
|
7007
|
+
fs4.rmSync(tmpDir, { recursive: true, force: true });
|
|
7008
|
+
R2.success(import_picocolors13.default.green(import_picocolors13.default.bold("Restore complete!")));
|
|
6732
7009
|
R2.info("You may want to restart services: npx learnhouse stop && npx learnhouse start");
|
|
6733
7010
|
}
|
|
6734
7011
|
async function backupCommand(archivePath, options) {
|
|
6735
7012
|
if (options?.restore && archivePath) {
|
|
6736
|
-
We(
|
|
7013
|
+
We(import_picocolors13.default.cyan("LearnHouse Restore"));
|
|
6737
7014
|
await restoreBackup(archivePath);
|
|
6738
7015
|
return;
|
|
6739
7016
|
}
|
|
6740
|
-
We(
|
|
7017
|
+
We(import_picocolors13.default.cyan("LearnHouse Backup"));
|
|
6741
7018
|
const action = await Je({
|
|
6742
7019
|
message: "What would you like to do?",
|
|
6743
7020
|
options: [
|
|
@@ -6765,10 +7042,10 @@ async function backupCommand(archivePath, options) {
|
|
|
6765
7042
|
}
|
|
6766
7043
|
|
|
6767
7044
|
// src/commands/deployments.ts
|
|
6768
|
-
import
|
|
6769
|
-
import
|
|
7045
|
+
import fs5 from "fs";
|
|
7046
|
+
import path5 from "path";
|
|
6770
7047
|
import { execSync as execSync3 } from "child_process";
|
|
6771
|
-
var
|
|
7048
|
+
var import_picocolors14 = __toESM(require_picocolors(), 1);
|
|
6772
7049
|
var SERVICES = ["learnhouse-app", "db", "redis"];
|
|
6773
7050
|
function showDeployments() {
|
|
6774
7051
|
let psOutput;
|
|
@@ -6783,7 +7060,7 @@ function showDeployments() {
|
|
|
6783
7060
|
}
|
|
6784
7061
|
if (!psOutput) {
|
|
6785
7062
|
R2.info("No LearnHouse deployments found.");
|
|
6786
|
-
R2.message(
|
|
7063
|
+
R2.message(import_picocolors14.default.dim(" Run npx learnhouse setup to create one."));
|
|
6787
7064
|
return;
|
|
6788
7065
|
}
|
|
6789
7066
|
const deployments = /* @__PURE__ */ new Map();
|
|
@@ -6807,26 +7084,26 @@ function showDeployments() {
|
|
|
6807
7084
|
}
|
|
6808
7085
|
deployments.get(id).containers.push({ name, status, image });
|
|
6809
7086
|
}
|
|
6810
|
-
R2.info(`Found ${
|
|
7087
|
+
R2.info(`Found ${import_picocolors14.default.bold(String(deployments.size))} deployment${deployments.size === 1 ? "" : "s"}`);
|
|
6811
7088
|
console.log();
|
|
6812
7089
|
for (const [id, dep] of deployments) {
|
|
6813
7090
|
const running = dep.containers.filter((c) => c.status.toLowerCase().startsWith("up")).length;
|
|
6814
7091
|
const total = dep.containers.length;
|
|
6815
|
-
const statusColor = running === total ?
|
|
7092
|
+
const statusColor = running === total ? import_picocolors14.default.green : running > 0 ? import_picocolors14.default.yellow : import_picocolors14.default.red;
|
|
6816
7093
|
const statusText = statusColor(`${running}/${total} running`);
|
|
6817
|
-
console.log(` ${
|
|
7094
|
+
console.log(` ${import_picocolors14.default.bold(import_picocolors14.default.white(`Deployment ${id}`))} ${statusText}`);
|
|
6818
7095
|
console.log();
|
|
6819
7096
|
for (const c of dep.containers) {
|
|
6820
7097
|
const isUp = c.status.toLowerCase().startsWith("up");
|
|
6821
|
-
const icon = isUp ?
|
|
7098
|
+
const icon = isUp ? import_picocolors14.default.green("\u25CF") : import_picocolors14.default.red("\u25CF");
|
|
6822
7099
|
const svcName = c.name.replace(`-${id}`, "");
|
|
6823
|
-
console.log(` ${icon} ${
|
|
7100
|
+
console.log(` ${icon} ${import_picocolors14.default.white(svcName.padEnd(24))} ${import_picocolors14.default.dim(c.status)}`);
|
|
6824
7101
|
}
|
|
6825
7102
|
console.log();
|
|
6826
7103
|
}
|
|
6827
7104
|
}
|
|
6828
7105
|
function parseMemLimit(composePath) {
|
|
6829
|
-
const content =
|
|
7106
|
+
const content = fs5.readFileSync(composePath, "utf-8");
|
|
6830
7107
|
const limits = /* @__PURE__ */ new Map();
|
|
6831
7108
|
let currentService = null;
|
|
6832
7109
|
let inServices = false;
|
|
@@ -6893,14 +7170,14 @@ async function scaleResources() {
|
|
|
6893
7170
|
R2.step("Current Resource Usage");
|
|
6894
7171
|
try {
|
|
6895
7172
|
const stats = dockerStats(config.installDir);
|
|
6896
|
-
R2.message(
|
|
7173
|
+
R2.message(import_picocolors14.default.dim(stats.trim()));
|
|
6897
7174
|
} catch {
|
|
6898
7175
|
try {
|
|
6899
7176
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
6900
7177
|
const running = listDeploymentContainers(id || void 0).filter((c) => c.status.toLowerCase().startsWith("up")).map((c) => c.name);
|
|
6901
7178
|
if (running.length > 0) {
|
|
6902
7179
|
const stats = dockerStatsForContainers(running);
|
|
6903
|
-
R2.message(
|
|
7180
|
+
R2.message(import_picocolors14.default.dim(stats.trim()));
|
|
6904
7181
|
} else {
|
|
6905
7182
|
R2.warn("No running containers found.");
|
|
6906
7183
|
}
|
|
@@ -6908,19 +7185,19 @@ async function scaleResources() {
|
|
|
6908
7185
|
R2.warn("Could not retrieve current stats. Services may not be running.");
|
|
6909
7186
|
}
|
|
6910
7187
|
}
|
|
6911
|
-
const composePath =
|
|
6912
|
-
if (!
|
|
7188
|
+
const composePath = path5.join(config.installDir || dir, "docker-compose.yml");
|
|
7189
|
+
if (!fs5.existsSync(composePath)) {
|
|
6913
7190
|
R2.error("docker-compose.yml not found.");
|
|
6914
7191
|
process.exit(1);
|
|
6915
7192
|
}
|
|
6916
|
-
let composeContent =
|
|
7193
|
+
let composeContent = fs5.readFileSync(composePath, "utf-8");
|
|
6917
7194
|
const currentLimits = parseMemLimit(composePath);
|
|
6918
7195
|
R2.step("Set Memory Limits");
|
|
6919
|
-
R2.info(
|
|
7196
|
+
R2.info(import_picocolors14.default.dim("Examples: 256m, 512m, 1g, 2g (leave empty to skip)"));
|
|
6920
7197
|
let changed = false;
|
|
6921
7198
|
for (const service of SERVICES) {
|
|
6922
7199
|
const current = currentLimits.get(service);
|
|
6923
|
-
const label = current ? `Memory limit for ${
|
|
7200
|
+
const label = current ? `Memory limit for ${import_picocolors14.default.bold(service)} (current: ${current})` : `Memory limit for ${import_picocolors14.default.bold(service)} (not set)`;
|
|
6924
7201
|
const value = await text({
|
|
6925
7202
|
message: label,
|
|
6926
7203
|
placeholder: current ? void 0 : "e.g. 512m",
|
|
@@ -6943,7 +7220,7 @@ async function scaleResources() {
|
|
|
6943
7220
|
R2.info("No changes made.");
|
|
6944
7221
|
return;
|
|
6945
7222
|
}
|
|
6946
|
-
|
|
7223
|
+
fs5.writeFileSync(composePath, composeContent);
|
|
6947
7224
|
R2.success("docker-compose.yml updated");
|
|
6948
7225
|
const restart = await Re({
|
|
6949
7226
|
message: "Restart services to apply limits?",
|
|
@@ -6963,7 +7240,7 @@ async function scaleResources() {
|
|
|
6963
7240
|
}
|
|
6964
7241
|
}
|
|
6965
7242
|
async function deploymentsCommand() {
|
|
6966
|
-
We(
|
|
7243
|
+
We(import_picocolors14.default.cyan("LearnHouse Deployments"));
|
|
6967
7244
|
const action = await Je({
|
|
6968
7245
|
message: "What would you like to do?",
|
|
6969
7246
|
options: [
|
|
@@ -6980,24 +7257,24 @@ async function deploymentsCommand() {
|
|
|
6980
7257
|
} else {
|
|
6981
7258
|
await scaleResources();
|
|
6982
7259
|
}
|
|
6983
|
-
Le(
|
|
7260
|
+
Le(import_picocolors14.default.dim("Done"));
|
|
6984
7261
|
}
|
|
6985
7262
|
|
|
6986
7263
|
// src/commands/doctor.ts
|
|
6987
|
-
import
|
|
6988
|
-
import
|
|
7264
|
+
import fs6 from "fs";
|
|
7265
|
+
import path6 from "path";
|
|
6989
7266
|
import { execSync as execSync4 } from "child_process";
|
|
6990
|
-
var
|
|
7267
|
+
var import_picocolors15 = __toESM(require_picocolors(), 1);
|
|
6991
7268
|
function pass(msg) {
|
|
6992
|
-
console.log(` ${
|
|
7269
|
+
console.log(` ${import_picocolors15.default.green("\u2713")} ${msg}`);
|
|
6993
7270
|
}
|
|
6994
7271
|
function warn(msg, fix) {
|
|
6995
|
-
console.log(` ${
|
|
6996
|
-
if (fix) console.log(` ${
|
|
7272
|
+
console.log(` ${import_picocolors15.default.yellow("!")} ${msg}`);
|
|
7273
|
+
if (fix) console.log(` ${import_picocolors15.default.dim(`Fix: ${fix}`)}`);
|
|
6997
7274
|
}
|
|
6998
7275
|
function fail(msg, fix) {
|
|
6999
|
-
console.log(` ${
|
|
7000
|
-
if (fix) console.log(` ${
|
|
7276
|
+
console.log(` ${import_picocolors15.default.red("\u2717")} ${msg}`);
|
|
7277
|
+
if (fix) console.log(` ${import_picocolors15.default.dim(`Fix: ${fix}`)}`);
|
|
7001
7278
|
}
|
|
7002
7279
|
var REQUIRED_ENV_VARS = [
|
|
7003
7280
|
"LEARNHOUSE_DOMAIN",
|
|
@@ -7015,30 +7292,30 @@ var SECRET_ENV_VARS = [
|
|
|
7015
7292
|
async function doctorCommand() {
|
|
7016
7293
|
const dir = findInstallDir();
|
|
7017
7294
|
const config = readConfig(dir);
|
|
7018
|
-
We(
|
|
7295
|
+
We(import_picocolors15.default.cyan("LearnHouse Doctor"));
|
|
7019
7296
|
R2.step("Docker Environment");
|
|
7020
7297
|
if (!isDockerInstalled()) {
|
|
7021
7298
|
fail("Docker not installed", "Install Docker: https://docs.docker.com/get-docker/");
|
|
7022
|
-
Le(
|
|
7299
|
+
Le(import_picocolors15.default.red("Cannot continue without Docker"));
|
|
7023
7300
|
process.exit(1);
|
|
7024
7301
|
}
|
|
7025
7302
|
pass("Docker installed");
|
|
7026
7303
|
if (!isDockerRunning()) {
|
|
7027
7304
|
fail("Docker daemon not running", "Start Docker Desktop or run: sudo systemctl start docker");
|
|
7028
|
-
Le(
|
|
7305
|
+
Le(import_picocolors15.default.red("Cannot continue without Docker running"));
|
|
7029
7306
|
process.exit(1);
|
|
7030
7307
|
}
|
|
7031
7308
|
pass("Docker daemon running");
|
|
7032
7309
|
if (!config) {
|
|
7033
7310
|
R2.warn("No LearnHouse installation found. Skipping deployment checks.");
|
|
7034
|
-
Le(
|
|
7311
|
+
Le(import_picocolors15.default.dim("Done"));
|
|
7035
7312
|
return;
|
|
7036
7313
|
}
|
|
7037
7314
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
7038
7315
|
const installDir = dir;
|
|
7039
7316
|
if (!id) {
|
|
7040
7317
|
R2.warn("No deployment ID found. Skipping container checks.");
|
|
7041
|
-
Le(
|
|
7318
|
+
Le(import_picocolors15.default.dim("Done"));
|
|
7042
7319
|
return;
|
|
7043
7320
|
}
|
|
7044
7321
|
R2.step("Containers");
|
|
@@ -7109,7 +7386,7 @@ async function doctorCommand() {
|
|
|
7109
7386
|
}
|
|
7110
7387
|
try {
|
|
7111
7388
|
const diskUsage = getDockerDiskUsage();
|
|
7112
|
-
R2.message(
|
|
7389
|
+
R2.message(import_picocolors15.default.dim(diskUsage.trim()));
|
|
7113
7390
|
} catch {
|
|
7114
7391
|
}
|
|
7115
7392
|
R2.step("Log Analysis");
|
|
@@ -7123,7 +7400,7 @@ async function doctorCommand() {
|
|
|
7123
7400
|
if (errorLines.length > 0) {
|
|
7124
7401
|
warn(`${svcName} \u2014 ${errorLines.length} error(s) in last 50 log lines`);
|
|
7125
7402
|
for (const line of errorLines.slice(0, 3)) {
|
|
7126
|
-
console.log(` ${
|
|
7403
|
+
console.log(` ${import_picocolors15.default.dim(line.trim().slice(0, 120))}`);
|
|
7127
7404
|
}
|
|
7128
7405
|
} else {
|
|
7129
7406
|
pass(`${svcName} \u2014 no errors in recent logs`);
|
|
@@ -7133,11 +7410,11 @@ async function doctorCommand() {
|
|
|
7133
7410
|
}
|
|
7134
7411
|
}
|
|
7135
7412
|
R2.step("Environment File");
|
|
7136
|
-
const envPath =
|
|
7137
|
-
if (!
|
|
7413
|
+
const envPath = path6.join(installDir, ".env");
|
|
7414
|
+
if (!fs6.existsSync(envPath)) {
|
|
7138
7415
|
fail(".env file missing", "Run setup again: npx learnhouse setup");
|
|
7139
7416
|
} else {
|
|
7140
|
-
const envContent =
|
|
7417
|
+
const envContent = fs6.readFileSync(envPath, "utf-8");
|
|
7141
7418
|
const envMap = /* @__PURE__ */ new Map();
|
|
7142
7419
|
for (const line of envContent.split("\n")) {
|
|
7143
7420
|
const trimmed = line.trim();
|
|
@@ -7177,11 +7454,11 @@ async function doctorCommand() {
|
|
|
7177
7454
|
}
|
|
7178
7455
|
}
|
|
7179
7456
|
console.log();
|
|
7180
|
-
Le(
|
|
7457
|
+
Le(import_picocolors15.default.dim("Diagnosis complete"));
|
|
7181
7458
|
}
|
|
7182
7459
|
|
|
7183
7460
|
// src/commands/shell.ts
|
|
7184
|
-
var
|
|
7461
|
+
var import_picocolors16 = __toESM(require_picocolors(), 1);
|
|
7185
7462
|
async function shellCommand() {
|
|
7186
7463
|
const dir = findInstallDir();
|
|
7187
7464
|
const config = readConfig(dir);
|
|
@@ -7203,7 +7480,7 @@ async function shellCommand() {
|
|
|
7203
7480
|
message: "Select a container",
|
|
7204
7481
|
options: containers.map((c) => ({
|
|
7205
7482
|
value: c.name,
|
|
7206
|
-
label: `${c.name.replace(`-${id}`, "")} ${
|
|
7483
|
+
label: `${c.name.replace(`-${id}`, "")} ${import_picocolors16.default.dim(`(${c.name})`)}`
|
|
7207
7484
|
}))
|
|
7208
7485
|
});
|
|
7209
7486
|
if (Ct(selected)) {
|
|
@@ -7216,15 +7493,15 @@ async function shellCommand() {
|
|
|
7216
7493
|
|
|
7217
7494
|
// src/commands/dev.ts
|
|
7218
7495
|
import { spawn as spawn2, spawnSync as spawnSync2, execSync as execSync5 } from "child_process";
|
|
7219
|
-
var
|
|
7220
|
-
import * as
|
|
7221
|
-
import * as
|
|
7496
|
+
var import_picocolors18 = __toESM(require_picocolors(), 1);
|
|
7497
|
+
import * as path8 from "path";
|
|
7498
|
+
import * as fs8 from "fs";
|
|
7222
7499
|
|
|
7223
7500
|
// src/services/env-check.ts
|
|
7224
|
-
import * as
|
|
7225
|
-
import * as
|
|
7501
|
+
import * as fs7 from "fs";
|
|
7502
|
+
import * as path7 from "path";
|
|
7226
7503
|
import * as crypto4 from "crypto";
|
|
7227
|
-
var
|
|
7504
|
+
var import_picocolors17 = __toESM(require_picocolors(), 1);
|
|
7228
7505
|
function generateJwtSecret() {
|
|
7229
7506
|
return crypto4.randomBytes(32).toString("base64url");
|
|
7230
7507
|
}
|
|
@@ -7293,8 +7570,8 @@ var COLLAB_ENV = {
|
|
|
7293
7570
|
var ALL_APPS = [API_ENV, WEB_ENV, COLLAB_ENV];
|
|
7294
7571
|
function parseEnvFile(filePath) {
|
|
7295
7572
|
const vars = /* @__PURE__ */ new Map();
|
|
7296
|
-
if (!
|
|
7297
|
-
for (const line of
|
|
7573
|
+
if (!fs7.existsSync(filePath)) return vars;
|
|
7574
|
+
for (const line of fs7.readFileSync(filePath, "utf-8").split("\n")) {
|
|
7298
7575
|
const trimmed = line.trim();
|
|
7299
7576
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
7300
7577
|
const eq = trimmed.indexOf("=");
|
|
@@ -7312,17 +7589,17 @@ function parseEnvFile(filePath) {
|
|
|
7312
7589
|
}
|
|
7313
7590
|
function appendToEnvFile(filePath, newVars) {
|
|
7314
7591
|
let content = "";
|
|
7315
|
-
if (
|
|
7316
|
-
content =
|
|
7592
|
+
if (fs7.existsSync(filePath)) {
|
|
7593
|
+
content = fs7.readFileSync(filePath, "utf-8");
|
|
7317
7594
|
if (content.length > 0 && !content.endsWith("\n")) content += "\n";
|
|
7318
7595
|
}
|
|
7319
7596
|
for (const [key, value] of newVars) {
|
|
7320
7597
|
content += `${key}=${value}
|
|
7321
7598
|
`;
|
|
7322
7599
|
}
|
|
7323
|
-
const dir =
|
|
7324
|
-
if (!
|
|
7325
|
-
|
|
7600
|
+
const dir = path7.dirname(filePath);
|
|
7601
|
+
if (!fs7.existsSync(dir)) fs7.mkdirSync(dir, { recursive: true });
|
|
7602
|
+
fs7.writeFileSync(filePath, content);
|
|
7326
7603
|
}
|
|
7327
7604
|
function resolveDefault(v) {
|
|
7328
7605
|
return typeof v.defaultValue === "function" ? v.defaultValue() : v.defaultValue;
|
|
@@ -7330,7 +7607,7 @@ function resolveDefault(v) {
|
|
|
7330
7607
|
async function checkDevEnv(root) {
|
|
7331
7608
|
const missing = [];
|
|
7332
7609
|
for (const app of ALL_APPS) {
|
|
7333
|
-
const existing = parseEnvFile(
|
|
7610
|
+
const existing = parseEnvFile(path7.join(root, app.envFile));
|
|
7334
7611
|
for (const v of app.vars) {
|
|
7335
7612
|
const val = existing.get(v.name);
|
|
7336
7613
|
if (v.required && (!val || val.length === 0)) {
|
|
@@ -7351,9 +7628,9 @@ async function checkDevEnv(root) {
|
|
|
7351
7628
|
byApp.set(m.app.label, list);
|
|
7352
7629
|
}
|
|
7353
7630
|
for (const [label, vars] of byApp) {
|
|
7354
|
-
console.log(` ${
|
|
7631
|
+
console.log(` ${import_picocolors17.default.bold(label)} ${import_picocolors17.default.dim(`(${vars[0].app.envFile})`)}`);
|
|
7355
7632
|
for (const m of vars) {
|
|
7356
|
-
console.log(` ${
|
|
7633
|
+
console.log(` ${import_picocolors17.default.red("\u2717")} ${import_picocolors17.default.cyan(m.envVar.name)} \u2014 ${import_picocolors17.default.dim(m.envVar.description)}`);
|
|
7357
7634
|
}
|
|
7358
7635
|
console.log();
|
|
7359
7636
|
}
|
|
@@ -7368,12 +7645,12 @@ async function checkDevEnv(root) {
|
|
|
7368
7645
|
R2.info("Set the missing variables and run the command again.");
|
|
7369
7646
|
return false;
|
|
7370
7647
|
}
|
|
7371
|
-
const apiFile =
|
|
7648
|
+
const apiFile = path7.join(root, API_ENV.envFile);
|
|
7372
7649
|
const apiExisting = parseEnvFile(apiFile);
|
|
7373
7650
|
const jwtSecret = apiExisting.get("LEARNHOUSE_AUTH_JWT_SECRET_KEY") || generateJwtSecret();
|
|
7374
7651
|
const collabKey = apiExisting.get("COLLAB_INTERNAL_KEY") || "dev-collab-internal-key-change-in-prod";
|
|
7375
7652
|
for (const app of ALL_APPS) {
|
|
7376
|
-
const filePath =
|
|
7653
|
+
const filePath = path7.join(root, app.envFile);
|
|
7377
7654
|
const existing = parseEnvFile(filePath);
|
|
7378
7655
|
const toWrite = /* @__PURE__ */ new Map();
|
|
7379
7656
|
for (const v of app.vars) {
|
|
@@ -7389,8 +7666,8 @@ async function checkDevEnv(root) {
|
|
|
7389
7666
|
}
|
|
7390
7667
|
if (toWrite.size > 0) {
|
|
7391
7668
|
appendToEnvFile(filePath, toWrite);
|
|
7392
|
-
const names = [...toWrite.keys()].map((k2) =>
|
|
7393
|
-
R2.success(`${
|
|
7669
|
+
const names = [...toWrite.keys()].map((k2) => import_picocolors17.default.cyan(k2)).join(", ");
|
|
7670
|
+
R2.success(`${import_picocolors17.default.bold(app.label)}: wrote ${names} \u2192 ${import_picocolors17.default.dim(app.envFile)}`);
|
|
7394
7671
|
}
|
|
7395
7672
|
}
|
|
7396
7673
|
console.log();
|
|
@@ -7442,19 +7719,19 @@ volumes:
|
|
|
7442
7719
|
function findProjectRoot() {
|
|
7443
7720
|
let dir = process.cwd();
|
|
7444
7721
|
while (true) {
|
|
7445
|
-
if (
|
|
7722
|
+
if (fs8.existsSync(path8.join(dir, "apps", "api")) && fs8.existsSync(path8.join(dir, "apps", "web"))) {
|
|
7446
7723
|
return dir;
|
|
7447
7724
|
}
|
|
7448
|
-
const parent =
|
|
7725
|
+
const parent = path8.dirname(dir);
|
|
7449
7726
|
if (parent === dir) return null;
|
|
7450
7727
|
dir = parent;
|
|
7451
7728
|
}
|
|
7452
7729
|
}
|
|
7453
7730
|
function getDevComposePath(root) {
|
|
7454
|
-
const dotDir =
|
|
7455
|
-
if (!
|
|
7456
|
-
const composePath =
|
|
7457
|
-
|
|
7731
|
+
const dotDir = path8.join(root, ".learnhouse");
|
|
7732
|
+
if (!fs8.existsSync(dotDir)) fs8.mkdirSync(dotDir, { recursive: true });
|
|
7733
|
+
const composePath = path8.join(dotDir, "docker-compose.dev.yml");
|
|
7734
|
+
fs8.writeFileSync(composePath, DEV_COMPOSE);
|
|
7458
7735
|
return composePath;
|
|
7459
7736
|
}
|
|
7460
7737
|
function sleep(ms) {
|
|
@@ -7471,7 +7748,7 @@ async function waitForHealth2(label, command, args, maxAttempts = 30) {
|
|
|
7471
7748
|
}
|
|
7472
7749
|
return false;
|
|
7473
7750
|
}
|
|
7474
|
-
var CONTROLS_BAR =
|
|
7751
|
+
var CONTROLS_BAR = import_picocolors18.default.dim("\u2500".repeat(60)) + "\n" + import_picocolors18.default.dim(" ") + import_picocolors18.default.bold("ra") + import_picocolors18.default.dim(" restart api ") + import_picocolors18.default.bold("rw") + import_picocolors18.default.dim(" restart web ") + import_picocolors18.default.bold("rc") + import_picocolors18.default.dim(" restart collab ") + import_picocolors18.default.bold("rb") + import_picocolors18.default.dim(" restart all ") + import_picocolors18.default.bold("q") + import_picocolors18.default.dim(" quit") + "\n" + import_picocolors18.default.dim("\u2500".repeat(60));
|
|
7475
7752
|
var lineCount = 0;
|
|
7476
7753
|
var CONTROLS_INTERVAL = 50;
|
|
7477
7754
|
function printControls() {
|
|
@@ -7512,7 +7789,7 @@ function isInfraRunning() {
|
|
|
7512
7789
|
}
|
|
7513
7790
|
var serviceEnv = {};
|
|
7514
7791
|
function spawnService(command, args, cwd, label, color) {
|
|
7515
|
-
const localBin =
|
|
7792
|
+
const localBin = path8.join(cwd, "node_modules", ".bin");
|
|
7516
7793
|
const child = spawn2(command, args, {
|
|
7517
7794
|
cwd,
|
|
7518
7795
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -7520,7 +7797,7 @@ function spawnService(command, args, cwd, label, color) {
|
|
|
7520
7797
|
env: {
|
|
7521
7798
|
...process.env,
|
|
7522
7799
|
...serviceEnv,
|
|
7523
|
-
PATH: `${localBin}${
|
|
7800
|
+
PATH: `${localBin}${path8.delimiter}${process.env.PATH ?? ""}`
|
|
7524
7801
|
}
|
|
7525
7802
|
});
|
|
7526
7803
|
prefixStream(child, label, color);
|
|
@@ -7553,17 +7830,17 @@ async function devCommand(opts) {
|
|
|
7553
7830
|
R2.info("Run this command from within the learnhouse monorepo (must contain dev/docker-compose.yml, apps/api/, and apps/web/).");
|
|
7554
7831
|
process.exit(1);
|
|
7555
7832
|
}
|
|
7556
|
-
We(
|
|
7833
|
+
We(import_picocolors18.default.cyan("LearnHouse Dev Mode"));
|
|
7557
7834
|
const envOk = await checkDevEnv(root);
|
|
7558
7835
|
if (!envOk) process.exit(1);
|
|
7559
|
-
const eePath =
|
|
7836
|
+
const eePath = path8.join(root, "apps", "api", "ee");
|
|
7560
7837
|
if (opts.ee) {
|
|
7561
|
-
if (!
|
|
7562
|
-
const parentDir =
|
|
7563
|
-
const eeRepoPath =
|
|
7564
|
-
if (
|
|
7838
|
+
if (!fs8.existsSync(eePath)) {
|
|
7839
|
+
const parentDir = path8.dirname(root);
|
|
7840
|
+
const eeRepoPath = path8.join(parentDir, "ee", "apps", "api", "ee");
|
|
7841
|
+
if (fs8.existsSync(eeRepoPath)) {
|
|
7565
7842
|
try {
|
|
7566
|
-
|
|
7843
|
+
fs8.symlinkSync(eeRepoPath, eePath);
|
|
7567
7844
|
R2.success(`Linked EE folder \u2192 ${eeRepoPath}`);
|
|
7568
7845
|
} catch (err) {
|
|
7569
7846
|
R2.warning(`Could not create EE symlink: ${err.message}`);
|
|
@@ -7572,8 +7849,8 @@ async function devCommand(opts) {
|
|
|
7572
7849
|
R2.warning(`--ee passed but no ee/ folder found at ${eeRepoPath} \u2014 running in OSS mode`);
|
|
7573
7850
|
}
|
|
7574
7851
|
}
|
|
7575
|
-
if (
|
|
7576
|
-
R2.info(`Running in ${
|
|
7852
|
+
if (fs8.existsSync(eePath)) {
|
|
7853
|
+
R2.info(`Running in ${import_picocolors18.default.bold("EE")} mode`);
|
|
7577
7854
|
}
|
|
7578
7855
|
}
|
|
7579
7856
|
if (!isDockerInstalled()) {
|
|
@@ -7649,15 +7926,15 @@ async function devCommand(opts) {
|
|
|
7649
7926
|
process.exit(1);
|
|
7650
7927
|
}
|
|
7651
7928
|
healthSpinner.stop("DB and Redis are healthy");
|
|
7652
|
-
const webDir =
|
|
7653
|
-
const collabDir =
|
|
7654
|
-
const apiDir =
|
|
7929
|
+
const webDir = path8.join(root, "apps", "web");
|
|
7930
|
+
const collabDir = path8.join(root, "apps", "collab");
|
|
7931
|
+
const apiDir = path8.join(root, "apps", "api");
|
|
7655
7932
|
const bunProjects = [
|
|
7656
7933
|
{ label: "web", dir: webDir },
|
|
7657
7934
|
{ label: "collab", dir: collabDir }
|
|
7658
7935
|
];
|
|
7659
7936
|
for (const { label, dir } of bunProjects) {
|
|
7660
|
-
if (!
|
|
7937
|
+
if (!fs8.existsSync(path8.join(dir, "node_modules"))) {
|
|
7661
7938
|
R2.info(`Installing ${label} dependencies...`);
|
|
7662
7939
|
const result = spawnSync2("bun", ["install"], { cwd: dir, stdio: "inherit", shell: true });
|
|
7663
7940
|
if (result.status !== 0) {
|
|
@@ -7666,7 +7943,7 @@ async function devCommand(opts) {
|
|
|
7666
7943
|
}
|
|
7667
7944
|
}
|
|
7668
7945
|
}
|
|
7669
|
-
if (!
|
|
7946
|
+
if (!fs8.existsSync(path8.join(apiDir, ".venv"))) {
|
|
7670
7947
|
R2.info("Installing API dependencies...");
|
|
7671
7948
|
const result = spawnSync2("uv", ["sync"], { cwd: apiDir, stdio: "inherit", shell: true });
|
|
7672
7949
|
if (result.status !== 0) {
|
|
@@ -7678,35 +7955,35 @@ async function devCommand(opts) {
|
|
|
7678
7955
|
let webProc = null;
|
|
7679
7956
|
let collabProc = null;
|
|
7680
7957
|
const startApi = () => {
|
|
7681
|
-
return spawnService("uv", ["run", "python", "app.py"],
|
|
7958
|
+
return spawnService("uv", ["run", "python", "app.py"], path8.join(root, "apps", "api"), "api", import_picocolors18.default.magenta);
|
|
7682
7959
|
};
|
|
7683
7960
|
const startWeb = () => {
|
|
7684
|
-
return spawnService("next", ["dev", "--turbopack"],
|
|
7961
|
+
return spawnService("next", ["dev", "--turbopack"], path8.join(root, "apps", "web"), "web", import_picocolors18.default.cyan);
|
|
7685
7962
|
};
|
|
7686
7963
|
const startCollab = () => {
|
|
7687
|
-
return spawnService("tsx", ["watch", "src/index.ts"],
|
|
7964
|
+
return spawnService("tsx", ["watch", "src/index.ts"], path8.join(root, "apps", "collab"), "collab", import_picocolors18.default.yellow);
|
|
7688
7965
|
};
|
|
7689
7966
|
apiProc = startApi();
|
|
7690
7967
|
webProc = startWeb();
|
|
7691
7968
|
collabProc = startCollab();
|
|
7692
7969
|
R2.success("API, Web, and Collab servers started");
|
|
7693
7970
|
console.log();
|
|
7694
|
-
console.log(
|
|
7971
|
+
console.log(import_picocolors18.default.dim(" Thank you for contributing to LearnHouse!"));
|
|
7695
7972
|
console.log();
|
|
7696
7973
|
printControls();
|
|
7697
7974
|
let shuttingDown = false;
|
|
7698
7975
|
const shutdown = async () => {
|
|
7699
7976
|
if (shuttingDown) return;
|
|
7700
7977
|
shuttingDown = true;
|
|
7701
|
-
console.log("\n" +
|
|
7978
|
+
console.log("\n" + import_picocolors18.default.dim("Shutting down dev servers..."));
|
|
7702
7979
|
if (process.stdin.isTTY && process.stdin.isRaw) {
|
|
7703
7980
|
process.stdin.setRawMode(false);
|
|
7704
7981
|
}
|
|
7705
7982
|
process.stdin.pause();
|
|
7706
7983
|
await Promise.all([killProcess(apiProc), killProcess(webProc), killProcess(collabProc)]);
|
|
7707
|
-
console.log(
|
|
7708
|
-
console.log(
|
|
7709
|
-
console.log(
|
|
7984
|
+
console.log(import_picocolors18.default.dim("DB and Redis containers are still running for next session."));
|
|
7985
|
+
console.log(import_picocolors18.default.dim("To stop them: docker compose -f .learnhouse/docker-compose.dev.yml -p learnhouse-dev down"));
|
|
7986
|
+
console.log(import_picocolors18.default.dim("Thanks for building with LearnHouse!"));
|
|
7710
7987
|
process.exit(0);
|
|
7711
7988
|
};
|
|
7712
7989
|
process.on("SIGINT", shutdown);
|
|
@@ -7735,22 +8012,22 @@ async function devCommand(opts) {
|
|
|
7735
8012
|
if (pendingR) {
|
|
7736
8013
|
pendingR = false;
|
|
7737
8014
|
if (key === "a") {
|
|
7738
|
-
console.log(
|
|
8015
|
+
console.log(import_picocolors18.default.magenta("\n Restarting API...\n"));
|
|
7739
8016
|
await killProcess(apiProc);
|
|
7740
8017
|
apiProc = startApi();
|
|
7741
8018
|
printControls();
|
|
7742
8019
|
} else if (key === "w") {
|
|
7743
|
-
console.log(
|
|
8020
|
+
console.log(import_picocolors18.default.cyan("\n Restarting Web...\n"));
|
|
7744
8021
|
await killProcess(webProc);
|
|
7745
8022
|
webProc = startWeb();
|
|
7746
8023
|
printControls();
|
|
7747
8024
|
} else if (key === "c") {
|
|
7748
|
-
console.log(
|
|
8025
|
+
console.log(import_picocolors18.default.yellow("\n Restarting Collab...\n"));
|
|
7749
8026
|
await killProcess(collabProc);
|
|
7750
8027
|
collabProc = startCollab();
|
|
7751
8028
|
printControls();
|
|
7752
8029
|
} else if (key === "b") {
|
|
7753
|
-
console.log(
|
|
8030
|
+
console.log(import_picocolors18.default.yellow("\n Restarting all...\n"));
|
|
7754
8031
|
await Promise.all([killProcess(apiProc), killProcess(webProc), killProcess(collabProc)]);
|
|
7755
8032
|
apiProc = startApi();
|
|
7756
8033
|
webProc = startWeb();
|
|
@@ -7768,7 +8045,7 @@ async function devCommand(opts) {
|
|
|
7768
8045
|
import { execSync as execSync6 } from "child_process";
|
|
7769
8046
|
import { readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
7770
8047
|
import { join as join3 } from "path";
|
|
7771
|
-
var
|
|
8048
|
+
var import_picocolors19 = __toESM(require_picocolors(), 1);
|
|
7772
8049
|
var GHCR_BASE2 = "ghcr.io/learnhouse/app";
|
|
7773
8050
|
async function resolveTag(version) {
|
|
7774
8051
|
try {
|
|
@@ -7802,9 +8079,9 @@ async function updateCommand(options) {
|
|
|
7802
8079
|
}
|
|
7803
8080
|
const targetVersion = options.version?.replace(/^v/, "");
|
|
7804
8081
|
if (targetVersion) {
|
|
7805
|
-
We(
|
|
8082
|
+
We(import_picocolors19.default.cyan(`Updating LearnHouse to v${targetVersion}`));
|
|
7806
8083
|
} else {
|
|
7807
|
-
We(
|
|
8084
|
+
We(import_picocolors19.default.cyan("Updating LearnHouse to latest"));
|
|
7808
8085
|
}
|
|
7809
8086
|
const s = bt2();
|
|
7810
8087
|
try {
|
|
@@ -7838,6 +8115,33 @@ async function updateCommand(options) {
|
|
|
7838
8115
|
writeFileSync3(composePath, updatedCompose);
|
|
7839
8116
|
s.start("Pulling image");
|
|
7840
8117
|
s.stop("Image reference updated");
|
|
8118
|
+
s.start("Checking content storage");
|
|
8119
|
+
try {
|
|
8120
|
+
const migration = migrateContentVolume(config.installDir, config.deploymentId);
|
|
8121
|
+
switch (migration.status) {
|
|
8122
|
+
case "migrated":
|
|
8123
|
+
s.stop(
|
|
8124
|
+
`Migrated uploaded content into persistent volume (${formatBytes(migration.copiedBytes ?? 0)})`
|
|
8125
|
+
);
|
|
8126
|
+
break;
|
|
8127
|
+
case "patched_no_data":
|
|
8128
|
+
s.stop("Added persistent content volume to docker-compose.yml");
|
|
8129
|
+
break;
|
|
8130
|
+
case "already_mounted":
|
|
8131
|
+
s.stop("Content storage already persistent");
|
|
8132
|
+
break;
|
|
8133
|
+
case "skipped_s3":
|
|
8134
|
+
s.stop("Content served from S3 \u2014 no local volume needed");
|
|
8135
|
+
break;
|
|
8136
|
+
case "no_compose":
|
|
8137
|
+
s.stop("Skipped content migration (no docker-compose.yml found)");
|
|
8138
|
+
break;
|
|
8139
|
+
}
|
|
8140
|
+
} catch (err) {
|
|
8141
|
+
s.stop("Content migration failed");
|
|
8142
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
8143
|
+
R2.warn(`Could not migrate uploaded content: ${msg}`);
|
|
8144
|
+
}
|
|
7841
8145
|
s.start("Restarting services");
|
|
7842
8146
|
dockerComposeDown(config.installDir);
|
|
7843
8147
|
dockerComposeUp(config.installDir);
|
|
@@ -7850,10 +8154,10 @@ async function updateCommand(options) {
|
|
|
7850
8154
|
} else {
|
|
7851
8155
|
R2.info("");
|
|
7852
8156
|
R2.warn(
|
|
7853
|
-
|
|
8157
|
+
import_picocolors19.default.bold("This update may include database migrations.")
|
|
7854
8158
|
);
|
|
7855
8159
|
R2.info(
|
|
7856
|
-
`Before proceeding, check the release notes at ${
|
|
8160
|
+
`Before proceeding, check the release notes at ${import_picocolors19.default.cyan("https://docs.learnhouse.app")} for migration guides and breaking changes.`
|
|
7857
8161
|
);
|
|
7858
8162
|
R2.info("");
|
|
7859
8163
|
const runMigrations = await Re({
|
|
@@ -7907,6 +8211,12 @@ async function updateCommand(options) {
|
|
|
7907
8211
|
process.exit(1);
|
|
7908
8212
|
}
|
|
7909
8213
|
}
|
|
8214
|
+
function formatBytes(bytes) {
|
|
8215
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
8216
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
8217
|
+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
8218
|
+
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
8219
|
+
}
|
|
7910
8220
|
function getAppContainerName(cwd) {
|
|
7911
8221
|
try {
|
|
7912
8222
|
const output = execSync6('docker compose ps --format "{{.Name}}"', {
|
|
@@ -7943,7 +8253,7 @@ function waitForContainer(containerName, timeoutMs = 6e4) {
|
|
|
7943
8253
|
}
|
|
7944
8254
|
|
|
7945
8255
|
// src/commands/status.ts
|
|
7946
|
-
var
|
|
8256
|
+
var import_picocolors20 = __toESM(require_picocolors(), 1);
|
|
7947
8257
|
async function statusCommand() {
|
|
7948
8258
|
const dir = findInstallDir();
|
|
7949
8259
|
const config = readConfig(dir);
|
|
@@ -7951,7 +8261,7 @@ async function statusCommand() {
|
|
|
7951
8261
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
7952
8262
|
process.exit(1);
|
|
7953
8263
|
}
|
|
7954
|
-
We(
|
|
8264
|
+
We(import_picocolors20.default.cyan("LearnHouse Status"));
|
|
7955
8265
|
const protocol = config.useHttps ? "https" : "http";
|
|
7956
8266
|
const portSuffix = config.useHttps && config.httpPort === 443 || !config.useHttps && config.httpPort === 80 ? "" : `:${config.httpPort}`;
|
|
7957
8267
|
R2.info(`URL: ${protocol}://${config.domain}${portSuffix}`);
|
|
@@ -7965,12 +8275,12 @@ async function statusCommand() {
|
|
|
7965
8275
|
}
|
|
7966
8276
|
|
|
7967
8277
|
// src/commands/health.ts
|
|
7968
|
-
var
|
|
8278
|
+
var import_picocolors21 = __toESM(require_picocolors(), 1);
|
|
7969
8279
|
function pass2(msg) {
|
|
7970
|
-
return `${
|
|
8280
|
+
return `${import_picocolors21.default.green("\u25CF")} ${msg}`;
|
|
7971
8281
|
}
|
|
7972
8282
|
function fail2(msg) {
|
|
7973
|
-
return `${
|
|
8283
|
+
return `${import_picocolors21.default.red("\u25CF")} ${msg}`;
|
|
7974
8284
|
}
|
|
7975
8285
|
async function healthCommand() {
|
|
7976
8286
|
const dir = findInstallDir();
|
|
@@ -7979,7 +8289,7 @@ async function healthCommand() {
|
|
|
7979
8289
|
R2.error("No LearnHouse installation found. Run setup first.");
|
|
7980
8290
|
process.exit(1);
|
|
7981
8291
|
}
|
|
7982
|
-
We(
|
|
8292
|
+
We(import_picocolors21.default.cyan("LearnHouse Health Check"));
|
|
7983
8293
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
7984
8294
|
if (!id) {
|
|
7985
8295
|
R2.error("No deployment found. Start services first.");
|
|
@@ -8039,20 +8349,20 @@ async function healthCommand() {
|
|
|
8039
8349
|
R2.step("Disk Usage");
|
|
8040
8350
|
try {
|
|
8041
8351
|
const diskOutput = getDockerDiskUsage();
|
|
8042
|
-
R2.message(
|
|
8352
|
+
R2.message(import_picocolors21.default.dim(diskOutput.trim()));
|
|
8043
8353
|
} catch {
|
|
8044
8354
|
R2.message(fail2("Could not retrieve disk usage"));
|
|
8045
8355
|
}
|
|
8046
8356
|
R2.step("Resource Usage");
|
|
8047
8357
|
try {
|
|
8048
8358
|
const stats = dockerStats(config.installDir);
|
|
8049
|
-
R2.message(
|
|
8359
|
+
R2.message(import_picocolors21.default.dim(stats.trim()));
|
|
8050
8360
|
} catch {
|
|
8051
8361
|
try {
|
|
8052
8362
|
const names = containers.filter((c) => c.status.toLowerCase().startsWith("up")).map((c) => c.name);
|
|
8053
8363
|
if (names.length > 0) {
|
|
8054
8364
|
const stats = dockerStatsForContainers(names);
|
|
8055
|
-
R2.message(
|
|
8365
|
+
R2.message(import_picocolors21.default.dim(stats.trim()));
|
|
8056
8366
|
} else {
|
|
8057
8367
|
R2.message(fail2("No running containers to get stats from"));
|
|
8058
8368
|
}
|
|
@@ -8060,13 +8370,13 @@ async function healthCommand() {
|
|
|
8060
8370
|
R2.message(fail2("Could not retrieve resource stats"));
|
|
8061
8371
|
}
|
|
8062
8372
|
}
|
|
8063
|
-
Le(
|
|
8373
|
+
Le(import_picocolors21.default.dim("Health check complete"));
|
|
8064
8374
|
}
|
|
8065
8375
|
|
|
8066
8376
|
// src/commands/env.ts
|
|
8067
|
-
import
|
|
8068
|
-
import
|
|
8069
|
-
var
|
|
8377
|
+
import fs9 from "fs";
|
|
8378
|
+
import path9 from "path";
|
|
8379
|
+
var import_picocolors22 = __toESM(require_picocolors(), 1);
|
|
8070
8380
|
var SECRET_PATTERNS = ["PASSWORD", "SECRET", "API_KEY", "CLIENT_SECRET"];
|
|
8071
8381
|
var CATEGORIES = {
|
|
8072
8382
|
domain: {
|
|
@@ -8187,13 +8497,13 @@ async function envCommand() {
|
|
|
8187
8497
|
R2.error("No LearnHouse installation found. Run setup first.");
|
|
8188
8498
|
process.exit(1);
|
|
8189
8499
|
}
|
|
8190
|
-
const envPath =
|
|
8191
|
-
if (!
|
|
8500
|
+
const envPath = path9.join(config.installDir, ".env");
|
|
8501
|
+
if (!fs9.existsSync(envPath)) {
|
|
8192
8502
|
R2.error(`No .env file found at ${envPath}`);
|
|
8193
8503
|
process.exit(1);
|
|
8194
8504
|
}
|
|
8195
|
-
We(
|
|
8196
|
-
const originalContent =
|
|
8505
|
+
We(import_picocolors22.default.cyan("LearnHouse Environment Editor"));
|
|
8506
|
+
const originalContent = fs9.readFileSync(envPath, "utf-8");
|
|
8197
8507
|
const envMap = parseEnv(originalContent);
|
|
8198
8508
|
let editing = true;
|
|
8199
8509
|
while (editing) {
|
|
@@ -8201,7 +8511,7 @@ async function envCommand() {
|
|
|
8201
8511
|
message: "Select a category to edit",
|
|
8202
8512
|
options: [
|
|
8203
8513
|
...Object.entries(CATEGORIES).map(([value, { label }]) => ({ value, label })),
|
|
8204
|
-
{ value: "_done", label:
|
|
8514
|
+
{ value: "_done", label: import_picocolors22.default.dim("Done editing") }
|
|
8205
8515
|
]
|
|
8206
8516
|
});
|
|
8207
8517
|
if (Ct(category) || category === "_done") {
|
|
@@ -8217,14 +8527,14 @@ async function envCommand() {
|
|
|
8217
8527
|
}
|
|
8218
8528
|
R2.step(`${cat.label} \u2014 Current Values`);
|
|
8219
8529
|
for (const key2 of presentKeys) {
|
|
8220
|
-
R2.message(` ${
|
|
8530
|
+
R2.message(` ${import_picocolors22.default.dim(key2)} = ${maskValue(key2, envMap.get(key2))}`);
|
|
8221
8531
|
}
|
|
8222
8532
|
const keyToEdit = await Je({
|
|
8223
8533
|
message: "Select a variable to edit",
|
|
8224
8534
|
options: [
|
|
8225
8535
|
...presentKeys.map((k2) => ({ value: k2, label: `${k2} = ${maskValue(k2, envMap.get(k2))}` })),
|
|
8226
|
-
...missingKeys.map((k2) => ({ value: k2, label: `${k2} ${
|
|
8227
|
-
{ value: "_back", label:
|
|
8536
|
+
...missingKeys.map((k2) => ({ value: k2, label: `${k2} ${import_picocolors22.default.dim("(not set)")}` })),
|
|
8537
|
+
{ value: "_back", label: import_picocolors22.default.dim("Back") }
|
|
8228
8538
|
]
|
|
8229
8539
|
});
|
|
8230
8540
|
if (Ct(keyToEdit) || keyToEdit === "_back") continue;
|
|
@@ -8241,7 +8551,7 @@ async function envCommand() {
|
|
|
8241
8551
|
}
|
|
8242
8552
|
const newContent = serializeEnv(originalContent, envMap);
|
|
8243
8553
|
if (newContent !== originalContent) {
|
|
8244
|
-
|
|
8554
|
+
fs9.writeFileSync(envPath, newContent);
|
|
8245
8555
|
R2.success(".env file updated");
|
|
8246
8556
|
const restart = await Re({
|
|
8247
8557
|
message: "Restart services to apply changes?",
|
|
@@ -8262,21 +8572,21 @@ async function envCommand() {
|
|
|
8262
8572
|
} else {
|
|
8263
8573
|
R2.info("No changes made.");
|
|
8264
8574
|
}
|
|
8265
|
-
Le(
|
|
8575
|
+
Le(import_picocolors22.default.dim("Done"));
|
|
8266
8576
|
}
|
|
8267
8577
|
|
|
8268
8578
|
// src/commands/restore.ts
|
|
8269
|
-
import
|
|
8270
|
-
import
|
|
8579
|
+
import fs10 from "fs";
|
|
8580
|
+
import path10 from "path";
|
|
8271
8581
|
import { execSync as execSync7 } from "child_process";
|
|
8272
|
-
var
|
|
8582
|
+
var import_picocolors23 = __toESM(require_picocolors(), 1);
|
|
8273
8583
|
async function restoreCommand(archivePath) {
|
|
8274
8584
|
if (!archivePath) {
|
|
8275
8585
|
R2.error("Please provide the path to a backup archive.");
|
|
8276
8586
|
R2.info("Usage: npx learnhouse restore <backup-file.tar.gz>");
|
|
8277
8587
|
process.exit(1);
|
|
8278
8588
|
}
|
|
8279
|
-
if (!
|
|
8589
|
+
if (!fs10.existsSync(archivePath)) {
|
|
8280
8590
|
R2.error(`Backup file not found: ${archivePath}`);
|
|
8281
8591
|
process.exit(1);
|
|
8282
8592
|
}
|
|
@@ -8301,7 +8611,7 @@ async function restoreCommand(archivePath) {
|
|
|
8301
8611
|
R2.error("Database container is not running. Start services first.");
|
|
8302
8612
|
process.exit(1);
|
|
8303
8613
|
}
|
|
8304
|
-
R2.warn(
|
|
8614
|
+
R2.warn(import_picocolors23.default.yellow("This will overwrite the current database with the backup data."));
|
|
8305
8615
|
const confirm = await Re({
|
|
8306
8616
|
message: "Are you sure you want to restore from this backup?",
|
|
8307
8617
|
initialValue: false
|
|
@@ -8310,8 +8620,8 @@ async function restoreCommand(archivePath) {
|
|
|
8310
8620
|
Ne("Restore cancelled.");
|
|
8311
8621
|
process.exit(0);
|
|
8312
8622
|
}
|
|
8313
|
-
const tmpDir =
|
|
8314
|
-
|
|
8623
|
+
const tmpDir = path10.join(installDir, ".restore-tmp");
|
|
8624
|
+
fs10.mkdirSync(tmpDir, { recursive: true });
|
|
8315
8625
|
const s = bt2();
|
|
8316
8626
|
s.start("Extracting backup archive");
|
|
8317
8627
|
try {
|
|
@@ -8319,20 +8629,20 @@ async function restoreCommand(archivePath) {
|
|
|
8319
8629
|
s.stop("Archive extracted");
|
|
8320
8630
|
} catch {
|
|
8321
8631
|
s.stop("Extraction failed");
|
|
8322
|
-
|
|
8632
|
+
fs10.rmSync(tmpDir, { recursive: true, force: true });
|
|
8323
8633
|
R2.error("Failed to extract backup archive.");
|
|
8324
8634
|
process.exit(1);
|
|
8325
8635
|
}
|
|
8326
|
-
const entries =
|
|
8636
|
+
const entries = fs10.readdirSync(tmpDir);
|
|
8327
8637
|
const backupFolder = entries.find(
|
|
8328
|
-
(e2) =>
|
|
8638
|
+
(e2) => fs10.existsSync(path10.join(tmpDir, e2, "database.sql"))
|
|
8329
8639
|
);
|
|
8330
8640
|
if (!backupFolder) {
|
|
8331
8641
|
R2.error("No database.sql found in the backup archive.");
|
|
8332
|
-
|
|
8642
|
+
fs10.rmSync(tmpDir, { recursive: true, force: true });
|
|
8333
8643
|
process.exit(1);
|
|
8334
8644
|
}
|
|
8335
|
-
const dumpPath =
|
|
8645
|
+
const dumpPath = path10.join(tmpDir, backupFolder, "database.sql");
|
|
8336
8646
|
const s2 = bt2();
|
|
8337
8647
|
s2.start("Restoring database");
|
|
8338
8648
|
try {
|
|
@@ -8344,23 +8654,23 @@ async function restoreCommand(archivePath) {
|
|
|
8344
8654
|
s2.stop("Database restored");
|
|
8345
8655
|
} catch {
|
|
8346
8656
|
s2.stop("Database restore failed");
|
|
8347
|
-
|
|
8657
|
+
fs10.rmSync(tmpDir, { recursive: true, force: true });
|
|
8348
8658
|
R2.error("Failed to restore database. The backup file may be corrupted.");
|
|
8349
8659
|
process.exit(1);
|
|
8350
8660
|
}
|
|
8351
|
-
const envBackup =
|
|
8352
|
-
if (
|
|
8661
|
+
const envBackup = path10.join(tmpDir, backupFolder, ".env");
|
|
8662
|
+
if (fs10.existsSync(envBackup)) {
|
|
8353
8663
|
const restoreEnv = await Re({
|
|
8354
8664
|
message: "Backup contains a .env file. Restore it? (overwrites current .env)",
|
|
8355
8665
|
initialValue: false
|
|
8356
8666
|
});
|
|
8357
8667
|
if (!Ct(restoreEnv) && restoreEnv) {
|
|
8358
|
-
|
|
8668
|
+
fs10.copyFileSync(envBackup, path10.join(installDir, ".env"));
|
|
8359
8669
|
R2.info(".env file restored");
|
|
8360
8670
|
}
|
|
8361
8671
|
}
|
|
8362
|
-
|
|
8363
|
-
R2.success(
|
|
8672
|
+
fs10.rmSync(tmpDir, { recursive: true, force: true });
|
|
8673
|
+
R2.success(import_picocolors23.default.green(import_picocolors23.default.bold("Restore complete!")));
|
|
8364
8674
|
R2.info("You may want to restart services: npx learnhouse stop && npx learnhouse start");
|
|
8365
8675
|
}
|
|
8366
8676
|
|
|
@@ -8384,18 +8694,18 @@ var COMMANDS = [
|
|
|
8384
8694
|
];
|
|
8385
8695
|
async function showWelcome() {
|
|
8386
8696
|
await printBanner();
|
|
8387
|
-
console.log(
|
|
8697
|
+
console.log(import_picocolors24.default.bold(import_picocolors24.default.white(" Available commands:\n")));
|
|
8388
8698
|
for (const cmd of COMMANDS) {
|
|
8389
|
-
console.log(` ${
|
|
8699
|
+
console.log(` ${import_picocolors24.default.cyan(cmd.name.padEnd(14))} ${import_picocolors24.default.dim(cmd.desc)}`);
|
|
8390
8700
|
}
|
|
8391
8701
|
console.log();
|
|
8392
|
-
console.log(
|
|
8393
|
-
console.log(
|
|
8702
|
+
console.log(import_picocolors24.default.dim(" Run a command with: npx learnhouse <command>"));
|
|
8703
|
+
console.log(import_picocolors24.default.dim(" Get started with: npx learnhouse setup"));
|
|
8394
8704
|
console.log();
|
|
8395
8705
|
}
|
|
8396
8706
|
var program2 = new Command();
|
|
8397
8707
|
program2.name("learnhouse").description("The official LearnHouse CLI \u2014 deploy, manage, and operate your LearnHouse instance").version(VERSION).action(showWelcome);
|
|
8398
|
-
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);
|
|
8708
|
+
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("--org-name <name>", 'Organization display name (default: "Default Organization")').option("--org-slug <slug>", 'Organization slug used in URLs (default: "default")').option("--channel <channel>", 'Release channel: stable or dev (default: "stable")').option("--no-start", "Skip starting services after setup").action(setupCommand);
|
|
8399
8709
|
program2.command("start").description("Start LearnHouse services").action(startCommand);
|
|
8400
8710
|
program2.command("stop").description("Stop LearnHouse services").action(stopCommand);
|
|
8401
8711
|
program2.command("logs").description("Stream logs from LearnHouse services").action(logsCommand);
|