learnhouse 1.4.5 → 1.4.7

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.
Files changed (2) hide show
  1. package/dist/bin/learnhouse.js +295 -115
  2. package/package.json +1 -1
@@ -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 path10 = __require("path");
1206
- var fs10 = __require("fs");
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 (fs10.existsSync(executableFile)) return;
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 = path10.resolve(baseDir, baseName);
2219
- if (fs10.existsSync(localBin)) return localBin;
2220
- if (sourceExt.includes(path10.extname(baseName))) return void 0;
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) => fs10.existsSync(`${localBin}${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 = fs10.realpathSync(this._scriptPath);
2234
+ resolvedScriptPath = fs11.realpathSync(this._scriptPath);
2235
2235
  } catch {
2236
2236
  resolvedScriptPath = this._scriptPath;
2237
2237
  }
2238
- executableDir = path10.resolve(
2239
- path10.dirname(resolvedScriptPath),
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 = path10.basename(
2246
+ const legacyName = path11.basename(
2247
2247
  this._scriptPath,
2248
- path10.extname(this._scriptPath)
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(path10.extname(executableFile));
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 = path10.basename(filename, path10.extname(filename));
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(path11) {
3189
- if (path11 === void 0) return this._executableDir;
3190
- this._executableDir = path11;
3188
+ executableDir(path12) {
3189
+ if (path12 === void 0) return this._executableDir;
3190
+ this._executableDir = path12;
3191
3191
  return this;
3192
3192
  }
3193
3193
  /**
@@ -3616,7 +3616,7 @@ var {
3616
3616
  var import_picocolors24 = __toESM(require_picocolors(), 1);
3617
3617
 
3618
3618
  // src/constants.ts
3619
- var VERSION = "1.4.5";
3619
+ var VERSION = "1.4.7";
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";
@@ -5738,6 +5738,10 @@ ${deps.join("\n")}` : "";
5738
5738
  interval: 5s
5739
5739
  timeout: 4s
5740
5740
  retries: 5
5741
+ ` : "";
5742
+ const useLocalContent = !config.s3Enabled;
5743
+ const appVolumes = useLocalContent ? ` volumes:
5744
+ - learnhouse_content_${id}:/app/api/content
5741
5745
  ` : "";
5742
5746
  const volumeEntries = [];
5743
5747
  if (config.autoSsl) {
@@ -5746,6 +5750,7 @@ ${deps.join("\n")}` : "";
5746
5750
  }
5747
5751
  if (useLocalDb) volumeEntries.push(` learnhouse_db_data_${id}:`);
5748
5752
  if (useLocalRedis) volumeEntries.push(` learnhouse_redis_data_${id}:`);
5753
+ if (useLocalContent) volumeEntries.push(` learnhouse_content_${id}:`);
5749
5754
  const volumesSection = volumeEntries.length > 0 ? `volumes:
5750
5755
  ${volumeEntries.join("\n")}` : "";
