@camunda8/cli 4.7.0-alpha.22 → 4.7.0-alpha.23

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.
@@ -1,6 +1,6 @@
1
1
  # c8ctl-plugin-modeler
2
2
 
3
- Default c8ctl plugin that installs Camunda Desktop Modeler.
3
+ Default c8ctl plugin that manages Camunda Desktop Modeler.
4
4
 
5
5
  ## Commands
6
6
 
@@ -8,5 +8,14 @@ Default c8ctl plugin that installs Camunda Desktop Modeler.
8
8
  macOS (Homebrew or the Camunda-signed release into `/Applications`),
9
9
  Windows (winget), or Linux (x64, into `/usr/bin` via sudo). Skips the
10
10
  installation when Modeler is already installed.
11
+ - `c8ctl modeler update` — update through Homebrew, winget, or the direct
12
+ release installation method. Reports when the installation is already up to
13
+ date.
14
+ - `c8ctl modeler remove` — uninstall through the matching package manager or
15
+ remove the direct app/release installation. Linux file-type registrations
16
+ are removed with Modeler's bundled XDG unregister script. Unmanaged
17
+ installations are left untouched: direct macOS bundles in `/Applications` or
18
+ `~/Applications` must be signed by Camunda, Windows installs must be managed by
19
+ winget, and Linux installs must use c8ctl's versioned `/usr/bin` link.
11
20
 
12
21
  Supports the global `--dry-run`, `--json`, `--quiet`, and `--verbose` flags.
@@ -722,8 +722,8 @@ var require_gt = __commonJS({
722
722
  "node_modules/semver/functions/gt.js"(exports, module) {
723
723
  "use strict";
724
724
  var compare = require_compare();
725
- var gt = (a, b, loose) => compare(a, b, loose) > 0;
726
- module.exports = gt;
725
+ var gt2 = (a, b, loose) => compare(a, b, loose) > 0;
726
+ module.exports = gt2;
727
727
  }
728
728
  });
729
729
 
