learnhouse 1.4.3 → 1.4.5
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 +435 -261
- package/package.json +1 -1
package/dist/bin/learnhouse.js
CHANGED
|
@@ -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.5";
|
|
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,11 +5683,24 @@ ${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
|
|
5632
5691
|
`;
|
|
5692
|
+
const needsSsrPortForward = !config.autoSsl && !config.useHttps && config.httpPort !== 80;
|
|
5693
|
+
const ssrForwardService = needsSsrPortForward ? `
|
|
5694
|
+
ssr-fwd:
|
|
5695
|
+
image: alpine/socat:1.8.0.0
|
|
5696
|
+
container_name: learnhouse-ssr-fwd-${id}
|
|
5697
|
+
restart: unless-stopped
|
|
5698
|
+
network_mode: "service:learnhouse-app"
|
|
5699
|
+
command: TCP-LISTEN:${config.httpPort},fork,reuseaddr TCP:localhost:80
|
|
5700
|
+
depends_on:
|
|
5701
|
+
learnhouse-app:
|
|
5702
|
+
condition: service_healthy
|
|
5703
|
+
` : "";
|
|
5633
5704
|
const dbImage = config.useAiDatabase ? POSTGRES_AI_IMAGE : POSTGRES_IMAGE;
|
|
5634
5705
|
const dbService = useLocalDb ? `
|
|
5635
5706
|
db:
|
|
@@ -5699,7 +5770,7 @@ ${appDependsOn}
|
|
|
5699
5770
|
timeout: 10s
|
|
5700
5771
|
retries: 3
|
|
5701
5772
|
start_period: 60s
|
|
5702
|
-
${proxyService}${dbService}${redisService}
|
|
5773
|
+
${proxyService}${ssrForwardService}${dbService}${redisService}
|
|
5703
5774
|
networks:
|
|
5704
5775
|
learnhouse-network-${id}:
|
|
5705
5776
|
driver: bridge
|
|
@@ -5749,7 +5820,7 @@ function generateEnvFile(config) {
|
|
|
5749
5820
|
`NEXT_PUBLIC_LEARNHOUSE_DOMAIN=${domainWithPort}`,
|
|
5750
5821
|
`NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN=${topDomain}`,
|
|
5751
5822
|
"NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG=False",
|
|
5752
|
-
"
|
|
5823
|
+
`NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG=${config.orgSlug || "default"}`,
|
|
5753
5824
|
`NEXT_PUBLIC_LEARNHOUSE_HTTPS=${config.useHttps ? "True" : "False"}`
|
|
5754
5825
|
];
|
|
5755
5826
|
if (config.unsplashEnabled && config.unsplashAccessKey) {
|
|
@@ -5788,6 +5859,8 @@ function generateEnvFile(config) {
|
|
|
5788
5859
|
`LEARNHOUSE_AUTH_JWT_SECRET_KEY=${jwtSecret}`,
|
|
5789
5860
|
`LEARNHOUSE_INITIAL_ADMIN_EMAIL=${quoteEnvValue(config.adminEmail)}`,
|
|
5790
5861
|
`LEARNHOUSE_INITIAL_ADMIN_PASSWORD=${quoteEnvValue(config.adminPassword)}`,
|
|
5862
|
+
`LEARNHOUSE_INITIAL_ORG_NAME=${quoteEnvValue(config.orgName || "Default Organization")}`,
|
|
5863
|
+
`LEARNHOUSE_INITIAL_ORG_SLUG=${quoteEnvValue(config.orgSlug || "default")}`,
|
|
5791
5864
|
"",
|
|
5792
5865
|
"# =============================================================================",
|
|
5793
5866
|
"# Collaboration Server",
|
|
@@ -5892,6 +5965,7 @@ function generateNginxConf() {
|
|
|
5892
5965
|
return `
|
|
5893
5966
|
server {
|
|
5894
5967
|
listen 80;
|
|
5968
|
+
listen [::]:80;
|
|
5895
5969
|
server_name _;
|
|
5896
5970
|
client_max_body_size 500M;
|
|
5897
5971
|
|
|
@@ -5908,7 +5982,10 @@ server {
|
|
|
5908
5982
|
# The app container has internal nginx routing between frontend, backend, and collab
|
|
5909
5983
|
location / {
|
|
5910
5984
|
proxy_pass http://learnhouse-app:80;
|
|
5911
|
-
|
|
5985
|
+
# Use $http_host (not $host) so the port is preserved \u2014 Next.js Server
|
|
5986
|
+
# Actions reject POSTs where origin and x-forwarded-host disagree.
|
|
5987
|
+
proxy_set_header Host $http_host;
|
|
5988
|
+
proxy_set_header X-Forwarded-Host $http_host;
|
|
5912
5989
|
proxy_set_header X-Real-IP $remote_addr;
|
|
5913
5990
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
5914
5991
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
@@ -5955,7 +6032,7 @@ function writeConfig(config) {
|
|
|
5955
6032
|
useHttps: config.useHttps,
|
|
5956
6033
|
autoSsl: config.autoSsl,
|
|
5957
6034
|
useExternalDb: config.useExternalDb,
|
|
5958
|
-
orgSlug: "default"
|
|
6035
|
+
orgSlug: config.orgSlug || "default"
|
|
5959
6036
|
};
|
|
5960
6037
|
fs.writeFileSync(
|
|
5961
6038
|
path.join(config.installDir, CONFIG_FILENAME),
|
|
@@ -6001,12 +6078,14 @@ function listInstallations() {
|
|
|
6001
6078
|
return results;
|
|
6002
6079
|
}
|
|
6003
6080
|
function findInstallDir() {
|
|
6004
|
-
const baseDir = path.join(os.homedir(), ".learnhouse");
|
|
6005
|
-
const defaultDir = path.join(baseDir, "default");
|
|
6006
6081
|
const installations = listInstallations();
|
|
6007
6082
|
if (installations.length === 1) return installations[0].dir;
|
|
6008
|
-
if (
|
|
6009
|
-
|
|
6083
|
+
if (installations.length > 1) {
|
|
6084
|
+
const running = installations.find(
|
|
6085
|
+
(i) => isContainerRunning(`learnhouse-app-${i.config.deploymentId}`)
|
|
6086
|
+
);
|
|
6087
|
+
return (running ?? installations[0]).dir;
|
|
6088
|
+
}
|
|
6010
6089
|
const cwd = process.cwd();
|
|
6011
6090
|
if (isCompleteInstall(cwd)) return cwd;
|
|
6012
6091
|
return process.cwd();
|
|
@@ -6026,6 +6105,19 @@ async function waitForHealth(baseUrl) {
|
|
|
6026
6105
|
}
|
|
6027
6106
|
return false;
|
|
6028
6107
|
}
|
|
6108
|
+
async function waitForOrgSeed(baseUrl, orgSlug) {
|
|
6109
|
+
const url = `${baseUrl}/api/v1/orgs/slug/${encodeURIComponent(orgSlug)}`;
|
|
6110
|
+
const deadline = Date.now() + 3e4;
|
|
6111
|
+
while (Date.now() < deadline) {
|
|
6112
|
+
try {
|
|
6113
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(5e3) });
|
|
6114
|
+
if (res.ok) return true;
|
|
6115
|
+
} catch {
|
|
6116
|
+
}
|
|
6117
|
+
await new Promise((r) => setTimeout(r, HEALTH_CHECK_INTERVAL_MS));
|
|
6118
|
+
}
|
|
6119
|
+
return false;
|
|
6120
|
+
}
|
|
6029
6121
|
|
|
6030
6122
|
// src/commands/setup.ts
|
|
6031
6123
|
var STEP_NAMES = [
|
|
@@ -6043,7 +6135,7 @@ async function confirmOrBack(message) {
|
|
|
6043
6135
|
message,
|
|
6044
6136
|
options: [
|
|
6045
6137
|
{ value: "continue", label: "Continue" },
|
|
6046
|
-
{ value: "back", label:
|
|
6138
|
+
{ value: "back", label: import_picocolors9.default.dim("Go back to previous step") }
|
|
6047
6139
|
]
|
|
6048
6140
|
});
|
|
6049
6141
|
if (Ct(result)) {
|
|
@@ -6054,7 +6146,7 @@ async function confirmOrBack(message) {
|
|
|
6054
6146
|
}
|
|
6055
6147
|
async function stepInstallDir() {
|
|
6056
6148
|
const baseDir = path2.join(os2.homedir(), ".learnhouse");
|
|
6057
|
-
R2.info(`All installations are stored in ${
|
|
6149
|
+
R2.info(`All installations are stored in ${import_picocolors9.default.cyan("~/.learnhouse/<name>")}`);
|
|
6058
6150
|
const name = await text({
|
|
6059
6151
|
message: "Name for this installation:",
|
|
6060
6152
|
placeholder: "default",
|
|
@@ -6085,28 +6177,23 @@ async function stepInstallDir() {
|
|
|
6085
6177
|
return resolved;
|
|
6086
6178
|
}
|
|
6087
6179
|
async function stepDomain() {
|
|
6088
|
-
R2.step(
|
|
6089
|
-
|
|
6090
|
-
const portAvailable = await checkPort(config.httpPort);
|
|
6091
|
-
if (!portAvailable) {
|
|
6092
|
-
R2.warn(`Port ${config.httpPort} is already in use. You may need to free it before starting.`);
|
|
6093
|
-
}
|
|
6094
|
-
return config;
|
|
6180
|
+
R2.step(import_picocolors9.default.cyan(`Step 2/6`) + " Domain Configuration");
|
|
6181
|
+
return await promptDomain();
|
|
6095
6182
|
}
|
|
6096
6183
|
async function stepDatabase() {
|
|
6097
|
-
R2.step(
|
|
6184
|
+
R2.step(import_picocolors9.default.cyan(`Step 3/6`) + " Database & Redis");
|
|
6098
6185
|
return await promptDatabase();
|
|
6099
6186
|
}
|
|
6100
6187
|
async function stepOrganization() {
|
|
6101
|
-
R2.step(
|
|
6188
|
+
R2.step(import_picocolors9.default.cyan(`Step 4/6`) + " Organization Setup");
|
|
6102
6189
|
return await promptOrganization();
|
|
6103
6190
|
}
|
|
6104
6191
|
async function stepAdmin() {
|
|
6105
|
-
R2.step(
|
|
6192
|
+
R2.step(import_picocolors9.default.cyan(`Step 5/6`) + " Admin Account");
|
|
6106
6193
|
return await promptAdmin();
|
|
6107
6194
|
}
|
|
6108
6195
|
async function stepFeatures() {
|
|
6109
|
-
R2.step(
|
|
6196
|
+
R2.step(import_picocolors9.default.cyan(`Step 6/6`) + " Optional Features");
|
|
6110
6197
|
return await promptFeatures();
|
|
6111
6198
|
}
|
|
6112
6199
|
async function setupCommand(options) {
|
|
@@ -6115,6 +6202,13 @@ async function setupCommand(options) {
|
|
|
6115
6202
|
console.error("Error: --admin-password is required in --ci mode");
|
|
6116
6203
|
process.exit(1);
|
|
6117
6204
|
}
|
|
6205
|
+
if (options.adminEmail) {
|
|
6206
|
+
const emailErr = validateEmail(options.adminEmail);
|
|
6207
|
+
if (emailErr) {
|
|
6208
|
+
console.error(`Error: --admin-email "${options.adminEmail}" \u2014 ${emailErr}`);
|
|
6209
|
+
process.exit(1);
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6118
6212
|
await checkPrerequisites();
|
|
6119
6213
|
const installName = options.name || "default";
|
|
6120
6214
|
const baseDir = path2.join(os2.homedir(), ".learnhouse");
|
|
@@ -6122,18 +6216,35 @@ async function setupCommand(options) {
|
|
|
6122
6216
|
fs2.mkdirSync(resolvedDir2, { recursive: true });
|
|
6123
6217
|
const deploymentId2 = crypto3.randomBytes(4).toString("hex");
|
|
6124
6218
|
const channel2 = options.channel === "dev" ? "dev" : "stable";
|
|
6219
|
+
const dbPassword = crypto3.randomBytes(24).toString("base64url");
|
|
6220
|
+
let httpPort = options.port || 80;
|
|
6221
|
+
if (!options.port) {
|
|
6222
|
+
const available = await findAvailablePort(httpPort);
|
|
6223
|
+
if (available && available !== httpPort) {
|
|
6224
|
+
console.log(`Port ${httpPort} is in use \u2014 falling back to ${available}.`);
|
|
6225
|
+
httpPort = available;
|
|
6226
|
+
} else if (!available) {
|
|
6227
|
+
console.error("No common port is available. Pass --port=<port> explicitly.");
|
|
6228
|
+
process.exit(1);
|
|
6229
|
+
}
|
|
6230
|
+
} else if (!await checkPort(httpPort)) {
|
|
6231
|
+
console.error(`Port ${httpPort} is already in use. Free it or pass a different --port.`);
|
|
6232
|
+
process.exit(1);
|
|
6233
|
+
}
|
|
6125
6234
|
const config2 = {
|
|
6126
6235
|
deploymentId: deploymentId2,
|
|
6127
6236
|
installDir: resolvedDir2,
|
|
6128
6237
|
channel: channel2,
|
|
6129
6238
|
domain: options.domain || "localhost",
|
|
6130
6239
|
useHttps: false,
|
|
6131
|
-
httpPort
|
|
6240
|
+
httpPort,
|
|
6132
6241
|
autoSsl: false,
|
|
6133
6242
|
useExternalDb: false,
|
|
6243
|
+
dbPassword,
|
|
6134
6244
|
useAiDatabase: false,
|
|
6135
6245
|
useExternalRedis: false,
|
|
6136
|
-
orgName: "Default",
|
|
6246
|
+
orgName: options.orgName || "Default Organization",
|
|
6247
|
+
orgSlug: (options.orgSlug || "default").toLowerCase(),
|
|
6137
6248
|
adminEmail: options.adminEmail || "admin@school.dev",
|
|
6138
6249
|
adminPassword: options.adminPassword,
|
|
6139
6250
|
aiEnabled: false,
|
|
@@ -6158,12 +6269,27 @@ async function setupCommand(options) {
|
|
|
6158
6269
|
dockerComposeUp(resolvedDir2);
|
|
6159
6270
|
const healthy = await waitForHealth(`http://localhost:${config2.httpPort}`);
|
|
6160
6271
|
if (healthy) {
|
|
6161
|
-
|
|
6272
|
+
const seeded = await waitForOrgSeed(`http://localhost:${config2.httpPort}`, "default");
|
|
6273
|
+
if (seeded) {
|
|
6274
|
+
console.log("LearnHouse is ready!");
|
|
6275
|
+
} else {
|
|
6276
|
+
console.error("");
|
|
6277
|
+
console.error("API is healthy but the default organization was not seeded.");
|
|
6278
|
+
console.error("Run `npx learnhouse logs` to inspect; pin a different image tag and re-run.");
|
|
6279
|
+
console.error("");
|
|
6280
|
+
process.exit(1);
|
|
6281
|
+
}
|
|
6162
6282
|
} else {
|
|
6163
6283
|
console.log("Health check timed out \u2014 services may still be starting");
|
|
6164
6284
|
}
|
|
6165
|
-
} catch {
|
|
6166
|
-
|
|
6285
|
+
} catch (err) {
|
|
6286
|
+
const stderr = err?.stderr?.toString?.() ?? "";
|
|
6287
|
+
const message = err?.message ?? "";
|
|
6288
|
+
if (/port is already allocated/i.test(stderr) || /address already in use/i.test(stderr) || /port is already allocated/i.test(message)) {
|
|
6289
|
+
console.error(`Port ${config2.httpPort} is already bound \u2014 pass --port=<other> and re-run.`);
|
|
6290
|
+
} else {
|
|
6291
|
+
console.error("Failed to start services");
|
|
6292
|
+
}
|
|
6167
6293
|
process.exit(1);
|
|
6168
6294
|
}
|
|
6169
6295
|
}
|
|
@@ -6174,7 +6300,7 @@ async function setupCommand(options) {
|
|
|
6174
6300
|
return;
|
|
6175
6301
|
}
|
|
6176
6302
|
await printBanner();
|
|
6177
|
-
We(
|
|
6303
|
+
We(import_picocolors9.default.cyan("LearnHouse Setup Wizard"));
|
|
6178
6304
|
await checkPrerequisites();
|
|
6179
6305
|
const channelChoice = await Je({
|
|
6180
6306
|
message: "Which release channel do you want to use?",
|
|
@@ -6207,7 +6333,7 @@ async function setupCommand(options) {
|
|
|
6207
6333
|
while (step < totalSteps) {
|
|
6208
6334
|
switch (step) {
|
|
6209
6335
|
case 0: {
|
|
6210
|
-
R2.step(
|
|
6336
|
+
R2.step(import_picocolors9.default.cyan(`Step 1/${totalSteps}`) + " Install Directory");
|
|
6211
6337
|
const result = await stepInstallDir();
|
|
6212
6338
|
if (result === BACK) {
|
|
6213
6339
|
step = Math.max(0, step - 1);
|
|
@@ -6280,19 +6406,19 @@ async function setupCommand(options) {
|
|
|
6280
6406
|
const url = `${protocol}://${config.domain}${portSuffix}`;
|
|
6281
6407
|
R2.step("Configuration Summary");
|
|
6282
6408
|
R2.message([
|
|
6283
|
-
` ${
|
|
6284
|
-
` ${
|
|
6285
|
-
` ${
|
|
6286
|
-
` ${
|
|
6287
|
-
` ${
|
|
6288
|
-
` ${
|
|
6289
|
-
` ${
|
|
6290
|
-
` ${
|
|
6291
|
-
` ${
|
|
6292
|
-
` ${
|
|
6293
|
-
` ${
|
|
6294
|
-
` ${
|
|
6295
|
-
` ${
|
|
6409
|
+
` ${import_picocolors9.default.dim("Directory:")} ${resolvedDir}`,
|
|
6410
|
+
` ${import_picocolors9.default.dim("Channel:")} ${config.channel === "dev" ? import_picocolors9.default.yellow("Dev (:dev)") : import_picocolors9.default.green("Stable")}`,
|
|
6411
|
+
` ${import_picocolors9.default.dim("URL:")} ${url}`,
|
|
6412
|
+
` ${import_picocolors9.default.dim("HTTPS:")} ${config.autoSsl ? "Auto SSL (Caddy)" : config.useHttps ? "Manual" : "Disabled"}`,
|
|
6413
|
+
` ${import_picocolors9.default.dim("Database:")} ${config.useExternalDb ? "External" : config.useAiDatabase ? "Local (Docker, AI-enabled)" : "Local (Docker)"}`,
|
|
6414
|
+
` ${import_picocolors9.default.dim("Redis:")} ${config.useExternalRedis ? "External" : "Local (Docker)"}`,
|
|
6415
|
+
` ${import_picocolors9.default.dim("Organization:")} ${config.orgName}`,
|
|
6416
|
+
` ${import_picocolors9.default.dim("Admin:")} ${config.adminEmail}`,
|
|
6417
|
+
` ${import_picocolors9.default.dim("AI:")} ${config.aiEnabled ? "Enabled" : "Disabled"}`,
|
|
6418
|
+
` ${import_picocolors9.default.dim("Email:")} ${config.emailEnabled ? "Enabled" : "Disabled"}`,
|
|
6419
|
+
` ${import_picocolors9.default.dim("S3 Storage:")} ${config.s3Enabled ? "Enabled" : "Disabled"}`,
|
|
6420
|
+
` ${import_picocolors9.default.dim("Google OAuth:")} ${config.googleOAuthEnabled ? "Enabled" : "Disabled"}`,
|
|
6421
|
+
` ${import_picocolors9.default.dim("Unsplash:")} ${config.unsplashEnabled ? "Enabled" : "Disabled"}`
|
|
6296
6422
|
].join("\n"));
|
|
6297
6423
|
let confirmed = false;
|
|
6298
6424
|
while (!confirmed) {
|
|
@@ -6300,8 +6426,8 @@ async function setupCommand(options) {
|
|
|
6300
6426
|
message: "What would you like to do?",
|
|
6301
6427
|
options: [
|
|
6302
6428
|
{ value: "confirm", label: "Proceed with this configuration" },
|
|
6303
|
-
{ value: "edit", label:
|
|
6304
|
-
{ value: "cancel", label:
|
|
6429
|
+
{ value: "edit", label: import_picocolors9.default.dim("Go back and edit a step") },
|
|
6430
|
+
{ value: "cancel", label: import_picocolors9.default.dim("Cancel setup") }
|
|
6305
6431
|
]
|
|
6306
6432
|
});
|
|
6307
6433
|
if (Ct(action) || action === "cancel") {
|
|
@@ -6317,7 +6443,7 @@ async function setupCommand(options) {
|
|
|
6317
6443
|
const idx = stepChoice;
|
|
6318
6444
|
switch (idx) {
|
|
6319
6445
|
case 0: {
|
|
6320
|
-
R2.step(
|
|
6446
|
+
R2.step(import_picocolors9.default.cyan(`Step 1/${totalSteps}`) + " Install Directory");
|
|
6321
6447
|
const result = await stepInstallDir();
|
|
6322
6448
|
if (result !== BACK) {
|
|
6323
6449
|
resolvedDir = result;
|
|
@@ -6356,19 +6482,19 @@ async function setupCommand(options) {
|
|
|
6356
6482
|
const url2 = `${p2}://${config.domain}${ps2}`;
|
|
6357
6483
|
R2.step("Updated Configuration Summary");
|
|
6358
6484
|
R2.message([
|
|
6359
|
-
` ${
|
|
6360
|
-
` ${
|
|
6361
|
-
` ${
|
|
6362
|
-
` ${
|
|
6363
|
-
` ${
|
|
6364
|
-
` ${
|
|
6365
|
-
` ${
|
|
6366
|
-
` ${
|
|
6367
|
-
` ${
|
|
6368
|
-
` ${
|
|
6369
|
-
` ${
|
|
6370
|
-
` ${
|
|
6371
|
-
` ${
|
|
6485
|
+
` ${import_picocolors9.default.dim("Directory:")} ${config.installDir}`,
|
|
6486
|
+
` ${import_picocolors9.default.dim("Channel:")} ${config.channel === "dev" ? import_picocolors9.default.yellow("Dev (:dev)") : import_picocolors9.default.green("Stable")}`,
|
|
6487
|
+
` ${import_picocolors9.default.dim("URL:")} ${url2}`,
|
|
6488
|
+
` ${import_picocolors9.default.dim("HTTPS:")} ${config.autoSsl ? "Auto SSL (Caddy)" : config.useHttps ? "Manual" : "Disabled"}`,
|
|
6489
|
+
` ${import_picocolors9.default.dim("Database:")} ${config.useExternalDb ? "External" : config.useAiDatabase ? "Local (Docker, AI-enabled)" : "Local (Docker)"}`,
|
|
6490
|
+
` ${import_picocolors9.default.dim("Redis:")} ${config.useExternalRedis ? "External" : "Local (Docker)"}`,
|
|
6491
|
+
` ${import_picocolors9.default.dim("Organization:")} ${config.orgName}`,
|
|
6492
|
+
` ${import_picocolors9.default.dim("Admin:")} ${config.adminEmail}`,
|
|
6493
|
+
` ${import_picocolors9.default.dim("AI:")} ${config.aiEnabled ? "Enabled" : "Disabled"}`,
|
|
6494
|
+
` ${import_picocolors9.default.dim("Email:")} ${config.emailEnabled ? "Enabled" : "Disabled"}`,
|
|
6495
|
+
` ${import_picocolors9.default.dim("S3 Storage:")} ${config.s3Enabled ? "Enabled" : "Disabled"}`,
|
|
6496
|
+
` ${import_picocolors9.default.dim("Google OAuth:")} ${config.googleOAuthEnabled ? "Enabled" : "Disabled"}`,
|
|
6497
|
+
` ${import_picocolors9.default.dim("Unsplash:")} ${config.unsplashEnabled ? "Enabled" : "Disabled"}`
|
|
6372
6498
|
].join("\n"));
|
|
6373
6499
|
} else {
|
|
6374
6500
|
confirmed = true;
|
|
@@ -6421,47 +6547,71 @@ async function setupCommand(options) {
|
|
|
6421
6547
|
s2.stop("Services started");
|
|
6422
6548
|
} catch (err) {
|
|
6423
6549
|
s2.stop("Failed to start services");
|
|
6424
|
-
|
|
6425
|
-
|
|
6550
|
+
const stderr = err?.stderr?.toString?.() ?? "";
|
|
6551
|
+
const message = err?.message ?? "";
|
|
6552
|
+
const portAllocated = /port is already allocated/i.test(stderr) || /port is already allocated/i.test(message) || /bind:.*address already in use/i.test(stderr);
|
|
6553
|
+
if (portAllocated) {
|
|
6554
|
+
R2.error(
|
|
6555
|
+
`Port ${config.httpPort} is already bound by another process or container \u2014 Docker couldn't publish to it.`
|
|
6556
|
+
);
|
|
6557
|
+
R2.info(
|
|
6558
|
+
`Fix one of these and re-run \`learnhouse start\` (your config is already saved):
|
|
6559
|
+
\u2022 Stop whatever is using port ${config.httpPort}, or
|
|
6560
|
+
\u2022 Re-run \`learnhouse setup\` and pick a different port, or
|
|
6561
|
+
\u2022 Edit HTTP_PORT in ${finalDir}/.env and run \`docker compose up -d\` from there.`
|
|
6562
|
+
);
|
|
6563
|
+
} else {
|
|
6564
|
+
R2.error("Docker Compose failed. Check the output above for details.");
|
|
6565
|
+
R2.info(`You can manually start with: cd ${finalDir} && docker compose up -d`);
|
|
6566
|
+
}
|
|
6426
6567
|
process.exit(1);
|
|
6427
6568
|
}
|
|
6428
6569
|
const s3 = bt2();
|
|
6429
6570
|
s3.start("Waiting for LearnHouse to be ready (up to 3 minutes)");
|
|
6430
6571
|
const healthy = await waitForHealth(`http://localhost:${config.httpPort}`);
|
|
6431
6572
|
if (healthy) {
|
|
6432
|
-
|
|
6573
|
+
const seeded = await waitForOrgSeed(`http://localhost:${config.httpPort}`, "default");
|
|
6574
|
+
if (seeded) {
|
|
6575
|
+
s3.stop("LearnHouse is ready!");
|
|
6576
|
+
} else {
|
|
6577
|
+
s3.stop("API is healthy but the default organization was not seeded");
|
|
6578
|
+
R2.error(
|
|
6579
|
+
"`/api/v1/orgs/slug/default` returns no org. Run `learnhouse logs` to inspect, pin a different image tag, and re-run setup."
|
|
6580
|
+
);
|
|
6581
|
+
process.exit(1);
|
|
6582
|
+
}
|
|
6433
6583
|
} else {
|
|
6434
6584
|
s3.stop("Health check timed out");
|
|
6435
6585
|
R2.warn("LearnHouse may still be starting. Check status with:");
|
|
6436
6586
|
R2.message(` cd ${finalDir} && docker compose ps`);
|
|
6437
6587
|
}
|
|
6438
|
-
R2.success(
|
|
6588
|
+
R2.success(import_picocolors9.default.green(import_picocolors9.default.bold("LearnHouse is installed!")));
|
|
6439
6589
|
R2.message([
|
|
6440
6590
|
"",
|
|
6441
|
-
` ${
|
|
6442
|
-
` ${
|
|
6443
|
-
` ${
|
|
6591
|
+
` ${import_picocolors9.default.cyan("URL:")} ${finalUrl}`,
|
|
6592
|
+
` ${import_picocolors9.default.cyan("Admin:")} ${config.adminEmail}`,
|
|
6593
|
+
` ${import_picocolors9.default.cyan("Password:")} ${config.adminPassword}`,
|
|
6444
6594
|
"",
|
|
6445
|
-
` ${
|
|
6446
|
-
` ${
|
|
6447
|
-
` ${
|
|
6448
|
-
` ${
|
|
6449
|
-
` ${
|
|
6450
|
-
` ${
|
|
6451
|
-
` ${
|
|
6452
|
-
` ${
|
|
6453
|
-
` ${
|
|
6595
|
+
` ${import_picocolors9.default.dim("Management commands:")}`,
|
|
6596
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse start ${import_picocolors9.default.dim("Start services")}`,
|
|
6597
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse stop ${import_picocolors9.default.dim("Stop services")}`,
|
|
6598
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse logs ${import_picocolors9.default.dim("View logs")}`,
|
|
6599
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse config ${import_picocolors9.default.dim("Show configuration")}`,
|
|
6600
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse backup ${import_picocolors9.default.dim("Backup & restore")}`,
|
|
6601
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse deployments ${import_picocolors9.default.dim("Manage deployments")}`,
|
|
6602
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse doctor ${import_picocolors9.default.dim("Diagnose issues")}`,
|
|
6603
|
+
` ${import_picocolors9.default.dim("$")} npx learnhouse shell ${import_picocolors9.default.dim("Container shell")}`,
|
|
6454
6604
|
""
|
|
6455
6605
|
].join("\n"));
|
|
6456
6606
|
} else {
|
|
6457
6607
|
R2.info(`Files have been generated in ${finalDir}`);
|
|
6458
6608
|
R2.message(` Start later with: cd ${finalDir} && docker compose up -d`);
|
|
6459
6609
|
}
|
|
6460
|
-
Le(
|
|
6610
|
+
Le(import_picocolors9.default.dim("Happy teaching!"));
|
|
6461
6611
|
}
|
|
6462
6612
|
|
|
6463
6613
|
// src/commands/start.ts
|
|
6464
|
-
var
|
|
6614
|
+
var import_picocolors10 = __toESM(require_picocolors(), 1);
|
|
6465
6615
|
async function startCommand() {
|
|
6466
6616
|
const dir = findInstallDir();
|
|
6467
6617
|
const config = readConfig(dir);
|
|
@@ -6469,7 +6619,7 @@ async function startCommand() {
|
|
|
6469
6619
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6470
6620
|
process.exit(1);
|
|
6471
6621
|
}
|
|
6472
|
-
We(
|
|
6622
|
+
We(import_picocolors10.default.cyan("Starting LearnHouse"));
|
|
6473
6623
|
try {
|
|
6474
6624
|
dockerComposeUp(config.installDir);
|
|
6475
6625
|
R2.success("LearnHouse is running!");
|
|
@@ -6480,7 +6630,7 @@ async function startCommand() {
|
|
|
6480
6630
|
}
|
|
6481
6631
|
|
|
6482
6632
|
// src/commands/stop.ts
|
|
6483
|
-
var
|
|
6633
|
+
var import_picocolors11 = __toESM(require_picocolors(), 1);
|
|
6484
6634
|
async function stopCommand() {
|
|
6485
6635
|
const dir = findInstallDir();
|
|
6486
6636
|
const config = readConfig(dir);
|
|
@@ -6488,7 +6638,7 @@ async function stopCommand() {
|
|
|
6488
6638
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6489
6639
|
process.exit(1);
|
|
6490
6640
|
}
|
|
6491
|
-
We(
|
|
6641
|
+
We(import_picocolors11.default.cyan("Stopping LearnHouse"));
|
|
6492
6642
|
try {
|
|
6493
6643
|
dockerComposeDown(config.installDir);
|
|
6494
6644
|
R2.success("LearnHouse stopped.");
|
|
@@ -6528,7 +6678,7 @@ async function logsCommand() {
|
|
|
6528
6678
|
}
|
|
6529
6679
|
|
|
6530
6680
|
// src/commands/config.ts
|
|
6531
|
-
var
|
|
6681
|
+
var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
6532
6682
|
async function configCommand() {
|
|
6533
6683
|
const dir = findInstallDir();
|
|
6534
6684
|
const config = readConfig(dir);
|
|
@@ -6536,25 +6686,25 @@ async function configCommand() {
|
|
|
6536
6686
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
6537
6687
|
process.exit(1);
|
|
6538
6688
|
}
|
|
6539
|
-
We(
|
|
6689
|
+
We(import_picocolors12.default.cyan("LearnHouse Configuration"));
|
|
6540
6690
|
const protocol = config.useHttps ? "https" : "http";
|
|
6541
6691
|
const portSuffix = config.useHttps && config.httpPort === 443 || !config.useHttps && config.httpPort === 80 ? "" : `:${config.httpPort}`;
|
|
6542
6692
|
R2.message([
|
|
6543
|
-
` ${
|
|
6544
|
-
` ${
|
|
6545
|
-
` ${
|
|
6546
|
-
` ${
|
|
6547
|
-
` ${
|
|
6693
|
+
` ${import_picocolors12.default.dim("Version:")} ${config.version}`,
|
|
6694
|
+
` ${import_picocolors12.default.dim("Created:")} ${config.createdAt}`,
|
|
6695
|
+
` ${import_picocolors12.default.dim("Directory:")} ${config.installDir}`,
|
|
6696
|
+
` ${import_picocolors12.default.dim("URL:")} ${protocol}://${config.domain}${portSuffix}`,
|
|
6697
|
+
` ${import_picocolors12.default.dim("Org slug:")} ${config.orgSlug}`
|
|
6548
6698
|
].join("\n"));
|
|
6549
|
-
R2.info(
|
|
6550
|
-
R2.info(
|
|
6699
|
+
R2.info(import_picocolors12.default.dim(`Full config: ${dir}/learnhouse.config.json`));
|
|
6700
|
+
R2.info(import_picocolors12.default.dim(`Environment: ${config.installDir}/.env (contains secrets)`));
|
|
6551
6701
|
}
|
|
6552
6702
|
|
|
6553
6703
|
// src/commands/backup.ts
|
|
6554
6704
|
import fs3 from "fs";
|
|
6555
6705
|
import path3 from "path";
|
|
6556
6706
|
import { execSync as execSync2 } from "child_process";
|
|
6557
|
-
var
|
|
6707
|
+
var import_picocolors13 = __toESM(require_picocolors(), 1);
|
|
6558
6708
|
function resolveDbContainer(config) {
|
|
6559
6709
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
6560
6710
|
if (!id) return null;
|
|
@@ -6618,13 +6768,13 @@ async function createBackup() {
|
|
|
6618
6768
|
fs3.rmSync(tmpDir, { recursive: true, force: true });
|
|
6619
6769
|
const stats = fs3.statSync(archivePath);
|
|
6620
6770
|
const sizeMb = (stats.size / (1024 * 1024)).toFixed(1);
|
|
6621
|
-
R2.success(
|
|
6771
|
+
R2.success(import_picocolors13.default.green(import_picocolors13.default.bold("Backup complete!")));
|
|
6622
6772
|
R2.message([
|
|
6623
6773
|
"",
|
|
6624
|
-
` ${
|
|
6625
|
-
` ${
|
|
6774
|
+
` ${import_picocolors13.default.dim("File:")} ${archivePath}`,
|
|
6775
|
+
` ${import_picocolors13.default.dim("Size:")} ${sizeMb} MB`,
|
|
6626
6776
|
"",
|
|
6627
|
-
` ${
|
|
6777
|
+
` ${import_picocolors13.default.dim("Restore with:")} npx learnhouse backup --restore ${archivePath}`,
|
|
6628
6778
|
""
|
|
6629
6779
|
].join("\n"));
|
|
6630
6780
|
}
|
|
@@ -6649,7 +6799,7 @@ async function restoreBackup(archivePath) {
|
|
|
6649
6799
|
R2.error("Database container is not running. Start services first.");
|
|
6650
6800
|
process.exit(1);
|
|
6651
6801
|
}
|
|
6652
|
-
R2.warn(
|
|
6802
|
+
R2.warn(import_picocolors13.default.yellow("This will overwrite the current database with the backup data."));
|
|
6653
6803
|
const confirm = await Re({
|
|
6654
6804
|
message: "Are you sure you want to restore from this backup?",
|
|
6655
6805
|
initialValue: false
|
|
@@ -6708,16 +6858,16 @@ async function restoreBackup(archivePath) {
|
|
|
6708
6858
|
}
|
|
6709
6859
|
}
|
|
6710
6860
|
fs3.rmSync(tmpDir, { recursive: true, force: true });
|
|
6711
|
-
R2.success(
|
|
6861
|
+
R2.success(import_picocolors13.default.green(import_picocolors13.default.bold("Restore complete!")));
|
|
6712
6862
|
R2.info("You may want to restart services: npx learnhouse stop && npx learnhouse start");
|
|
6713
6863
|
}
|
|
6714
6864
|
async function backupCommand(archivePath, options) {
|
|
6715
6865
|
if (options?.restore && archivePath) {
|
|
6716
|
-
We(
|
|
6866
|
+
We(import_picocolors13.default.cyan("LearnHouse Restore"));
|
|
6717
6867
|
await restoreBackup(archivePath);
|
|
6718
6868
|
return;
|
|
6719
6869
|
}
|
|
6720
|
-
We(
|
|
6870
|
+
We(import_picocolors13.default.cyan("LearnHouse Backup"));
|
|
6721
6871
|
const action = await Je({
|
|
6722
6872
|
message: "What would you like to do?",
|
|
6723
6873
|
options: [
|
|
@@ -6748,7 +6898,7 @@ async function backupCommand(archivePath, options) {
|
|
|
6748
6898
|
import fs4 from "fs";
|
|
6749
6899
|
import path4 from "path";
|
|
6750
6900
|
import { execSync as execSync3 } from "child_process";
|
|
6751
|
-
var
|
|
6901
|
+
var import_picocolors14 = __toESM(require_picocolors(), 1);
|
|
6752
6902
|
var SERVICES = ["learnhouse-app", "db", "redis"];
|
|
6753
6903
|
function showDeployments() {
|
|
6754
6904
|
let psOutput;
|
|
@@ -6763,7 +6913,7 @@ function showDeployments() {
|
|
|
6763
6913
|
}
|
|
6764
6914
|
if (!psOutput) {
|
|
6765
6915
|
R2.info("No LearnHouse deployments found.");
|
|
6766
|
-
R2.message(
|
|
6916
|
+
R2.message(import_picocolors14.default.dim(" Run npx learnhouse setup to create one."));
|
|
6767
6917
|
return;
|
|
6768
6918
|
}
|
|
6769
6919
|
const deployments = /* @__PURE__ */ new Map();
|
|
@@ -6787,20 +6937,20 @@ function showDeployments() {
|
|
|
6787
6937
|
}
|
|
6788
6938
|
deployments.get(id).containers.push({ name, status, image });
|
|
6789
6939
|
}
|
|
6790
|
-
R2.info(`Found ${
|
|
6940
|
+
R2.info(`Found ${import_picocolors14.default.bold(String(deployments.size))} deployment${deployments.size === 1 ? "" : "s"}`);
|
|
6791
6941
|
console.log();
|
|
6792
6942
|
for (const [id, dep] of deployments) {
|
|
6793
6943
|
const running = dep.containers.filter((c) => c.status.toLowerCase().startsWith("up")).length;
|
|
6794
6944
|
const total = dep.containers.length;
|
|
6795
|
-
const statusColor = running === total ?
|
|
6945
|
+
const statusColor = running === total ? import_picocolors14.default.green : running > 0 ? import_picocolors14.default.yellow : import_picocolors14.default.red;
|
|
6796
6946
|
const statusText = statusColor(`${running}/${total} running`);
|
|
6797
|
-
console.log(` ${
|
|
6947
|
+
console.log(` ${import_picocolors14.default.bold(import_picocolors14.default.white(`Deployment ${id}`))} ${statusText}`);
|
|
6798
6948
|
console.log();
|
|
6799
6949
|
for (const c of dep.containers) {
|
|
6800
6950
|
const isUp = c.status.toLowerCase().startsWith("up");
|
|
6801
|
-
const icon = isUp ?
|
|
6951
|
+
const icon = isUp ? import_picocolors14.default.green("\u25CF") : import_picocolors14.default.red("\u25CF");
|
|
6802
6952
|
const svcName = c.name.replace(`-${id}`, "");
|
|
6803
|
-
console.log(` ${icon} ${
|
|
6953
|
+
console.log(` ${icon} ${import_picocolors14.default.white(svcName.padEnd(24))} ${import_picocolors14.default.dim(c.status)}`);
|
|
6804
6954
|
}
|
|
6805
6955
|
console.log();
|
|
6806
6956
|
}
|
|
@@ -6873,14 +7023,14 @@ async function scaleResources() {
|
|
|
6873
7023
|
R2.step("Current Resource Usage");
|
|
6874
7024
|
try {
|
|
6875
7025
|
const stats = dockerStats(config.installDir);
|
|
6876
|
-
R2.message(
|
|
7026
|
+
R2.message(import_picocolors14.default.dim(stats.trim()));
|
|
6877
7027
|
} catch {
|
|
6878
7028
|
try {
|
|
6879
7029
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
6880
7030
|
const running = listDeploymentContainers(id || void 0).filter((c) => c.status.toLowerCase().startsWith("up")).map((c) => c.name);
|
|
6881
7031
|
if (running.length > 0) {
|
|
6882
7032
|
const stats = dockerStatsForContainers(running);
|
|
6883
|
-
R2.message(
|
|
7033
|
+
R2.message(import_picocolors14.default.dim(stats.trim()));
|
|
6884
7034
|
} else {
|
|
6885
7035
|
R2.warn("No running containers found.");
|
|
6886
7036
|
}
|
|
@@ -6896,11 +7046,11 @@ async function scaleResources() {
|
|
|
6896
7046
|
let composeContent = fs4.readFileSync(composePath, "utf-8");
|
|
6897
7047
|
const currentLimits = parseMemLimit(composePath);
|
|
6898
7048
|
R2.step("Set Memory Limits");
|
|
6899
|
-
R2.info(
|
|
7049
|
+
R2.info(import_picocolors14.default.dim("Examples: 256m, 512m, 1g, 2g (leave empty to skip)"));
|
|
6900
7050
|
let changed = false;
|
|
6901
7051
|
for (const service of SERVICES) {
|
|
6902
7052
|
const current = currentLimits.get(service);
|
|
6903
|
-
const label = current ? `Memory limit for ${
|
|
7053
|
+
const label = current ? `Memory limit for ${import_picocolors14.default.bold(service)} (current: ${current})` : `Memory limit for ${import_picocolors14.default.bold(service)} (not set)`;
|
|
6904
7054
|
const value = await text({
|
|
6905
7055
|
message: label,
|
|
6906
7056
|
placeholder: current ? void 0 : "e.g. 512m",
|
|
@@ -6943,7 +7093,7 @@ async function scaleResources() {
|
|
|
6943
7093
|
}
|
|
6944
7094
|
}
|
|
6945
7095
|
async function deploymentsCommand() {
|
|
6946
|
-
We(
|
|
7096
|
+
We(import_picocolors14.default.cyan("LearnHouse Deployments"));
|
|
6947
7097
|
const action = await Je({
|
|
6948
7098
|
message: "What would you like to do?",
|
|
6949
7099
|
options: [
|
|
@@ -6960,24 +7110,24 @@ async function deploymentsCommand() {
|
|
|
6960
7110
|
} else {
|
|
6961
7111
|
await scaleResources();
|
|
6962
7112
|
}
|
|
6963
|
-
Le(
|
|
7113
|
+
Le(import_picocolors14.default.dim("Done"));
|
|
6964
7114
|
}
|
|
6965
7115
|
|
|
6966
7116
|
// src/commands/doctor.ts
|
|
6967
7117
|
import fs5 from "fs";
|
|
6968
7118
|
import path5 from "path";
|
|
6969
7119
|
import { execSync as execSync4 } from "child_process";
|
|
6970
|
-
var
|
|
7120
|
+
var import_picocolors15 = __toESM(require_picocolors(), 1);
|
|
6971
7121
|
function pass(msg) {
|
|
6972
|
-
console.log(` ${
|
|
7122
|
+
console.log(` ${import_picocolors15.default.green("\u2713")} ${msg}`);
|
|
6973
7123
|
}
|
|
6974
7124
|
function warn(msg, fix) {
|
|
6975
|
-
console.log(` ${
|
|
6976
|
-
if (fix) console.log(` ${
|
|
7125
|
+
console.log(` ${import_picocolors15.default.yellow("!")} ${msg}`);
|
|
7126
|
+
if (fix) console.log(` ${import_picocolors15.default.dim(`Fix: ${fix}`)}`);
|
|
6977
7127
|
}
|
|
6978
7128
|
function fail(msg, fix) {
|
|
6979
|
-
console.log(` ${
|
|
6980
|
-
if (fix) console.log(` ${
|
|
7129
|
+
console.log(` ${import_picocolors15.default.red("\u2717")} ${msg}`);
|
|
7130
|
+
if (fix) console.log(` ${import_picocolors15.default.dim(`Fix: ${fix}`)}`);
|
|
6981
7131
|
}
|
|
6982
7132
|
var REQUIRED_ENV_VARS = [
|
|
6983
7133
|
"LEARNHOUSE_DOMAIN",
|
|
@@ -6995,30 +7145,30 @@ var SECRET_ENV_VARS = [
|
|
|
6995
7145
|
async function doctorCommand() {
|
|
6996
7146
|
const dir = findInstallDir();
|
|
6997
7147
|
const config = readConfig(dir);
|
|
6998
|
-
We(
|
|
7148
|
+
We(import_picocolors15.default.cyan("LearnHouse Doctor"));
|
|
6999
7149
|
R2.step("Docker Environment");
|
|
7000
7150
|
if (!isDockerInstalled()) {
|
|
7001
7151
|
fail("Docker not installed", "Install Docker: https://docs.docker.com/get-docker/");
|
|
7002
|
-
Le(
|
|
7152
|
+
Le(import_picocolors15.default.red("Cannot continue without Docker"));
|
|
7003
7153
|
process.exit(1);
|
|
7004
7154
|
}
|
|
7005
7155
|
pass("Docker installed");
|
|
7006
7156
|
if (!isDockerRunning()) {
|
|
7007
7157
|
fail("Docker daemon not running", "Start Docker Desktop or run: sudo systemctl start docker");
|
|
7008
|
-
Le(
|
|
7158
|
+
Le(import_picocolors15.default.red("Cannot continue without Docker running"));
|
|
7009
7159
|
process.exit(1);
|
|
7010
7160
|
}
|
|
7011
7161
|
pass("Docker daemon running");
|
|
7012
7162
|
if (!config) {
|
|
7013
7163
|
R2.warn("No LearnHouse installation found. Skipping deployment checks.");
|
|
7014
|
-
Le(
|
|
7164
|
+
Le(import_picocolors15.default.dim("Done"));
|
|
7015
7165
|
return;
|
|
7016
7166
|
}
|
|
7017
7167
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
7018
7168
|
const installDir = dir;
|
|
7019
7169
|
if (!id) {
|
|
7020
7170
|
R2.warn("No deployment ID found. Skipping container checks.");
|
|
7021
|
-
Le(
|
|
7171
|
+
Le(import_picocolors15.default.dim("Done"));
|
|
7022
7172
|
return;
|
|
7023
7173
|
}
|
|
7024
7174
|
R2.step("Containers");
|
|
@@ -7089,11 +7239,11 @@ async function doctorCommand() {
|
|
|
7089
7239
|
}
|
|
7090
7240
|
try {
|
|
7091
7241
|
const diskUsage = getDockerDiskUsage();
|
|
7092
|
-
R2.message(
|
|
7242
|
+
R2.message(import_picocolors15.default.dim(diskUsage.trim()));
|
|
7093
7243
|
} catch {
|
|
7094
7244
|
}
|
|
7095
7245
|
R2.step("Log Analysis");
|
|
7096
|
-
const errorPatterns =
|
|
7246
|
+
const errorPatterns = /\bERROR\b[:\s]|\bFATAL\b[:\s]|\bTraceback\b|\bException\b[:\s]/;
|
|
7097
7247
|
for (const c of containers) {
|
|
7098
7248
|
if (!isContainerRunning(c.name)) continue;
|
|
7099
7249
|
try {
|
|
@@ -7103,7 +7253,7 @@ async function doctorCommand() {
|
|
|
7103
7253
|
if (errorLines.length > 0) {
|
|
7104
7254
|
warn(`${svcName} \u2014 ${errorLines.length} error(s) in last 50 log lines`);
|
|
7105
7255
|
for (const line of errorLines.slice(0, 3)) {
|
|
7106
|
-
console.log(` ${
|
|
7256
|
+
console.log(` ${import_picocolors15.default.dim(line.trim().slice(0, 120))}`);
|
|
7107
7257
|
}
|
|
7108
7258
|
} else {
|
|
7109
7259
|
pass(`${svcName} \u2014 no errors in recent logs`);
|
|
@@ -7157,11 +7307,11 @@ async function doctorCommand() {
|
|
|
7157
7307
|
}
|
|
7158
7308
|
}
|
|
7159
7309
|
console.log();
|
|
7160
|
-
Le(
|
|
7310
|
+
Le(import_picocolors15.default.dim("Diagnosis complete"));
|
|
7161
7311
|
}
|
|
7162
7312
|
|
|
7163
7313
|
// src/commands/shell.ts
|
|
7164
|
-
var
|
|
7314
|
+
var import_picocolors16 = __toESM(require_picocolors(), 1);
|
|
7165
7315
|
async function shellCommand() {
|
|
7166
7316
|
const dir = findInstallDir();
|
|
7167
7317
|
const config = readConfig(dir);
|
|
@@ -7183,7 +7333,7 @@ async function shellCommand() {
|
|
|
7183
7333
|
message: "Select a container",
|
|
7184
7334
|
options: containers.map((c) => ({
|
|
7185
7335
|
value: c.name,
|
|
7186
|
-
label: `${c.name.replace(`-${id}`, "")} ${
|
|
7336
|
+
label: `${c.name.replace(`-${id}`, "")} ${import_picocolors16.default.dim(`(${c.name})`)}`
|
|
7187
7337
|
}))
|
|
7188
7338
|
});
|
|
7189
7339
|
if (Ct(selected)) {
|
|
@@ -7196,7 +7346,7 @@ async function shellCommand() {
|
|
|
7196
7346
|
|
|
7197
7347
|
// src/commands/dev.ts
|
|
7198
7348
|
import { spawn as spawn2, spawnSync as spawnSync2, execSync as execSync5 } from "child_process";
|
|
7199
|
-
var
|
|
7349
|
+
var import_picocolors18 = __toESM(require_picocolors(), 1);
|
|
7200
7350
|
import * as path7 from "path";
|
|
7201
7351
|
import * as fs7 from "fs";
|
|
7202
7352
|
|
|
@@ -7204,7 +7354,7 @@ import * as fs7 from "fs";
|
|
|
7204
7354
|
import * as fs6 from "fs";
|
|
7205
7355
|
import * as path6 from "path";
|
|
7206
7356
|
import * as crypto4 from "crypto";
|
|
7207
|
-
var
|
|
7357
|
+
var import_picocolors17 = __toESM(require_picocolors(), 1);
|
|
7208
7358
|
function generateJwtSecret() {
|
|
7209
7359
|
return crypto4.randomBytes(32).toString("base64url");
|
|
7210
7360
|
}
|
|
@@ -7331,9 +7481,9 @@ async function checkDevEnv(root) {
|
|
|
7331
7481
|
byApp.set(m.app.label, list);
|
|
7332
7482
|
}
|
|
7333
7483
|
for (const [label, vars] of byApp) {
|
|
7334
|
-
console.log(` ${
|
|
7484
|
+
console.log(` ${import_picocolors17.default.bold(label)} ${import_picocolors17.default.dim(`(${vars[0].app.envFile})`)}`);
|
|
7335
7485
|
for (const m of vars) {
|
|
7336
|
-
console.log(` ${
|
|
7486
|
+
console.log(` ${import_picocolors17.default.red("\u2717")} ${import_picocolors17.default.cyan(m.envVar.name)} \u2014 ${import_picocolors17.default.dim(m.envVar.description)}`);
|
|
7337
7487
|
}
|
|
7338
7488
|
console.log();
|
|
7339
7489
|
}
|
|
@@ -7369,8 +7519,8 @@ async function checkDevEnv(root) {
|
|
|
7369
7519
|
}
|
|
7370
7520
|
if (toWrite.size > 0) {
|
|
7371
7521
|
appendToEnvFile(filePath, toWrite);
|
|
7372
|
-
const names = [...toWrite.keys()].map((k2) =>
|
|
7373
|
-
R2.success(`${
|
|
7522
|
+
const names = [...toWrite.keys()].map((k2) => import_picocolors17.default.cyan(k2)).join(", ");
|
|
7523
|
+
R2.success(`${import_picocolors17.default.bold(app.label)}: wrote ${names} \u2192 ${import_picocolors17.default.dim(app.envFile)}`);
|
|
7374
7524
|
}
|
|
7375
7525
|
}
|
|
7376
7526
|
console.log();
|
|
@@ -7451,7 +7601,7 @@ async function waitForHealth2(label, command, args, maxAttempts = 30) {
|
|
|
7451
7601
|
}
|
|
7452
7602
|
return false;
|
|
7453
7603
|
}
|
|
7454
|
-
var CONTROLS_BAR =
|
|
7604
|
+
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));
|
|
7455
7605
|
var lineCount = 0;
|
|
7456
7606
|
var CONTROLS_INTERVAL = 50;
|
|
7457
7607
|
function printControls() {
|
|
@@ -7533,15 +7683,27 @@ async function devCommand(opts) {
|
|
|
7533
7683
|
R2.info("Run this command from within the learnhouse monorepo (must contain dev/docker-compose.yml, apps/api/, and apps/web/).");
|
|
7534
7684
|
process.exit(1);
|
|
7535
7685
|
}
|
|
7536
|
-
We(
|
|
7686
|
+
We(import_picocolors18.default.cyan("LearnHouse Dev Mode"));
|
|
7537
7687
|
const envOk = await checkDevEnv(root);
|
|
7538
7688
|
if (!envOk) process.exit(1);
|
|
7539
7689
|
const eePath = path7.join(root, "apps", "api", "ee");
|
|
7540
7690
|
if (opts.ee) {
|
|
7691
|
+
if (!fs7.existsSync(eePath)) {
|
|
7692
|
+
const parentDir = path7.dirname(root);
|
|
7693
|
+
const eeRepoPath = path7.join(parentDir, "ee", "apps", "api", "ee");
|
|
7694
|
+
if (fs7.existsSync(eeRepoPath)) {
|
|
7695
|
+
try {
|
|
7696
|
+
fs7.symlinkSync(eeRepoPath, eePath);
|
|
7697
|
+
R2.success(`Linked EE folder \u2192 ${eeRepoPath}`);
|
|
7698
|
+
} catch (err) {
|
|
7699
|
+
R2.warning(`Could not create EE symlink: ${err.message}`);
|
|
7700
|
+
}
|
|
7701
|
+
} else {
|
|
7702
|
+
R2.warning(`--ee passed but no ee/ folder found at ${eeRepoPath} \u2014 running in OSS mode`);
|
|
7703
|
+
}
|
|
7704
|
+
}
|
|
7541
7705
|
if (fs7.existsSync(eePath)) {
|
|
7542
|
-
R2.info(`Running in ${
|
|
7543
|
-
} else {
|
|
7544
|
-
R2.warning("--ee was passed but no ee/ folder found \u2014 running in OSS mode");
|
|
7706
|
+
R2.info(`Running in ${import_picocolors18.default.bold("EE")} mode`);
|
|
7545
7707
|
}
|
|
7546
7708
|
}
|
|
7547
7709
|
if (!isDockerInstalled()) {
|
|
@@ -7597,9 +7759,12 @@ async function devCommand(opts) {
|
|
|
7597
7759
|
}
|
|
7598
7760
|
serviceEnv = {
|
|
7599
7761
|
FORCE_COLOR: "1",
|
|
7762
|
+
LEARNHOUSE_DEVELOPMENT_MODE: "true",
|
|
7600
7763
|
...adminEmail && { LEARNHOUSE_INITIAL_ADMIN_EMAIL: adminEmail },
|
|
7601
7764
|
...adminPassword && { LEARNHOUSE_INITIAL_ADMIN_PASSWORD: adminPassword },
|
|
7602
|
-
...!opts.ee && { LEARNHOUSE_DISABLE_EE: "1" }
|
|
7765
|
+
...!opts.ee && { LEARNHOUSE_DISABLE_EE: "1" },
|
|
7766
|
+
// Bypass license verification for local dev when --ee is active
|
|
7767
|
+
...opts.ee && { LEARNHOUSE_FORCE_EE: "1" }
|
|
7603
7768
|
};
|
|
7604
7769
|
const healthSpinner = bt2();
|
|
7605
7770
|
healthSpinner.start("Waiting for DB and Redis to be healthy...");
|
|
@@ -7643,35 +7808,35 @@ async function devCommand(opts) {
|
|
|
7643
7808
|
let webProc = null;
|
|
7644
7809
|
let collabProc = null;
|
|
7645
7810
|
const startApi = () => {
|
|
7646
|
-
return spawnService("uv", ["run", "python", "app.py"], path7.join(root, "apps", "api"), "api",
|
|
7811
|
+
return spawnService("uv", ["run", "python", "app.py"], path7.join(root, "apps", "api"), "api", import_picocolors18.default.magenta);
|
|
7647
7812
|
};
|
|
7648
7813
|
const startWeb = () => {
|
|
7649
|
-
return spawnService("next", ["dev", "--turbopack"], path7.join(root, "apps", "web"), "web",
|
|
7814
|
+
return spawnService("next", ["dev", "--turbopack"], path7.join(root, "apps", "web"), "web", import_picocolors18.default.cyan);
|
|
7650
7815
|
};
|
|
7651
7816
|
const startCollab = () => {
|
|
7652
|
-
return spawnService("tsx", ["watch", "src/index.ts"], path7.join(root, "apps", "collab"), "collab",
|
|
7817
|
+
return spawnService("tsx", ["watch", "src/index.ts"], path7.join(root, "apps", "collab"), "collab", import_picocolors18.default.yellow);
|
|
7653
7818
|
};
|
|
7654
7819
|
apiProc = startApi();
|
|
7655
7820
|
webProc = startWeb();
|
|
7656
7821
|
collabProc = startCollab();
|
|
7657
7822
|
R2.success("API, Web, and Collab servers started");
|
|
7658
7823
|
console.log();
|
|
7659
|
-
console.log(
|
|
7824
|
+
console.log(import_picocolors18.default.dim(" Thank you for contributing to LearnHouse!"));
|
|
7660
7825
|
console.log();
|
|
7661
7826
|
printControls();
|
|
7662
7827
|
let shuttingDown = false;
|
|
7663
7828
|
const shutdown = async () => {
|
|
7664
7829
|
if (shuttingDown) return;
|
|
7665
7830
|
shuttingDown = true;
|
|
7666
|
-
console.log("\n" +
|
|
7831
|
+
console.log("\n" + import_picocolors18.default.dim("Shutting down dev servers..."));
|
|
7667
7832
|
if (process.stdin.isTTY && process.stdin.isRaw) {
|
|
7668
7833
|
process.stdin.setRawMode(false);
|
|
7669
7834
|
}
|
|
7670
7835
|
process.stdin.pause();
|
|
7671
7836
|
await Promise.all([killProcess(apiProc), killProcess(webProc), killProcess(collabProc)]);
|
|
7672
|
-
console.log(
|
|
7673
|
-
console.log(
|
|
7674
|
-
console.log(
|
|
7837
|
+
console.log(import_picocolors18.default.dim("DB and Redis containers are still running for next session."));
|
|
7838
|
+
console.log(import_picocolors18.default.dim("To stop them: docker compose -f .learnhouse/docker-compose.dev.yml -p learnhouse-dev down"));
|
|
7839
|
+
console.log(import_picocolors18.default.dim("Thanks for building with LearnHouse!"));
|
|
7675
7840
|
process.exit(0);
|
|
7676
7841
|
};
|
|
7677
7842
|
process.on("SIGINT", shutdown);
|
|
@@ -7700,22 +7865,22 @@ async function devCommand(opts) {
|
|
|
7700
7865
|
if (pendingR) {
|
|
7701
7866
|
pendingR = false;
|
|
7702
7867
|
if (key === "a") {
|
|
7703
|
-
console.log(
|
|
7868
|
+
console.log(import_picocolors18.default.magenta("\n Restarting API...\n"));
|
|
7704
7869
|
await killProcess(apiProc);
|
|
7705
7870
|
apiProc = startApi();
|
|
7706
7871
|
printControls();
|
|
7707
7872
|
} else if (key === "w") {
|
|
7708
|
-
console.log(
|
|
7873
|
+
console.log(import_picocolors18.default.cyan("\n Restarting Web...\n"));
|
|
7709
7874
|
await killProcess(webProc);
|
|
7710
7875
|
webProc = startWeb();
|
|
7711
7876
|
printControls();
|
|
7712
7877
|
} else if (key === "c") {
|
|
7713
|
-
console.log(
|
|
7878
|
+
console.log(import_picocolors18.default.yellow("\n Restarting Collab...\n"));
|
|
7714
7879
|
await killProcess(collabProc);
|
|
7715
7880
|
collabProc = startCollab();
|
|
7716
7881
|
printControls();
|
|
7717
7882
|
} else if (key === "b") {
|
|
7718
|
-
console.log(
|
|
7883
|
+
console.log(import_picocolors18.default.yellow("\n Restarting all...\n"));
|
|
7719
7884
|
await Promise.all([killProcess(apiProc), killProcess(webProc), killProcess(collabProc)]);
|
|
7720
7885
|
apiProc = startApi();
|
|
7721
7886
|
webProc = startWeb();
|
|
@@ -7733,7 +7898,7 @@ async function devCommand(opts) {
|
|
|
7733
7898
|
import { execSync as execSync6 } from "child_process";
|
|
7734
7899
|
import { readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
7735
7900
|
import { join as join3 } from "path";
|
|
7736
|
-
var
|
|
7901
|
+
var import_picocolors19 = __toESM(require_picocolors(), 1);
|
|
7737
7902
|
var GHCR_BASE2 = "ghcr.io/learnhouse/app";
|
|
7738
7903
|
async function resolveTag(version) {
|
|
7739
7904
|
try {
|
|
@@ -7767,9 +7932,9 @@ async function updateCommand(options) {
|
|
|
7767
7932
|
}
|
|
7768
7933
|
const targetVersion = options.version?.replace(/^v/, "");
|
|
7769
7934
|
if (targetVersion) {
|
|
7770
|
-
We(
|
|
7935
|
+
We(import_picocolors19.default.cyan(`Updating LearnHouse to v${targetVersion}`));
|
|
7771
7936
|
} else {
|
|
7772
|
-
We(
|
|
7937
|
+
We(import_picocolors19.default.cyan("Updating LearnHouse to latest"));
|
|
7773
7938
|
}
|
|
7774
7939
|
const s = bt2();
|
|
7775
7940
|
try {
|
|
@@ -7815,10 +7980,10 @@ async function updateCommand(options) {
|
|
|
7815
7980
|
} else {
|
|
7816
7981
|
R2.info("");
|
|
7817
7982
|
R2.warn(
|
|
7818
|
-
|
|
7983
|
+
import_picocolors19.default.bold("This update may include database migrations.")
|
|
7819
7984
|
);
|
|
7820
7985
|
R2.info(
|
|
7821
|
-
`Before proceeding, check the release notes at ${
|
|
7986
|
+
`Before proceeding, check the release notes at ${import_picocolors19.default.cyan("https://docs.learnhouse.app")} for migration guides and breaking changes.`
|
|
7822
7987
|
);
|
|
7823
7988
|
R2.info("");
|
|
7824
7989
|
const runMigrations = await Re({
|
|
@@ -7843,10 +8008,19 @@ async function updateCommand(options) {
|
|
|
7843
8008
|
R2.warn("Could not find the app container to run migrations. Run them manually:");
|
|
7844
8009
|
R2.warn(' docker exec <container> sh -c "cd /app/api && uv run alembic upgrade head"');
|
|
7845
8010
|
}
|
|
7846
|
-
} catch {
|
|
7847
|
-
s.stop("
|
|
7848
|
-
|
|
7849
|
-
|
|
8011
|
+
} catch (err) {
|
|
8012
|
+
s.stop("Database migrations failed");
|
|
8013
|
+
const stderr = err?.stderr?.toString?.() ?? "";
|
|
8014
|
+
const stdout = err?.stdout?.toString?.() ?? "";
|
|
8015
|
+
const output = (stderr || stdout).trim();
|
|
8016
|
+
if (output) {
|
|
8017
|
+
for (const line of output.split("\n")) R2.error(` ${line}`);
|
|
8018
|
+
}
|
|
8019
|
+
const container = getAppContainerName(config.installDir) ?? "<container>";
|
|
8020
|
+
R2.warn("Retry manually with:");
|
|
8021
|
+
R2.warn(
|
|
8022
|
+
` docker exec ${container} sh -c "cd /app/api && uv run alembic upgrade head"`
|
|
8023
|
+
);
|
|
7850
8024
|
}
|
|
7851
8025
|
} else {
|
|
7852
8026
|
R2.info("Skipped database migrations. You can run them later with:");
|
|
@@ -7899,7 +8073,7 @@ function waitForContainer(containerName, timeoutMs = 6e4) {
|
|
|
7899
8073
|
}
|
|
7900
8074
|
|
|
7901
8075
|
// src/commands/status.ts
|
|
7902
|
-
var
|
|
8076
|
+
var import_picocolors20 = __toESM(require_picocolors(), 1);
|
|
7903
8077
|
async function statusCommand() {
|
|
7904
8078
|
const dir = findInstallDir();
|
|
7905
8079
|
const config = readConfig(dir);
|
|
@@ -7907,7 +8081,7 @@ async function statusCommand() {
|
|
|
7907
8081
|
R2.error("No LearnHouse installation found. Run `npx learnhouse setup` first.");
|
|
7908
8082
|
process.exit(1);
|
|
7909
8083
|
}
|
|
7910
|
-
We(
|
|
8084
|
+
We(import_picocolors20.default.cyan("LearnHouse Status"));
|
|
7911
8085
|
const protocol = config.useHttps ? "https" : "http";
|
|
7912
8086
|
const portSuffix = config.useHttps && config.httpPort === 443 || !config.useHttps && config.httpPort === 80 ? "" : `:${config.httpPort}`;
|
|
7913
8087
|
R2.info(`URL: ${protocol}://${config.domain}${portSuffix}`);
|
|
@@ -7921,12 +8095,12 @@ async function statusCommand() {
|
|
|
7921
8095
|
}
|
|
7922
8096
|
|
|
7923
8097
|
// src/commands/health.ts
|
|
7924
|
-
var
|
|
8098
|
+
var import_picocolors21 = __toESM(require_picocolors(), 1);
|
|
7925
8099
|
function pass2(msg) {
|
|
7926
|
-
return `${
|
|
8100
|
+
return `${import_picocolors21.default.green("\u25CF")} ${msg}`;
|
|
7927
8101
|
}
|
|
7928
8102
|
function fail2(msg) {
|
|
7929
|
-
return `${
|
|
8103
|
+
return `${import_picocolors21.default.red("\u25CF")} ${msg}`;
|
|
7930
8104
|
}
|
|
7931
8105
|
async function healthCommand() {
|
|
7932
8106
|
const dir = findInstallDir();
|
|
@@ -7935,7 +8109,7 @@ async function healthCommand() {
|
|
|
7935
8109
|
R2.error("No LearnHouse installation found. Run setup first.");
|
|
7936
8110
|
process.exit(1);
|
|
7937
8111
|
}
|
|
7938
|
-
We(
|
|
8112
|
+
We(import_picocolors21.default.cyan("LearnHouse Health Check"));
|
|
7939
8113
|
const id = config.deploymentId || autoDetectDeploymentId();
|
|
7940
8114
|
if (!id) {
|
|
7941
8115
|
R2.error("No deployment found. Start services first.");
|
|
@@ -7995,20 +8169,20 @@ async function healthCommand() {
|
|
|
7995
8169
|
R2.step("Disk Usage");
|
|
7996
8170
|
try {
|
|
7997
8171
|
const diskOutput = getDockerDiskUsage();
|
|
7998
|
-
R2.message(
|
|
8172
|
+
R2.message(import_picocolors21.default.dim(diskOutput.trim()));
|
|
7999
8173
|
} catch {
|
|
8000
8174
|
R2.message(fail2("Could not retrieve disk usage"));
|
|
8001
8175
|
}
|
|
8002
8176
|
R2.step("Resource Usage");
|
|
8003
8177
|
try {
|
|
8004
8178
|
const stats = dockerStats(config.installDir);
|
|
8005
|
-
R2.message(
|
|
8179
|
+
R2.message(import_picocolors21.default.dim(stats.trim()));
|
|
8006
8180
|
} catch {
|
|
8007
8181
|
try {
|
|
8008
8182
|
const names = containers.filter((c) => c.status.toLowerCase().startsWith("up")).map((c) => c.name);
|
|
8009
8183
|
if (names.length > 0) {
|
|
8010
8184
|
const stats = dockerStatsForContainers(names);
|
|
8011
|
-
R2.message(
|
|
8185
|
+
R2.message(import_picocolors21.default.dim(stats.trim()));
|
|
8012
8186
|
} else {
|
|
8013
8187
|
R2.message(fail2("No running containers to get stats from"));
|
|
8014
8188
|
}
|
|
@@ -8016,13 +8190,13 @@ async function healthCommand() {
|
|
|
8016
8190
|
R2.message(fail2("Could not retrieve resource stats"));
|
|
8017
8191
|
}
|
|
8018
8192
|
}
|
|
8019
|
-
Le(
|
|
8193
|
+
Le(import_picocolors21.default.dim("Health check complete"));
|
|
8020
8194
|
}
|
|
8021
8195
|
|
|
8022
8196
|
// src/commands/env.ts
|
|
8023
8197
|
import fs8 from "fs";
|
|
8024
8198
|
import path8 from "path";
|
|
8025
|
-
var
|
|
8199
|
+
var import_picocolors22 = __toESM(require_picocolors(), 1);
|
|
8026
8200
|
var SECRET_PATTERNS = ["PASSWORD", "SECRET", "API_KEY", "CLIENT_SECRET"];
|
|
8027
8201
|
var CATEGORIES = {
|
|
8028
8202
|
domain: {
|
|
@@ -8148,7 +8322,7 @@ async function envCommand() {
|
|
|
8148
8322
|
R2.error(`No .env file found at ${envPath}`);
|
|
8149
8323
|
process.exit(1);
|
|
8150
8324
|
}
|
|
8151
|
-
We(
|
|
8325
|
+
We(import_picocolors22.default.cyan("LearnHouse Environment Editor"));
|
|
8152
8326
|
const originalContent = fs8.readFileSync(envPath, "utf-8");
|
|
8153
8327
|
const envMap = parseEnv(originalContent);
|
|
8154
8328
|
let editing = true;
|
|
@@ -8157,7 +8331,7 @@ async function envCommand() {
|
|
|
8157
8331
|
message: "Select a category to edit",
|
|
8158
8332
|
options: [
|
|
8159
8333
|
...Object.entries(CATEGORIES).map(([value, { label }]) => ({ value, label })),
|
|
8160
|
-
{ value: "_done", label:
|
|
8334
|
+
{ value: "_done", label: import_picocolors22.default.dim("Done editing") }
|
|
8161
8335
|
]
|
|
8162
8336
|
});
|
|
8163
8337
|
if (Ct(category) || category === "_done") {
|
|
@@ -8173,14 +8347,14 @@ async function envCommand() {
|
|
|
8173
8347
|
}
|
|
8174
8348
|
R2.step(`${cat.label} \u2014 Current Values`);
|
|
8175
8349
|
for (const key2 of presentKeys) {
|
|
8176
|
-
R2.message(` ${
|
|
8350
|
+
R2.message(` ${import_picocolors22.default.dim(key2)} = ${maskValue(key2, envMap.get(key2))}`);
|
|
8177
8351
|
}
|
|
8178
8352
|
const keyToEdit = await Je({
|
|
8179
8353
|
message: "Select a variable to edit",
|
|
8180
8354
|
options: [
|
|
8181
8355
|
...presentKeys.map((k2) => ({ value: k2, label: `${k2} = ${maskValue(k2, envMap.get(k2))}` })),
|
|
8182
|
-
...missingKeys.map((k2) => ({ value: k2, label: `${k2} ${
|
|
8183
|
-
{ value: "_back", label:
|
|
8356
|
+
...missingKeys.map((k2) => ({ value: k2, label: `${k2} ${import_picocolors22.default.dim("(not set)")}` })),
|
|
8357
|
+
{ value: "_back", label: import_picocolors22.default.dim("Back") }
|
|
8184
8358
|
]
|
|
8185
8359
|
});
|
|
8186
8360
|
if (Ct(keyToEdit) || keyToEdit === "_back") continue;
|
|
@@ -8218,14 +8392,14 @@ async function envCommand() {
|
|
|
8218
8392
|
} else {
|
|
8219
8393
|
R2.info("No changes made.");
|
|
8220
8394
|
}
|
|
8221
|
-
Le(
|
|
8395
|
+
Le(import_picocolors22.default.dim("Done"));
|
|
8222
8396
|
}
|
|
8223
8397
|
|
|
8224
8398
|
// src/commands/restore.ts
|
|
8225
8399
|
import fs9 from "fs";
|
|
8226
8400
|
import path9 from "path";
|
|
8227
8401
|
import { execSync as execSync7 } from "child_process";
|
|
8228
|
-
var
|
|
8402
|
+
var import_picocolors23 = __toESM(require_picocolors(), 1);
|
|
8229
8403
|
async function restoreCommand(archivePath) {
|
|
8230
8404
|
if (!archivePath) {
|
|
8231
8405
|
R2.error("Please provide the path to a backup archive.");
|
|
@@ -8257,7 +8431,7 @@ async function restoreCommand(archivePath) {
|
|
|
8257
8431
|
R2.error("Database container is not running. Start services first.");
|
|
8258
8432
|
process.exit(1);
|
|
8259
8433
|
}
|
|
8260
|
-
R2.warn(
|
|
8434
|
+
R2.warn(import_picocolors23.default.yellow("This will overwrite the current database with the backup data."));
|
|
8261
8435
|
const confirm = await Re({
|
|
8262
8436
|
message: "Are you sure you want to restore from this backup?",
|
|
8263
8437
|
initialValue: false
|
|
@@ -8316,7 +8490,7 @@ async function restoreCommand(archivePath) {
|
|
|
8316
8490
|
}
|
|
8317
8491
|
}
|
|
8318
8492
|
fs9.rmSync(tmpDir, { recursive: true, force: true });
|
|
8319
|
-
R2.success(
|
|
8493
|
+
R2.success(import_picocolors23.default.green(import_picocolors23.default.bold("Restore complete!")));
|
|
8320
8494
|
R2.info("You may want to restart services: npx learnhouse stop && npx learnhouse start");
|
|
8321
8495
|
}
|
|
8322
8496
|
|
|
@@ -8340,18 +8514,18 @@ var COMMANDS = [
|
|
|
8340
8514
|
];
|
|
8341
8515
|
async function showWelcome() {
|
|
8342
8516
|
await printBanner();
|
|
8343
|
-
console.log(
|
|
8517
|
+
console.log(import_picocolors24.default.bold(import_picocolors24.default.white(" Available commands:\n")));
|
|
8344
8518
|
for (const cmd of COMMANDS) {
|
|
8345
|
-
console.log(` ${
|
|
8519
|
+
console.log(` ${import_picocolors24.default.cyan(cmd.name.padEnd(14))} ${import_picocolors24.default.dim(cmd.desc)}`);
|
|
8346
8520
|
}
|
|
8347
8521
|
console.log();
|
|
8348
|
-
console.log(
|
|
8349
|
-
console.log(
|
|
8522
|
+
console.log(import_picocolors24.default.dim(" Run a command with: npx learnhouse <command>"));
|
|
8523
|
+
console.log(import_picocolors24.default.dim(" Get started with: npx learnhouse setup"));
|
|
8350
8524
|
console.log();
|
|
8351
8525
|
}
|
|
8352
8526
|
var program2 = new Command();
|
|
8353
8527
|
program2.name("learnhouse").description("The official LearnHouse CLI \u2014 deploy, manage, and operate your LearnHouse instance").version(VERSION).action(showWelcome);
|
|
8354
|
-
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);
|
|
8528
|
+
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);
|
|
8355
8529
|
program2.command("start").description("Start LearnHouse services").action(startCommand);
|
|
8356
8530
|
program2.command("stop").description("Stop LearnHouse services").action(stopCommand);
|
|
8357
8531
|
program2.command("logs").description("Stream logs from LearnHouse services").action(logsCommand);
|