5751
5756
  return `name: learnhouse-${id}
@@ -5761,7 +5766,7 @@ services:
5761
5766
  # HOSTNAME needs to be set explicitly for the container
5762
5767
  - HOSTNAME=0.0.0.0
5763
5768
  - LEARNHOUSE_API_URL=http://localhost:9000
5764
- ${appDependsOn}
5769
+ ${appVolumes}${appDependsOn}
5765
5770
  networks:
5766
5771
  - learnhouse-network-${id}
5767
5772
  healthcheck:
@@ -6612,6 +6617,137 @@ async function setupCommand(options) {
6612
6617
 
6613
6618
  // src/commands/start.ts
6614
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;
6748
+ }
6749
+
6750
+ // src/commands/start.ts
6615
6751
  async function startCommand() {
6616
6752
  const dir = findInstallDir();
6617
6753
  const config = readConfig(dir);
@@ -6620,6 +6756,17 @@ async function startCommand() {
6620
6756
  process.exit(1);
6621
6757
  }
6622
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
+ }
6623
6770
  try {
6624
6771
  dockerComposeUp(config.installDir);
6625
6772
  R2.success("LearnHouse is running!");
@@ -6701,8 +6848,8 @@ async function configCommand() {
6701
6848
  }
6702
6849
 
6703
6850
  // src/commands/backup.ts
6704
- import fs3 from "fs";
6705
- import path3 from "path";
6851
+ import fs4 from "fs";
6852
+ import path4 from "path";
6706
6853
  import { execSync as execSync2 } from "child_process";
6707
6854
  var import_picocolors13 = __toESM(require_picocolors(), 1);
6708
6855
  function resolveDbContainer(config) {
@@ -6728,15 +6875,15 @@ async function createBackup() {
6728
6875
  process.exit(1);
6729
6876
  }
6730
6877
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
6731
- const backupDir = path3.join(installDir, "backups");
6878
+ const backupDir = path4.join(installDir, "backups");
6732
6879
  const backupName = `learnhouse-backup-${timestamp}`;
6733
- const tmpDir = path3.join(backupDir, backupName);
6734
- const archivePath = path3.join(backupDir, `${backupName}.tar.gz`);
6735
- fs3.mkdirSync(tmpDir, { recursive: true });
6880
+ const tmpDir = path4.join(backupDir, backupName);
6881
+ const archivePath = path4.join(backupDir, `${backupName}.tar.gz`);
6882
+ fs4.mkdirSync(tmpDir, { recursive: true });
6736
6883
  const s = bt2();
6737
6884
  s.start("Creating database dump");
6738
6885
  try {
6739
- const dumpPath = path3.join(tmpDir, "database.sql");
6886
+ const dumpPath = path4.join(tmpDir, "database.sql");
6740
6887
  dockerExecToFile(
6741
6888
  dbContainer,
6742
6889
  "pg_dump -U learnhouse learnhouse",
@@ -6746,12 +6893,12 @@ async function createBackup() {
6746
6893
  } catch (err) {
6747
6894
  s.stop("Database dump failed");
6748
6895
  R2.error("Failed to create database dump. Check that the database is running.");
6749
- fs3.rmSync(tmpDir, { recursive: true, force: true });
6896
+ fs4.rmSync(tmpDir, { recursive: true, force: true });
6750
6897
  process.exit(1);
6751
6898
  }
6752
- const envPath = path3.join(installDir, ".env");
6753
- if (fs3.existsSync(envPath)) {
6754
- fs3.copyFileSync(envPath, path3.join(tmpDir, ".env"));
6899
+ const envPath = path4.join(installDir, ".env");
6900
+ if (fs4.existsSync(envPath)) {
6901
+ fs4.copyFileSync(envPath, path4.join(tmpDir, ".env"));
6755
6902
  }
6756
6903
  const s2 = bt2();
6757
6904
  s2.start("Creating archive");
@@ -6765,8 +6912,8 @@ async function createBackup() {
6765
6912
  R2.error("Failed to create archive.");
6766
6913
  process.exit(1);
6767
6914
  }
6768
- fs3.rmSync(tmpDir, { recursive: true, force: true });
6769
- const stats = fs3.statSync(archivePath);
6915
+ fs4.rmSync(tmpDir, { recursive: true, force: true });
6916
+ const stats = fs4.statSync(archivePath);
6770
6917
  const sizeMb = (stats.size / (1024 * 1024)).toFixed(1);
6771
6918
  R2.success(import_picocolors13.default.green(import_picocolors13.default.bold("Backup complete!")));
6772
6919
  R2.message([
@@ -6779,7 +6926,7 @@ async function createBackup() {
6779
6926
  ].join("\n"));
6780
6927
  }
6781
6928
  async function restoreBackup(archivePath) {
6782
- if (!fs3.existsSync(archivePath)) {
6929
+ if (!fs4.existsSync(archivePath)) {
6783
6930
  R2.error(`Backup file not found: ${archivePath}`);
6784
6931
  process.exit(1);
6785
6932
  }
@@ -6808,8 +6955,8 @@ async function restoreBackup(archivePath) {
6808
6955
  Ne("Restore cancelled.");
6809
6956
  process.exit(0);
6810
6957
  }
6811
- const tmpDir = path3.join(installDir, ".restore-tmp");
6812
- fs3.mkdirSync(tmpDir, { recursive: true });
6958
+ const tmpDir = path4.join(installDir, ".restore-tmp");
6959
+ fs4.mkdirSync(tmpDir, { recursive: true });
6813
6960
  const s = bt2();
6814
6961
  s.start("Extracting backup archive");
6815
6962
  try {
@@ -6817,20 +6964,20 @@ async function restoreBackup(archivePath) {
6817
6964
  s.stop("Archive extracted");
6818
6965
  } catch {
6819
6966
  s.stop("Extraction failed");
6820
- fs3.rmSync(tmpDir, { recursive: true, force: true });
6967
+ fs4.rmSync(tmpDir, { recursive: true, force: true });
6821
6968
  R2.error("Failed to extract backup archive.");
6822
6969
  process.exit(1);
6823
6970
  }
6824
- const entries = fs3.readdirSync(tmpDir);
6971
+ const entries = fs4.readdirSync(tmpDir);
6825
6972
  const backupFolder = entries.find(
6826
- (e2) => fs3.existsSync(path3.join(tmpDir, e2, "database.sql"))
6973
+ (e2) => fs4.existsSync(path4.join(tmpDir, e2, "database.sql"))
6827
6974
  );
6828
6975
  if (!backupFolder) {
6829
6976
  R2.error("No database.sql found in the backup archive.");
6830
- fs3.rmSync(tmpDir, { recursive: true, force: true });
6977
+ fs4.rmSync(tmpDir, { recursive: true, force: true });
6831
6978
  process.exit(1);
6832
6979
  }
6833
- const dumpPath = path3.join(tmpDir, backupFolder, "database.sql");
6980
+ const dumpPath = path4.join(tmpDir, backupFolder, "database.sql");
6834
6981
  const s2 = bt2();
6835
6982
  s2.start("Restoring database");
6836
6983
  try {
@@ -6842,22 +6989,22 @@ async function restoreBackup(archivePath) {
6842
6989
  s2.stop("Database restored");
6843
6990
  } catch {
6844
6991
  s2.stop("Database restore failed");
6845
- fs3.rmSync(tmpDir, { recursive: true, force: true });
6992
+ fs4.rmSync(tmpDir, { recursive: true, force: true });
6846
6993
  R2.error("Failed to restore database. The backup file may be corrupted.");
6847
6994
  process.exit(1);
6848
6995
  }
6849
- const envBackup = path3.join(tmpDir, backupFolder, ".env");
6850
- if (fs3.existsSync(envBackup)) {
6996
+ const envBackup = path4.join(tmpDir, backupFolder, ".env");
6997
+ if (fs4.existsSync(envBackup)) {
6851
6998
  const restoreEnv = await Re({
6852
6999
  message: "Backup contains a .env file. Restore it? (overwrites current .env)",
6853
7000
  initialValue: false
6854
7001
  });
6855
7002
  if (!Ct(restoreEnv) && restoreEnv) {
6856
- fs3.copyFileSync(envBackup, path3.join(installDir, ".env"));
7003
+ fs4.copyFileSync(envBackup, path4.join(installDir, ".env"));
6857
7004
  R2.info(".env file restored");
6858
7005
  }
6859
7006
  }
6860
- fs3.rmSync(tmpDir, { recursive: true, force: true });
7007
+ fs4.rmSync(tmpDir, { recursive: true, force: true });
6861
7008
  R2.success(import_picocolors13.default.green(import_picocolors13.default.bold("Restore complete!")));
6862
7009
  R2.info("You may want to restart services: npx learnhouse stop && npx learnhouse start");
6863
7010
  }
@@ -6895,8 +7042,8 @@ async function backupCommand(archivePath, options) {
6895
7042
  }
6896
7043
 
6897
7044
  // src/commands/deployments.ts
6898
- import fs4 from "fs";
6899
- import path4 from "path";
7045
+ import fs5 from "fs";
7046
+ import path5 from "path";
6900
7047
  import { execSync as execSync3 } from "child_process";
6901
7048
  var import_picocolors14 = __toESM(require_picocolors(), 1);
6902
7049
  var SERVICES = ["learnhouse-app", "db", "redis"];
@@ -6956,7 +7103,7 @@ function showDeployments() {
6956
7103
  }
6957
7104
  }
6958
7105
  function parseMemLimit(composePath) {
6959
- const content = fs4.readFileSync(composePath, "utf-8");
7106
+ const content = fs5.readFileSync(composePath, "utf-8");
6960
7107
  const limits = /* @__PURE__ */ new Map();
6961
7108
  let currentService = null;
6962
7109
  let inServices = false;
@@ -7038,12 +7185,12 @@ async function scaleResources() {
7038
7185
  R2.warn("Could not retrieve current stats. Services may not be running.");
7039
7186
  }
7040
7187
  }
7041
- const composePath = path4.join(config.installDir || dir, "docker-compose.yml");
7042
- if (!fs4.existsSync(composePath)) {
7188
+ const composePath = path5.join(config.installDir || dir, "docker-compose.yml");
7189
+ if (!fs5.existsSync(composePath)) {
7043
7190
  R2.error("docker-compose.yml not found.");
7044
7191
  process.exit(1);
7045
7192
  }
7046
- let composeContent = fs4.readFileSync(composePath, "utf-8");
7193
+ let composeContent = fs5.readFileSync(composePath, "utf-8");
7047
7194
  const currentLimits = parseMemLimit(composePath);
7048
7195
  R2.step("Set Memory Limits");
7049
7196
  R2.info(import_picocolors14.default.dim("Examples: 256m, 512m, 1g, 2g (leave empty to skip)"));
@@ -7073,7 +7220,7 @@ async function scaleResources() {
7073
7220
  R2.info("No changes made.");
7074
7221
  return;
7075
7222
  }
7076
- fs4.writeFileSync(composePath, composeContent);
7223
+ fs5.writeFileSync(composePath, composeContent);
7077
7224
  R2.success("docker-compose.yml updated");
7078
7225
  const restart = await Re({
7079
7226
  message: "Restart services to apply limits?",
@@ -7114,8 +7261,8 @@ async function deploymentsCommand() {
7114
7261
  }
7115
7262
 
7116
7263
  // src/commands/doctor.ts
7117
- import fs5 from "fs";
7118
- import path5 from "path";
7264
+ import fs6 from "fs";
7265
+ import path6 from "path";
7119
7266
  import { execSync as execSync4 } from "child_process";
7120
7267
  var import_picocolors15 = __toESM(require_picocolors(), 1);
7121
7268
  function pass(msg) {
@@ -7263,11 +7410,11 @@ async function doctorCommand() {
7263
7410
  }
7264
7411
  }
7265
7412
  R2.step("Environment File");
7266
- const envPath = path5.join(installDir, ".env");
7267
- if (!fs5.existsSync(envPath)) {
7413
+ const envPath = path6.join(installDir, ".env");
7414
+ if (!fs6.existsSync(envPath)) {
7268
7415
  fail(".env file missing", "Run setup again: npx learnhouse setup");
7269
7416
  } else {
7270
- const envContent = fs5.readFileSync(envPath, "utf-8");
7417
+ const envContent = fs6.readFileSync(envPath, "utf-8");
7271
7418
  const envMap = /* @__PURE__ */ new Map();
7272
7419
  for (const line of envContent.split("\n")) {
7273
7420
  const trimmed = line.trim();
@@ -7347,12 +7494,12 @@ async function shellCommand() {
7347
7494
  // src/commands/dev.ts
7348
7495
  import { spawn as spawn2, spawnSync as spawnSync2, execSync as execSync5 } from "child_process";
7349
7496
  var import_picocolors18 = __toESM(require_picocolors(), 1);
7350
- import * as path7 from "path";
7351
- import * as fs7 from "fs";
7497
+ import * as path8 from "path";
7498
+ import * as fs8 from "fs";
7352
7499
 
7353
7500
  // src/services/env-check.ts
7354
- import * as fs6 from "fs";
7355
- import * as path6 from "path";
7501
+ import * as fs7 from "fs";
7502
+ import * as path7 from "path";
7356
7503
  import * as crypto4 from "crypto";
7357
7504
  var import_picocolors17 = __toESM(require_picocolors(), 1);
7358
7505
  function generateJwtSecret() {
@@ -7423,8 +7570,8 @@ var COLLAB_ENV = {
7423
7570
  var ALL_APPS = [API_ENV, WEB_ENV, COLLAB_ENV];
7424
7571
  function parseEnvFile(filePath) {
7425
7572
  const vars = /* @__PURE__ */ new Map();
7426
- if (!fs6.existsSync(filePath)) return vars;
7427
- for (const line of fs6.readFileSync(filePath, "utf-8").split("\n")) {
7573
+ if (!fs7.existsSync(filePath)) return vars;
7574
+ for (const line of fs7.readFileSync(filePath, "utf-8").split("\n")) {
7428
7575
  const trimmed = line.trim();
7429
7576
  if (!trimmed || trimmed.startsWith("#")) continue;
7430
7577
  const eq = trimmed.indexOf("=");
@@ -7442,17 +7589,17 @@ function parseEnvFile(filePath) {
7442
7589
  }
7443
7590
  function appendToEnvFile(filePath, newVars) {
7444
7591
  let content = "";
7445
- if (fs6.existsSync(filePath)) {
7446
- content = fs6.readFileSync(filePath, "utf-8");
7592
+ if (fs7.existsSync(filePath)) {
7593
+ content = fs7.readFileSync(filePath, "utf-8");
7447
7594
  if (content.length > 0 && !content.endsWith("\n")) content += "\n";
7448
7595
  }
7449
7596
  for (const [key, value] of newVars) {
7450
7597
  content += `${key}=${value}