@@ -783,7 +783,7 @@ var require_cmp = __commonJS({
783
783
  "use strict";
784
784
  var eq = require_eq();
785
785
  var neq = require_neq();
786
- var gt = require_gt();
786
+ var gt2 = require_gt();
787
787
  var gte = require_gte();
788
788
  var lt = require_lt();
789
789
  var lte = require_lte();
@@ -812,7 +812,7 @@ var require_cmp = __commonJS({
812
812
  case "!=":
813
813
  return neq(a, b, loose);
814
814
  case ">":
815
- return gt(a, b, loose);
815
+ return gt2(a, b, loose);
816
816
  case ">=":
817
817
  return gte(a, b, loose);
818
818
  case "<":
@@ -1541,7 +1541,7 @@ var require_min_version = __commonJS({
1541
1541
  "use strict";
1542
1542
  var SemVer = require_semver();
1543
1543
  var Range = require_range();
1544
- var gt = require_gt();
1544
+ var gt2 = require_gt();
1545
1545
  var minVersion = (range, loose) => {
1546
1546
  range = new Range(range, loose);
1547
1547
  let minver = new SemVer("0.0.0");
@@ -1569,7 +1569,7 @@ var require_min_version = __commonJS({
1569
1569
  /* fallthrough */
1570
1570
  case "":
1571
1571
  case ">=":
1572
- if (!setMin || gt(compver, setMin)) {
1572
+ if (!setMin || gt2(compver, setMin)) {
1573
1573
  setMin = compver;
1574
1574
  }
1575
1575
  break;
@@ -1581,7 +1581,7 @@ var require_min_version = __commonJS({
1581
1581
  throw new Error(`Unexpected operation: ${comparator.operator}`);
1582
1582
  }
1583
1583
  });
1584
- if (setMin && (!minver || gt(minver, setMin))) {
1584
+ if (setMin && (!minver || gt2(minver, setMin))) {
1585
1585
  minver = setMin;
1586
1586
  }
1587
1587
  }
@@ -1619,7 +1619,7 @@ var require_outside = __commonJS({
1619
1619
  var { ANY } = Comparator;
1620
1620
  var Range = require_range();
1621
1621
  var satisfies = require_satisfies();
1622
- var gt = require_gt();
1622
+ var gt2 = require_gt();
1623
1623
  var lt = require_lt();
1624
1624
  var lte = require_lte();
1625
1625
  var gte = require_gte();
@@ -1629,7 +1629,7 @@ var require_outside = __commonJS({
1629
1629
  let gtfn, ltefn, ltfn, comp, ecomp;
1630
1630
  switch (hilo) {
1631
1631
  case ">":
1632
- gtfn = gt;
1632
+ gtfn = gt2;
1633
1633
  ltefn = lte;
1634
1634
  ltfn = lt;
1635
1635
  comp = ">";
@@ -1638,7 +1638,7 @@ var require_outside = __commonJS({
1638
1638
  case "<":
1639
1639
  gtfn = lt;
1640
1640
  ltefn = gte;
1641
- ltfn = gt;
1641
+ ltfn = gt2;
1642
1642
  comp = "<";
1643
1643
  ecomp = "<=";
1644
1644
  break;
@@ -1816,10 +1816,10 @@ var require_subset = __commonJS({
1816
1816
  }
1817
1817
  }
1818
1818
  const eqSet = /* @__PURE__ */ new Set();
1819
- let gt, lt;
1819
+ let gt2, lt;
1820
1820
  for (const c of sub) {
1821
1821
  if (c.operator === ">" || c.operator === ">=") {
1822
- gt = higherGT(gt, c, options);
1822
+ gt2 = higherGT(gt2, c, options);
1823
1823
  } else if (c.operator === "<" || c.operator === "<=") {
1824
1824
  lt = lowerLT(lt, c, options);
1825
1825
  } else {
@@ -1830,16 +1830,16 @@ var require_subset = __commonJS({
1830
1830
  return null;
1831
1831
  }
1832
1832
  let gtltComp;
1833
- if (gt && lt) {
1834
- gtltComp = compare(gt.semver, lt.semver, options);
1833
+ if (gt2 && lt) {
1834
+ gtltComp = compare(gt2.semver, lt.semver, options);
1835
1835
  if (gtltComp > 0) {
1836
1836
  return null;
1837
- } else if (gtltComp === 0 && (gt.operator !== ">=" || lt.operator !== "<=")) {
1837
+ } else if (gtltComp === 0 && (gt2.operator !== ">=" || lt.operator !== "<=")) {
1838
1838
  return null;
1839
1839
  }
1840
1840
  }
1841
1841
  for (const eq of eqSet) {
1842
- if (gt && !satisfies(eq, String(gt), options)) {
1842
+ if (gt2 && !satisfies(eq, String(gt2), options)) {
1843
1843
  return null;
1844
1844
  }
1845
1845
  if (lt && !satisfies(eq, String(lt), options)) {
@@ -1855,25 +1855,25 @@ var require_subset = __commonJS({
1855
1855
  let higher, lower;
1856
1856
  let hasDomLT, hasDomGT;
1857
1857
  let needDomLTPre = lt && !options.includePrerelease && lt.semver.prerelease.length ? lt.semver : false;
1858
- let needDomGTPre = gt && !options.includePrerelease && gt.semver.prerelease.length ? gt.semver : false;
1858
+ let needDomGTPre = gt2 && !options.includePrerelease && gt2.semver.prerelease.length ? gt2.semver : false;
1859
1859
  if (needDomLTPre && needDomLTPre.prerelease.length === 1 && lt.operator === "<" && needDomLTPre.prerelease[0] === 0) {
1860
1860
  needDomLTPre = false;
1861
1861
  }
1862
1862
  for (const c of dom) {
1863
1863
  hasDomGT = hasDomGT || c.operator === ">" || c.operator === ">=";
1864
1864
  hasDomLT = hasDomLT || c.operator === "<" || c.operator === "<=";
1865
- if (gt) {
1865
+ if (gt2) {
1866
1866
  if (needDomGTPre) {
1867
1867
  if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomGTPre.major && c.semver.minor === needDomGTPre.minor && c.semver.patch === needDomGTPre.patch) {
1868
1868
  needDomGTPre = false;
1869
1869
  }
1870
1870
  }
1871
1871
  if (c.operator === ">" || c.operator === ">=") {
1872
- higher = higherGT(gt, c, options);
1873
- if (higher === c && higher !== gt) {
1872
+ higher = higherGT(gt2, c, options);
1873
+ if (higher === c && higher !== gt2) {
1874
1874
  return false;
1875
1875
  }
1876
- } else if (gt.operator === ">=" && !c.test(gt.semver)) {
1876
+ } else if (gt2.operator === ">=" && !c.test(gt2.semver)) {
1877
1877
  return false;
1878
1878
  }
1879
1879
  }
@@ -1892,14 +1892,14 @@ var require_subset = __commonJS({
1892
1892
  return false;
1893
1893
  }
1894
1894
  }
1895
- if (!c.operator && (lt || gt) && gtltComp !== 0) {
1895
+ if (!c.operator && (lt || gt2) && gtltComp !== 0) {
1896
1896
  return false;
1897
1897
  }
1898
1898
  }
1899
- if (gt && hasDomLT && !lt && gtltComp !== 0) {
1899
+ if (gt2 && hasDomLT && !lt && gtltComp !== 0) {
1900
1900
  return false;
1901
1901
  }
1902
- if (lt && hasDomGT && !gt && gtltComp !== 0) {
1902
+ if (lt && hasDomGT && !gt2 && gtltComp !== 0) {
1903
1903
  return false;
1904
1904
  }
1905
1905
  if (needDomGTPre || needDomLTPre) {
@@ -1948,7 +1948,7 @@ var require_semver2 = __commonJS({
1948
1948
  var compareBuild = require_compare_build();
1949
1949
  var sort = require_sort();
1950
1950
  var rsort = require_rsort();
1951
- var gt = require_gt();
1951
+ var gt2 = require_gt();
1952
1952
  var lt = require_lt();
1953
1953
  var eq = require_eq();
1954
1954
  var neq = require_neq();
@@ -1987,7 +1987,7 @@ var require_semver2 = __commonJS({
1987
1987
  compareBuild,
1988
1988
  sort,
1989
1989
  rsort,
1990
- gt,
1990
+ gt: gt2,
1991
1991
  lt,
1992
1992
  eq,
1993
1993
  neq,
@@ -2228,20 +2228,27 @@ var CHECK_INTERVAL_MS = 60 * 60 * 1e3;
2228
2228
 
2229
2229
  // default-plugins/modeler/install.ts
2230
2230
  import { spawnSync } from "node:child_process";
2231
+ import { randomUUID } from "node:crypto";
2231
2232
  import {
2232
2233
  accessSync,
2233
2234
  constants,
2234
2235
  createWriteStream,
2235
2236
  existsSync,
2237
+ linkSync,
2238
+ lstatSync,
2236
2239
  mkdirSync,
2237
2240
  mkdtempSync,
2241
+ readFileSync as readFileSync2,
2242
+ readlinkSync,
2238
2243
  realpathSync,
2239
2244
  renameSync,
2240
2245
  rmSync,
2241
- statSync
2246
+ statSync,
2247
+ unlinkSync,
2248
+ writeFileSync
2242
2249
  } from "node:fs";
2243
2250
  import { homedir as homedir2, tmpdir } from "node:os";
2244
- import { delimiter, join as join2 } from "node:path";
2251
+ import { delimiter, dirname as dirname2, join as join2 } from "node:path";
2245
2252
  import { Readable, Transform } from "node:stream";
2246
2253
  import { pipeline } from "node:stream/promises";
2247
2254
 
@@ -2264,6 +2271,16 @@ function latestStableModelerVersion(indexHtml) {
2264
2271
  }
2265
2272
  return latest;
2266
2273
  }
2274
+ function isNewerModelerVersion(candidate, current) {
2275
+ const candidateVersion = (0, import_semver.parse)(candidate);
2276
+ const currentVersion = (0, import_semver.parse)(current);
2277
+ if (!candidateVersion || !currentVersion) {
2278
+ throw new Error(
2279
+ `Invalid Camunda Modeler version "${candidate}" or "${current}"`
2280
+ );
2281
+ }
2282
+ return (0, import_semver.gt)(candidateVersion, currentVersion);
2283
+ }
2267
2284
  function modelerMacArchiveName(version, architecture) {
2268
2285
  if (architecture !== "arm64" && architecture !== "x64") {
2269
2286
  throw new Error(
@@ -2329,12 +2346,124 @@ var WINGET_INSTALL_URL = "https://learn.microsoft.com/windows/package-manager/wi
2329
2346
  var WINGET_NO_APPLICATIONS_FOUND = 2316632084;
2330
2347
  var WINDOWS_EXECUTABLE = "Camunda Modeler.exe";
2331
2348
  var MODELER_FILE_TYPES = ["bpmn", "dmn", "form", "rpa"];
2349
+ var UNREGISTER_WINDOWS_SCRIPT = `$ErrorActionPreference='Stop'; $base=[Microsoft.Win32.Registry]::CurrentUser; foreach ($type in @('bpmn','dmn','form','rpa')) { $prog='CamundaModeler.'+$type.ToUpper(); $path='Software\\Classes\\'+$prog+'\\shell\\open\\command'; $key=$base.OpenSubKey($path); if ($key -and $key.GetValue('') -ieq ('"'+$env:C8CTL_TARGET+'" "%1"')) { $key.Close(); $ext=$base.OpenSubKey('Software\\Classes\\.'+$type,$true); if ($ext) { if ($ext.GetValue('') -ieq $prog) { $ext.DeleteValue('', $false) }; $ext.Close() }; Remove-Item -LiteralPath ('Registry::HKEY_CURRENT_USER\\Software\\Classes\\'+$prog) -Recurse -Force } elseif ($key) { $key.Close() } }; $shortcut=(New-Object -ComObject WScript.Shell).CreateShortcut($env:C8CTL_SHORTCUT); if ((Test-Path -LiteralPath $env:C8CTL_SHORTCUT) -and $shortcut.TargetPath -ieq $env:C8CTL_TARGET) { Remove-Item -LiteralPath $env:C8CTL_SHORTCUT -Force }`;
2332
2350
  var CREATE_SHORTCUT_SCRIPT = "$ErrorActionPreference = 'Stop'; $shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut($env:C8CTL_SHORTCUT); $shortcut.TargetPath = $env:C8CTL_TARGET; $shortcut.Save()";
2333
2351
  var LINUX_INSTALL_ROOT = "/usr/bin";
2334
2352
  var LINUX_EXECUTABLE = "camunda-modeler";
2353
+ var LINUX_LIFECYCLE_LOCK = "/tmp/c8ctl-modeler-lifecycle.lock";
2354
+ var LINUX_LIFECYCLE_RECLAIM_LOCK = `${LINUX_LIFECYCLE_LOCK}.reclaim`;
2335
2355
  function errorMessage(error) {
2336
2356
  return error instanceof Error ? error.message : String(error);
2337
2357
  }
2358
+ function errorCode(error) {
2359
+ if (error instanceof Error && "code" in error) {
2360
+ const { code } = error;
2361
+ if (typeof code === "string") return code;
2362
+ }
2363
+ return void 0;
2364
+ }
2365
+ var lifecycleToken = randomUUID();
2366
+ function readLifecycleLock(path) {
2367
+ try {
2368
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
2369
+ return isRecord(parsed) ? parsed : void 0;
2370
+ } catch {
2371
+ return void 0;
2372
+ }
2373
+ }
2374
+ function isProcessAlive(pid) {
2375
+ try {
2376
+ process.kill(pid, 0);
2377
+ return true;
2378
+ } catch (error) {
2379
+ return errorCode(error) === "EPERM";
2380
+ }
2381
+ }
2382
+ function isStaleLock(path) {
2383
+ const pid = readLifecycleLock(path)?.pid;
2384
+ if (typeof pid !== "number" || !Number.isInteger(pid)) return true;
2385
+ return !isProcessAlive(pid);
2386
+ }
2387
+ function tryCreateLifecycleLock(path) {
2388
+ const payload = {
2389
+ pid: process.pid,
2390
+ token: lifecycleToken
2391
+ };
2392
+ const staging = `${path}.${process.pid}.${lifecycleToken}`;
2393
+ writeFileSync(staging, JSON.stringify(payload), { flag: "wx", mode: 420 });
2394
+ try {
2395
+ linkSync(staging, path);
2396
+ return true;
2397
+ } catch (error) {
2398
+ if (errorCode(error) === "EEXIST") return false;
2399
+ throw error;
2400
+ } finally {
2401
+ try {
2402
+ unlinkSync(staging);
2403
+ } catch {
2404
+ }
2405
+ }
2406
+ }
2407
+ function releaseOwnLifecycleLock(path) {
2408
+ if (readLifecycleLock(path)?.token !== lifecycleToken) return;
2409
+ try {
2410
+ unlinkSync(path);
2411
+ } catch {
2412
+ }
2413
+ }
2414
+ function lifecycleLockBusy() {
2415
+ return new Error(
2416
+ `Another c8ctl Modeler operation is in progress. Wait for it to finish, or remove ${LINUX_LIFECYCLE_LOCK} if you are sure none is running.`
2417
+ );
2418
+ }
2419
+ function reclaimStaleLifecycleLock(logger) {
2420
+ if (!tryCreateLifecycleLock(LINUX_LIFECYCLE_RECLAIM_LOCK)) {
2421
+ throw new Error(
2422
+ `Another c8ctl Modeler operation is recovering an interrupted run's lock. If no such operation is running, remove ${LINUX_LIFECYCLE_RECLAIM_LOCK} and ${LINUX_LIFECYCLE_LOCK} manually.`
2423
+ );
2424
+ }
2425
+ try {
2426
+ if (!pathExists(LINUX_LIFECYCLE_LOCK) || !isStaleLock(LINUX_LIFECYCLE_LOCK)) {
2427
+ return false;
2428
+ }
2429
+ logger.warn(
2430
+ `Reclaiming a stale Camunda Modeler lifecycle lock at ${LINUX_LIFECYCLE_LOCK} from a previous run.`
2431
+ );
2432
+ try {
2433
+ unlinkSync(LINUX_LIFECYCLE_LOCK);
2434
+ } catch (error) {
2435
+ throw new Error(
2436
+ `Could not reclaim the stale Modeler lifecycle lock at ${LINUX_LIFECYCLE_LOCK} (${errorMessage(error)}). Remove it manually if no other c8ctl modeler command is running.`
2437
+ );
2438
+ }
2439
+ return tryCreateLifecycleLock(LINUX_LIFECYCLE_LOCK);
2440
+ } finally {
2441
+ releaseOwnLifecycleLock(LINUX_LIFECYCLE_RECLAIM_LOCK);
2442
+ }
2443
+ }
2444
+ function acquireLinuxLifecycleLock(logger) {
2445
+ if (tryCreateLifecycleLock(LINUX_LIFECYCLE_LOCK)) return;
2446
+ if (isStaleLock(LINUX_LIFECYCLE_LOCK) && reclaimStaleLifecycleLock(logger)) {
2447
+ return;
2448
+ }
2449
+ throw lifecycleLockBusy();
2450
+ }
2451
+ function releaseLinuxLifecycleLock() {
2452
+ releaseOwnLifecycleLock(LINUX_LIFECYCLE_LOCK);
2453
+ }
2454
+ async function withLinuxLifecycleLock(ctx, body) {
2455
+ acquireLinuxLifecycleLock(ctx.logger);
2456
+ const onSignal = () => releaseLinuxLifecycleLock();
2457
+ process.once("SIGINT", onSignal);
2458
+ process.once("SIGTERM", onSignal);
2459
+ try {
2460
+ return await body();
2461
+ } finally {
2462
+ process.off("SIGINT", onSignal);
2463
+ process.off("SIGTERM", onSignal);
2464
+ releaseLinuxLifecycleLock();
2465
+ }
2466
+ }
2338
2467
  function reportProgress({ logger, quiet }, message) {
2339
2468
  if (!quiet) logger.info(message);
2340
2469
  }
@@ -2347,11 +2476,13 @@ function formatExitCode(status) {
2347
2476
  function runCommand(command, args, {
2348
2477
  failureMessage,
2349
2478
  quiet,
2350
- stdin = "inherit"
2479
+ stdin = "inherit",
2480
+ env
2351
2481
  }) {
2352
2482
  const result = spawnSync(command, args, {
2353
2483
  encoding: "utf8",
2354
- stdio: quiet ? [stdin, "pipe", "pipe"] : [stdin, process.stderr.fd, process.stderr.fd]
2484
+ stdio: quiet ? [stdin, "pipe", "pipe"] : [stdin, process.stderr.fd, process.stderr.fd],
2485
+ env
2355
2486
  });
2356
2487
  const diagnostics = quiet ? `${result.stdout ?? ""}${result.stderr ?? ""}`.trim() : "";
2357
2488
  const details = diagnostics ? `
@@ -2365,6 +2496,24 @@ ${diagnostics}` : "";
2365
2496
  );
2366
2497
  }
2367
2498
  }
2499
+ function runCommandCapture(command, args, failureMessage) {
2500
+ const result = spawnSync(command, args, {
2501
+ encoding: "utf8",
2502
+ stdio: ["ignore", "pipe", "pipe"]
2503
+ });
2504
+ const diagnostics = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
2505
+ const details = diagnostics ? `
2506
+ ${diagnostics}` : "";
2507
+ if (result.error) {
2508
+ throw new Error(`${failureMessage}: ${result.error.message}${details}`);
2509
+ }
2510
+ if (result.status !== 0) {
2511
+ throw new Error(
2512
+ `${failureMessage} (exit code ${formatExitCode(result.status)}).${details}`
2513
+ );
2514
+ }
2515
+ return result.stdout ?? "";
2516
+ }
2368
2517
  function registerWithLaunchServices(appPath, logger) {
2369
2518
  const result = spawnSync(LAUNCH_SERVICES_REGISTER, ["-f", appPath], {
2370
2519
  stdio: "ignore"
@@ -2375,6 +2524,16 @@ function registerWithLaunchServices(appPath, logger) {
2375
2524
  );
2376
2525
  }
2377
2526
  }
2527
+ function unregisterWithLaunchServices(appPath, logger) {
2528
+ const result = spawnSync(LAUNCH_SERVICES_REGISTER, ["-u", "-f", appPath], {
2529
+ stdio: "ignore"
2530
+ });
2531
+ if (result.error || result.status !== 0) {
2532
+ logger.warn(
2533
+ `Could not unregister ${appPath} from macOS Launch Services. Remove its file associations manually if they remain.`
2534
+ );
2535
+ }
2536
+ }
2378
2537
  function hasPackageManager(command, name) {
2379
2538
  const result = spawnSync(command, ["--version"], { stdio: "ignore" });
2380
2539
  if (result.error) {
@@ -2565,6 +2724,50 @@ async function downloadLatestRelease({
2565
2724
  });
2566
2725
  return { version, archivePath };
2567
2726
  }
2727
+ async function downloadReleaseVersion({
2728
+ dir,
2729
+ version,
2730
+ platform: platform2,
2731
+ archiveName,
2732
+ logger,
2733
+ quiet,
2734
+ signal
2735
+ }) {
2736
+ const name = archiveName(version);
2737
+ const archivePath = join2(dir, name);
2738
+ reportProgress(
2739
+ { logger, quiet },
2740
+ `Downloading Camunda Modeler ${version} for ${platform2}...`
2741
+ );
2742
+ await downloadArchive({
2743
+ url: new URL(`${version}/${name}`, MODELER_RELEASE_URL).toString(),
2744
+ destination: archivePath,
2745
+ logger,
2746
+ quiet,
2747
+ signal
2748
+ });
2749
+ return { version, archivePath };
2750
+ }
2751
+ function registerDownloadInterrupts(operation) {
2752
+ const controller = new AbortController();
2753
+ let interruptedSignal;
2754
+ const interrupt = (signal) => {
2755
+ interruptedSignal ??= signal;
2756
+ controller.abort(new Error(`${operation} interrupted by ${signal}`));
2757
+ };
2758
+ const onSigint = () => interrupt("SIGINT");
2759
+ const onSigterm = () => interrupt("SIGTERM");
2760
+ process.on("SIGINT", onSigint);
2761
+ process.on("SIGTERM", onSigterm);
2762
+ return {
2763
+ signal: controller.signal,
2764
+ cleanup: () => {
2765
+ process.off("SIGINT", onSigint);
2766
+ process.off("SIGTERM", onSigterm);
2767
+ if (interruptedSignal) process.kill(process.pid, interruptedSignal);
2768
+ }
2769
+ };
2770
+ }
2568
2771
  async function installFromOfficialDownload({
2569
2772
  applicationsDir,
2570
2773
  logger,
@@ -2768,12 +2971,13 @@ function findOnPath(command) {
2768
2971
  }
2769
2972
  });
2770
2973
  }
2771
- function runAsRoot(args, failureMessage, quiet) {
2974
+ function runAsRoot(args, failureMessage, quiet, includeManualDownload = true) {
2772
2975
  const [command, ...rest] = process.getuid?.() === 0 ? args : ["sudo", ...args];
2773
2976
  try {
2774
2977
  runCommand(command, rest, { failureMessage, quiet });
2775
2978
  } catch (error) {
2776
- throw manualDownloadError(errorMessage(error));
2979
+ const message = errorMessage(error);
2980
+ throw includeManualDownload ? manualDownloadError(message) : new Error(message);
2777
2981
  }
2778
2982
  }
2779
2983
  function registerWithDesktop({
@@ -2798,6 +3002,39 @@ function registerWithDesktop({
2798
3002
  logger.warn(errorMessage(error));
2799
3003
  }
2800
3004
  }
3005
+ function unregisterWithDesktop({
3006
+ installDir,
3007
+ logger,
3008
+ quiet
3009
+ }) {
3010
+ const script = join2(installDir, "support", "xdg_unregister.sh");
3011
+ if (!existsSync(script)) {
3012
+ logger.warn(
3013
+ `Could not unregister Camunda Modeler file types because ${script} is missing.`
3014
+ );
3015
+ return;
3016
+ }
3017
+ const missingTools = [
3018
+ "xdg-mime",
3019
+ "xdg-desktop-menu",
3020
+ "xdg-icon-resource"
3021
+ ].filter((tool) => !findOnPath(tool));
3022
+ if (missingTools.length > 0) {
3023
+ logger.warn(
3024
+ `Could not unregister Camunda Modeler file types because these xdg-utils are not installed: ${missingTools.join(", ")}.`
3025
+ );
3026
+ return;
3027
+ }
3028
+ try {
3029
+ runCommand("/bin/bash", [script], {
3030
+ failureMessage: `Could not unregister Camunda Modeler file types using ${script}`,
3031
+ quiet,
3032
+ stdin: "ignore"
3033
+ });
3034
+ } catch (error) {
3035
+ logger.warn(`${errorMessage(error)} File registrations may remain.`);
3036
+ }
3037
+ }
2801
3038
  async function installOnLinux({
2802
3039
  isDryRun,
2803
3040
  logger,
@@ -2893,7 +3130,9 @@ async function installOnLinux({
2893
3130
  }
2894
3131
  async function installDesktopModeler(ctx) {
2895
3132
  if (process.platform === "win32") return installOnWindows(ctx);
2896
- if (process.platform === "linux") return installOnLinux(ctx);
3133
+ if (process.platform === "linux") {
3134
+ return withLinuxLifecycleLock(ctx, () => installOnLinux(ctx));
3135
+ }
2897
3136
  if (process.platform !== "darwin") {
2898
3137
  throw new Error(
2899
3138
  `c8ctl modeler install currently supports macOS, Windows, and Linux only. Download Modeler manually from ${MANUAL_DOWNLOAD_URL}`
@@ -2971,25 +3210,682 @@ async function installDesktopModeler(ctx) {
2971
3210
  message: `Installed Camunda Modeler ${version} to ${destination}.`
2972
3211
  };
2973
3212
  }
3213
+ function noModelerInstalled() {
3214
+ return {
3215
+ kind: "info",
3216
+ message: "Camunda Modeler is not installed; run `c8ctl modeler install` first."
3217
+ };
3218
+ }
3219
+ function dryRunResult(command, message) {
3220
+ return {
3221
+ kind: "dryRun",
3222
+ info: { dryRun: true, command, message }
3223
+ };
3224
+ }
3225
+ function homebrewModelerInstalled() {
3226
+ return isInstalledWith({
3227
+ command: "brew",
3228
+ args: ["list", "--cask", "--versions", "camunda-modeler"],
3229
+ notInstalledStatus: 1,
3230
+ description: "the Homebrew Modeler cask"
3231
+ });
3232
+ }
3233
+ function updateHomebrewModeler(ctx) {
3234
+ const outdated = runCommandCapture(
3235
+ "brew",
3236
+ ["outdated", "--cask", "--quiet", "camunda-modeler"],
3237
+ "Could not check Homebrew for Camunda Modeler updates"
3238
+ ).trim();
3239
+ if (!outdated) {
3240
+ return {
3241
+ kind: "info",
3242
+ message: "Camunda Modeler is already up to date with Homebrew."
3243
+ };
3244
+ }
3245
+ if (ctx.isDryRun) {
3246
+ return dryRunResult(
3247
+ "modeler update",
3248
+ "Dry run: would update Camunda Modeler with `brew upgrade --cask camunda-modeler`."
3249
+ );
3250
+ }
3251
+ reportProgress(ctx, "Updating Camunda Modeler with Homebrew...");
3252
+ runCommand("brew", ["upgrade", "--cask", "camunda-modeler"], {
3253
+ failureMessage: "Homebrew could not update Camunda Modeler",
3254
+ quiet: ctx.quiet
3255
+ });
3256
+ return {
3257
+ kind: "success",
3258
+ message: "Updated Camunda Modeler with Homebrew."
3259
+ };
3260
+ }
3261
+ function isHomebrewCaskPath(appPath) {
3262
+ return /\/Caskroom\/camunda-modeler\//i.test(realpathSync(appPath));
3263
+ }
3264
+ function verifyMacModelerBundle(appPath, action, quiet) {
3265
+ runCommand(
3266
+ "codesign",
3267
+ [
3268
+ "--verify",
3269
+ "--deep",
3270
+ "--strict",
3271
+ `-R=${MODELER_CODE_REQUIREMENT}`,
3272
+ appPath
3273
+ ],
3274
+ {
3275
+ failureMessage: `Camunda Modeler at ${appPath} is not signed by Camunda; refusing to ${action} it`,
3276
+ quiet
3277
+ }
3278
+ );
3279
+ }
3280
+ function readMacModelerVersion(appPath) {
3281
+ const plistPath = join2(appPath, "Contents", "Info.plist");
3282
+ const plist = readFileSync2(plistPath, "utf8");
3283
+ const version = /<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/.exec(plist)?.[1]?.trim();
3284
+ if (!version) {
3285
+ throw new Error(
3286
+ `Could not read the installed Camunda Modeler version from ${plistPath}; reinstall it with c8ctl before updating.`
3287
+ );
3288
+ }
3289
+ return version;
3290
+ }
3291
+ async function updateDirectMacModeler(ctx, appPath) {
3292
+ if (isHomebrewCaskPath(appPath)) {
3293
+ throw new Error(
3294
+ "Camunda Modeler appears to be Homebrew-managed, but its cask was not found; refusing to update the app bundle directly."
3295
+ );
3296
+ }
3297
+ verifyMacModelerBundle(appPath, "update", ctx.quiet);
3298
+ const currentVersion = readMacModelerVersion(appPath);
3299
+ const tempDir = mkdtempSync(join2(tmpdir(), "c8ctl-modeler-"));
3300
+ const interruption = registerDownloadInterrupts("Modeler update");
3301
+ try {
3302
+ reportProgress(
3303
+ ctx,
3304
+ "Checking for the latest stable Camunda Modeler release..."
3305
+ );
3306
+ const latestVersion = latestStableModelerVersion(
3307
+ await fetchReleaseIndex(interruption.signal)
3308
+ );
3309
+ if (!isNewerModelerVersion(latestVersion, currentVersion)) {
3310
+ return {
3311
+ kind: "info",
3312
+ message: `Camunda Modeler is already up to date (installed ${currentVersion}; latest stable ${latestVersion}).`
3313
+ };
3314
+ }
3315
+ if (ctx.isDryRun) {
3316
+ return dryRunResult(
3317
+ "modeler update",
3318
+ `Dry run: would update Camunda Modeler from ${currentVersion} to ${latestVersion} at ${appPath}.`
3319
+ );
3320
+ }
3321
+ const { archivePath } = await downloadReleaseVersion({
3322
+ dir: tempDir,
3323
+ version: latestVersion,
3324
+ platform: "macOS",
3325
+ archiveName: (version) => modelerMacArchiveName(version, process.arch),
3326
+ logger: ctx.logger,
3327
+ quiet: ctx.quiet,
3328
+ signal: interruption.signal
3329
+ });
3330
+ const stagingDir = mkdtempSync(
3331
+ join2(dirname2(appPath), ".c8ctl-modeler-update-")
3332
+ );
3333
+ const stagedApp = join2(stagingDir, APP_BUNDLE_NAME);
3334
+ const backupApp = join2(stagingDir, "previous.app");
3335
+ try {
3336
+ reportProgress(ctx, `Updating Camunda Modeler to ${latestVersion}...`);
3337
+ runCommand("ditto", ["-x", "-k", archivePath, stagingDir], {
3338
+ failureMessage: "Could not extract Camunda Modeler",
3339
+ quiet: ctx.quiet
3340
+ });
3341
+ if (!existsSync(stagedApp)) {
3342
+ throw manualDownloadError(
3343
+ `The Camunda Modeler ${latestVersion} archive did not contain ${APP_BUNDLE_NAME}`
3344
+ );
3345
+ }
3346
+ verifyMacModelerBundle(stagedApp, "update", ctx.quiet);
3347
+ renameSync(appPath, backupApp);
3348
+ try {
3349
+ renameSync(stagedApp, appPath);
3350
+ } catch (error) {
3351
+ try {
3352
+ renameSync(backupApp, appPath);
3353
+ } catch (restoreError) {
3354
+ throw new Error(
3355
+ `Could not install the new Camunda Modeler bundle; the previous bundle remains at ${backupApp}: ${errorMessage(restoreError)}`
3356
+ );
3357
+ }
3358
+ throw new Error(
3359
+ `Could not replace the Camunda Modeler bundle: ${errorMessage(error)}`
3360
+ );
3361
+ }
3362
+ try {
3363
+ rmSync(backupApp, { recursive: true, force: true });
3364
+ } catch (error) {
3365
+ ctx.logger.warn(
3366
+ `Could not remove the previous Camunda Modeler bundle at ${backupApp}: ${errorMessage(error)}`
3367
+ );
3368
+ }
3369
+ } finally {
3370
+ if (!existsSync(backupApp)) {
3371
+ try {
3372
+ rmSync(stagingDir, { recursive: true, force: true });
3373
+ } catch (error) {
3374
+ ctx.logger.warn(
3375
+ `Could not clean up the Modeler update directory ${stagingDir}: ${errorMessage(error)}`
3376
+ );
3377
+ }
3378
+ }
3379
+ }
3380
+ registerWithLaunchServices(appPath, ctx.logger);
3381
+ return {
3382
+ kind: "success",
3383
+ message: `Updated Camunda Modeler to ${latestVersion} at ${appPath}.`
3384
+ };
3385
+ } finally {
3386
+ try {
3387
+ rmSync(tempDir, { recursive: true, force: true });
3388
+ } finally {
3389
+ interruption.cleanup();
3390
+ }
3391
+ }
3392
+ }
3393
+ async function updateMacModeler(ctx) {
3394
+ if (hasPackageManager("brew", "Homebrew") && homebrewModelerInstalled()) {
3395
+ return updateHomebrewModeler(ctx);
3396
+ }
3397
+ const appPath = findInstalledModeler();
3398
+ if (!appPath) return noModelerInstalled();
3399
+ return updateDirectMacModeler(ctx, appPath);
3400
+ }
3401
+ function wingetUpgradeAvailable() {
3402
+ const result = spawnSync(
3403
+ "winget",
3404
+ ["list", "--upgrade-available", ...WINGET_PACKAGE],
3405
+ {
3406
+ encoding: "utf8",
3407
+ stdio: ["ignore", "pipe", "pipe"]
3408
+ }
3409
+ );
3410
+ if (result.error) {
3411
+ throw new Error(
3412
+ `Could not check for Camunda Modeler updates with winget: ${result.error.message}`
3413
+ );
3414
+ }
3415
+ if (result.status === WINGET_NO_APPLICATIONS_FOUND) return false;
3416
+ if (result.status !== 0) {
3417
+ throw new Error(
3418
+ `Could not check for Camunda Modeler updates with winget (exit code ${formatExitCode(result.status)})`
3419
+ );
3420
+ }
3421
+ return `${result.stdout ?? ""}
3422
+ ${result.stderr ?? ""}`.split(/\r?\n/).some((line) => line.includes(WINGET_PACKAGE_ID));
3423
+ }
3424
+ function wingetModelerPaths() {
3425
+ const localAppData = process.env.LOCALAPPDATA || join2(homedir2(), "AppData", "Local");
3426
+ const installDir = join2(localAppData, "Programs", "Camunda Modeler");
3427
+ return { installDir, executable: join2(installDir, WINDOWS_EXECUTABLE) };
3428
+ }
3429
+ function updateWindowsModeler(ctx) {
3430
+ const { executable, installDir } = wingetModelerPaths();
3431
+ if (!hasPackageManager("winget", "winget")) {
3432
+ if (existsSync(executable)) {
3433
+ throw new Error(
3434
+ `winget is not available, so c8ctl cannot safely update the Modeler installation at ${installDir}.`
3435
+ );
3436
+ }
3437
+ return noModelerInstalled();
3438
+ }
3439
+ if (!isInstalledWith({
3440
+ command: "winget",
3441
+ args: ["list", ...WINGET_PACKAGE],
3442
+ notInstalledStatus: WINGET_NO_APPLICATIONS_FOUND,
3443
+ description: "the winget Modeler package"
3444
+ })) {
3445
+ if (existsSync(executable)) {
3446
+ throw new Error(
3447
+ `Camunda Modeler at ${installDir} is not installed with winget; refusing to update it.`
3448
+ );
3449
+ }
3450
+ return noModelerInstalled();
3451
+ }
3452
+ if (!wingetUpgradeAvailable()) {
3453
+ return {
3454
+ kind: "info",
3455
+ message: "Camunda Modeler is already up to date with winget."
3456
+ };
3457
+ }
3458
+ if (ctx.isDryRun) {
3459
+ return dryRunResult(
3460
+ "modeler update",
3461
+ "Dry run: would update Camunda Modeler with `winget upgrade --id Camunda.Modeler --exact --source winget`."
3462
+ );
3463
+ }
3464
+ reportProgress(ctx, "Updating Camunda Modeler with winget...");
3465
+ runCommand("winget", ["upgrade", ...WINGET_PACKAGE], {
3466
+ failureMessage: "winget could not update Camunda Modeler",
3467
+ quiet: ctx.quiet
3468
+ });
3469
+ return { kind: "success", message: "Updated Camunda Modeler with winget." };
3470
+ }
3471
+ function unregisterWindowsModeler(ctx, executable) {
3472
+ const appData = process.env.APPDATA || join2(homedir2(), "AppData", "Roaming");
3473
+ const shortcut = join2(
3474
+ appData,
3475
+ "Microsoft",
3476
+ "Windows",
3477
+ "Start Menu",
3478
+ "Programs",
3479
+ "Camunda Modeler.lnk"
3480
+ );
3481
+ try {
3482
+ runCommand(
3483
+ "powershell",
3484
+ ["-NoProfile", "-NonInteractive", "-Command", UNREGISTER_WINDOWS_SCRIPT],
3485
+ {
3486
+ failureMessage: "Could not unregister Camunda Modeler file types",
3487
+ quiet: ctx.quiet,
3488
+ stdin: "ignore",
3489
+ env: {
3490
+ ...process.env,
3491
+ C8CTL_SHORTCUT: shortcut,
3492
+ C8CTL_TARGET: executable
3493
+ }
3494
+ }
3495
+ );
3496
+ } catch (error) {
3497
+ ctx.logger.warn(
3498
+ `${errorMessage(error)} File associations or the Start Menu shortcut may remain.`
3499
+ );
3500
+ }
3501
+ }
3502
+ function removeWindowsModeler(ctx) {
3503
+ const { executable, installDir } = wingetModelerPaths();
3504
+ if (!hasPackageManager("winget", "winget")) {
3505
+ if (existsSync(executable)) {
3506
+ throw new Error(
3507
+ `winget is not available, so c8ctl cannot safely remove the Modeler installation at ${installDir}.`
3508
+ );
3509
+ }
3510
+ return noModelerInstalled();
3511
+ }
3512
+ if (!isInstalledWith({
3513
+ command: "winget",
3514
+ args: ["list", ...WINGET_PACKAGE],
3515
+ notInstalledStatus: WINGET_NO_APPLICATIONS_FOUND,
3516
+ description: "the winget Modeler package"
3517
+ })) {
3518
+ if (existsSync(executable)) {
3519
+ throw new Error(
3520
+ `Camunda Modeler at ${installDir} is not installed with winget; refusing to remove it.`
3521
+ );
3522
+ }
3523
+ return noModelerInstalled();
3524
+ }
3525
+ if (ctx.isDryRun) {
3526
+ return dryRunResult(
3527
+ "modeler remove",
3528
+ "Dry run: would remove Camunda Modeler with `winget uninstall --id Camunda.Modeler --exact --source winget`."
3529
+ );
3530
+ }
3531
+ reportProgress(ctx, "Removing Camunda Modeler with winget...");
3532
+ runCommand("winget", ["uninstall", ...WINGET_PACKAGE], {
3533
+ failureMessage: "winget could not remove Camunda Modeler",
3534
+ quiet: ctx.quiet
3535
+ });
3536
+ unregisterWindowsModeler(ctx, executable);
3537
+ return {
3538
+ kind: "success",
3539
+ message: "Removed Camunda Modeler with winget."
3540
+ };
3541
+ }
3542
+ function pathExists(path) {
3543
+ try {
3544
+ lstatSync(path);
3545
+ return true;
3546
+ } catch {
3547
+ return false;
3548
+ }
3549
+ }
3550
+ function findManagedLinuxModeler() {
3551
+ const launcher = join2(LINUX_INSTALL_ROOT, LINUX_EXECUTABLE);
3552
+ let target;
3553
+ try {
3554
+ target = readlinkSync(launcher);
3555
+ } catch {
3556
+ return void 0;
3557
+ }
3558
+ const version = /^camunda-modeler-(\d+\.\d+\.\d+)-linux-x64\/camunda-modeler$/.exec(
3559
+ target
3560
+ )?.[1];
3561
+ if (!version) return void 0;
3562
+ const installDir = join2(
3563
+ LINUX_INSTALL_ROOT,
3564
+ `camunda-modeler-${version}-linux-x64`
3565
+ );
3566
+ return { version, target, installDir, launcher };
3567
+ }
3568
+ function linuxModelerForAction(action) {
3569
+ const installation = findManagedLinuxModeler();
3570
+ if (installation) return installation;
3571
+ const launcher = join2(LINUX_INSTALL_ROOT, LINUX_EXECUTABLE);
3572
+ const installedPath = findOnPath(LINUX_EXECUTABLE);
3573
+ if (installedPath || pathExists(launcher)) {
3574
+ throw new Error(
3575
+ `Camunda Modeler at ${installedPath ?? launcher} is not installed by c8ctl; refusing to ${action} it.`
3576
+ );
3577
+ }
3578
+ return void 0;
3579
+ }
3580
+ async function updateLinuxModeler(ctx) {
3581
+ if (process.arch !== "x64") {
3582
+ throw manualDownloadError(
3583
+ `Unsupported Linux architecture "${process.arch}"`
3584
+ );
3585
+ }
3586
+ const installation = linuxModelerForAction("update");
3587
+ if (!installation) return noModelerInstalled();
3588
+ if (!existsSync(join2(installation.installDir, LINUX_EXECUTABLE))) {
3589
+ throw new Error(
3590
+ `Camunda Modeler ${installation.version} is only partially installed: ${join2(installation.installDir, LINUX_EXECUTABLE)} is missing. Run \`c8ctl modeler remove\` to clean up, then \`c8ctl modeler install\` to install it again.`
3591
+ );
3592
+ }
3593
+ const tempDir = mkdtempSync(join2(tmpdir(), "c8ctl-modeler-"));
3594
+ const interruption = registerDownloadInterrupts("Modeler update");
3595
+ try {
3596
+ reportProgress(
3597
+ ctx,
3598
+ "Checking for the latest stable Camunda Modeler release..."
3599
+ );
3600
+ const latestVersion = latestStableModelerVersion(
3601
+ await fetchReleaseIndex(interruption.signal)
3602
+ );
3603
+ if (!isNewerModelerVersion(latestVersion, installation.version)) {
3604
+ return {
3605
+ kind: "info",
3606
+ message: `Camunda Modeler is already up to date (installed ${installation.version}; latest stable ${latestVersion}).`
3607
+ };
3608
+ }
3609
+ const newReleaseName = `camunda-modeler-${latestVersion}-linux-x64`;
3610
+ const newInstallDir = join2(LINUX_INSTALL_ROOT, newReleaseName);
3611
+ if (ctx.isDryRun) {
3612
+ return dryRunResult(
3613
+ "modeler update",
3614
+ `Dry run: would update Camunda Modeler from ${installation.version} to ${latestVersion} in ${newInstallDir}.`
3615
+ );
3616
+ }
3617
+ if (existsSync(newInstallDir)) {
3618
+ throw new Error(
3619
+ `A release directory already exists at ${newInstallDir}; refusing to overwrite it.`
3620
+ );
3621
+ }
3622
+ if (process.getuid?.() !== 0) {
3623
+ reportProgress(
3624
+ ctx,
3625
+ `Updating in ${LINUX_INSTALL_ROOT} needs root privileges; sudo may ask for your password.`
3626
+ );
3627
+ }
3628
+ runAsRoot(["true"], "Could not get root privileges", ctx.quiet);
3629
+ const { archivePath } = await downloadReleaseVersion({
3630
+ dir: tempDir,
3631
+ version: latestVersion,
3632
+ platform: "Linux",
3633
+ archiveName: (version) => `camunda-modeler-${version}-linux-x64.tar.gz`,
3634
+ logger: ctx.logger,
3635
+ quiet: ctx.quiet,
3636
+ signal: interruption.signal
3637
+ });
3638
+ const temporaryLauncher = join2(
3639
+ LINUX_INSTALL_ROOT,
3640
+ ".c8ctl-camunda-modeler-update"
3641
+ );
3642
+ let launcherUpdated = false;
3643
+ try {
3644
+ reportProgress(
3645
+ ctx,
3646
+ `Installing Camunda Modeler ${latestVersion} to ${newInstallDir}...`
3647
+ );
3648
+ runAsRoot(
3649
+ [
3650
+ "tar",
3651
+ "--no-same-owner",
3652
+ "-xzf",
3653
+ archivePath,
3654
+ "-C",
3655
+ LINUX_INSTALL_ROOT
3656
+ ],
3657
+ "Could not extract Camunda Modeler",
3658
+ ctx.quiet
3659
+ );
3660
+ if (!existsSync(join2(newInstallDir, LINUX_EXECUTABLE))) {
3661
+ throw manualDownloadError(
3662
+ `The Camunda Modeler ${latestVersion} archive did not contain ${newReleaseName}/${LINUX_EXECUTABLE}`
3663
+ );
3664
+ }
3665
+ runAsRoot(
3666
+ ["chmod", "4755", join2(newInstallDir, "chrome-sandbox")],
3667
+ "Could not set up the Camunda Modeler sandbox",
3668
+ ctx.quiet
3669
+ );
3670
+ runAsRoot(
3671
+ [
3672
+ "ln",
3673
+ "-sfn",
3674
+ join2(newReleaseName, LINUX_EXECUTABLE),
3675
+ temporaryLauncher
3676
+ ],
3677
+ `Could not prepare ${LINUX_EXECUTABLE}`,
3678
+ ctx.quiet
3679
+ );
3680
+ runAsRoot(
3681
+ ["mv", "-f", temporaryLauncher, installation.launcher],
3682
+ `Could not switch ${LINUX_EXECUTABLE} to the updated release`,
3683
+ ctx.quiet
3684
+ );
3685
+ launcherUpdated = true;
3686
+ } catch (error) {
3687
+ if (!launcherUpdated) {
3688
+ try {
3689
+ runAsRoot(
3690
+ ["rm", "-f", temporaryLauncher],
3691
+ `Could not remove ${temporaryLauncher}`,
3692
+ ctx.quiet,
3693
+ false
3694
+ );
3695
+ } catch (cleanupError) {
3696
+ ctx.logger.warn(errorMessage(cleanupError));
3697
+ }
3698
+ if (existsSync(newInstallDir)) {
3699
+ try {
3700
+ runAsRoot(
3701
+ ["rm", "-rf", newInstallDir],
3702
+ `Could not remove incomplete release ${newInstallDir}`,
3703
+ ctx.quiet,
3704
+ false
3705
+ );
3706
+ } catch (cleanupError) {
3707
+ ctx.logger.warn(errorMessage(cleanupError));
3708
+ }
3709
+ }
3710
+ }
3711
+ throw error;
3712
+ }
3713
+ unregisterWithDesktop({
3714
+ installDir: installation.installDir,
3715
+ logger: ctx.logger,
3716
+ quiet: ctx.quiet
3717
+ });
3718
+ registerWithDesktop({
3719
+ installDir: newInstallDir,
3720
+ logger: ctx.logger,
3721
+ quiet: ctx.quiet
3722
+ });
3723
+ try {
3724
+ runAsRoot(
3725
+ ["rm", "-rf", installation.installDir],
3726
+ `Could not remove previous Modeler release ${installation.installDir}`,
3727
+ ctx.quiet,
3728
+ false
3729
+ );
3730
+ } catch (error) {
3731
+ ctx.logger.warn(
3732
+ `Updated Camunda Modeler, but could not remove the previous release at ${installation.installDir}: ${errorMessage(error)}`
3733
+ );
3734
+ }
3735
+ return {
3736
+ kind: "success",
3737
+ message: `Updated Camunda Modeler to ${latestVersion} in ${newInstallDir}.`
3738
+ };
3739
+ } finally {
3740
+ try {
3741
+ rmSync(tempDir, { recursive: true, force: true });
3742
+ } finally {
3743
+ interruption.cleanup();
3744
+ }
3745
+ }
3746
+ }
3747
+ function removeLinuxModeler(ctx) {
3748
+ const installation = linuxModelerForAction("remove");
3749
+ if (!installation) return noModelerInstalled();
3750
+ if (ctx.isDryRun) {
3751
+ return dryRunResult(
3752
+ "modeler remove",
3753
+ `Dry run: would remove Camunda Modeler ${installation.version} from ${installation.installDir} and unregister its file types.`
3754
+ );
3755
+ }
3756
+ if (process.getuid?.() !== 0) {
3757
+ reportProgress(
3758
+ ctx,
3759
+ `Removing from ${LINUX_INSTALL_ROOT} needs root privileges; sudo may ask for your password.`
3760
+ );
3761
+ }
3762
+ runAsRoot(["true"], "Could not get root privileges", ctx.quiet, false);
3763
+ unregisterWithDesktop({
3764
+ installDir: installation.installDir,
3765
+ logger: ctx.logger,
3766
+ quiet: ctx.quiet
3767
+ });
3768
+ runAsRoot(
3769
+ ["rm", "-rf", installation.installDir],
3770
+ `Could not remove ${installation.installDir}`,
3771
+ ctx.quiet,
3772
+ false
3773
+ );
3774
+ runAsRoot(
3775
+ ["rm", "-f", installation.launcher],
3776
+ `Could not remove ${installation.launcher}`,
3777
+ ctx.quiet,
3778
+ false
3779
+ );
3780
+ return {
3781
+ kind: "success",
3782
+ message: `Removed Camunda Modeler ${installation.version} from ${installation.installDir}.`
3783
+ };
3784
+ }
3785
+ async function removeMacModeler(ctx) {
3786
+ if (hasPackageManager("brew", "Homebrew") && homebrewModelerInstalled()) {
3787
+ if (ctx.isDryRun) {
3788
+ return dryRunResult(
3789
+ "modeler remove",
3790
+ "Dry run: would remove Camunda Modeler with `brew uninstall --cask camunda-modeler`."
3791
+ );
3792
+ }
3793
+ let appPath2;
3794
+ try {
3795
+ appPath2 = resolveHomebrewModelerPath();
3796
+ } catch (error) {
3797
+ ctx.logger.warn(
3798
+ `Could not locate the Homebrew Modeler bundle before uninstalling it: ${errorMessage(error)}`
3799
+ );
3800
+ }
3801
+ reportProgress(ctx, "Removing Camunda Modeler with Homebrew...");
3802
+ runCommand("brew", ["uninstall", "--cask", "camunda-modeler"], {
3803
+ failureMessage: "Homebrew could not remove Camunda Modeler",
3804
+ quiet: ctx.quiet
3805
+ });
3806
+ if (appPath2) unregisterWithLaunchServices(appPath2, ctx.logger);
3807
+ return {
3808
+ kind: "success",
3809
+ message: "Removed Camunda Modeler with Homebrew."
3810
+ };
3811
+ }
3812
+ const appPath = findInstalledModeler();
3813
+ if (!appPath) return noModelerInstalled();
3814
+ if (isHomebrewCaskPath(appPath)) {
3815
+ throw new Error(
3816
+ "Camunda Modeler appears to be Homebrew-managed, but its cask was not found; refusing to remove the app bundle directly."
3817
+ );
3818
+ }
3819
+ verifyMacModelerBundle(appPath, "remove", ctx.quiet);
3820
+ if (ctx.isDryRun) {
3821
+ return dryRunResult(
3822
+ "modeler remove",
3823
+ `Dry run: would remove the Camunda Modeler app bundle at ${appPath}.`
3824
+ );
3825
+ }
3826
+ reportProgress(ctx, `Removing Camunda Modeler from ${appPath}...`);
3827
+ unregisterWithLaunchServices(appPath, ctx.logger);
3828
+ rmSync(appPath, { recursive: true });
3829
+ return {
3830
+ kind: "success",
3831
+ message: `Removed Camunda Modeler from ${appPath}.`
3832
+ };
3833
+ }
3834
+ async function updateDesktopModeler(ctx) {
3835
+ if (process.platform === "win32") return updateWindowsModeler(ctx);
3836
+ if (process.platform === "linux") {
3837
+ return withLinuxLifecycleLock(ctx, () => updateLinuxModeler(ctx));
3838
+ }
3839
+ if (process.platform === "darwin") return updateMacModeler(ctx);
3840
+ throw new Error(
3841
+ `c8ctl modeler update currently supports macOS, Windows, and Linux only. Download Modeler manually from ${MANUAL_DOWNLOAD_URL}`
3842
+ );
3843
+ }
3844
+ async function removeDesktopModeler(ctx) {
3845
+ if (process.platform === "win32") return removeWindowsModeler(ctx);
3846
+ if (process.platform === "linux") {
3847
+ return withLinuxLifecycleLock(ctx, () => removeLinuxModeler(ctx));
3848
+ }
3849
+ if (process.platform === "darwin") return removeMacModeler(ctx);
3850
+ throw new Error(
3851
+ `c8ctl modeler remove currently supports macOS, Windows, and Linux only. Download Modeler manually from ${MANUAL_DOWNLOAD_URL}`
3852
+ );
3853
+ }
2974
3854
 
2975
3855
  // default-plugins/modeler/c8ctl-plugin.ts
2976
3856
  var metadata = {
2977
3857
  name: "modeler",
2978
- description: "Install Camunda Desktop Modeler",
3858
+ description: "Manage Camunda Desktop Modeler",
2979
3859
  commands: {
2980
3860
  modeler: {
2981
- description: "Install Camunda Desktop Modeler",
2982
- helpDescription: "Install the latest stable Camunda Desktop Modeler on macOS, Windows, or Linux, skipping the installation when Modeler is already installed. On macOS, uses Homebrew when available, and otherwise installs the Camunda-signed release into /Applications (or ~/Applications when /Applications is not writable). On Windows, installs it with winget into %LOCALAPPDATA%\\Programs\\Camunda Modeler, then registers its file types and adds it to the Start Menu. On Linux (x64), installs the release into /usr/bin as root, using sudo, as the Camunda documentation describes, then registers its file types with the bundled support/xdg_register.sh.",
3861
+ description: "Manage Camunda Desktop Modeler",
3862
+ helpDescription: "Manage Camunda Desktop Modeler on macOS, Windows, or Linux. Install the latest stable release, update it using the same installation method, or remove it. On macOS, uses Homebrew when available and otherwise downloads the Camunda-signed release into /Applications (or ~/Applications when /Applications is not writable). On Windows, uses winget and registers file types and a Start Menu shortcut. On Linux (x64), installs into /usr/bin as root and registers file types with Modeler's bundled support scripts.",
2983
3863
  subcommands: [
2984
3864
  {
2985
3865
  name: "install",
2986
3866
  description: "Install the latest stable Camunda Desktop Modeler"
3867
+ },
3868
+ {
3869
+ name: "update",
3870
+ description: "Update Camunda Desktop Modeler to the latest stable release"
3871
+ },
3872
+ {
3873
+ name: "remove",
3874
+ description: "Remove a c8ctl-managed Camunda Desktop Modeler installation"
2987
3875
  }
2988
3876
  ],
2989
3877
  examples: [
2990
3878
  {
2991
3879
  command: "c8ctl modeler install",
2992
3880
  description: "Install the latest stable Camunda Desktop Modeler"
3881
+ },
3882
+ {
3883
+ command: "c8ctl modeler update",
3884
+ description: "Update Camunda Desktop Modeler"
3885
+ },
3886
+ {
3887
+ command: "c8ctl modeler remove --dry-run",
3888
+ description: "Preview removal of Camunda Desktop Modeler"
2993
3889
  }
2994
3890
  ]
2995
3891
  }
@@ -2998,36 +3894,49 @@ var metadata = {
2998
3894
  async function modelerHandler(args, _flags, ctx) {
2999
3895
  if (!ctx) throw new Error("modeler requires the plugin host context");
3000
3896
  const { logger } = ctx;
3001
- if (args[0] !== "install") {
3002
- if (args[0] === void 0) {
3003
- logger.info(
3004
- "\nUsage: c8ctl modeler install\n\nAvailable resources:\n install",
3005
- {
3006
- essential: true
3007
- }
3008
- );
3009
- } else {
3010
- logger.error(`Unknown command: modeler ${args.join(" ")}`);
3011
- logger.info('Run "c8 help" for usage information', { essential: true });
3012
- }
3897
+ const action = args[0];
3898
+ if (action === void 0) {
3899
+ logger.info(
3900
+ "\nUsage: c8ctl modeler <install|update|remove>\n\nAvailable commands:\n install\n update\n remove",
3901
+ { essential: true }
3902
+ );
3903
+ process.exitCode = 1;
3904
+ return;
3905
+ }
3906
+ if (action !== "install" && action !== "update" && action !== "remove") {
3907
+ logger.error(`Unknown command: modeler ${args.join(" ")}`);
3908
+ logger.info('Run "c8 help" for usage information', { essential: true });
3013
3909
  process.exitCode = 1;
3014
3910
  return;
3015
3911
  }
3016
3912
  try {
3017
- const result = await installDesktopModeler({
3913
+ const operation = {
3914
+ install: installDesktopModeler,
3915
+ update: updateDesktopModeler,
3916
+ remove: removeDesktopModeler
3917
+ }[action];
3918
+ const result = await operation({
3018
3919
  isDryRun: ctx.dryRun,
3019
3920
  logger,
3020
3921
  quiet: ctx.quiet
3021
3922
  });
3022
- if (result.kind === "dryRun") {
3023
- logger.json(result.info);
3024
- } else if (result.kind === "info") {
3025
- logger.info(result.message, { essential: true });
3923
+ const normalized = result.kind === "info" && ctx.dryRun ? {
3924
+ kind: "dryRun",
3925
+ info: {
3926
+ dryRun: true,
3927
+ command: `modeler ${action}`,
3928
+ message: result.message
3929
+ }
3930
+ } : result;
3931
+ if (normalized.kind === "dryRun") {
3932
+ logger.json(normalized.info);
3933
+ } else if (normalized.kind === "info") {
3934
+ logger.info(normalized.message, { essential: true });
3026
3935
  } else {
3027
- logger.success(result.message);
3936
+ logger.success(normalized.message);
3028
3937
  }
3029
3938
  } catch (error) {
3030
- renderCommandFailure(logger, "Failed to modeler install", error, {
3939
+ renderCommandFailure(logger, `Failed to ${action} Camunda Modeler`, error, {
3031
3940
  verbose: ctx.verbose
3032
3941
  });
3033
3942
  process.exitCode = 1;
@@ -2,7 +2,7 @@
2
2
  "name": "c8ctl-plugin-modeler",
3
3
  "version": "0.1.0",
4
4
  "type": "module",
5
- "description": "c8ctl default plugin to install Camunda Desktop Modeler",
5
+ "description": "c8ctl default plugin to manage Camunda Desktop Modeler",
6
6
  "keywords": ["c8ctl", "c8ctl-plugin", "modeler", "camunda"],
7
7
  "main": "c8ctl-plugin.js"
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camunda8/cli",
3
- "version": "4.7.0-alpha.22",
3
+ "version": "4.7.0-alpha.23",
4
4
  "description": "Camunda 8 CLI - minimal-dependency CLI for Camunda 8 operations",
5
5
  "type": "module",
6
6
  "engines": {