@naseej/blox 1.6.3 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/run.js CHANGED
@@ -57,6 +57,8 @@ var defaultConfig = {
57
57
  var bloxFilePath = ".blox";
58
58
  var blocksDir = "blocks";
59
59
  var defaultBranch = "main";
60
+ var CURRENT_SCHEMA_VERSION = 1;
61
+ var SCHEMA_BASE_URL = "https://raw.githubusercontent.com/Naseej-its/blox/main/schemas";
60
62
 
61
63
  // src/shared/logger.ts
62
64
  var console2 = __toESM(require("console"));
@@ -199,18 +201,69 @@ var checkForCliUpdate = async (currentVersion, argv = []) => {
199
201
  };
200
202
 
201
203
  // package.json
202
- var version = "1.6.3";
204
+ var version = "1.8.0";
203
205
 
204
206
  // src/commands/add/index.ts
205
- var import_fs_extra10 = __toESM(require("fs-extra"));
207
+ var import_fs_extra11 = __toESM(require("fs-extra"));
206
208
 
207
209
  // src/migrations/index.ts
208
- var import_node_path10 = __toESM(require("path"));
209
- var import_fs_extra7 = __toESM(require("fs-extra"));
210
+ var import_node_path11 = __toESM(require("path"));
211
+ var import_fs_extra8 = __toESM(require("fs-extra"));
212
+
213
+ // src/migrations/updateSchemaUrls.ts
214
+ var import_node_path3 = __toESM(require("path"));
215
+ var import_fs_extra3 = __toESM(require("fs-extra"));
216
+ async function updateSchemaUrls(cwd = ".") {
217
+ const locations = [
218
+ { filePath: import_node_path3.default.join(cwd, bloxFilePath), type: "template" },
219
+ ...readBlockPaths(cwd).map((filePath) => ({ filePath, type: "block" }))
220
+ ];
221
+ let anyChanged = false;
222
+ for (const { filePath, type } of locations) {
223
+ const changed = rewriteIfStale(filePath, type);
224
+ anyChanged = anyChanged || changed;
225
+ }
226
+ if (anyChanged) {
227
+ import_prompts2.log.warn(fmt.yellow("Schema URLs updated to v" + CURRENT_SCHEMA_VERSION));
228
+ }
229
+ return anyChanged;
230
+ }
231
+ function readBlockPaths(cwd) {
232
+ const dir = import_node_path3.default.join(cwd, blocksDir);
233
+ if (!import_fs_extra3.default.existsSync(dir)) return [];
234
+ return import_fs_extra3.default.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => import_node_path3.default.join(dir, e.name, bloxFilePath));
235
+ }
236
+ function rewriteIfStale(filePath, type) {
237
+ if (!import_fs_extra3.default.existsSync(filePath)) return false;
238
+ let raw;
239
+ try {
240
+ raw = import_fs_extra3.default.readJSONSync(filePath);
241
+ } catch {
242
+ debug(`updateSchemaUrls: skipping unreadable file ${filePath}`);
243
+ return false;
244
+ }
245
+ const existingSchema = raw["$schema"];
246
+ const schemaVersion = typeof raw["schemaVersion"] === "number" ? raw["schemaVersion"] : CURRENT_SCHEMA_VERSION;
247
+ const expectedSchemaUrl = buildSchemaUrl(type, schemaVersion);
248
+ if (existingSchema === expectedSchemaUrl) {
249
+ return false;
250
+ }
251
+ const { $schema: _previousSchema, ...rest } = raw;
252
+ const updated = {
253
+ $schema: expectedSchemaUrl,
254
+ ...rest
255
+ };
256
+ import_fs_extra3.default.writeFileSync(filePath, JSON.stringify(updated, null, 2));
257
+ debug(`updateSchemaUrls: updated ${filePath} \u2192 ${expectedSchemaUrl}`);
258
+ return true;
259
+ }
260
+ function buildSchemaUrl(type, generation = CURRENT_SCHEMA_VERSION) {
261
+ return `${SCHEMA_BASE_URL}/v${generation}/${type}.json`;
262
+ }
210
263
 
211
264
  // src/migrations/utils.ts
212
- var import_node_path9 = __toESM(require("path"));
213
- var import_fs_extra6 = __toESM(require("fs-extra"));
265
+ var import_node_path10 = __toESM(require("path"));
266
+ var import_fs_extra7 = __toESM(require("fs-extra"));
214
267
 
215
268
  // src/migrations/list/v1.ts