7451
7598
  `;
7452
7599
  }
7453
- const dir = path6.dirname(filePath);
7454
- if (!fs6.existsSync(dir)) fs6.mkdirSync(dir, { recursive: true });
7455
- fs6.writeFileSync(filePath, content);
7600
+ const dir = path7.dirname(filePath);
7601
+ if (!fs7.existsSync(dir)) fs7.mkdirSync(dir, { recursive: true });
7602
+ fs7.writeFileSync(filePath, content);
7456
7603
  }
7457
7604
  function resolveDefault(v) {
7458
7605
  return typeof v.defaultValue === "function" ? v.defaultValue() : v.defaultValue;
@@ -7460,7 +7607,7 @@ function resolveDefault(v) {
7460
7607
  async function checkDevEnv(root) {
7461
7608
  const missing = [];
7462
7609
  for (const app of ALL_APPS) {
7463
- const existing = parseEnvFile(path6.join(root, app.envFile));
7610
+ const existing = parseEnvFile(path7.join(root, app.envFile));
7464
7611
  for (const v of app.vars) {
7465
7612
  const val = existing.get(v.name);
7466
7613
  if (v.required && (!val || val.length === 0)) {
@@ -7498,12 +7645,12 @@ async function checkDevEnv(root) {
7498
7645
  R2.info("Set the missing variables and run the command again.");
7499
7646
  return false;
7500
7647
  }
7501
- const apiFile = path6.join(root, API_ENV.envFile);
7648
+ const apiFile = path7.join(root, API_ENV.envFile);
7502
7649
  const apiExisting = parseEnvFile(apiFile);
7503
7650
  const jwtSecret = apiExisting.get("LEARNHOUSE_AUTH_JWT_SECRET_KEY") || generateJwtSecret();
7504
7651
  const collabKey = apiExisting.get("COLLAB_INTERNAL_KEY") || "dev-collab-internal-key-change-in-prod";
7505
7652
  for (const app of ALL_APPS) {
7506
- const filePath = path6.join(root, app.envFile);
7653
+ const filePath = path7.join(root, app.envFile);
7507
7654
  const existing = parseEnvFile(filePath);
7508
7655
  const toWrite = /* @__PURE__ */ new Map();
7509
7656
  for (const v of app.vars) {
@@ -7572,19 +7719,19 @@ volumes:
7572
7719
  function findProjectRoot() {
7573
7720
  let dir = process.cwd();
7574
7721
  while (true) {
7575
- if (fs7.existsSync(path7.join(dir, "apps", "api")) && fs7.existsSync(path7.join(dir, "apps", "web"))) {
7722
+ if (fs8.existsSync(path8.join(dir, "apps", "api")) && fs8.existsSync(path8.join(dir, "apps", "web"))) {
7576
7723
  return dir;
7577
7724
  }
7578
- const parent = path7.dirname(dir);
7725
+ const parent = path8.dirname(dir);
7579
7726
  if (parent === dir) return null;
7580
7727
  dir = parent;
7581
7728
  }
7582
7729
  }
7583
7730
  function getDevComposePath(root) {
7584
- const dotDir = path7.join(root, ".learnhouse");
7585
- if (!fs7.existsSync(dotDir)) fs7.mkdirSync(dotDir, { recursive: true });
7586
- const composePath = path7.join(dotDir, "docker-compose.dev.yml");
7587
- fs7.writeFileSync(composePath, DEV_COMPOSE);
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);
7588
7735
  return composePath;
7589
7736
  }
7590
7737
  function sleep(ms) {
@@ -7642,7 +7789,7 @@ function isInfraRunning() {
7642
7789
  }
7643
7790
  var serviceEnv = {};
7644
7791
  function spawnService(command, args, cwd, label, color) {
7645
- const localBin = path7.join(cwd, "node_modules", ".bin");
7792
+ const localBin = path8.join(cwd, "node_modules", ".bin");
7646
7793
  const child = spawn2(command, args, {
7647
7794
  cwd,
7648
7795
  stdio: ["ignore", "pipe", "pipe"],
@@ -7650,7 +7797,7 @@ function spawnService(command, args, cwd, label, color) {
7650
7797
  env: {
7651
7798
  ...process.env,
7652
7799
  ...serviceEnv,
7653
- PATH: `${localBin}${path7.delimiter}${process.env.PATH ?? ""}`
7800
+ PATH: `${localBin}${path8.delimiter}${process.env.PATH ?? ""}`
7654
7801
  }
7655
7802
  });
7656
7803
  prefixStream(child, label, color);
@@ -7686,14 +7833,14 @@ async function devCommand(opts) {
7686
7833
  We(import_picocolors18.default.cyan("LearnHouse Dev Mode"));
7687
7834
  const envOk = await checkDevEnv(root);
7688
7835
  if (!envOk) process.exit(1);
7689
- const eePath = path7.join(root, "apps", "api", "ee");
7836
+ const eePath = path8.join(root, "apps", "api", "ee");
7690
7837
  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)) {
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)) {
7695
7842
  try {
7696
- fs7.symlinkSync(eeRepoPath, eePath);
7843
+ fs8.symlinkSync(eeRepoPath, eePath);
7697
7844
  R2.success(`Linked EE folder \u2192 ${eeRepoPath}`);
7698
7845
  } catch (err) {
7699
7846
  R2.warning(`Could not create EE symlink: ${err.message}`);
@@ -7702,7 +7849,7 @@ async function devCommand(opts) {
7702
7849
  R2.warning(`--ee passed but no ee/ folder found at ${eeRepoPath} \u2014 running in OSS mode`);
7703
7850
  }
7704
7851
  }
7705
- if (fs7.existsSync(eePath)) {
7852
+ if (fs8.existsSync(eePath)) {
7706
7853
  R2.info(`Running in ${import_picocolors18.default.bold("EE")} mode`);
7707
7854
  }
7708
7855
  }
@@ -7779,15 +7926,15 @@ async function devCommand(opts) {
7779
7926
  process.exit(1);
7780
7927
  }
7781
7928
  healthSpinner.stop("DB and Redis are healthy");
7782
- const webDir = path7.join(root, "apps", "web");
7783
- const collabDir = path7.join(root, "apps", "collab");
7784
- const apiDir = path7.join(root, "apps", "api");
7929
+ const webDir = path8.join(root, "apps", "web");
7930
+ const collabDir = path8.join(root, "apps", "collab");
7931
+ const apiDir = path8.join(root, "apps", "api");
7785
7932
  const bunProjects = [
7786
7933
  { label: "web", dir: webDir },
7787
7934
  { label: "collab", dir: collabDir }
7788
7935
  ];
7789
7936
  for (const { label, dir } of bunProjects) {
7790
- if (!fs7.existsSync(path7.join(dir, "node_modules"))) {
7937
+ if (!fs8.existsSync(path8.join(dir, "node_modules"))) {
7791
7938
  R2.info(`Installing ${label} dependencies...`);
7792
7939
  const result = spawnSync2("bun", ["install"], { cwd: dir, stdio: "inherit", shell: true });
7793
7940
  if (result.status !== 0) {
@@ -7796,7 +7943,7 @@ async function devCommand(opts) {
7796
7943
  }
7797
7944
  }
7798
7945
  }
7799
- if (!fs7.existsSync(path7.join(apiDir, ".venv"))) {
7946
+ if (!fs8.existsSync(path8.join(apiDir, ".venv"))) {
7800
7947
  R2.info("Installing API dependencies...");
7801
7948
  const result = spawnSync2("uv", ["sync"], { cwd: apiDir, stdio: "inherit", shell: true });
7802
7949
  if (result.status !== 0) {
@@ -7808,13 +7955,13 @@ async function devCommand(opts) {
7808
7955
  let webProc = null;
7809
7956
  let collabProc = null;
7810
7957
  const startApi = () => {
7811
- return spawnService("uv", ["run", "python", "app.py"], path7.join(root, "apps", "api"), "api", import_picocolors18.default.magenta);
7958
+ return spawnService("uv", ["run", "python", "app.py"], path8.join(root, "apps", "api"), "api", import_picocolors18.default.magenta);
7812
7959
  };
7813
7960
  const startWeb = () => {
7814
- return spawnService("next", ["dev", "--turbopack"], path7.join(root, "apps", "web"), "web", import_picocolors18.default.cyan);
7961
+ return spawnService("next", ["dev", "--turbopack"], path8.join(root, "apps", "web"), "web", import_picocolors18.default.cyan);
7815
7962
  };
7816
7963
  const startCollab = () => {
7817
- return spawnService("tsx", ["watch", "src/index.ts"], path7.join(root, "apps", "collab"), "collab", import_picocolors18.default.yellow);
7964
+ return spawnService("tsx", ["watch", "src/index.ts"], path8.join(root, "apps", "collab"), "collab", import_picocolors18.default.yellow);
7818
7965
  };
7819
7966
  apiProc = startApi();
7820
7967
  webProc = startWeb();
@@ -7968,6 +8115,33 @@ async function updateCommand(options) {
7968
8115
  writeFileSync3(composePath, updatedCompose);
7969
8116
  s.start("Pulling image");
7970
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
+ }
7971
8145
  s.start("Restarting services");
7972
8146
  dockerComposeDown(config.installDir);
7973
8147
  dockerComposeUp(config.installDir);
@@ -8037,6 +8211,12 @@ async function updateCommand(options) {
8037
8211
  process.exit(1);
8038
8212
  }
8039
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
+ }
8040
8220
  function getAppContainerName(cwd) {
8041
8221
  try {
8042
8222
  const output = execSync6('docker compose ps --format "{{.Name}}"', {
@@ -8194,8 +8374,8 @@ async function healthCommand() {
8194
8374
  }
8195
8375
 
8196
8376
  // src/commands/env.ts
8197
- import fs8 from "fs";
8198
- import path8 from "path";
8377
+ import fs9 from "fs";
8378
+ import path9 from "path";
8199
8379
  var import_picocolors22 = __toESM(require_picocolors(), 1);
8200
8380
  var SECRET_PATTERNS = ["PASSWORD", "SECRET", "API_KEY", "CLIENT_SECRET"];
8201
8381
  var CATEGORIES = {
@@ -8317,13 +8497,13 @@ async function envCommand() {
8317
8497
  R2.error("No LearnHouse installation found. Run setup first.");
8318
8498
  process.exit(1);
8319
8499
  }
8320
- const envPath = path8.join(config.installDir, ".env");
8321
- if (!fs8.existsSync(envPath)) {
8500
+ const envPath = path9.join(config.installDir, ".env");
8501
+ if (!fs9.existsSync(envPath)) {
8322
8502
  R2.error(`No .env file found at ${envPath}`);
8323
8503
  process.exit(1);
8324
8504
  }
8325
8505
  We(import_picocolors22.default.cyan("LearnHouse Environment Editor"));
8326
- const originalContent = fs8.readFileSync(envPath, "utf-8");
8506
+ const originalContent = fs9.readFileSync(envPath, "utf-8");
8327
8507
  const envMap = parseEnv(originalContent);
8328
8508
  let editing = true;
8329
8509
  while (editing) {
@@ -8371,7 +8551,7 @@ async function envCommand() {
8371
8551
  }
8372
8552
  const newContent = serializeEnv(originalContent, envMap);
8373
8553
  if (newContent !== originalContent) {
8374
- fs8.writeFileSync(envPath, newContent);
8554
+ fs9.writeFileSync(envPath, newContent);
8375
8555
  R2.success(".env file updated");
8376
8556
  const restart = await Re({
8377
8557
  message: "Restart services to apply changes?",
@@ -8396,8 +8576,8 @@ async function envCommand() {
8396
8576
  }
8397
8577
 
8398
8578
  // src/commands/restore.ts
8399
- import fs9 from "fs";
8400
- import path9 from "path";
8579
+ import fs10 from "fs";
8580
+ import path10 from "path";
8401
8581
  import { execSync as execSync7 } from "child_process";
8402
8582
  var import_picocolors23 = __toESM(require_picocolors(), 1);
8403
8583
  async function restoreCommand(archivePath) {
@@ -8406,7 +8586,7 @@ async function restoreCommand(archivePath) {
8406
8586
  R2.info("Usage: npx learnhouse restore <backup-file.tar.gz>");
8407
8587
  process.exit(1);
8408
8588
  }
8409
- if (!fs9.existsSync(archivePath)) {
8589
+ if (!fs10.existsSync(archivePath)) {
8410
8590
  R2.error(`Backup file not found: ${archivePath}`);
8411
8591
  process.exit(1);
8412
8592
  }
@@ -8440,8 +8620,8 @@ async function restoreCommand(archivePath) {
8440
8620
  Ne("Restore cancelled.");
8441
8621
  process.exit(0);
8442
8622
  }
8443
- const tmpDir = path9.join(installDir, ".restore-tmp");
8444
- fs9.mkdirSync(tmpDir, { recursive: true });
8623
+ const tmpDir = path10.join(installDir, ".restore-tmp");
8624
+ fs10.mkdirSync(tmpDir, { recursive: true });
8445
8625
  const s = bt2();
8446
8626
  s.start("Extracting backup archive");
8447
8627
  try {
@@ -8449,20 +8629,20 @@ async function restoreCommand(archivePath) {
8449
8629
  s.stop("Archive extracted");
8450
8630
  } catch {
8451
8631
  s.stop("Extraction failed");
8452
- fs9.rmSync(tmpDir, { recursive: true, force: true });
8632
+ fs10.rmSync(tmpDir, { recursive: true, force: true });
8453
8633
  R2.error("Failed to extract backup archive.");
8454
8634
  process.exit(1);
8455
8635
  }
8456
- const entries = fs9.readdirSync(tmpDir);
8636
+ const entries = fs10.readdirSync(tmpDir);
8457
8637
  const backupFolder = entries.find(
8458
- (e2) => fs9.existsSync(path9.join(tmpDir, e2, "database.sql"))
8638
+ (e2) => fs10.existsSync(path10.join(tmpDir, e2, "database.sql"))
8459
8639
  );
8460
8640
  if (!backupFolder) {
8461
8641
  R2.error("No database.sql found in the backup archive.");
8462
- fs9.rmSync(tmpDir, { recursive: true, force: true });
8642
+ fs10.rmSync(tmpDir, { recursive: true, force: true });
8463
8643
  process.exit(1);
8464
8644
  }
8465
- const dumpPath = path9.join(tmpDir, backupFolder, "database.sql");
8645
+ const dumpPath = path10.join(tmpDir, backupFolder, "database.sql");
8466
8646
  const s2 = bt2();
8467
8647
  s2.start("Restoring database");
8468
8648
  try {
@@ -8474,22 +8654,22 @@ async function restoreCommand(archivePath) {
8474
8654
  s2.stop("Database restored");
8475
8655
  } catch {
8476
8656
  s2.stop("Database restore failed");
8477
- fs9.rmSync(tmpDir, { recursive: true, force: true });
8657
+ fs10.rmSync(tmpDir, { recursive: true, force: true });
8478
8658
  R2.error("Failed to restore database. The backup file may be corrupted.");
8479
8659
  process.exit(1);
8480
8660
  }
8481
- const envBackup = path9.join(tmpDir, backupFolder, ".env");
8482
- if (fs9.existsSync(envBackup)) {
8661
+ const envBackup = path10.join(tmpDir, backupFolder, ".env");
8662
+ if (fs10.existsSync(envBackup)) {
8483
8663
  const restoreEnv = await Re({
8484
8664
  message: "Backup contains a .env file. Restore it? (overwrites current .env)",
8485
8665
  initialValue: false
8486
8666
  });
8487
8667
  if (!Ct(restoreEnv) && restoreEnv) {
8488
- fs9.copyFileSync(envBackup, path9.join(installDir, ".env"));
8668
+ fs10.copyFileSync(envBackup, path10.join(installDir, ".env"));
8489
8669
  R2.info(".env file restored");
8490
8670
  }
8491
8671
  }
8492
- fs9.rmSync(tmpDir, { recursive: true, force: true });
8672
+ fs10.rmSync(tmpDir, { recursive: true, force: true });
8493
8673
  R2.success(import_picocolors23.default.green(import_picocolors23.default.bold("Restore complete!")));
8494
8674
  R2.info("You may want to restart services: npx learnhouse stop && npx learnhouse start");
8495
8675
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "learnhouse",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "description": "The official LearnHouse CLI — deploy, manage, and operate your LearnHouse instance",
5
5
  "type": "module",
6
6
  "bin": {