216
269
  var v1 = {
@@ -247,8 +300,8 @@ var migrationsList = [v1];
247
300
 
248
301
  // src/services/git.ts
249
302
  var import_node_os = __toESM(require("os"));
250
- var import_node_path8 = __toESM(require("path"));
251
- var import_fs_extra5 = __toESM(require("fs-extra"));
303
+ var import_node_path9 = __toESM(require("path"));
304
+ var import_fs_extra6 = __toESM(require("fs-extra"));
252
305
 
253
306
  // src/services/shell.ts
254
307
  var import_cross_spawn = __toESM(require("cross-spawn"));
@@ -337,14 +390,14 @@ var looksLikeDirectory = (pattern) => {
337
390
  };
338
391
 
339
392
  // src/shared/utils/gitignoreMatcher.ts
340
- var import_node_path3 = __toESM(require("path"));
393
+ var import_node_path4 = __toESM(require("path"));
341
394
  var import_ignore = __toESM(require("ignore"));
342
395
  var createGitignoreMatcher = (patterns) => {
343
396
  const cleaned = patterns.map((p) => p.trim()).filter((p) => p && !p.startsWith("#"));
344
397
  return (0, import_ignore.default)().add(cleaned);
345
398
  };
346
399
  var toIgnorePath = (repoRelativePath) => {
347
- let p = repoRelativePath.split(import_node_path3.default.sep).join("/");
400
+ let p = repoRelativePath.split(import_node_path4.default.sep).join("/");
348
401
  if (p.startsWith("./")) p = p.slice(2);
349
402
  return p;
350
403
  };
@@ -401,9 +454,9 @@ function openUrlInBrowser(url) {
401
454
  }
402
455
 
403
456
  // src/shared/utils/isBloxConfigFile.ts
404
- var import_node_path4 = __toESM(require("path"));
457
+ var import_node_path5 = __toESM(require("path"));
405
458
  function isBloxConfigFile(file) {
406
- const normalized = file.split(import_node_path4.default.sep).join("/");
459
+ const normalized = file.split(import_node_path5.default.sep).join("/");
407
460
  return normalized === bloxFilePath || normalized.endsWith(`/${bloxFilePath}`);
408
461
  }
409
462
 
@@ -423,40 +476,40 @@ function omitKeys(value, keysToOmit) {
423
476
  var normalizeCommitRef = (commit2) => commit2.trim().replace(/\r/g, "").replace(/^"+|"+$/g, "");
424
477
 
425
478
  // src/shared/utils/isBlockDirectory.ts
426
- var import_node_path5 = __toESM(require("path"));
427
- var import_fs_extra3 = __toESM(require("fs-extra"));
479
+ var import_node_path6 = __toESM(require("path"));
480
+ var import_fs_extra4 = __toESM(require("fs-extra"));
428
481
  function isBlockDirectory(blockDir) {
429
- const bloxPath = import_node_path5.default.join(blockDir, bloxFilePath);
430
- if (!import_fs_extra3.default.existsSync(bloxPath)) {
482
+ const bloxPath = import_node_path6.default.join(blockDir, bloxFilePath);
483
+ if (!import_fs_extra4.default.existsSync(bloxPath)) {
431
484
  return false;
432
485
  }
433
486
  try {
434
- return import_fs_extra3.default.statSync(bloxPath).isFile();
487
+ return import_fs_extra4.default.statSync(bloxPath).isFile();
435
488
  } catch {
436
489
  return false;
437
490
  }
438
491
  }
439
492
 
440
493
  // src/services/template.ts
441
- var import_node_path6 = __toESM(require("path"));
494
+ var import_node_path7 = __toESM(require("path"));
442
495
  var import_ejs = __toESM(require("ejs"));
443
- var import_fs_extra4 = __toESM(require("fs-extra"));
496
+ var import_fs_extra5 = __toESM(require("fs-extra"));
444
497
  var import_klaw = __toESM(require("klaw"));
445
498
  async function replacePlaceholders(dir, context) {
446
499
  debug("Replace placeholders");
447
500
  for await (const file of (0, import_klaw.default)(dir)) {
448
501
  if (!file.stats.isFile()) continue;
449
- const ext = import_node_path6.default.extname(file.path).toLowerCase();
502
+ const ext = import_node_path7.default.extname(file.path).toLowerCase();
450
503
  if (isBinaryFile(ext)) {
451
504
  continue;
452
505
  }
453
- const templateContent = import_fs_extra4.default.readFileSync(file.path, "utf8");
506
+ const templateContent = import_fs_extra5.default.readFileSync(file.path, "utf8");
454
507
  if (!templateContent.includes("<%")) {
455
508
  continue;
456
509
  }
457
510
  try {
458
511
  const rendered = import_ejs.default.render(templateContent, context);
459
- import_fs_extra4.default.writeFileSync(file.path, rendered, "utf8");
512
+ import_fs_extra5.default.writeFileSync(file.path, rendered, "utf8");
460
513
  } catch (err) {
461
514
  console.error("\u274C Error rendering EJS for file:", file.path);
462
515
  throw err;
@@ -477,7 +530,7 @@ function getBlockDef(cwd = ".") {
477
530
  }
478
531
  function getBloxFile(cwd = ".") {
479
532
  try {
480
- const file = import_fs_extra4.default.readJSONSync(import_node_path6.default.join(cwd, bloxFilePath));
533
+ const file = import_fs_extra5.default.readJSONSync(import_node_path7.default.join(cwd, bloxFilePath));
481
534
  if (!file.checkpoints) {
482
535
  file.checkpoints = {};
483
536
  }
@@ -488,7 +541,7 @@ function getBloxFile(cwd = ".") {
488
541
  }
489
542
  function saveBloxFile(info, cwd = ".") {
490
543
  debug("Save info");
491
- import_fs_extra4.default.writeFileSync(import_node_path6.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
544
+ import_fs_extra5.default.writeFileSync(import_node_path7.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
492
545
  }
493
546
  function updateCheckpoint(name, checkpoint, cwd = ".") {
494
547
  const info = getBloxFile(cwd);
@@ -504,12 +557,12 @@ function getUsedBlocksDef() {
504
557
  function getUsedBlocks() {
505
558
  debug("Get used blocks");
506
559
  const blocks = [];
507
- if (import_fs_extra4.default.existsSync(blocksDir)) {
508
- import_fs_extra4.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
560
+ if (import_fs_extra5.default.existsSync(blocksDir)) {
561
+ import_fs_extra5.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
509
562
  if (!file.isDirectory()) {
510
563
  return;
511
564
  }
512
- const blockDef = getBloxFile(import_node_path6.default.join(blocksDir, file.name));
565
+ const blockDef = getBloxFile(import_node_path7.default.join(blocksDir, file.name));
513
566
  if (blockDef && blockDef.definition) {
514
567
  blocks.push(blockDef);
515
568
  }
@@ -524,12 +577,22 @@ var import_prompts3 = require("@clack/prompts");
524
577
  var spinner = () => {
525
578
  const s = (0, import_prompts3.spinner)();
526
579
  const minimal = isMinimalMode() || isDebugMode();
580
+ const stop = (msg = "error", code) => {
581
+ minimal ? code ? import_prompts2.log.error(msg) : import_prompts2.log.step(msg || "success") : s.stop(code ? fmt.red(msg) : fmt.green(msg), code);
582
+ };
527
583
  return {
528
584
  start: (msg) => {
529
585
  minimal ? import_prompts2.log.step(`${msg || "start"}...`) : s.start(msg);
530
586
  },
531
- stop: (msg = "error", code) => {
532
- minimal ? code ? import_prompts2.log.error(msg) : import_prompts2.log.step(msg || "success") : s.stop(code ? fmt.red(msg) : fmt.green(msg), code);
587
+ stop,
588
+ success: (msg = "success") => {
589
+ stop(msg, 0);
590
+ },
591
+ fail: (msg = "error", code = 1) => {
592
+ stop(msg, code);
593
+ },
594
+ finish: (msg = "success") => {
595
+ stop(msg, 0);
533
596
  },
534
597
  message: (msg) => {
535
598
  minimal ? import_prompts2.log.message(msg) : s.message(msg);
@@ -561,11 +624,14 @@ function getLifecycleHookScript(cwd, hook) {
561
624
  }
562
625
  async function runLifecycleHookScript(cwd, script) {
563
626
  const isWin = process.platform === "win32";
627
+ const onStdout = (data) => {
628
+ process.stdout.write(data);
629
+ };
564
630
  if (isWin) {
565
- await $("cmd.exe", ["/d", "/s", "/c", script], { cwd });
631
+ await $("cmd.exe", ["/d", "/s", "/c", script], { cwd, onStdout });
566
632
  return;
567
633
  }
568
- await $("/bin/sh", ["-lc", script], { cwd });
634
+ await $("/bin/sh", ["-lc", script], { cwd, onStdout });
569
635
  }
570
636
  async function runLifecycleHookWithTask(cwd, hook, message) {
571
637
  const script = getLifecycleHookScript(cwd, hook);
@@ -577,9 +643,9 @@ async function runLifecycleHookWithTask(cwd, hook, message) {
577
643
  }
578
644
 
579
645
  // src/services/path.ts
580
- var import_node_path7 = __toESM(require("path"));
646
+ var import_node_path8 = __toESM(require("path"));
581
647
  var normalizePath = (_path) => {
582
- return _path.split(import_node_path7.default.sep).join("/");
648
+ return _path.split(import_node_path8.default.sep).join("/");
583
649
  };
584
650
 
585
651
  // src/services/git.ts
@@ -610,16 +676,16 @@ var getRemoteWorktree = async (remote, commit2) => {
610
676
  return remoteWorktrees.get(key);
611
677
  }
612
678
  const tmpDir = import_node_os.default.tmpdir();
613
- const worktreeDir = import_node_path8.default.join(tmpDir, "blox-cli-worktrees", remote, commit2);
679
+ const worktreeDir = import_node_path9.default.join(tmpDir, "blox-cli-worktrees", remote, commit2);
614
680
  try {
615
681
  await $("git", ["worktree", "prune"]);
616
682
  } catch {
617
683
  }
618
- if (await import_fs_extra5.default.pathExists(worktreeDir)) {
684
+ if (await import_fs_extra6.default.pathExists(worktreeDir)) {
619
685
  try {
620
686
  await $("git", ["worktree", "remove", "--force", worktreeDir]);
621
687
  } catch {
622
- await import_fs_extra5.default.remove(worktreeDir);
688
+ await import_fs_extra6.default.remove(worktreeDir);
623
689
  try {
624
690
  await $("git", ["worktree", "prune"]);
625
691
  } catch {
@@ -735,8 +801,8 @@ var update = (shellOptions = {}) => {
735
801
  var getLatestCommitFromRemote = async (remote, branch) => {
736
802
  return getLatestCommit(`${remote}/${branch}`);
737
803
  };
738
- var getLatestCommitFromPath = async (path23) => {
739
- return getLatestCommit("HEAD", path23);
804
+ var getLatestCommitFromPath = async (path24) => {
805
+ return getLatestCommit("HEAD", path24);
740
806
  };
741
807
  var getLatestCommit = async (rev, cwd = ".") => {
742
808
  debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
@@ -760,7 +826,7 @@ var getChangesLog = async (fromCommit, toCommit) => {
760
826
  };
761
827
  var unInit = (cwd) => {
762
828
  debug("UnInit");
763
- return import_fs_extra5.default.remove(import_node_path8.default.join(cwd, ".git"));
829
+ return import_fs_extra6.default.remove(import_node_path9.default.join(cwd, ".git"));
764
830
  };
765
831
  var init = async (cwd) => {
766
832
  debug("Init");
@@ -877,11 +943,11 @@ var createBranch = async (branch, from, cwd = ".") => {
877
943
  var push = async (remote, branch, cwd = ".") => {
878
944
  await $("git", ["push", "--progress", remote, `refs/heads/${branch}`], { cwd });
879
945
  };
880
- var checkoutFile = async (path23, ref, cwd = ".") => {
946
+ var checkoutFile = async (path24, ref, cwd = ".") => {
881
947
  const args = ["checkout"];
882
948
  if (ref) args.push(ref);
883
949
  else args.push("HEAD");
884
- args.push("--", path23);
950
+ args.push("--", path24);
885
951
  await $("git", args, { cwd });
886
952
  };
887
953
  var pathExistsAsBlobInRev = async (rev, filePath, cwd = ".") => {
@@ -943,10 +1009,10 @@ var cherryPick = async (commitHash, subtree, noCommit, cwd = ".") => {
943
1009
  args.push(normalizeCommitRef(commitHash));
944
1010
  await $("git", args, { cwd });
945
1011
  };
946
- var reset = async (path23, hard, cwd = ".") => {
1012
+ var reset = async (path24, hard, cwd = ".") => {
947
1013
  const args = ["reset"];
948
1014
  if (hard) args.push("--hard");
949
- if (path23) args.push(path23);
1015
+ if (path24) args.push(path24);
950
1016
  await $("git", args, { cwd });
951
1017
  };
952
1018
  var commitAll = async (message, cwd = ".") => {
@@ -966,15 +1032,30 @@ var getUnmergedFiles = async (cwd = ".") => {
966
1032
  var fetchRepo = async (cwd = ".") => {
967
1033
  await $("git", ["fetch", "--progress", "origin"], { cwd });
968
1034
  };
969
- var getStagedFiles = async (cwd = ".") => {
1035
+ var getChangedFilesFromHead = async (cwd = ".") => {
970
1036
  let out = "";
971
- await $("git", ["diff", "--cached", "--name-only"], {
1037
+ await $("git", ["diff", "--name-status", "-z", "HEAD"], {
972
1038
  cwd,
973
1039
  onStdout: (text2) => {
974
1040
  out += text2;
975
1041
  }
976
1042
  });
977
- return out.split("\n").map((l) => l.trim()).filter(Boolean);
1043
+ const entries = out.split("\0").filter(Boolean);
1044
+ const files = /* @__PURE__ */ new Set();
1045
+ for (let i = 0; i < entries.length; ) {
1046
+ const status = entries[i++] || "";
1047
+ const code = status.trim().toUpperCase();
1048
+ if (code.startsWith("R") || code.startsWith("C")) {
1049
+ const oldPath = entries[i++];
1050
+ const newPath = entries[i++];
1051
+ if (oldPath) files.add(oldPath);
1052
+ if (newPath) files.add(newPath);
1053
+ continue;
1054
+ }
1055
+ const file = entries[i++];
1056
+ if (file) files.add(file);
1057
+ }
1058
+ return [...files];
978
1059
  };
979
1060
  var git = {
980
1061
  clone,
@@ -1017,7 +1098,7 @@ var git = {
1017
1098
  commitAll,
1018
1099
  getUnmergedFiles,
1019
1100
  fetchRepo,
1020
- getStagedFiles
1101
+ getChangedFilesFromHead
1021
1102
  };
1022
1103
 
1023
1104
  // src/shared/prompts/index.ts
@@ -1129,26 +1210,28 @@ async function migrate(name, { getPath = (f) => f, read, write }) {
1129
1210
  }
1130
1211
  function migrateOnLocal(name, cwd = ".") {
1131
1212
  return migrate(name, {
1132
- getPath: (file) => import_node_path9.default.join(cwd, file),
1133
- read: import_fs_extra6.default.readJson,
1134
- write: import_fs_extra6.default.writeFile
1213
+ getPath: (file) => import_node_path10.default.join(cwd, file),
1214
+ read: import_fs_extra7.default.readJson,
1215
+ write: import_fs_extra7.default.writeFile
1135
1216
  });
1136
1217
  }
1137
1218
  function migrateOnRemote(name, commit2, cwd) {
1138
1219
  return migrate(name, {
1139
1220
  read: (file) => git.readJsonFromCommit(commit2, file),
1140
- getPath: cwd ? (file) => import_node_path9.default.join(cwd, file) : void 0
1221
+ getPath: cwd ? (file) => import_node_path10.default.join(cwd, file) : void 0
1141
1222
  });
1142
1223
  }
1143
1224
 
1144
1225
  // src/migrations/index.ts
1145
1226
  async function migrateAll(autoCommit) {
1146
1227
  let filesChanged = (await migrateOnLocal("app")).filesChanged;
1147
- const blocks = import_fs_extra7.default.existsSync(blocksDir) ? import_fs_extra7.default.readdirSync(blocksDir) : [];
1228
+ const blocks = import_fs_extra8.default.existsSync(blocksDir) ? import_fs_extra8.default.readdirSync(blocksDir) : [];
1148
1229
  for (const block of blocks) {
1149
- const res = await migrateOnLocal(block, import_node_path10.default.join(blocksDir, block));
1230
+ const res = await migrateOnLocal(block, import_node_path11.default.join(blocksDir, block));
1150
1231
  filesChanged = filesChanged || res.filesChanged;
1151
1232
  }
1233
+ const urlsChanged = await updateSchemaUrls(".");
1234
+ filesChanged = filesChanged || urlsChanged;
1152
1235
  if (autoCommit && filesChanged && await git.hasUncommittedChanges()) {
1153
1236
  import_prompts2.log.warn(fmt.yellow(`Migrations done and will be commited`));
1154
1237
  await git.add(".");
@@ -1157,8 +1240,8 @@ async function migrateAll(autoCommit) {
1157
1240
  }
1158
1241
 
1159
1242
  // src/services/fs.ts
1160
- var import_node_path11 = __toESM(require("path"));
1161
- var import_fs_extra8 = __toESM(require("fs-extra"));
1243
+ var import_node_path12 = __toESM(require("path"));
1244
+ var import_fs_extra9 = __toESM(require("fs-extra"));
1162
1245
  var import_ignore2 = __toESM(require("ignore"));
1163
1246
  var import_klaw2 = __toESM(require("klaw"));
1164
1247
  var filterBlacklisted = (item) => {
@@ -1167,22 +1250,22 @@ var filterBlacklisted = (item) => {
1167
1250
  var deletePattern = async (cwd, patterns = []) => {
1168
1251
  const ig = (0, import_ignore2.default)().add(patterns);
1169
1252
  for await (const file of (0, import_klaw2.default)(cwd, { filter: filterBlacklisted })) {
1170
- const relativePath = import_node_path11.default.relative(cwd, file.path);
1253
+ const relativePath = import_node_path12.default.relative(cwd, file.path);
1171
1254
  if (relativePath && ig.ignores(relativePath)) {
1172
- if (!await import_fs_extra8.default.exists(file.path)) {
1255
+ if (!await import_fs_extra9.default.exists(file.path)) {
1173
1256
  continue;
1174
1257
  }
1175
1258
  debug(`deleting: ${relativePath}`);
1176
- await import_fs_extra8.default.remove(file.path);
1259
+ await import_fs_extra9.default.remove(file.path);
1177
1260
  }
1178
1261
  }
1179
1262
  };
1180
1263
 
1181
1264
  // src/services/registry.ts
1182
- var import_node_path12 = __toESM(require("path"));
1183
- var import_fs_extra9 = __toESM(require("fs-extra"));
1265
+ var import_node_path13 = __toESM(require("path"));
1266
+ var import_fs_extra10 = __toESM(require("fs-extra"));
1184
1267
  var import_merge = __toESM(require("lodash/merge"));
1185
- var registriesDataPath = import_node_path12.default.join(appPaths.data, "registries");
1268
+ var registriesDataPath = import_node_path13.default.join(appPaths.data, "registries");
1186
1269
  var upeToDate = false;
1187
1270
  var cacheDirNameForRegistry = (registry) => {
1188
1271
  return encodeURIComponent(registry).replace(/%/g, "_");
@@ -1191,30 +1274,50 @@ var getConfiguredRegistryDirs = () => {
1191
1274
  const config = getLocalConfig();
1192
1275
  return config.registries.map((registry) => ({
1193
1276
  registry,
1194
- dir: import_node_path12.default.join(registriesDataPath, cacheDirNameForRegistry(registry))
1277
+ dir: import_node_path13.default.isAbsolute(registry) ? registry : import_node_path13.default.join(registriesDataPath, cacheDirNameForRegistry(registry))
1195
1278
  }));
1196
1279
  };
1197
1280
  var syncRegistries = async (branch) => {
1198
1281
  if (upeToDate) return;
1199
1282
  upeToDate = true;
1200
1283
  debug("Sync registries");
1201
- import_fs_extra9.default.ensureDirSync(registriesDataPath);
1284
+ import_fs_extra10.default.ensureDirSync(registriesDataPath);
1202
1285
  const config = getLocalConfig();
1203
1286
  return await runTask("Update registries", async () => {
1204
1287
  await Promise.all(
1205
1288
  config.registries.map(async (registry) => {
1206
1289
  debug(`update registry: ${registry}`);
1290
+ if (import_node_path13.default.isAbsolute(registry)) {
1291
+ debug(`local registry (absolute path): ${registry}`);
1292
+ return;
1293
+ }
1207
1294
  const repoName = cacheDirNameForRegistry(registry);
1208
- const repoDir = import_node_path12.default.join(registriesDataPath, repoName);
1209
- if (!import_fs_extra9.default.existsSync(repoDir)) {
1295
+ const repoDir = import_node_path13.default.join(registriesDataPath, repoName);
1296
+ if (!import_fs_extra10.default.existsSync(repoDir)) {
1210
1297
  await git.clone(registry, repoName, branch, {
1211
1298
  cwd: registriesDataPath,
1212
1299
  depth: 1
1213
1300
  });
1214
- } else if (import_fs_extra9.default.existsSync(import_node_path12.default.join(repoDir, ".git"))) {
1301
+ return;
1302
+ }
1303
+ if (!import_fs_extra10.default.existsSync(import_node_path13.default.join(repoDir, ".git"))) {
1304
+ debug(`local registry: ${registry}`);
1305
+ return;
1306
+ }
1307
+ try {
1215
1308
  await git.update({ cwd: repoDir });
1216
- } else {
1217
- debug(`local registry`);
1309
+ } catch (e) {
1310
+ const hasConflicts2 = await git.hasConflicts(repoDir);
1311
+ if (hasConflicts2) {
1312
+ debug(`Registry has conflicts, recreating: ${registry}`);
1313
+ await import_fs_extra10.default.remove(repoDir);
1314
+ await git.clone(registry, repoName, branch, {
1315
+ cwd: registriesDataPath,
1316
+ depth: 1
1317
+ });
1318
+ return;
1319
+ }
1320
+ import_prompts2.log.error(`Failed to update registry: ${e}`);
1218
1321
  }
1219
1322
  })
1220
1323
  );
@@ -1224,9 +1327,9 @@ var getAvailableTemplates = async () => {
1224
1327
  debug("Get available templates");
1225
1328
  const templates = {};
1226
1329
  for (const { dir } of getConfiguredRegistryDirs()) {
1227
- const indexPath = import_node_path12.default.join(dir, "index.json");
1228
- if (import_fs_extra9.default.existsSync(indexPath)) {
1229
- const data = import_fs_extra9.default.readJSONSync(indexPath);
1330
+ const indexPath = import_node_path13.default.join(dir, "index.json");
1331
+ if (import_fs_extra10.default.existsSync(indexPath)) {
1332
+ const data = import_fs_extra10.default.readJSONSync(indexPath);
1230
1333
  Object.entries(data.templates || {}).forEach(([templateName, template]) => {
1231
1334
  if (!template.source) {
1232
1335
  template.source = `/template-${templateName}`;
@@ -1242,10 +1345,11 @@ var getAvailableTemplates = async () => {
1242
1345
  block.source = data.baseUrl + block.source;
1243
1346
  }
1244
1347
  });
1348
+ const resolvedTemplate = template;
1245
1349
  if (templates[templateName]) {
1246
- templates[templateName] = (0, import_merge.default)(templates[templateName], template);
1350
+ templates[templateName] = (0, import_merge.default)(templates[templateName], resolvedTemplate);
1247
1351
  } else {
1248
- templates[templateName] = template;
1352
+ templates[templateName] = resolvedTemplate;
1249
1353
  }
1250
1354
  });
1251
1355
  }
@@ -1267,17 +1371,17 @@ var getAvailableBlocks = async (templateInfo) => {
1267
1371
  };
1268
1372
  var getAvailableVersions = async (source) => {
1269
1373
  for (const { dir } of getConfiguredRegistryDirs()) {
1270
- const indexPath = import_node_path12.default.join(dir, "index.json");
1271
- if (!import_fs_extra9.default.existsSync(indexPath)) continue;
1272
- const registryData = import_fs_extra9.default.readJSONSync(indexPath);
1273
- const versionDirPath = import_node_path12.default.join(dir, "versions");
1374
+ const indexPath = import_node_path13.default.join(dir, "index.json");
1375
+ if (!import_fs_extra10.default.existsSync(indexPath)) continue;
1376
+ const registryData = import_fs_extra10.default.readJSONSync(indexPath);
1377
+ const versionDirPath = import_node_path13.default.join(dir, "versions");
1274
1378
  const versionsFilePaths = [
1275
- import_node_path12.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
1276
- import_node_path12.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
1379
+ import_node_path13.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
1380
+ import_node_path13.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
1277
1381
  ];
1278
1382
  for (const versionsFile of versionsFilePaths) {
1279
- if (import_fs_extra9.default.existsSync(versionsFile)) {
1280
- return import_fs_extra9.default.readJSONSync(versionsFile);
1383
+ if (import_fs_extra10.default.existsSync(versionsFile)) {
1384
+ return import_fs_extra10.default.readJSONSync(versionsFile);
1281
1385
  }
1282
1386
  }
1283
1387
  }
@@ -1414,7 +1518,7 @@ var addBlock = async (block, blocks, branch, destination) => {
1414
1518
  }
1415
1519
  const blockPath = `blocks/${destination}`;
1416
1520
  let newBlockAdded = false;
1417
- if (!import_fs_extra10.default.existsSync(blockPath)) {
1521
+ if (!import_fs_extra11.default.existsSync(blockPath)) {
1418
1522
  newBlockAdded = true;
1419
1523
  await runTask(
1420
1524
  { start: `Fetching block: ${block}`, end: `Added block: ${block}` },
@@ -1543,7 +1647,7 @@ var ContributionTargetType = /* @__PURE__ */ ((ContributionTargetType2) => {
1543
1647
  })(ContributionTargetType || {});
1544
1648
 
1545
1649
  // src/services/contribute/utils/bloxCheckpoint.ts
1546
- var import_node_path13 = __toESM(require("path"));
1650
+ var import_node_path14 = __toESM(require("path"));
1547
1651
  function getCheckpointForTarget(cwd, target) {
1548
1652
  const bloxDir = getBloxDirForTarget(cwd, target);
1549
1653
  const blox = getBloxFile(bloxDir);
@@ -1553,7 +1657,7 @@ function getCheckpointForTarget(cwd, target) {
1553
1657
  }
1554
1658
  function getBloxDirForTarget(cwd, target) {
1555
1659
  if (target.type === "block" /* BLOCK */) {
1556
- return import_node_path13.default.join(cwd, blocksDir, target.name);
1660
+ return import_node_path14.default.join(cwd, blocksDir, target.name);
1557
1661
  }
1558
1662
  return cwd;
1559
1663
  }
@@ -1823,28 +1927,28 @@ ${prUrl}` : "\nPush completed.")
1823
1927
  };
1824
1928
 
1825
1929
  // src/services/contribute/services/CommitApplierService.ts
1826
- var import_node_path15 = __toESM(require("path"));
1827
- var import_fs_extra12 = __toESM(require("fs-extra"));
1930
+ var import_node_path16 = __toESM(require("path"));
1931
+ var import_fs_extra13 = __toESM(require("fs-extra"));
1828
1932
 
1829
1933
  // src/services/contribute/config/index.ts
1830
1934
  var tempRepoName = "tmp";
1831
1935
  var bloxConfigControlledKeys = ["checkpoints", "project"];
1832
1936
 
1833
1937
  // src/services/contribute/utils/getExcludedPrefixesForTarget.ts
1834
- var import_node_path14 = __toESM(require("path"));
1835
- var import_fs_extra11 = __toESM(require("fs-extra"));
1938
+ var import_node_path15 = __toESM(require("path"));
1939
+ var import_fs_extra12 = __toESM(require("fs-extra"));
1836
1940
  function getExcludedPrefixesForTarget(target, cwd) {
1837
1941
  if (target.type === "block" /* BLOCK */) {
1838
1942
  return [];
1839
1943
  }
1840
1944
  const excluded = [];
1841
- const blocksPath = import_node_path14.default.join(cwd, blocksDir);
1842
- if (import_fs_extra11.default.existsSync(blocksPath)) {
1843
- const entries = import_fs_extra11.default.readdirSync(blocksPath, { withFileTypes: true });
1945
+ const blocksPath = import_node_path15.default.join(cwd, blocksDir);
1946
+ if (import_fs_extra12.default.existsSync(blocksPath)) {
1947
+ const entries = import_fs_extra12.default.readdirSync(blocksPath, { withFileTypes: true });
1844
1948
  for (const entry of entries) {
1845
1949
  if (!entry.isDirectory()) continue;
1846
- const blockBloxFile = import_node_path14.default.join(blocksPath, entry.name, bloxFilePath);
1847
- if (import_fs_extra11.default.existsSync(blockBloxFile)) {
1950
+ const blockBloxFile = import_node_path15.default.join(blocksPath, entry.name, bloxFilePath);
1951
+ if (import_fs_extra12.default.existsSync(blockBloxFile)) {
1848
1952
  excluded.push(normalizePath(`${blocksDir}/${entry.name}/`));
1849
1953
  }
1850
1954
  }
@@ -1964,9 +2068,9 @@ ${e instanceof Error ? e.message : String(e)}`);
1964
2068
  }
1965
2069
  }
1966
2070
  async revertExcludedStagedFiles(tmpRepoCwd, commit2, exclusion, projectIgnoreMatcher, target) {
1967
- const stagedFiles = await git.getStagedFiles(tmpRepoCwd);
2071
+ const changedFromHeadFiles = await git.getChangedFilesFromHead(tmpRepoCwd);
1968
2072
  const unmergedFiles = await git.getUnmergedFiles(tmpRepoCwd);
1969
- const allTouchedFiles = [.../* @__PURE__ */ new Set([...stagedFiles, ...unmergedFiles])];
2073
+ const allTouchedFiles = [.../* @__PURE__ */ new Set([...changedFromHeadFiles, ...unmergedFiles])];
1970
2074
  for (const file of allTouchedFiles) {
1971
2075
  const isBloxFile = isBloxConfigFile(file);
1972
2076
  const isExcludedByTarget = shouldExcludeFile(file, exclusion);
@@ -2022,8 +2126,8 @@ ${e instanceof Error ? e.message : String(e)}`);
2022
2126
  }
2023
2127
  const withoutGovernedKeys = omitKeys(stagedJson, bloxConfigControlledKeys);
2024
2128
  try {
2025
- const outPath = import_node_path15.default.join(tmpRepoCwd, file);
2026
- await import_fs_extra12.default.outputFile(outPath, JSON.stringify(withoutGovernedKeys, null, 2));
2129
+ const outPath = import_node_path16.default.join(tmpRepoCwd, file);
2130
+ await import_fs_extra13.default.outputFile(outPath, JSON.stringify(withoutGovernedKeys, null, 2));
2027
2131
  await git.add(file, tmpRepoCwd);
2028
2132
  } catch (e) {
2029
2133
  this.logger.warn("apply.commit.blox_merge_fallback", {
@@ -2085,65 +2189,86 @@ ${opts.description}`;
2085
2189
  };
2086
2190
 
2087
2191
  // src/services/contribute/services/CommitSelectorService.ts
2192
+ var NAV_PREV = "__prev__";
2193
+ var NAV_NEXT = "__next__";
2194
+ var NAV_FINISH = "__finish__";
2088
2195
  var CommitSelectorService = class {
2089
2196
  constructor(logger) {
2090
2197
  this.logger = logger;
2091
2198
  }
2092
2199
  async selectCommitsInteractive(opts) {
2093
- const selected = [];
2200
+ const selected = /* @__PURE__ */ new Set();
2201
+ const pages = /* @__PURE__ */ new Map();
2094
2202
  let page = 0;
2095
- let hasMore = true;
2096
- while (hasMore) {
2097
- const commits = await git.listCommits(UI_PAGE_SIZE, page * UI_PAGE_SIZE, opts.cwd);
2203
+ while (true) {
2204
+ let commits = pages.get(page);
2205
+ if (!commits) {
2206
+ commits = await git.listCommits(UI_PAGE_SIZE, page * UI_PAGE_SIZE, opts.cwd);
2207
+ pages.set(page, commits);
2208
+ }
2098
2209
  if (!commits.length) {
2099
2210
  if (page === 0) {
2100
2211
  throw new Error("No commits found in app repository.");
2101
2212
  }
2102
- break;
2213
+ page -= 1;
2214
+ continue;
2103
2215
  }
2216
+ const initialValues = commits.filter((c) => selected.has(c.hash)).map((c) => c.hash);
2104
2217
  const value = await multiselect({
2105
2218
  message: `Select commits (Press <space> to select, <enter> to continue) ${fmt.gray(`(page ${page + 1})`)}`,
2106
2219
  options: commits.map((c) => ({
2107
2220
  value: c.hash,
2108
2221
  label: `${c.hash.slice(0, 7)} ${c.subject}`
2109
2222
  })),
2110
- required: true
2223
+ initialValues,
2224
+ required: false
2111
2225
  });
2112
- for (const h of value) {
2113
- if (!selected.includes(h)) {
2114
- selected.push(h);
2226
+ for (const c of commits) {
2227
+ if (value.includes(c.hash)) {
2228
+ selected.add(c.hash);
2229
+ } else {
2230
+ selected.delete(c.hash);
2115
2231
  }
2116
2232
  }
2117
- hasMore = commits.length === UI_PAGE_SIZE;
2118
- if (!hasMore) {
2119
- break;
2120
- }
2121
- const loadMore = await confirm({
2122
- message: "Load next page of commits?",
2123
- initialValue: false
2233
+ const hasPrev = page > 0;
2234
+ const hasNext = commits.length === UI_PAGE_SIZE;
2235
+ const navigation = await select({
2236
+ message: `${selected.size} commit(s) selected. Choose an action:`,
2237
+ options: [
2238
+ ...hasPrev ? [{ label: "Previous page", value: NAV_PREV }] : [],
2239
+ ...hasNext ? [{ label: "Next page", value: NAV_NEXT }] : [],
2240
+ { label: "Finish selection", value: NAV_FINISH }
2241
+ ]
2124
2242
  });
2125
- if (!loadMore) {
2126
- break;
2243
+ if (navigation === NAV_PREV) {
2244
+ page -= 1;
2245
+ continue;
2127
2246
  }
2128
- page += 1;
2129
- }
2130
- if (!selected.length) {
2131
- throw new Error("No commits selected.");
2247
+ if (navigation === NAV_NEXT) {
2248
+ page += 1;
2249
+ continue;
2250
+ }
2251
+ if (!selected.size) {
2252
+ this.logger.warn("You must select at least one commit before finishing.");
2253
+ continue;
2254
+ }
2255
+ break;
2132
2256
  }
2133
- this.logger.debug("commits.selected", { count: selected.length });
2134
- this.logger.info(`${selected.length} Commits selected`);
2135
- return selected;
2257
+ const result = Array.from(selected);
2258
+ this.logger.debug("commits.selected", { count: result.length });
2259
+ this.logger.info(`${result.length} Commits selected`);
2260
+ return result;
2136
2261
  }
2137
2262
  };
2138
2263
 
2139
2264
  // src/services/contribute/utils/discoverContributionTargets.ts
2140
- var import_node_path16 = __toESM(require("path"));
2141
- var import_fs_extra13 = __toESM(require("fs-extra"));
2265
+ var import_node_path17 = __toESM(require("path"));
2266
+ var import_fs_extra14 = __toESM(require("fs-extra"));
2142
2267
  var readBloxFileIfExists = (cwd) => {
2143
- const p = import_node_path16.default.join(cwd, bloxFilePath);
2144
- if (!import_fs_extra13.default.existsSync(p)) return;
2268
+ const p = import_node_path17.default.join(cwd, bloxFilePath);
2269
+ if (!import_fs_extra14.default.existsSync(p)) return;
2145
2270
  try {
2146
- return import_fs_extra13.default.readJSONSync(p);
2271
+ return import_fs_extra14.default.readJSONSync(p);
2147
2272
  } catch {
2148
2273
  return;
2149
2274
  }
@@ -2171,13 +2296,13 @@ var discoverContributionTargets = (cwd) => {
2171
2296
  });
2172
2297
  }
2173
2298
  }
2174
- const blocksPath = import_node_path16.default.join(cwd, blocksDir);
2175
- if (import_fs_extra13.default.existsSync(blocksPath)) {
2176
- const entries = import_fs_extra13.default.readdirSync(blocksPath, { withFileTypes: true });
2299
+ const blocksPath = import_node_path17.default.join(cwd, blocksDir);
2300
+ if (import_fs_extra14.default.existsSync(blocksPath)) {
2301
+ const entries = import_fs_extra14.default.readdirSync(blocksPath, { withFileTypes: true });
2177
2302
  for (const entry of entries) {
2178
2303
  if (!entry.isDirectory()) continue;
2179
2304
  const blockName = entry.name;
2180
- const blockBlox = readBloxFileIfExists(import_node_path16.default.join(blocksPath, blockName));
2305
+ const blockBlox = readBloxFileIfExists(import_node_path17.default.join(blocksPath, blockName));
2181
2306
  if (!blockBlox?.definition?.name) continue;
2182
2307
  const def = blockBlox.definition;
2183
2308
  const templateName = def.templates?.[0]?.name || appTemplateName;
@@ -2239,9 +2364,7 @@ var ContributionTargetSelector = class {
2239
2364
  const start = page * pageSize;
2240
2365
  const slice = filtered.slice(start, start + pageSize);
2241
2366
  const value = await select({
2242
- message: `Select contribution target ${fmt.gray(
2243
- `(page ${page + 1}/${maxPage + 1})`
2244
- )}`,
2367
+ message: `Select contribution target ${fmt.gray(`(page ${page + 1}/${maxPage + 1})`)}`,
2245
2368
  options: buildTargetPageSelectOptions(slice, page, maxPage)
2246
2369
  });
2247
2370
  if (value === TARGET_SELECT_PAGE.PREV) {
@@ -2460,8 +2583,8 @@ ${fmt.cyan(createPageUrl)}
2460
2583
 
2461
2584
  // src/services/contribute/services/TmpRepoService.ts
2462
2585
  var import_node_os2 = require("os");
2463
- var import_node_path17 = __toESM(require("path"));
2464
- var import_fs_extra14 = __toESM(require("fs-extra"));
2586
+ var import_node_path18 = __toESM(require("path"));
2587
+ var import_fs_extra15 = __toESM(require("fs-extra"));
2465
2588
  var TmpRepoService = class {
2466
2589
  constructor(logger) {
2467
2590
  this.logger = logger;
@@ -2477,8 +2600,10 @@ var TmpRepoService = class {
2477
2600
  await git.update({ cwd: dir });
2478
2601
  }
2479
2602
  async getTmpDir(target) {
2480
- const slug = `${target.type}-${target.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-");
2481
- return import_node_path17.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
2603
+ const isBlock = target.type === "block" /* BLOCK */;
2604
+ const slugParts = isBlock && target.templateName ? [target.type, target.templateName, target.name] : [target.type, target.name];
2605
+ const slug = slugParts.join("-").replace(/[^a-zA-Z0-9._-]+/g, "-");
2606
+ return import_node_path18.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
2482
2607
  }
2483
2608
  async prepare(opts) {
2484
2609
  const taskSpinner = spinner();
@@ -2490,7 +2615,7 @@ var TmpRepoService = class {
2490
2615
  repoUrl: opts.repoUrl,
2491
2616
  branch: opts.branch
2492
2617
  });
2493
- if (await import_fs_extra14.default.pathExists(dir)) {
2618
+ if (await import_fs_extra15.default.pathExists(dir)) {
2494
2619
  this.logger.debug(`${tempRepoName} reuse_tmp_local_repo`, { dir });
2495
2620
  try {
2496
2621
  await this.refreshExistingTmpRepo(dir, opts.branch);
@@ -2501,10 +2626,10 @@ var TmpRepoService = class {
2501
2626
  dir,
2502
2627
  message: e instanceof Error ? e.message : String(e)
2503
2628
  });
2504
- await import_fs_extra14.default.remove(dir);
2629
+ await import_fs_extra15.default.remove(dir);
2505
2630
  }
2506
2631
  }
2507
- await import_fs_extra14.default.ensureDir(import_node_path17.default.dirname(dir));
2632
+ await import_fs_extra15.default.ensureDir(import_node_path18.default.dirname(dir));
2508
2633
  await git.clone(opts.repoUrl, dir, opts.branch);
2509
2634
  taskSpinner.stop("Prepared tmp repo");
2510
2635
  return dir;
@@ -2539,6 +2664,11 @@ var contribute = command("contribute").description("Contribute changes back to t
2539
2664
  option("--type <type>", "target type").choices(Object.values(ContributionTargetType))
2540
2665
  ).option("--name <name>", "target name").action(async (flags) => {
2541
2666
  try {
2667
+ if (await git.hasUncommittedChanges()) {
2668
+ throw new Error(
2669
+ "Make sure to commit or stash any changes in the app repo before contributing."
2670
+ );
2671
+ }
2542
2672
  await migrateAll(true);
2543
2673
  await syncRegistries();
2544
2674
  const workflow = await buildContributionWorkflow({
@@ -2592,7 +2722,7 @@ var detach = command("detach").description("Migrate blox schema").option("--basi
2592
2722
  });
2593
2723
 
2594
2724
  // src/commands/init/index.ts
2595
- var import_fs_extra15 = __toESM(require("fs-extra"));
2725
+ var import_fs_extra16 = __toESM(require("fs-extra"));
2596
2726
  var init2 = command("init").description("Init new app").alias("i").option("-n, --name <name>", "App name").option("-t, --template <template>", "Template to use").option("--branch <name>", "branch name").action(async ({ name, template, branch }) => {
2597
2727
  await syncRegistries();
2598
2728
  try {
@@ -2633,8 +2763,8 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
2633
2763
  task.stop(`App initialized in ${name}`);
2634
2764
  await runLifecycleHookWithTask(name || "", "init", "Run template init");
2635
2765
  } catch (e) {
2636
- if (name && import_fs_extra15.default.existsSync(name)) {
2637
- await import_fs_extra15.default.remove(name);
2766
+ if (name && import_fs_extra16.default.existsSync(name)) {
2767
+ await import_fs_extra16.default.remove(name);
2638
2768
  }
2639
2769
  error(e);
2640
2770
  }
@@ -2654,30 +2784,30 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
2654
2784
  });
2655
2785
 
2656
2786
  // src/commands/remove/index.ts
2657
- var import_node_path18 = __toESM(require("path"));
2658
- var import_fs_extra16 = __toESM(require("fs-extra"));
2659
- var blocksAbsolutePath = () => import_node_path18.default.resolve(process.cwd(), blocksDir);
2787
+ var import_node_path19 = __toESM(require("path"));
2788
+ var import_fs_extra17 = __toESM(require("fs-extra"));
2789
+ var blocksAbsolutePath = () => import_node_path19.default.resolve(process.cwd(), blocksDir);
2660
2790
  function listInstalledBlockRelPaths() {
2661
2791
  const root = blocksAbsolutePath();
2662
- if (!import_fs_extra16.default.existsSync(root)) {
2792
+ if (!import_fs_extra17.default.existsSync(root)) {
2663
2793
  return [];
2664
2794
  }
2665
2795
  const paths2 = [];
2666
- for (const entry of import_fs_extra16.default.readdirSync(root, { withFileTypes: true })) {
2796
+ for (const entry of import_fs_extra17.default.readdirSync(root, { withFileTypes: true })) {
2667
2797
  if (!entry.isDirectory()) {
2668
2798
  continue;
2669
2799
  }
2670
- const abs = import_node_path18.default.join(root, entry.name);
2800
+ const abs = import_node_path19.default.join(root, entry.name);
2671
2801
  if (!isBlockDirectory(abs)) {
2672
2802
  continue;
2673
2803
  }
2674
- paths2.push(import_node_path18.default.join(blocksDir, entry.name));
2804
+ paths2.push(import_node_path19.default.join(blocksDir, entry.name));
2675
2805
  }
2676
2806
  return paths2;
2677
2807
  }
2678
2808
  function getInstalledBlockSelectOptions() {
2679
2809
  return listInstalledBlockRelPaths().map((rel) => {
2680
- const folder = import_node_path18.default.basename(rel);
2810
+ const folder = import_node_path19.default.basename(rel);
2681
2811
  const def = getBlockDef(rel);
2682
2812
  const label = def?.name && def.name !== folder ? `${def.name} (${folder})` : folder;
2683
2813
  return { value: folder, label, hint: def?.name };
@@ -2685,7 +2815,7 @@ function getInstalledBlockSelectOptions() {
2685
2815
  }
2686
2816
  function assertNoDependents(blockPathAbs, targetBlockName) {
2687
2817
  for (const rel of listInstalledBlockRelPaths()) {
2688
- const abs = import_node_path18.default.resolve(process.cwd(), rel);
2818
+ const abs = import_node_path19.default.resolve(process.cwd(), rel);
2689
2819
  if (abs === blockPathAbs) {
2690
2820
  continue;
2691
2821
  }
@@ -2701,19 +2831,19 @@ function assertNoDependents(blockPathAbs, targetBlockName) {
2701
2831
  }
2702
2832
  function assertUnderBlocksRoot(blockPathAbs) {
2703
2833
  const root = blocksAbsolutePath();
2704
- const rel = import_node_path18.default.relative(root, blockPathAbs);
2705
- if (!rel || rel.startsWith("..") || import_node_path18.default.isAbsolute(rel)) {
2834
+ const rel = import_node_path19.default.relative(root, blockPathAbs);
2835
+ if (!rel || rel.startsWith("..") || import_node_path19.default.isAbsolute(rel)) {
2706
2836
  throw new Error("Block path escapes the blocks directory");
2707
2837
  }
2708
2838
  }
2709
2839
  async function removeBlock(block, blocks, force = false) {
2710
2840
  const reg = blocks[block];
2711
2841
  const destination = reg ? reg.destination ?? block : block;
2712
- const blockPathRel = import_node_path18.default.join(blocksDir, destination);
2713
- const blockPathAbs = import_node_path18.default.resolve(process.cwd(), blockPathRel);
2842
+ const blockPathRel = import_node_path19.default.join(blocksDir, destination);
2843
+ const blockPathAbs = import_node_path19.default.resolve(process.cwd(), blockPathRel);
2714
2844
  assertUnderBlocksRoot(blockPathAbs);
2715
- if (!import_fs_extra16.default.existsSync(blockPathAbs) || !isBlockDirectory(blockPathAbs)) {
2716
- throw new Error(`Block is not installed at ${import_node_path18.default.relative(process.cwd(), blockPathAbs)}`);
2845
+ if (!import_fs_extra17.default.existsSync(blockPathAbs) || !isBlockDirectory(blockPathAbs)) {
2846
+ throw new Error(`Block is not installed at ${import_node_path19.default.relative(process.cwd(), blockPathAbs)}`);
2717
2847
  }
2718
2848
  const targetDef = getBlockDef(blockPathRel);
2719
2849
  if (!targetDef?.name) {
@@ -2725,7 +2855,7 @@ async function removeBlock(block, blocks, force = false) {
2725
2855
  await runLifecycleHookWithTask(blockPathRel, "remove", "Run block remove");
2726
2856
  await runTask("Remove block files", async () => {
2727
2857
  assertUnderBlocksRoot(blockPathAbs);
2728
- await import_fs_extra16.default.remove(blockPathAbs);
2858
+ await import_fs_extra17.default.remove(blockPathAbs);
2729
2859
  });
2730
2860
  return true;
2731
2861
  }
@@ -2783,17 +2913,16 @@ var remove = command("remove").description("Remove block from app").alias("rm").
2783
2913
  // src/commands/skills/index.ts
2784
2914
  var import_node_crypto = require("crypto");
2785
2915
  var import_node_os3 = __toESM(require("os"));
2786
- var import_node_path20 = __toESM(require("path"));
2916
+ var import_node_path21 = __toESM(require("path"));
2787
2917
  var import_cross_spawn2 = __toESM(require("cross-spawn"));
2788
- var import_fs_extra18 = __toESM(require("fs-extra"));
2918
+ var import_fs_extra19 = __toESM(require("fs-extra"));
2789
2919
 
2790
2920
  // src/commands/skills/constants.ts
2791
- var SKILLS_REPO_URL = "https://tfs.aas.com.sa/Medad/BLOX/_git/cli";
2792
- var SKILLS_TEMP_ROOT_PREFIX = "blox-skills";
2921
+ var SKILLS_REPO_URL = "https://github.com/Naseej-its/blox.git";
2793
2922
 
2794
2923
  // src/commands/skills/utils/cliCompatibility.ts
2795
- var import_node_path19 = __toESM(require("path"));
2796
- var import_fs_extra17 = __toESM(require("fs-extra"));
2924
+ var import_node_path20 = __toESM(require("path"));
2925
+ var import_fs_extra18 = __toESM(require("fs-extra"));
2797
2926
  var import_semver = __toESM(require("semver"));
2798
2927
  var SKILLS_CLI_COMPATIBILITY_COMMANDS = ["add", "update"];
2799
2928
  function getSkillscommandIndex(args, subcommand) {
@@ -2817,18 +2946,18 @@ function getAddCommandIndex(args) {
2817
2946
  return getSkillscommandIndex(args, "add");
2818
2947
  }
2819
2948
  async function loadSkillsData(cloneRoot) {
2820
- const skillsDir = import_node_path19.default.join(cloneRoot, "skills");
2821
- if (!await import_fs_extra17.default.pathExists(skillsDir)) {
2949
+ const skillsDir = import_node_path20.default.join(cloneRoot, "skills");
2950
+ if (!await import_fs_extra18.default.pathExists(skillsDir)) {
2822
2951
  return [];
2823
2952
  }
2824
- const entries = await import_fs_extra17.default.readdir(skillsDir, { withFileTypes: true });
2953
+ const entries = await import_fs_extra18.default.readdir(skillsDir, { withFileTypes: true });
2825
2954
  const manifests = await Promise.all(
2826
2955
  entries.filter((entry) => entry.isDirectory()).map(async (entry) => {
2827
- const filePath = import_node_path19.default.join(skillsDir, entry.name, "skill.json");
2828
- if (!await import_fs_extra17.default.pathExists(filePath)) {
2956
+ const filePath = import_node_path20.default.join(skillsDir, entry.name, "skill.json");
2957
+ if (!await import_fs_extra18.default.pathExists(filePath)) {
2829
2958
  return null;
2830
2959
  }
2831
- const raw = await import_fs_extra17.default.readJson(filePath);
2960
+ const raw = await import_fs_extra18.default.readJson(filePath);
2832
2961
  const range = raw.cliCompatibility?.trim();
2833
2962
  if (!range) {
2834
2963
  return null;
@@ -2879,12 +3008,11 @@ var skills = command("skills").description("Install, update, and manage BLOX CLI
2879
3008
  async function runSkills() {
2880
3009
  const idx = process.argv.indexOf("skills");
2881
3010
  const args = idx === -1 ? [] : process.argv.slice(idx + 1);
2882
- const tempDir = import_node_path20.default.join(import_node_os3.default.tmpdir(), `${SKILLS_TEMP_ROOT_PREFIX}-${(0, import_node_crypto.randomUUID)()}`);
2883
- await import_fs_extra18.default.mkdir(tempDir);
2884
- let exitCode = 1;
2885
- try {
2886
- await git.clone(SKILLS_REPO_URL, tempDir);
2887
- if (needsCliCompatibilityCheck(args)) {
3011
+ if (needsCliCompatibilityCheck(args)) {
3012
+ const tempDir = import_node_path21.default.join(import_node_os3.default.tmpdir(), `blox-skills-compat-${(0, import_node_crypto.randomUUID)()}`);
3013
+ await import_fs_extra19.default.mkdir(tempDir);
3014
+ try {
3015
+ await git.clone(SKILLS_REPO_URL, tempDir);
2888
3016
  const skills2 = await loadSkillsData(tempDir);
2889
3017
  const cliVersion = getBloxCliVersion();
2890
3018
  const uncompatibleSkill = getFirstIncompatibleSkill(skills2, cliVersion);
@@ -2898,19 +3026,18 @@ async function runSkills() {
2898
3026
  return 1;
2899
3027
  }
2900
3028
  }
2901
- }
2902
- const finalArgs = injectRepoPathIfAdd(args, import_node_path20.default.resolve(tempDir));
2903
- exitCode = await runSkillsCommand(finalArgs, process.cwd());
2904
- } finally {
2905
- try {
2906
- await import_fs_extra18.default.remove(tempDir);
2907
- } catch {
2908
- debug(`Failed to cleanup temp dir: ${tempDir}`);
3029
+ } finally {
3030
+ try {
3031
+ await import_fs_extra19.default.remove(tempDir);
3032
+ } catch {
3033
+ debug(`Failed to cleanup temp dir: ${tempDir}`);
3034
+ }
2909
3035
  }
2910
3036
  }
2911
- return exitCode;
3037
+ const finalArgs = injectRepoUrlIfAdd(args, SKILLS_REPO_URL);
3038
+ return runSkillsCommand(finalArgs, process.cwd());
2912
3039
  }
2913
- function injectRepoPathIfAdd(args, repoPath) {
3040
+ function injectRepoUrlIfAdd(args, repoPath) {
2914
3041
  const addIndex = getAddCommandIndex(args);
2915
3042
  if (addIndex === -1) return args;
2916
3043
  const next = args[addIndex + 1];
@@ -2937,11 +3064,11 @@ function runSkillsCommand(args, cwd) {
2937
3064
  var import_prompts23 = require("@clack/prompts");
2938
3065
 
2939
3066
  // src/commands/update/utils.ts
2940
- var import_node_path22 = __toESM(require("path"));
3067
+ var import_node_path23 = __toESM(require("path"));
2941
3068
 
2942
3069
  // src/services/updater.ts
2943
- var import_node_path21 = __toESM(require("path"));
2944
- var import_fs_extra19 = __toESM(require("fs-extra"));
3070
+ var import_node_path22 = __toESM(require("path"));
3071
+ var import_fs_extra20 = __toESM(require("fs-extra"));
2945
3072
  var import_klaw3 = __toESM(require("klaw"));
2946
3073
  async function updateFromRemote({
2947
3074
  name,
@@ -2988,9 +3115,9 @@ async function updateFromRemote({
2988
3115
  const remoteIgnore = remoteBloxFile.definition?.ignore || [];
2989
3116
  const projectIgnore = bloxFile.project?.ignore || [];
2990
3117
  ignore3.push(...remoteIgnore, ...projectIgnore, bloxFilePath, `**/${bloxFilePath}`);
2991
- const gitIgnorePath = import_node_path21.default.join(dir, ".gitignore");
2992
- if (await import_fs_extra19.default.pathExists(gitIgnorePath)) {
2993
- const gitIgnoreContent = await import_fs_extra19.default.readFile(gitIgnorePath, "utf8");
3118
+ const gitIgnorePath = import_node_path22.default.join(dir, ".gitignore");
3119
+ if (await import_fs_extra20.default.pathExists(gitIgnorePath)) {
3120
+ const gitIgnoreContent = await import_fs_extra20.default.readFile(gitIgnorePath, "utf8");
2994
3121
  const gitIgnorePatterns = gitIgnoreContent.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
2995
3122
  ignore3.push(...gitIgnorePatterns);
2996
3123
  debug(`Added ${gitIgnorePatterns.length} patterns from .gitignore`);
@@ -3002,14 +3129,14 @@ async function updateFromRemote({
3002
3129
  if (hard) {
3003
3130
  const getAllFiles = async (d) => {
3004
3131
  const files = [];
3005
- if (await import_fs_extra19.default.pathExists(d)) {
3132
+ if (await import_fs_extra20.default.pathExists(d)) {
3006
3133
  for await (const file of (0, import_klaw3.default)(d)) {
3007
3134
  if (file.path.includes("/.git/") || file.path.endsWith("/.git") || file.path.includes("\\.git\\") || file.path.endsWith("\\.git"))
3008
3135
  continue;
3009
3136
  if (file.path.includes("/node_modules/") || file.path.includes("\\node_modules\\"))
3010
3137
  continue;
3011
3138
  if (file.stats.isFile()) {
3012
- files.push(import_node_path21.default.relative(d, file.path));
3139
+ files.push(import_node_path22.default.relative(d, file.path));
3013
3140
  }
3014
3141
  }
3015
3142
  }
@@ -3028,23 +3155,23 @@ async function updateFromRemote({
3028
3155
  for (const file of filesToProcess) {
3029
3156
  if (file === ".git" || file.startsWith(".git/") || file.startsWith(".git\\")) continue;
3030
3157
  if (ignoredMatcher.ignores(toIgnorePath(file))) continue;
3031
- const localPath = import_node_path21.default.join(dir, file);
3032
- const basePath = import_node_path21.default.join(baseDir, file);
3033
- const remotePath = import_node_path21.default.join(remoteDir, file);
3034
- const existsLocal = await import_fs_extra19.default.pathExists(localPath);
3035
- const existsBase = await import_fs_extra19.default.pathExists(basePath);
3036
- const existsRemote = await import_fs_extra19.default.pathExists(remotePath);
3037
- const ext = import_node_path21.default.extname(file);
3158
+ const localPath = import_node_path22.default.join(dir, file);
3159
+ const basePath = import_node_path22.default.join(baseDir, file);
3160
+ const remotePath = import_node_path22.default.join(remoteDir, file);
3161
+ const existsLocal = await import_fs_extra20.default.pathExists(localPath);
3162
+ const existsBase = await import_fs_extra20.default.pathExists(basePath);
3163
+ const existsRemote = await import_fs_extra20.default.pathExists(remotePath);
3164
+ const ext = import_node_path22.default.extname(file);
3038
3165
  const isBinary = isBinaryFile(ext);
3039
3166
  if (existsRemote) {
3040
- await import_fs_extra19.default.ensureDir(import_node_path21.default.dirname(localPath));
3167
+ await import_fs_extra20.default.ensureDir(import_node_path22.default.dirname(localPath));
3041
3168
  }
3042
3169
  if (hard) {
3043
3170
  if (existsRemote) {
3044
- await import_fs_extra19.default.copy(remotePath, localPath, { overwrite: true });
3171
+ await import_fs_extra20.default.copy(remotePath, localPath, { overwrite: true });
3045
3172
  debug(`Hard update: Overwrote ${file}`);
3046
3173
  } else if (existsLocal) {
3047
- await import_fs_extra19.default.remove(localPath);
3174
+ await import_fs_extra20.default.remove(localPath);
3048
3175
  debug(`Hard update: Removed ${file}`);
3049
3176
  }
3050
3177
  continue;
@@ -3053,29 +3180,29 @@ async function updateFromRemote({
3053
3180
  if (existsLocal) {
3054
3181
  if (isBinary) {
3055
3182
  debug(`Binary collision: ${file}, overwriting.`);
3056
- await import_fs_extra19.default.copy(remotePath, localPath, { overwrite: true });
3183
+ await import_fs_extra20.default.copy(remotePath, localPath, { overwrite: true });
3057
3184
  logWarningSection(`Overwrote binary file collision: ${file}`);
3058
3185
  } else {
3059
- const emptyBase = import_node_path21.default.join(baseDir, `${file}.empty`);
3060
- await import_fs_extra19.default.ensureFile(emptyBase);
3186
+ const emptyBase = import_node_path22.default.join(baseDir, `${file}.empty`);
3187
+ await import_fs_extra20.default.ensureFile(emptyBase);
3061
3188
  const result = await git.mergeFile(localPath, emptyBase, remotePath);
3062
3189
  if (!result) {
3063
3190
  hasConflicts2 = true;
3064
3191
  conflictFiles.push(file);
3065
3192
  }
3066
- await import_fs_extra19.default.remove(emptyBase);
3193
+ await import_fs_extra20.default.remove(emptyBase);
3067
3194
  }
3068
3195
  } else {
3069
- await import_fs_extra19.default.copy(remotePath, localPath);
3196
+ await import_fs_extra20.default.copy(remotePath, localPath);
3070
3197
  }
3071
3198
  continue;
3072
3199
  }
3073
3200
  if (existsBase && !existsRemote) {
3074
3201
  if (existsLocal) {
3075
- const localBuffer = await import_fs_extra19.default.readFile(localPath);
3076
- const baseBuffer = await import_fs_extra19.default.readFile(basePath);
3202
+ const localBuffer = await import_fs_extra20.default.readFile(localPath);
3203
+ const baseBuffer = await import_fs_extra20.default.readFile(basePath);
3077
3204
  if (localBuffer.equals(baseBuffer)) {
3078
- await import_fs_extra19.default.remove(localPath);
3205
+ await import_fs_extra20.default.remove(localPath);
3079
3206
  } else {
3080
3207
  logWarningSection(
3081
3208
  `File ${file} was deleted in remote but modified locally. Kept local version.`
@@ -3086,7 +3213,7 @@ async function updateFromRemote({
3086
3213
  }
3087
3214
  if (existsBase && existsRemote) {
3088
3215
  if (!existsLocal) {
3089
- await import_fs_extra19.default.copy(remotePath, localPath);
3216
+ await import_fs_extra20.default.copy(remotePath, localPath);
3090
3217
  logWarningSection(
3091
3218
  `File restored: ${file}`,
3092
3219
  `This file was deleted locally but updated in the remote block.
@@ -3095,7 +3222,7 @@ It has been recreated to apply upstream changes.`
3095
3222
  continue;
3096
3223
  }
3097
3224
  if (isBinary) {
3098
- await import_fs_extra19.default.copy(remotePath, localPath, { overwrite: true });
3225
+ await import_fs_extra20.default.copy(remotePath, localPath, { overwrite: true });
3099
3226
  logWarningSection(`Updated binary file: ${file} (overwritten)`);
3100
3227
  } else {
3101
3228
  const result = await git.mergeFile(localPath, basePath, remotePath);
@@ -3172,7 +3299,7 @@ async function updateApp({
3172
3299
  continue;
3173
3300
  }
3174
3301
  await git.updateRemote(block.name, blockRegistryData.source);
3175
- const blockPath = import_node_path22.default.join(blocksDir, block.name);
3302
+ const blockPath = import_node_path23.default.join(blocksDir, block.name);
3176
3303
  const currentBloxFile = getBloxFile(blockPath);
3177
3304
  const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
3178
3305
  const blockFromCommit = currentBloxFile.checkpoints?.[block.name]?.commit;
@@ -3194,7 +3321,10 @@ async function updateAppBases(templateDef, templates, ignore3, hard = false) {
3194
3321
  let shouldContinue = true;
3195
3322
  for (const base of templateDef.bases || []) {
3196
3323
  await runTask(
3197
- { start: `Update App base: ${base.name}`, end: `Updated App base: ${base.name}` },
3324
+ {
3325
+ start: `Update App base: ${base.name}`,
3326
+ end: `Updated App base: ${base.name}`
3327
+ },
3198
3328
  async () => {
3199
3329
  const template = templates[base.name];
3200
3330
  if (!template) {
@@ -3219,13 +3349,13 @@ async function updateAppBases(templateDef, templates, ignore3, hard = false) {
3219
3349
  }
3220
3350
  async function updateBlock(block, blocks, ignore3, hard = false) {
3221
3351
  const blockRegistryData = blocks[block];
3222
- const blockPath = import_node_path22.default.join(blocksDir, block);
3352
+ const blockPath = import_node_path23.default.join(blocksDir, block);
3223
3353
  let updated = false;
3224
- let shouldContinue = true;
3225
- await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
3354
+ try {
3226
3355
  if (!blockRegistryData) {
3227
- shouldContinue = await confirmContinueWhenMissing("block" /* BLOCK */, block);
3228
- return;
3356
+ throw new Error(
3357
+ `${"block" /* BLOCK */}: ${block} does not exist in registries.`
3358
+ );
3229
3359
  }
3230
3360
  const toCommit = await updateFromRemote({
3231
3361
  name: block,
@@ -3234,18 +3364,64 @@ async function updateBlock(block, blocks, ignore3, hard = false) {
3234
3364
  ignore: ignore3,
3235
3365
  hard
3236
3366
  });
3237
- if (toCommit) updated = true;
3238
- });
3239
- if (updated) {
3240
- await runLifecycleHookWithTask(blockPath, "update", "Run block update");
3367
+ if (toCommit) {
3368
+ updated = true;
3369
+ }
3370
+ return {
3371
+ block,
3372
+ updated,
3373
+ shouldContinue: true
3374
+ };
3375
+ } catch (error2) {
3376
+ return {
3377
+ block,
3378
+ updated,
3379
+ shouldContinue: true,
3380
+ error: error2
3381
+ };
3241
3382
  }
3242
- return { updated, shouldContinue };
3383
+ }
3384
+ async function updateBlocks(blocks, availableBlocks, ignoresByName, hard = false) {
3385
+ if (blocks.length === 0) {
3386
+ return [];
3387
+ }
3388
+ if (blocks.length === 1) {
3389
+ const block = blocks[0];
3390
+ if (!block) {
3391
+ return [];
3392
+ }
3393
+ let result;
3394
+ await runTask(
3395
+ {
3396
+ start: `Update block: ${block}`,
3397
+ end: `Updated block: ${block}`
3398
+ },
3399
+ async () => {
3400
+ result = await updateBlock(block, availableBlocks, ignoresByName[block], hard);
3401
+ }
3402
+ );
3403
+ return result ? [result] : [];
3404
+ }
3405
+ const blockNames = blocks.join(", ");
3406
+ import_prompts2.log.info(`Update blocks: ${blockNames}`);
3407
+ const results = await Promise.all(
3408
+ blocks.map((block) => updateBlock(block, availableBlocks, ignoresByName[block], hard))
3409
+ );
3410
+ import_prompts2.log.success(`Updated blocks: ${blockNames}`);
3411
+ return results;
3412
+ }
3413
+ async function runBlockUpdateHook(block) {
3414
+ const blockPath = import_node_path23.default.join(blocksDir, block);
3415
+ await runLifecycleHookWithTask(blockPath, "update", "Run block update");
3243
3416
  }
3244
3417
  async function getCurrentCheckpoints() {
3245
3418
  const bloxFile = getBloxFile();
3246
3419
  let checkpoints = { ...bloxFile.checkpoints };
3247
3420
  for (const block of getUsedBlocks()) {
3248
- checkpoints = { ...checkpoints, ...block.checkpoints };
3421
+ checkpoints = {
3422
+ ...checkpoints,
3423
+ ...block.checkpoints
3424
+ };
3249
3425
  }
3250
3426
  return checkpoints;
3251
3427
  }
@@ -3265,7 +3441,7 @@ ${changes}`);
3265
3441
  }
3266
3442
  if (allChanges.length) {
3267
3443
  logWarningSection(
3268
- `ChangeLog, These is the changes from last update, make sure to review for breaking changes`,
3444
+ "ChangeLog, These is the changes from last update, make sure to review for breaking changes",
3269
3445
  allChanges.join(`
3270
3446
  ${fmt.gray("-".repeat(82))}
3271
3447
 
@@ -3329,17 +3505,50 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
3329
3505
  shouldContinue = basesResult.shouldContinue;
3330
3506
  }
3331
3507
  if (shouldContinue && args.scope === "all") {
3332
- for (const block of usedBlocks) {
3333
- const blockResult = await updateBlock(
3334
- block.name,
3508
+ const missingBlocks = usedBlocks.filter((block) => !availableBlocks[block.name]);
3509
+ for (const block of missingBlocks) {
3510
+ const shouldUpdateRemaining = await select({
3511
+ message: `${block.name} does not exist in registries. Continue updating remaining parts?`,
3512
+ options: [
3513
+ {
3514
+ value: true,
3515
+ label: "Continue"
3516
+ },
3517
+ {
3518
+ value: false,
3519
+ label: "Stop"
3520
+ }
3521
+ ]
3522
+ });
3523
+ if (!shouldUpdateRemaining) {
3524
+ shouldContinue = false;
3525
+ break;
3526
+ }
3527
+ }
3528
+ if (shouldContinue) {
3529
+ const blocksToUpdate = usedBlocks.filter((block) => availableBlocks[block.name]).map((block) => block.name);
3530
+ const blockResults = await updateBlocks(
3531
+ blocksToUpdate,
3335
3532
  availableBlocks,
3336
- ignoresByName[block.name],
3533
+ ignoresByName,
3337
3534
  args.hard
3338
3535
  );
3339
- hasUpdate = hasUpdate || blockResult.updated;
3340
- if (!blockResult.shouldContinue) {
3341
- shouldContinue = false;
3342
- break;
3536
+ hasUpdate = hasUpdate || blockResults.some((result) => result.updated);
3537
+ const failedBlocks = blockResults.filter((result) => result.error);
3538
+ if (failedBlocks.length) {
3539
+ import_prompts23.log.warn(
3540
+ fmt.yellow(
3541
+ `${failedBlocks.length} block update${failedBlocks.length === 1 ? "" : "s"} failed.`
3542
+ )
3543
+ );
3544
+ for (const result of failedBlocks) {
3545
+ import_prompts23.log.error(fmt.red(`${result.block}: ${getErrorMessage(result.error)}`));
3546
+ }
3547
+ await waitForConflictResolution();
3548
+ }
3549
+ for (const result of blockResults) {
3550
+ if (!result.updated) continue;
3551
+ await runBlockUpdateHook(result.block);
3343
3552
  }
3344
3553
  }
3345
3554
  }
@@ -3358,14 +3567,24 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
3358
3567
  error("Selected block not used in app");
3359
3568
  return;
3360
3569
  }
3361
- const blockResult = await updateBlock(
3362
- blockDef.name,
3570
+ const [blockResult] = await updateBlocks(
3571
+ [blockDef.name],
3363
3572
  availableBlocks,
3364
- ignoresByName[blockDef.name],
3573
+ ignoresByName,
3365
3574
  args.hard
3366
3575
  );
3576
+ if (!blockResult) {
3577
+ return;
3578
+ }
3579
+ if (blockResult.error) {
3580
+ import_prompts23.log.error(fmt.red(`${blockDef.name}: ${getErrorMessage(blockResult.error)}`));
3581
+ await waitForConflictResolution();
3582
+ }
3367
3583
  hasUpdate = hasUpdate || blockResult.updated;
3368
3584
  shouldContinue = blockResult.shouldContinue;
3585
+ if (blockResult.updated) {
3586
+ await runBlockUpdateHook(blockDef.name);
3587
+ }
3369
3588
  }
3370
3589
  if (!shouldContinue) {
3371
3590
  import_prompts23.log.warn(fmt.yellow("Stopped updating remaining parts by user choice"));
@@ -3386,6 +3605,31 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
3386
3605
  await git.cleanUpWorktrees();
3387
3606
  }
3388
3607
  });
3608
+ function getErrorMessage(error2) {
3609
+ if (error2 instanceof Error) {
3610
+ return error2.message;
3611
+ }
3612
+ return String(error2);
3613
+ }
3614
+ async function waitForConflictResolution() {
3615
+ import_prompts23.log.warn(
3616
+ fmt.yellow(
3617
+ [
3618
+ "",
3619
+ "Block update conflicts/errors detected.",
3620
+ "Resolve the conflicts in the affected blocks, then press Enter to continue.",
3621
+ ""
3622
+ ].join("\n")
3623
+ )
3624
+ );
3625
+ await new Promise((resolve) => {
3626
+ process.stdin.resume();
3627
+ process.stdin.once("data", () => {
3628
+ process.stdin.pause();
3629
+ resolve();
3630
+ });
3631
+ });
3632
+ }
3389
3633
 
3390
3634
  // src/commands/upgrade/index.ts
3391
3635
  var upgrade = command("upgrade").description("Upgrade blox cli to latest version").action(async () => {