@naseej/blox 1.5.1 → 1.5.2

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
@@ -22,6 +22,23 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  mod
23
23
  ));
24
24
 
25
+ // src/shared/command/index.ts
26
+ var import_extra_typings = require("@commander-js/extra-typings");
27
+ var import_extra_typings2 = require("@commander-js/extra-typings");
28
+ var command = (name) => new import_extra_typings.Command(name);
29
+ var option = (flags, description) => {
30
+ return new import_extra_typings.Option(flags, description);
31
+ };
32
+
33
+ // src/config/runtime.ts
34
+ var bloxCliVersion = "0.0.0";
35
+ var setBloxCliVersion = (version2) => {
36
+ bloxCliVersion = version2;
37
+ };
38
+ var getBloxCliVersion = () => bloxCliVersion;
39
+ var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
40
+ var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
41
+
25
42
  // src/services/cliVersion.ts
26
43
  var import_node_https = __toESM(require("https"));
27
44
  var import_node_path2 = __toESM(require("path"));
@@ -45,18 +62,6 @@ var defaultBranch = "main";
45
62
  var console2 = __toESM(require("console"));
46
63
  var import_prompts = require("@clack/prompts");
47
64
 
48
- // src/shared/command/index.ts
49
- var import_extra_typings = require("@commander-js/extra-typings");
50
- var import_extra_typings2 = require("@commander-js/extra-typings");
51
- var command = (name) => new import_extra_typings.Command(name);
52
- var option = (flags, description) => {
53
- return new import_extra_typings.Option(flags, description);
54
- };
55
-
56
- // src/config/runtime.ts
57
- var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
58
- var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
59
-
60
65
  // src/shared/terminal/index.ts
61
66
  var import_ansis = __toESM(require("ansis"));
62
67
  var fmt = import_ansis.default;
@@ -180,18 +185,18 @@ var checkForCliUpdate = async (currentVersion) => {
180
185
  };
181
186
 
182
187
  // package.json
183
- var version = "1.5.1";
188
+ var version = "1.5.2";
184
189
 
185
190
  // src/commands/add/index.ts
186
- var import_fs_extra9 = __toESM(require("fs-extra"));
191
+ var import_fs_extra10 = __toESM(require("fs-extra"));
187
192
 
188
193
  // src/migrations/index.ts
189
- var import_node_path8 = __toESM(require("path"));
190
- var import_fs_extra5 = __toESM(require("fs-extra"));
194
+ var import_node_path10 = __toESM(require("path"));
195
+ var import_fs_extra7 = __toESM(require("fs-extra"));
191
196
 
192
197
  // src/migrations/utils.ts
193
- var import_node_path7 = __toESM(require("path"));
194
- var import_fs_extra4 = __toESM(require("fs-extra"));
198
+ var import_node_path9 = __toESM(require("path"));
199
+ var import_fs_extra6 = __toESM(require("fs-extra"));
195
200
 
196
201
  // src/migrations/list/v1.ts
197
202
  var v1 = {
@@ -228,8 +233,8 @@ var migrationsList = [v1];
228
233
 
229
234
  // src/services/git.ts
230
235
  var import_node_os = __toESM(require("os"));
231
- var import_node_path6 = __toESM(require("path"));
232
- var import_fs_extra3 = __toESM(require("fs-extra"));
236
+ var import_node_path8 = __toESM(require("path"));
237
+ var import_fs_extra5 = __toESM(require("fs-extra"));
233
238
 
234
239
  // src/services/shell.ts
235
240
  var import_cross_spawn = __toESM(require("cross-spawn"));
@@ -403,10 +408,164 @@ function omitKeys(value, keysToOmit) {
403
408
  // src/shared/utils/normalizeCommitRef.ts
404
409
  var normalizeCommitRef = (commit2) => commit2.trim().replace(/\r/g, "").replace(/^"+|"+$/g, "");
405
410
 
406
- // src/services/path.ts
411
+ // src/shared/utils/isBlockDirectory.ts
407
412
  var import_node_path5 = __toESM(require("path"));
413
+ var import_fs_extra3 = __toESM(require("fs-extra"));
414
+ function isBlockDirectory(blockDir) {
415
+ const bloxPath = import_node_path5.default.join(blockDir, bloxFilePath);
416
+ if (!import_fs_extra3.default.existsSync(bloxPath)) {
417
+ return false;
418
+ }
419
+ try {
420
+ return import_fs_extra3.default.statSync(bloxPath).isFile();
421
+ } catch {
422
+ return false;
423
+ }
424
+ }
425
+
426
+ // src/services/template.ts
427
+ var import_node_path6 = __toESM(require("path"));
428
+ var import_ejs = __toESM(require("ejs"));
429
+ var import_fs_extra4 = __toESM(require("fs-extra"));
430
+ var import_klaw = __toESM(require("klaw"));
431
+ async function replacePlaceholders(dir, context) {
432
+ debug("Replace placeholders");
433
+ for await (const file of (0, import_klaw.default)(dir)) {
434
+ if (!file.stats.isFile()) continue;
435
+ const ext = import_node_path6.default.extname(file.path).toLowerCase();
436
+ if (isBinaryFile(ext)) {
437
+ continue;
438
+ }
439
+ const templateContent = import_fs_extra4.default.readFileSync(file.path, "utf8");
440
+ if (!templateContent.includes("<%")) {
441
+ continue;
442
+ }
443
+ try {
444
+ const rendered = import_ejs.default.render(templateContent, context);
445
+ import_fs_extra4.default.writeFileSync(file.path, rendered, "utf8");
446
+ } catch (err) {
447
+ console.error("\u274C Error rendering EJS for file:", file.path);
448
+ throw err;
449
+ }
450
+ }
451
+ }
452
+ function getTemplateDef(cwd = ".") {
453
+ debug("Get template def");
454
+ const def = getBloxFile(cwd).definition;
455
+ debug(def);
456
+ return def;
457
+ }
458
+ function getBlockDef(cwd = ".") {
459
+ debug("Get block def");
460
+ const def = getBloxFile(cwd).definition;
461
+ def && debug(def);
462
+ return def;
463
+ }
464
+ function getBloxFile(cwd = ".") {
465
+ try {
466
+ const file = import_fs_extra4.default.readJSONSync(import_node_path6.default.join(cwd, bloxFilePath));
467
+ if (!file.checkpoints) {
468
+ file.checkpoints = {};
469
+ }
470
+ return file;
471
+ } catch {
472
+ return {};
473
+ }
474
+ }
475
+ function saveBloxFile(info, cwd = ".") {
476
+ debug("Save info");
477
+ import_fs_extra4.default.writeFileSync(import_node_path6.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
478
+ }
479
+ function updateCheckpoint(name, checkpoint, cwd = ".") {
480
+ const info = getBloxFile(cwd);
481
+ if (!info.checkpoints) {
482
+ info.checkpoints = {};
483
+ }
484
+ info.checkpoints[name] = checkpoint;
485
+ saveBloxFile(info, cwd);
486
+ }
487
+ function getUsedBlocksDef() {
488
+ return getUsedBlocks().map((b) => b.definition);
489
+ }
490
+ function getUsedBlocks() {
491
+ debug("Get used blocks");
492
+ const blocks = [];
493
+ if (import_fs_extra4.default.existsSync(blocksDir)) {
494
+ import_fs_extra4.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
495
+ if (!file.isDirectory()) {
496
+ return;
497
+ }
498
+ const blockDef = getBloxFile(import_node_path6.default.join(blocksDir, file.name));
499
+ if (blockDef && blockDef.definition) {
500
+ blocks.push(blockDef);
501
+ }
502
+ });
503
+ }
504
+ debug(blocks);
505
+ return blocks;
506
+ }
507
+
508
+ // src/shared/spinner.ts
509
+ var import_prompts3 = require("@clack/prompts");
510
+ var spinner = () => {
511
+ const s = (0, import_prompts3.spinner)();
512
+ const minimal = isMinimalMode() || isDebugMode();
513
+ return {
514
+ start: (msg) => {
515
+ minimal ? import_prompts2.log.step(`${msg || "start"}...`) : s.start(msg);
516
+ },
517
+ stop: (msg = "error", code) => {
518
+ minimal ? code ? import_prompts2.log.error(msg) : import_prompts2.log.step(msg || "success") : s.stop(code ? fmt.red(msg) : fmt.green(msg), code);
519
+ },
520
+ message: (msg) => {
521
+ minimal ? import_prompts2.log.message(msg) : s.message(msg);
522
+ }
523
+ };
524
+ };
525
+ async function runTask(message, task) {
526
+ const startMessage = typeof message === "string" ? message : message.start;
527
+ const endMessage = typeof message === "string" ? message : message.end;
528
+ const taskSpinner = spinner();
529
+ taskSpinner.start(startMessage);
530
+ try {
531
+ await (typeof task === "function" ? task() : task);
532
+ taskSpinner.stop(endMessage);
533
+ } catch (e) {
534
+ taskSpinner.stop(`Failed: ${startMessage}`, 1);
535
+ throw e;
536
+ }
537
+ }
538
+
539
+ // src/shared/utils/runLifecycleHook.ts
540
+ function getLifecycleHookScript(cwd, hook) {
541
+ const definition = getTemplateDef(cwd);
542
+ const script = definition[hook];
543
+ if (typeof script !== "string" || !script.trim()) {
544
+ return void 0;
545
+ }
546
+ return script.trim();
547
+ }
548
+ async function runLifecycleHookScript(cwd, script) {
549
+ const isWin = process.platform === "win32";
550
+ if (isWin) {
551
+ await $("cmd.exe", ["/d", "/s", "/c", script], { cwd });
552
+ return;
553
+ }
554
+ await $("/bin/sh", ["-lc", script], { cwd });
555
+ }
556
+ async function runLifecycleHookWithTask(cwd, hook, message) {
557
+ const script = getLifecycleHookScript(cwd, hook);
558
+ if (!script) {
559
+ return;
560
+ }
561
+ debug(`Run lifecycle hook ${hook} in: ${cwd}`);
562
+ await runTask(message, async () => runLifecycleHookScript(cwd, script));
563
+ }
564
+
565
+ // src/services/path.ts
566
+ var import_node_path7 = __toESM(require("path"));
408
567
  var normalizePath = (_path) => {
409
- return _path.split(import_node_path5.default.sep).join("/");
568
+ return _path.split(import_node_path7.default.sep).join("/");
410
569
  };
411
570
 
412
571
  // src/services/git.ts
@@ -437,16 +596,16 @@ var getRemoteWorktree = async (remote, commit2) => {
437
596
  return remoteWorktrees.get(key);
438
597
  }
439
598
  const tmpDir = import_node_os.default.tmpdir();
440
- const worktreeDir = import_node_path6.default.join(tmpDir, "blox-cli-worktrees", remote, commit2);
599
+ const worktreeDir = import_node_path8.default.join(tmpDir, "blox-cli-worktrees", remote, commit2);
441
600
  try {
442
601
  await $("git", ["worktree", "prune"]);
443
602
  } catch {
444
603
  }
445
- if (await import_fs_extra3.default.pathExists(worktreeDir)) {
604
+ if (await import_fs_extra5.default.pathExists(worktreeDir)) {
446
605
  try {
447
606
  await $("git", ["worktree", "remove", "--force", worktreeDir]);
448
607
  } catch {
449
- await import_fs_extra3.default.remove(worktreeDir);
608
+ await import_fs_extra5.default.remove(worktreeDir);
450
609
  try {
451
610
  await $("git", ["worktree", "prune"]);
452
611
  } catch {
@@ -562,8 +721,8 @@ var update = (shellOptions = {}) => {
562
721
  var getLatestCommitFromRemote = async (remote, branch) => {
563
722
  return getLatestCommit(`${remote}/${branch}`);
564
723
  };
565
- var getLatestCommitFromPath = async (path19) => {
566
- return getLatestCommit("HEAD", path19);
724
+ var getLatestCommitFromPath = async (path23) => {
725
+ return getLatestCommit("HEAD", path23);
567
726
  };
568
727
  var getLatestCommit = async (rev, cwd = ".") => {
569
728
  debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
@@ -587,7 +746,7 @@ var getChangesLog = async (fromCommit, toCommit) => {
587
746
  };
588
747
  var unInit = (cwd) => {
589
748
  debug("UnInit");
590
- return import_fs_extra3.default.remove(import_node_path6.default.join(cwd, ".git"));
749
+ return import_fs_extra5.default.remove(import_node_path8.default.join(cwd, ".git"));
591
750
  };
592
751
  var init = async (cwd) => {
593
752
  debug("Init");
@@ -704,11 +863,11 @@ var createBranch = async (branch, from, cwd = ".") => {
704
863
  var push = async (remote, branch, cwd = ".") => {
705
864
  await $("git", ["push", "--progress", remote, `refs/heads/${branch}`], { cwd });
706
865
  };
707
- var checkoutFile = async (path19, ref, cwd = ".") => {
866
+ var checkoutFile = async (path23, ref, cwd = ".") => {
708
867
  const args = ["checkout"];
709
868
  if (ref) args.push(ref);
710
869
  else args.push("HEAD");
711
- args.push("--", path19);
870
+ args.push("--", path23);
712
871
  await $("git", args, { cwd });
713
872
  };
714
873
  var pathExistsAsBlobInRev = async (rev, filePath, cwd = ".") => {
@@ -760,10 +919,10 @@ var cherryPick = async (commitHash, subtree, noCommit, cwd = ".") => {
760
919
  args.push(normalizeCommitRef(commitHash));
761
920
  await $("git", args, { cwd });
762
921
  };
763
- var reset = async (path19, hard, cwd = ".") => {
922
+ var reset = async (path23, hard, cwd = ".") => {
764
923
  const args = ["reset"];
765
924
  if (hard) args.push("--hard");
766
- if (path19) args.push(path19);
925
+ if (path23) args.push(path23);
767
926
  await $("git", args, { cwd });
768
927
  };
769
928
  var commitAll = async (message, cwd = ".") => {
@@ -837,15 +996,15 @@ var git = {
837
996
  };
838
997
 
839
998
  // src/shared/prompts/index.ts
840
- var import_prompts3 = require("@clack/prompts");
999
+ var import_prompts4 = require("@clack/prompts");
841
1000
  var checkIfCanceled = (value) => {
842
- if ((0, import_prompts3.isCancel)(value)) {
843
- (0, import_prompts3.cancel)();
1001
+ if ((0, import_prompts4.isCancel)(value)) {
1002
+ (0, import_prompts4.cancel)();
844
1003
  process.exit(0);
845
1004
  }
846
1005
  };
847
1006
  var error = (error2, exit = true) => {
848
- import_prompts3.log.error(
1007
+ import_prompts4.log.error(
849
1008
  fmt.red(
850
1009
  typeof error2 === "string" ? error2 : error2?.shortMessage || error2?.message || JSON.stringify(error2)
851
1010
  )
@@ -853,28 +1012,28 @@ var error = (error2, exit = true) => {
853
1012
  exit && process.exit(-1);
854
1013
  };
855
1014
  var select = async (opts) => {
856
- const value = await (0, import_prompts3.select)(opts);
1015
+ const value = await (0, import_prompts4.select)(opts);
857
1016
  checkIfCanceled(value);
858
1017
  return value;
859
1018
  };
860
1019
  var text = async (opts) => {
861
- const value = await (0, import_prompts3.text)(opts);
1020
+ const value = await (0, import_prompts4.text)(opts);
862
1021
  checkIfCanceled(value);
863
1022
  return value;
864
1023
  };
865
1024
  var confirm = async (opts) => {
866
- const value = await (0, import_prompts3.confirm)(opts);
1025
+ const value = await (0, import_prompts4.confirm)(opts);
867
1026
  checkIfCanceled(value);
868
1027
  return value;
869
1028
  };
870
1029
  var multiselect = async (opts) => {
871
- const value = await (0, import_prompts3.multiselect)(opts);
1030
+ const value = await (0, import_prompts4.multiselect)(opts);
872
1031
  checkIfCanceled(value);
873
1032
  return value;
874
1033
  };
875
1034
  var textList = async (opts) => {
876
1035
  opts.message = `${opts.message} ${fmt.gray('(separated with ",")')}`;
877
- const value = await (0, import_prompts3.text)(opts);
1036
+ const value = await (0, import_prompts4.text)(opts);
878
1037
  checkIfCanceled(value);
879
1038
  opts.validate?.(value);
880
1039
  return value.split(",");
@@ -945,24 +1104,24 @@ async function migrate(name, { getPath = (f) => f, read, write }) {
945
1104
  }
946
1105
  function migrateOnLocal(name, cwd = ".") {
947
1106
  return migrate(name, {
948
- getPath: (file) => import_node_path7.default.join(cwd, file),
949
- read: import_fs_extra4.default.readJson,
950
- write: import_fs_extra4.default.writeFile
1107
+ getPath: (file) => import_node_path9.default.join(cwd, file),
1108
+ read: import_fs_extra6.default.readJson,
1109
+ write: import_fs_extra6.default.writeFile
951
1110
  });
952
1111
  }
953
1112
  function migrateOnRemote(name, commit2, cwd) {
954
1113
  return migrate(name, {
955
1114
  read: (file) => git.readJsonFromCommit(commit2, file),
956
- getPath: cwd ? (file) => import_node_path7.default.join(cwd, file) : void 0
1115
+ getPath: cwd ? (file) => import_node_path9.default.join(cwd, file) : void 0
957
1116
  });
958
1117
  }
959
1118
 
960
1119
  // src/migrations/index.ts
961
1120
  async function migrateAll(autoCommit) {
962
1121
  let filesChanged = (await migrateOnLocal("app")).filesChanged;
963
- const blocks = import_fs_extra5.default.existsSync(blocksDir) ? import_fs_extra5.default.readdirSync(blocksDir) : [];
1122
+ const blocks = import_fs_extra7.default.existsSync(blocksDir) ? import_fs_extra7.default.readdirSync(blocksDir) : [];
964
1123
  for (const block of blocks) {
965
- const res = await migrateOnLocal(block, import_node_path8.default.join(blocksDir, block));
1124
+ const res = await migrateOnLocal(block, import_node_path10.default.join(blocksDir, block));
966
1125
  filesChanged = filesChanged || res.filesChanged;
967
1126
  }
968
1127
  if (autoCommit && filesChanged && await git.hasUncommittedChanges()) {
@@ -973,84 +1132,51 @@ async function migrateAll(autoCommit) {
973
1132
  }
974
1133
 
975
1134
  // src/services/fs.ts
976
- var import_node_path9 = __toESM(require("path"));
977
- var import_fs_extra6 = __toESM(require("fs-extra"));
1135
+ var import_node_path11 = __toESM(require("path"));
1136
+ var import_fs_extra8 = __toESM(require("fs-extra"));
978
1137
  var import_ignore2 = __toESM(require("ignore"));
979
- var import_klaw = __toESM(require("klaw"));
1138
+ var import_klaw2 = __toESM(require("klaw"));
980
1139
  var filterBlacklisted = (item) => {
981
1140
  return !item.includes("node_modules") && !item.includes(".git");
982
1141
  };
983
1142
  var deletePattern = async (cwd, patterns = []) => {
984
1143
  const ig = (0, import_ignore2.default)().add(patterns);
985
- for await (const file of (0, import_klaw.default)(cwd, { filter: filterBlacklisted })) {
986
- const relativePath = import_node_path9.default.relative(cwd, file.path);
1144
+ for await (const file of (0, import_klaw2.default)(cwd, { filter: filterBlacklisted })) {
1145
+ const relativePath = import_node_path11.default.relative(cwd, file.path);
987
1146
  if (relativePath && ig.ignores(relativePath)) {
988
- if (!await import_fs_extra6.default.exists(file.path)) {
1147
+ if (!await import_fs_extra8.default.exists(file.path)) {
989
1148
  continue;
990
1149
  }
991
1150
  debug(`deleting: ${relativePath}`);
992
- await import_fs_extra6.default.remove(file.path);
1151
+ await import_fs_extra8.default.remove(file.path);
993
1152
  }
994
1153
  }
995
1154
  };
996
1155
 
997
1156
  // src/services/registry.ts
998
- var import_node_path10 = __toESM(require("path"));
999
- var import_fs_extra7 = __toESM(require("fs-extra"));
1157
+ var import_node_path12 = __toESM(require("path"));
1158
+ var import_fs_extra9 = __toESM(require("fs-extra"));
1000
1159
  var import_merge = __toESM(require("lodash/merge"));
1001
-
1002
- // src/shared/spinner.ts
1003
- var import_prompts5 = require("@clack/prompts");
1004
- var spinner = () => {
1005
- const s = (0, import_prompts5.spinner)();
1006
- const minimal = isMinimalMode() || isDebugMode();
1007
- return {
1008
- start: (msg) => {
1009
- minimal ? import_prompts2.log.step(`${msg || "start"}...`) : s.start(msg);
1010
- },
1011
- stop: (msg = "error", code) => {
1012
- minimal ? code ? import_prompts2.log.error(msg) : import_prompts2.log.step(msg || "success") : s.stop(code ? fmt.red(msg) : fmt.green(msg), code);
1013
- },
1014
- message: (msg) => {
1015
- minimal ? import_prompts2.log.message(msg) : s.message(msg);
1016
- }
1017
- };
1018
- };
1019
- async function runTask(message, task) {
1020
- const startMessage = typeof message === "string" ? message : message.start;
1021
- const endMessage = typeof message === "string" ? message : message.end;
1022
- const taskSpinner = spinner();
1023
- taskSpinner.start(startMessage);
1024
- try {
1025
- await (typeof task === "function" ? task() : task);
1026
- taskSpinner.stop(endMessage);
1027
- } catch (e) {
1028
- taskSpinner.stop(`Failed: ${startMessage}`, 1);
1029
- throw e;
1030
- }
1031
- }
1032
-
1033
- // src/services/registry.ts
1034
- var registriesDataPath = import_node_path10.default.join(appPaths.data, "registries");
1160
+ var registriesDataPath = import_node_path12.default.join(appPaths.data, "registries");
1035
1161
  var upeToDate = false;
1036
1162
  var syncRegistries = async (branch) => {
1037
1163
  if (upeToDate) return;
1038
1164
  upeToDate = true;
1039
1165
  debug("Sync registries");
1040
- import_fs_extra7.default.ensureDirSync(registriesDataPath);
1166
+ import_fs_extra9.default.ensureDirSync(registriesDataPath);
1041
1167
  const config = getLocalConfig();
1042
1168
  return await runTask("Update registries", async () => {
1043
1169
  await Promise.all(
1044
1170
  config.registries.map(async (registry) => {
1045
1171
  debug(`update registry: ${registry}`);
1046
1172
  const repoName = registry.split("/").pop() || "";
1047
- const repoDir = import_node_path10.default.join(registriesDataPath, repoName);
1048
- if (!import_fs_extra7.default.existsSync(repoDir)) {
1173
+ const repoDir = import_node_path12.default.join(registriesDataPath, repoName);
1174
+ if (!import_fs_extra9.default.existsSync(repoDir)) {
1049
1175
  await git.clone(registry, repoName, branch, {
1050
1176
  cwd: registriesDataPath,
1051
1177
  depth: 1
1052
1178
  });
1053
- } else if (import_fs_extra7.default.existsSync(import_node_path10.default.join(repoDir, ".git"))) {
1179
+ } else if (import_fs_extra9.default.existsSync(import_node_path12.default.join(repoDir, ".git"))) {
1054
1180
  await git.update({ cwd: repoDir });
1055
1181
  } else {
1056
1182
  debug(`local registry`);
@@ -1062,11 +1188,11 @@ var syncRegistries = async (branch) => {
1062
1188
  var getAvailableTemplates = async () => {
1063
1189
  debug("Get available templates");
1064
1190
  const templates = {};
1065
- const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
1191
+ const registries = import_fs_extra9.default.readdirSync(registriesDataPath);
1066
1192
  for (const registry of registries) {
1067
- const indexPath = import_node_path10.default.join(registriesDataPath, registry, "index.json");
1068
- if (import_fs_extra7.default.existsSync(indexPath)) {
1069
- const data = import_fs_extra7.default.readJSONSync(indexPath);
1193
+ const indexPath = import_node_path12.default.join(registriesDataPath, registry, "index.json");
1194
+ if (import_fs_extra9.default.existsSync(indexPath)) {
1195
+ const data = import_fs_extra9.default.readJSONSync(indexPath);
1070
1196
  Object.entries(data.templates || {}).forEach(([templateName, template]) => {
1071
1197
  if (!template.source) {
1072
1198
  template.source = `/template-${templateName}`;
@@ -1106,107 +1232,25 @@ var getAvailableBlocks = async (templateInfo) => {
1106
1232
  return blocks;
1107
1233
  };
1108
1234
  var getAvailableVersions = async (source) => {
1109
- const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
1235
+ const registries = import_fs_extra9.default.readdirSync(registriesDataPath);
1110
1236
  for (const registry of registries) {
1111
- const registryPath = import_node_path10.default.join(registriesDataPath, registry);
1112
- const indexPath = import_node_path10.default.join(registryPath, "index.json");
1113
- if (!import_fs_extra7.default.existsSync(indexPath)) continue;
1114
- const registryData = import_fs_extra7.default.readJSONSync(indexPath);
1115
- const versionDirPath = import_node_path10.default.join(registryPath, "versions");
1237
+ const registryPath = import_node_path12.default.join(registriesDataPath, registry);
1238
+ const indexPath = import_node_path12.default.join(registryPath, "index.json");
1239
+ if (!import_fs_extra9.default.existsSync(indexPath)) continue;
1240
+ const registryData = import_fs_extra9.default.readJSONSync(indexPath);
1241
+ const versionDirPath = import_node_path12.default.join(registryPath, "versions");
1116
1242
  const versionsFilePaths = [
1117
- import_node_path10.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
1118
- import_node_path10.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
1243
+ import_node_path12.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
1244
+ import_node_path12.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
1119
1245
  ];
1120
1246
  for (const versionsFile of versionsFilePaths) {
1121
- if (import_fs_extra7.default.existsSync(versionsFile)) {
1122
- return import_fs_extra7.default.readJSONSync(versionsFile);
1247
+ if (import_fs_extra9.default.existsSync(versionsFile)) {
1248
+ return import_fs_extra9.default.readJSONSync(versionsFile);
1123
1249
  }
1124
1250
  }
1125
1251
  }
1126
1252
  };
1127
1253
 
1128
- // src/services/template.ts
1129
- var import_node_path11 = __toESM(require("path"));
1130
- var import_ejs = __toESM(require("ejs"));
1131
- var import_fs_extra8 = __toESM(require("fs-extra"));
1132
- var import_klaw2 = __toESM(require("klaw"));
1133
- async function replacePlaceholders(dir, context) {
1134
- debug("Replace placeholders");
1135
- for await (const file of (0, import_klaw2.default)(dir)) {
1136
- if (!file.stats.isFile()) continue;
1137
- const ext = import_node_path11.default.extname(file.path).toLowerCase();
1138
- if (isBinaryFile(ext)) {
1139
- continue;
1140
- }
1141
- const templateContent = import_fs_extra8.default.readFileSync(file.path, "utf8");
1142
- if (!templateContent.includes("<%")) {
1143
- continue;
1144
- }
1145
- try {
1146
- const rendered = import_ejs.default.render(templateContent, context);
1147
- import_fs_extra8.default.writeFileSync(file.path, rendered, "utf8");
1148
- } catch (err) {
1149
- console.error("\u274C Error rendering EJS for file:", file.path);
1150
- throw err;
1151
- }
1152
- }
1153
- }
1154
- function getTemplateDef(cwd = ".") {
1155
- debug("Get template def");
1156
- const def = getBloxFile(cwd).definition;
1157
- debug(def);
1158
- return def;
1159
- }
1160
- function getBlockDef(cwd = ".") {
1161
- debug("Get block def");
1162
- const def = getBloxFile(cwd).definition;
1163
- def && debug(def);
1164
- return def;
1165
- }
1166
- function getBloxFile(cwd = ".") {
1167
- try {
1168
- const file = import_fs_extra8.default.readJSONSync(import_node_path11.default.join(cwd, bloxFilePath));
1169
- if (!file.checkpoints) {
1170
- file.checkpoints = {};
1171
- }
1172
- return file;
1173
- } catch {
1174
- return {};
1175
- }
1176
- }
1177
- function saveBloxFile(info, cwd = ".") {
1178
- debug("Save info");
1179
- import_fs_extra8.default.writeFileSync(import_node_path11.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
1180
- }
1181
- function updateCheckpoint(name, checkpoint, cwd = ".") {
1182
- const info = getBloxFile(cwd);
1183
- if (!info.checkpoints) {
1184
- info.checkpoints = {};
1185
- }
1186
- info.checkpoints[name] = checkpoint;
1187
- saveBloxFile(info, cwd);
1188
- }
1189
- function getUsedBlocksDef() {
1190
- return getUsedBlocks().map((b) => b.definition);
1191
- }
1192
- function getUsedBlocks() {
1193
- debug("Get used blocks");
1194
- const blocks = [];
1195
- if (import_fs_extra8.default.existsSync(blocksDir)) {
1196
- import_fs_extra8.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
1197
- if (!file.isDirectory()) {
1198
- return;
1199
- }
1200
- const blockDef = getBloxFile(import_node_path11.default.join(blocksDir, file.name));
1201
- if (blockDef && blockDef.definition) {
1202
- blocks.push(blockDef);
1203
- }
1204
- });
1205
- }
1206
- debug(blocks);
1207
- return blocks;
1208
- }
1209
-
1210
1254
  // src/services/versions/checkCompatibility.ts
1211
1255
  function processDependencyVersion(dep) {
1212
1256
  if (!dep.version) dep.version = 0;
@@ -1330,15 +1374,6 @@ async function selectVersion(source, fromCommit) {
1330
1374
  return versionsData[version2]?.lastCommit;
1331
1375
  }
1332
1376
 
1333
- // src/commands/init/utils/index.ts
1334
- function runInitScript(cwd) {
1335
- debug(`Run init script in: ${cwd}`);
1336
- const info = getTemplateDef(cwd);
1337
- if (info.init) {
1338
- return $(info.init, [], { cwd, shell: true });
1339
- }
1340
- }
1341
-
1342
1377
  // src/commands/add/index.ts
1343
1378
  var addBlock = async (block, blocks, branch, destination) => {
1344
1379
  const blockRegistryData = blocks[block];
@@ -1346,7 +1381,9 @@ var addBlock = async (block, blocks, branch, destination) => {
1346
1381
  destination = blockRegistryData?.destination || block;
1347
1382
  }
1348
1383
  const blockPath = `blocks/${destination}`;
1349
- if (!import_fs_extra9.default.existsSync(blockPath)) {
1384
+ let newBlockAdded = false;
1385
+ if (!import_fs_extra10.default.existsSync(blockPath)) {
1386
+ newBlockAdded = true;
1350
1387
  await runTask(
1351
1388
  { start: `Fetching block: ${block}`, end: `Added block: ${block}` },
1352
1389
  async () => {
@@ -1366,16 +1403,19 @@ var addBlock = async (block, blocks, branch, destination) => {
1366
1403
  updateCheckpoint(block, { commit: commit2, branch }, blockPath);
1367
1404
  }
1368
1405
  );
1369
- await runTask("Run init script", async () => runInitScript(blockPath));
1406
+ await runLifecycleHookWithTask(blockPath, "init", "Run block init");
1407
+ await runLifecycleHookWithTask(blockPath, "add", "Run block add");
1370
1408
  } else {
1371
1409
  debug(`${block} already exists`);
1372
1410
  }
1373
1411
  const blockDef = getBlockDef(blockPath);
1374
1412
  for (const dep of blockDef?.dependencies || []) {
1375
- await addBlock(dep.name, blocks);
1413
+ const depNew = await addBlock(dep.name, blocks);
1414
+ newBlockAdded = newBlockAdded || depNew;
1376
1415
  }
1416
+ return newBlockAdded;
1377
1417
  };
1378
- var add2 = command("add").description("Add block to app").alias("a").argument("[block]", "Block to be added").option("--branch <name>", "branch name").option("--dest <name>", "destination dir").action(async (block, { branch, dest }) => {
1418
+ var add2 = command("add").description("Add block to app").alias("a").argument("[blocks...]", "Blocks to be added").option("--branch <name>", "branch name").option("--dest <name>", "destination dir").action(async (selectedBlocks, { branch, dest }) => {
1379
1419
  if (await git.hasUncommittedChanges()) {
1380
1420
  import_prompts2.log.warn(fmt.yellow("Make sure to commit any changes first"));
1381
1421
  return;
@@ -1385,9 +1425,10 @@ var add2 = command("add").description("Add block to app").alias("a").argument("[
1385
1425
  try {
1386
1426
  const templateDef = getTemplateDef();
1387
1427
  const blocks = await getAvailableBlocks(templateDef);
1388
- if (!block) {
1389
- block = await select({
1390
- message: "Select template to be used",
1428
+ let blocksToAdd = Array.isArray(selectedBlocks) ? selectedBlocks : [];
1429
+ if (!blocksToAdd.length) {
1430
+ blocksToAdd = await multiselect({
1431
+ message: "Select blocks to add",
1391
1432
  options: Object.entries(blocks).map(([tmpl, { description }]) => ({
1392
1433
  value: tmpl,
1393
1434
  label: tmpl,
@@ -1395,10 +1436,21 @@ var add2 = command("add").description("Add block to app").alias("a").argument("[
1395
1436
  }))
1396
1437
  });
1397
1438
  }
1398
- if (!blocks[block]) {
1399
- error("Selected block not available in registries");
1439
+ if (!blocksToAdd.length) {
1440
+ error("No blocks selected");
1441
+ }
1442
+ const invalidBlocks = blocksToAdd.filter((blockName) => !blocks[blockName]);
1443
+ if (invalidBlocks.length) {
1444
+ error(`Selected blocks not available in registries: ${invalidBlocks.join(", ")}`);
1445
+ }
1446
+ let added = false;
1447
+ for (const blockName of blocksToAdd) {
1448
+ const blockAdded = await addBlock(blockName, blocks, branch, dest);
1449
+ added = added || blockAdded;
1450
+ }
1451
+ if (added) {
1452
+ await runLifecycleHookWithTask(".", "add", "Run template add");
1400
1453
  }
1401
- await addBlock(block, blocks, branch, dest);
1402
1454
  await checkVersionsCompatibility();
1403
1455
  } catch (e) {
1404
1456
  if (!isDebugMode()) {
@@ -1459,7 +1511,7 @@ var ContributionTargetType = /* @__PURE__ */ ((ContributionTargetType2) => {
1459
1511
  })(ContributionTargetType || {});
1460
1512
 
1461
1513
  // src/services/contribute/utils/bloxCheckpoint.ts
1462
- var import_node_path12 = __toESM(require("path"));
1514
+ var import_node_path13 = __toESM(require("path"));
1463
1515
  function getCheckpointForTarget(cwd, target) {
1464
1516
  const bloxDir = getBloxDirForTarget(cwd, target);
1465
1517
  const blox = getBloxFile(bloxDir);
@@ -1469,7 +1521,7 @@ function getCheckpointForTarget(cwd, target) {
1469
1521
  }
1470
1522
  function getBloxDirForTarget(cwd, target) {
1471
1523
  if (target.type === "block" /* BLOCK */) {
1472
- return import_node_path12.default.join(cwd, blocksDir, target.name);
1524
+ return import_node_path13.default.join(cwd, blocksDir, target.name);
1473
1525
  }
1474
1526
  return cwd;
1475
1527
  }
@@ -1733,28 +1785,28 @@ ${prUrl}` : "\nPush completed.")
1733
1785
  };
1734
1786
 
1735
1787
  // src/services/contribute/services/CommitApplierService.ts
1736
- var import_node_path14 = __toESM(require("path"));
1737
- var import_fs_extra11 = __toESM(require("fs-extra"));
1788
+ var import_node_path15 = __toESM(require("path"));
1789
+ var import_fs_extra12 = __toESM(require("fs-extra"));
1738
1790
 
1739
1791
  // src/services/contribute/config/index.ts
1740
1792
  var tempRepoName = "tmp";
1741
1793
  var bloxConfigControlledKeys = ["checkpoints"];
1742
1794
 
1743
1795
  // src/services/contribute/utils/getExcludedPrefixesForTarget.ts
1744
- var import_node_path13 = __toESM(require("path"));
1745
- var import_fs_extra10 = __toESM(require("fs-extra"));
1796
+ var import_node_path14 = __toESM(require("path"));
1797
+ var import_fs_extra11 = __toESM(require("fs-extra"));
1746
1798
  function getExcludedPrefixesForTarget(target, cwd) {
1747
1799
  if (target.type === "block" /* BLOCK */) {
1748
1800
  return [];
1749
1801
  }
1750
1802
  const excluded = [];
1751
- const blocksPath = import_node_path13.default.join(cwd, blocksDir);
1752
- if (import_fs_extra10.default.existsSync(blocksPath)) {
1753
- const entries = import_fs_extra10.default.readdirSync(blocksPath, { withFileTypes: true });
1803
+ const blocksPath = import_node_path14.default.join(cwd, blocksDir);
1804
+ if (import_fs_extra11.default.existsSync(blocksPath)) {
1805
+ const entries = import_fs_extra11.default.readdirSync(blocksPath, { withFileTypes: true });
1754
1806
  for (const entry of entries) {
1755
1807
  if (!entry.isDirectory()) continue;
1756
- const blockBloxFile = import_node_path13.default.join(blocksPath, entry.name, bloxFilePath);
1757
- if (import_fs_extra10.default.existsSync(blockBloxFile)) {
1808
+ const blockBloxFile = import_node_path14.default.join(blocksPath, entry.name, bloxFilePath);
1809
+ if (import_fs_extra11.default.existsSync(blockBloxFile)) {
1758
1810
  excluded.push(normalizePath(`${blocksDir}/${entry.name}/`));
1759
1811
  }
1760
1812
  }
@@ -1881,8 +1933,8 @@ ${e instanceof Error ? e.message : String(e)}`);
1881
1933
  }
1882
1934
  const withoutGovernedKeys = omitKeys(stagedJson, bloxConfigControlledKeys);
1883
1935
  try {
1884
- const outPath = import_node_path14.default.join(tmpRepoCwd, file);
1885
- await import_fs_extra11.default.outputFile(outPath, JSON.stringify(withoutGovernedKeys, null, 2));
1936
+ const outPath = import_node_path15.default.join(tmpRepoCwd, file);
1937
+ await import_fs_extra12.default.outputFile(outPath, JSON.stringify(withoutGovernedKeys, null, 2));
1886
1938
  await git.add(file, tmpRepoCwd);
1887
1939
  } catch (e) {
1888
1940
  this.logger.warn("apply.commit.blox_merge_fallback", {
@@ -1999,13 +2051,13 @@ var CommitSelectorService = class {
1999
2051
  };
2000
2052
 
2001
2053
  // src/services/contribute/utils/discoverContributionTargets.ts
2002
- var import_node_path15 = __toESM(require("path"));
2003
- var import_fs_extra12 = __toESM(require("fs-extra"));
2054
+ var import_node_path16 = __toESM(require("path"));
2055
+ var import_fs_extra13 = __toESM(require("fs-extra"));
2004
2056
  var readBloxFileIfExists = (cwd) => {
2005
- const p = import_node_path15.default.join(cwd, bloxFilePath);
2006
- if (!import_fs_extra12.default.existsSync(p)) return;
2057
+ const p = import_node_path16.default.join(cwd, bloxFilePath);
2058
+ if (!import_fs_extra13.default.existsSync(p)) return;
2007
2059
  try {
2008
- return import_fs_extra12.default.readJSONSync(p);
2060
+ return import_fs_extra13.default.readJSONSync(p);
2009
2061
  } catch {
2010
2062
  return;
2011
2063
  }
@@ -2033,13 +2085,13 @@ var discoverContributionTargets = (cwd) => {
2033
2085
  });
2034
2086
  }
2035
2087
  }
2036
- const blocksPath = import_node_path15.default.join(cwd, blocksDir);
2037
- if (import_fs_extra12.default.existsSync(blocksPath)) {
2038
- const entries = import_fs_extra12.default.readdirSync(blocksPath, { withFileTypes: true });
2088
+ const blocksPath = import_node_path16.default.join(cwd, blocksDir);
2089
+ if (import_fs_extra13.default.existsSync(blocksPath)) {
2090
+ const entries = import_fs_extra13.default.readdirSync(blocksPath, { withFileTypes: true });
2039
2091
  for (const entry of entries) {
2040
2092
  if (!entry.isDirectory()) continue;
2041
2093
  const blockName = entry.name;
2042
- const blockBlox = readBloxFileIfExists(import_node_path15.default.join(blocksPath, blockName));
2094
+ const blockBlox = readBloxFileIfExists(import_node_path16.default.join(blocksPath, blockName));
2043
2095
  if (!blockBlox?.definition?.name) continue;
2044
2096
  const def = blockBlox.definition;
2045
2097
  const templateName = def.templates?.[0]?.name || appTemplateName;
@@ -2319,15 +2371,15 @@ ${fmt.cyan(createPageUrl)}
2319
2371
 
2320
2372
  // src/services/contribute/services/TmpRepoService.ts
2321
2373
  var import_node_os2 = require("os");
2322
- var import_node_path16 = __toESM(require("path"));
2323
- var import_fs_extra13 = __toESM(require("fs-extra"));
2374
+ var import_node_path17 = __toESM(require("path"));
2375
+ var import_fs_extra14 = __toESM(require("fs-extra"));
2324
2376
  var TmpRepoService = class {
2325
2377
  constructor(logger) {
2326
2378
  this.logger = logger;
2327
2379
  }
2328
2380
  async getTmpDir(target) {
2329
2381
  const slug = `${target.type}-${target.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-");
2330
- return import_node_path16.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
2382
+ return import_node_path17.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
2331
2383
  }
2332
2384
  async prepare(opts) {
2333
2385
  const dir = await this.getTmpDir(opts.target);
@@ -2337,11 +2389,11 @@ var TmpRepoService = class {
2337
2389
  branch: opts.branch
2338
2390
  });
2339
2391
  this.logger.info("Prepare for tmp repo");
2340
- if (await import_fs_extra13.default.pathExists(dir)) {
2392
+ if (await import_fs_extra14.default.pathExists(dir)) {
2341
2393
  this.logger.debug(`${tempRepoName}.remove`, { dir });
2342
- await import_fs_extra13.default.remove(dir);
2394
+ await import_fs_extra14.default.remove(dir);
2343
2395
  }
2344
- await import_fs_extra13.default.ensureDir(import_node_path16.default.dirname(dir));
2396
+ await import_fs_extra14.default.ensureDir(import_node_path17.default.dirname(dir));
2345
2397
  await git.clone(opts.repoUrl, dir, opts.branch);
2346
2398
  return dir;
2347
2399
  }
@@ -2424,7 +2476,7 @@ var detach = command("detach").description("Migrate blox schema").option("--basi
2424
2476
  });
2425
2477
 
2426
2478
  // src/commands/init/index.ts
2427
- var import_fs_extra14 = __toESM(require("fs-extra"));
2479
+ var import_fs_extra15 = __toESM(require("fs-extra"));
2428
2480
  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 }) => {
2429
2481
  await syncRegistries();
2430
2482
  try {
@@ -2463,10 +2515,10 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
2463
2515
  updateCheckpoint(def.name, { commit: commit2, branch }, name);
2464
2516
  await git.init(name);
2465
2517
  task.stop(`App initialized in ${name}`);
2466
- await runTask("Run init script", async () => runInitScript(name || ""));
2518
+ await runLifecycleHookWithTask(name || "", "init", "Run template init");
2467
2519
  } catch (e) {
2468
- if (name && import_fs_extra14.default.existsSync(name)) {
2469
- await import_fs_extra14.default.remove(name);
2520
+ if (name && import_fs_extra15.default.existsSync(name)) {
2521
+ await import_fs_extra15.default.remove(name);
2470
2522
  }
2471
2523
  error(e);
2472
2524
  }
@@ -2485,15 +2537,295 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
2485
2537
  }
2486
2538
  });
2487
2539
 
2540
+ // src/commands/remove/index.ts
2541
+ var import_node_path18 = __toESM(require("path"));
2542
+ var import_fs_extra16 = __toESM(require("fs-extra"));
2543
+ var blocksAbsolutePath = () => import_node_path18.default.resolve(process.cwd(), blocksDir);
2544
+ function listInstalledBlockRelPaths() {
2545
+ const root = blocksAbsolutePath();
2546
+ if (!import_fs_extra16.default.existsSync(root)) {
2547
+ return [];
2548
+ }
2549
+ const paths2 = [];
2550
+ for (const entry of import_fs_extra16.default.readdirSync(root, { withFileTypes: true })) {
2551
+ if (!entry.isDirectory()) {
2552
+ continue;
2553
+ }
2554
+ const abs = import_node_path18.default.join(root, entry.name);
2555
+ if (!isBlockDirectory(abs)) {
2556
+ continue;
2557
+ }
2558
+ paths2.push(import_node_path18.default.join(blocksDir, entry.name));
2559
+ }
2560
+ return paths2;
2561
+ }
2562
+ function getInstalledBlockSelectOptions() {
2563
+ return listInstalledBlockRelPaths().map((rel) => {
2564
+ const folder = import_node_path18.default.basename(rel);
2565
+ const def = getBlockDef(rel);
2566
+ const label = def?.name && def.name !== folder ? `${def.name} (${folder})` : folder;
2567
+ return { value: folder, label, hint: def?.name };
2568
+ });
2569
+ }
2570
+ function assertNoDependents(blockPathAbs, targetBlockName) {
2571
+ for (const rel of listInstalledBlockRelPaths()) {
2572
+ const abs = import_node_path18.default.resolve(process.cwd(), rel);
2573
+ if (abs === blockPathAbs) {
2574
+ continue;
2575
+ }
2576
+ const def = getBlockDef(rel);
2577
+ for (const dep of def.dependencies || []) {
2578
+ if (dep.name === targetBlockName) {
2579
+ throw new Error(
2580
+ `Cannot remove "${targetBlockName}": block "${def.name}" declares a dependency on it. Remove that dependency or the dependent block first.`
2581
+ );
2582
+ }
2583
+ }
2584
+ }
2585
+ }
2586
+ function assertUnderBlocksRoot(blockPathAbs) {
2587
+ const root = blocksAbsolutePath();
2588
+ const rel = import_node_path18.default.relative(root, blockPathAbs);
2589
+ if (!rel || rel.startsWith("..") || import_node_path18.default.isAbsolute(rel)) {
2590
+ throw new Error("Block path escapes the blocks directory");
2591
+ }
2592
+ }
2593
+ async function removeBlock(block, blocks, force = false) {
2594
+ const reg = blocks[block];
2595
+ const destination = reg ? reg.destination ?? block : block;
2596
+ const blockPathRel = import_node_path18.default.join(blocksDir, destination);
2597
+ const blockPathAbs = import_node_path18.default.resolve(process.cwd(), blockPathRel);
2598
+ assertUnderBlocksRoot(blockPathAbs);
2599
+ if (!import_fs_extra16.default.existsSync(blockPathAbs) || !isBlockDirectory(blockPathAbs)) {
2600
+ throw new Error(`Block is not installed at ${import_node_path18.default.relative(process.cwd(), blockPathAbs)}`);
2601
+ }
2602
+ const targetDef = getBlockDef(blockPathRel);
2603
+ if (!targetDef?.name) {
2604
+ throw new Error("Invalid block: missing name in .blox definition");
2605
+ }
2606
+ if (!force) {
2607
+ assertNoDependents(blockPathAbs, targetDef.name);
2608
+ }
2609
+ await runLifecycleHookWithTask(blockPathRel, "remove", "Run block remove");
2610
+ await runTask("Remove block files", async () => {
2611
+ assertUnderBlocksRoot(blockPathAbs);
2612
+ await import_fs_extra16.default.remove(blockPathAbs);
2613
+ });
2614
+ return true;
2615
+ }
2616
+ var remove = command("remove").description("Remove block from app").alias("rm").argument("[blocks...]", "Blocks to remove (registry key or installed folder name)").option("-f, --force", "Remove even if other blocks declare a dependency on this block").action(async (selectedBlocks, { force }) => {
2617
+ if (await git.hasUncommittedChanges()) {
2618
+ import_prompts2.log.warn(fmt.yellow("Make sure to commit any changes first"));
2619
+ return;
2620
+ }
2621
+ await migrateAll();
2622
+ await syncRegistries();
2623
+ try {
2624
+ const templateDef = getTemplateDef();
2625
+ const blocks = await getAvailableBlocks(templateDef);
2626
+ let blocksToRemove = Array.isArray(selectedBlocks) ? selectedBlocks : [];
2627
+ if (!blocksToRemove.length) {
2628
+ const options = getInstalledBlockSelectOptions();
2629
+ if (!options.length) {
2630
+ error("No installed blocks found under blocks/");
2631
+ }
2632
+ blocksToRemove = await multiselect({
2633
+ message: "Select blocks to remove",
2634
+ options
2635
+ });
2636
+ }
2637
+ if (!blocksToRemove.length) {
2638
+ error("No blocks selected");
2639
+ }
2640
+ if (force) {
2641
+ import_prompts2.log.warn(
2642
+ fmt.yellow(
2643
+ "--force: skipping dependency check; dependent blocks may be left in a broken state."
2644
+ )
2645
+ );
2646
+ }
2647
+ let removed = false;
2648
+ for (const blockName of blocksToRemove) {
2649
+ const blockRemoved = await removeBlock(blockName, blocks, force);
2650
+ removed = removed || blockRemoved;
2651
+ }
2652
+ if (removed) {
2653
+ await runLifecycleHookWithTask(".", "remove", "Run template remove");
2654
+ }
2655
+ if (!force) {
2656
+ await checkVersionsCompatibility();
2657
+ }
2658
+ } catch (e) {
2659
+ if (!isDebugMode()) {
2660
+ import_prompts2.log.warn("Error happened, Will rollback changes");
2661
+ await git.rollback();
2662
+ }
2663
+ error(e);
2664
+ }
2665
+ });
2666
+
2667
+ // src/commands/skills/index.ts
2668
+ var import_node_crypto = require("crypto");
2669
+ var import_node_os3 = __toESM(require("os"));
2670
+ var import_node_path20 = __toESM(require("path"));
2671
+ var import_cross_spawn2 = __toESM(require("cross-spawn"));
2672
+ var import_fs_extra18 = __toESM(require("fs-extra"));
2673
+
2674
+ // src/commands/skills/constants.ts
2675
+ var SKILLS_REPO_URL = "https://tfs.aas.com.sa/Medad/BLOX/_git/cli";
2676
+ var SKILLS_TEMP_ROOT_PREFIX = "blox-skills";
2677
+
2678
+ // src/commands/skills/utils/cliCompatibility.ts
2679
+ var import_node_path19 = __toESM(require("path"));
2680
+ var import_fs_extra17 = __toESM(require("fs-extra"));
2681
+ var import_semver = __toESM(require("semver"));
2682
+ var SKILLS_CLI_COMPATIBILITY_COMMANDS = ["add", "update"];
2683
+ function getSkillscommandIndex(args, subcommand) {
2684
+ for (let i = 0; i < args.length; i++) {
2685
+ if (args[i] !== subcommand) {
2686
+ continue;
2687
+ }
2688
+ if (args.slice(0, i).every((t) => t.startsWith("-"))) {
2689
+ return i;
2690
+ }
2691
+ }
2692
+ return -1;
2693
+ }
2694
+ function hasSkillscommand(args, subcommand) {
2695
+ return getSkillscommandIndex(args, subcommand) !== -1;
2696
+ }
2697
+ function needsCliCompatibilityCheck(args) {
2698
+ return SKILLS_CLI_COMPATIBILITY_COMMANDS.some((cmd) => hasSkillscommand(args, cmd));
2699
+ }
2700
+ function getAddCommandIndex(args) {
2701
+ return getSkillscommandIndex(args, "add");
2702
+ }
2703
+ async function loadSkillsData(cloneRoot) {
2704
+ const skillsDir = import_node_path19.default.join(cloneRoot, "skills");
2705
+ if (!await import_fs_extra17.default.pathExists(skillsDir)) {
2706
+ return [];
2707
+ }
2708
+ const entries = await import_fs_extra17.default.readdir(skillsDir, { withFileTypes: true });
2709
+ const manifests = await Promise.all(
2710
+ entries.filter((entry) => entry.isDirectory()).map(async (entry) => {
2711
+ const filePath = import_node_path19.default.join(skillsDir, entry.name, "skill.json");
2712
+ if (!await import_fs_extra17.default.pathExists(filePath)) {
2713
+ return null;
2714
+ }
2715
+ const raw = await import_fs_extra17.default.readJson(filePath);
2716
+ const range = raw.cliCompatibility?.trim();
2717
+ if (!range) {
2718
+ return null;
2719
+ }
2720
+ return {
2721
+ name: raw.name || entry.name,
2722
+ version: raw.version || "0.0.0",
2723
+ cliCompatibility: range
2724
+ };
2725
+ })
2726
+ );
2727
+ return manifests.filter(Boolean);
2728
+ }
2729
+ function getFirstIncompatibleSkill(skills2, cliVersion) {
2730
+ const normalized = import_semver.default.coerce(cliVersion)?.version ?? cliVersion;
2731
+ return skills2.find((skill) => {
2732
+ const range = skill.cliCompatibility;
2733
+ return import_semver.default.validRange(range) && !import_semver.default.satisfies(normalized, range, {
2734
+ includePrerelease: true
2735
+ });
2736
+ }) || null;
2737
+ }
2738
+ function warnIncompatibleSkill(skill, cliVersion) {
2739
+ const label = `${skill.name}@${skill.version}`;
2740
+ console.log("");
2741
+ console.log(
2742
+ fmt.yellow(`\u26A0\uFE0F Skill "${label}" may be incompatible with your CLI (${cliVersion})`)
2743
+ );
2744
+ console.log("");
2745
+ console.log(`${fmt.bold("Required:")} ${skill.cliCompatibility}`);
2746
+ console.log(`${fmt.bold("Current :")} ${cliVersion}`);
2747
+ console.log("");
2748
+ console.log(fmt.bold("You can:"));
2749
+ console.log(` ${fmt.cyan("\u2022")} Upgrade CLI \u2192 ${fmt.cyan("blox upgrade")}`);
2750
+ console.log("");
2751
+ }
2752
+
2753
+ // src/commands/skills/index.ts
2754
+ var skills = command("skills").description("Install, update, and manage BLOX CLI skills from internal repositories").helpOption(false).allowUnknownOption(true).action(async () => {
2755
+ try {
2756
+ const code = await runSkills();
2757
+ process.exit(code);
2758
+ } catch (e) {
2759
+ error(e, false);
2760
+ process.exit(1);
2761
+ }
2762
+ });
2763
+ async function runSkills() {
2764
+ const idx = process.argv.indexOf("skills");
2765
+ const args = idx === -1 ? [] : process.argv.slice(idx + 1);
2766
+ const tempDir = import_node_path20.default.join(import_node_os3.default.tmpdir(), `${SKILLS_TEMP_ROOT_PREFIX}-${(0, import_node_crypto.randomUUID)()}`);
2767
+ await import_fs_extra18.default.mkdir(tempDir);
2768
+ let exitCode = 1;
2769
+ try {
2770
+ await git.clone(SKILLS_REPO_URL, tempDir);
2771
+ if (needsCliCompatibilityCheck(args)) {
2772
+ const skills2 = await loadSkillsData(tempDir);
2773
+ const cliVersion = getBloxCliVersion();
2774
+ const uncompatibleSkill = getFirstIncompatibleSkill(skills2, cliVersion);
2775
+ if (uncompatibleSkill) {
2776
+ warnIncompatibleSkill(uncompatibleSkill, cliVersion);
2777
+ const proceed = await confirm({
2778
+ message: "Continue anyway? (No \u2014 exit and run blox upgrade first)",
2779
+ initialValue: false
2780
+ });
2781
+ if (!proceed) {
2782
+ return 1;
2783
+ }
2784
+ }
2785
+ }
2786
+ const finalArgs = injectRepoPathIfAdd(args, import_node_path20.default.resolve(tempDir));
2787
+ exitCode = await runSkillsCommand(finalArgs, process.cwd());
2788
+ } finally {
2789
+ try {
2790
+ await import_fs_extra18.default.remove(tempDir);
2791
+ } catch {
2792
+ debug(`Failed to cleanup temp dir: ${tempDir}`);
2793
+ }
2794
+ }
2795
+ return exitCode;
2796
+ }
2797
+ function injectRepoPathIfAdd(args, repoPath) {
2798
+ const addIndex = getAddCommandIndex(args);
2799
+ if (addIndex === -1) return args;
2800
+ const next = args[addIndex + 1];
2801
+ if (!next || next.startsWith("-")) {
2802
+ return [...args.slice(0, addIndex + 1), repoPath, ...args.slice(addIndex + 1)];
2803
+ }
2804
+ const updated = [...args];
2805
+ updated[addIndex + 1] = repoPath;
2806
+ return updated;
2807
+ }
2808
+ function runSkillsCommand(args, cwd) {
2809
+ debug(`npx skills ${args.join(" ")}`);
2810
+ return new Promise((resolve, reject) => {
2811
+ const child = (0, import_cross_spawn2.default)("npx", ["skills", ...args], {
2812
+ cwd,
2813
+ stdio: "inherit"
2814
+ });
2815
+ child.on("error", reject);
2816
+ child.on("close", (code) => resolve(code ?? 1));
2817
+ });
2818
+ }
2819
+
2488
2820
  // src/commands/update/index.ts
2489
- var import_prompts21 = require("@clack/prompts");
2821
+ var import_prompts23 = require("@clack/prompts");
2490
2822
 
2491
2823
  // src/commands/update/utils.ts
2492
- var import_node_path18 = __toESM(require("path"));
2824
+ var import_node_path22 = __toESM(require("path"));
2493
2825
 
2494
2826
  // src/services/updater.ts
2495
- var import_node_path17 = __toESM(require("path"));
2496
- var import_fs_extra15 = __toESM(require("fs-extra"));
2827
+ var import_node_path21 = __toESM(require("path"));
2828
+ var import_fs_extra19 = __toESM(require("fs-extra"));
2497
2829
  var import_klaw3 = __toESM(require("klaw"));
2498
2830
  async function updateFromRemote({
2499
2831
  name,
@@ -2539,9 +2871,9 @@ async function updateFromRemote({
2539
2871
  }
2540
2872
  const remoteIgnore = remoteBloxFile.definition?.ignore || [];
2541
2873
  ignore3.push(...remoteIgnore, bloxFilePath, `**/${bloxFilePath}`);
2542
- const gitIgnorePath = import_node_path17.default.join(dir, ".gitignore");
2543
- if (await import_fs_extra15.default.pathExists(gitIgnorePath)) {
2544
- const gitIgnoreContent = await import_fs_extra15.default.readFile(gitIgnorePath, "utf8");
2874
+ const gitIgnorePath = import_node_path21.default.join(dir, ".gitignore");
2875
+ if (await import_fs_extra19.default.pathExists(gitIgnorePath)) {
2876
+ const gitIgnoreContent = await import_fs_extra19.default.readFile(gitIgnorePath, "utf8");
2545
2877
  const gitIgnorePatterns = gitIgnoreContent.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
2546
2878
  ignore3.push(...gitIgnorePatterns);
2547
2879
  debug(`Added ${gitIgnorePatterns.length} patterns from .gitignore`);
@@ -2553,14 +2885,14 @@ async function updateFromRemote({
2553
2885
  if (hard) {
2554
2886
  const getAllFiles = async (d) => {
2555
2887
  const files = [];
2556
- if (await import_fs_extra15.default.pathExists(d)) {
2888
+ if (await import_fs_extra19.default.pathExists(d)) {
2557
2889
  for await (const file of (0, import_klaw3.default)(d)) {
2558
2890
  if (file.path.includes("/.git/") || file.path.endsWith("/.git") || file.path.includes("\\.git\\") || file.path.endsWith("\\.git"))
2559
2891
  continue;
2560
2892
  if (file.path.includes("/node_modules/") || file.path.includes("\\node_modules\\"))
2561
2893
  continue;
2562
2894
  if (file.stats.isFile()) {
2563
- files.push(import_node_path17.default.relative(d, file.path));
2895
+ files.push(import_node_path21.default.relative(d, file.path));
2564
2896
  }
2565
2897
  }
2566
2898
  }
@@ -2579,23 +2911,23 @@ async function updateFromRemote({
2579
2911
  for (const file of filesToProcess) {
2580
2912
  if (file === ".git" || file.startsWith(".git/") || file.startsWith(".git\\")) continue;
2581
2913
  if (ignoredMatcher.ignores(toIgnorePath(file))) continue;
2582
- const localPath = import_node_path17.default.join(dir, file);
2583
- const basePath = import_node_path17.default.join(baseDir, file);
2584
- const remotePath = import_node_path17.default.join(remoteDir, file);
2585
- const existsLocal = await import_fs_extra15.default.pathExists(localPath);
2586
- const existsBase = await import_fs_extra15.default.pathExists(basePath);
2587
- const existsRemote = await import_fs_extra15.default.pathExists(remotePath);
2588
- const ext = import_node_path17.default.extname(file);
2914
+ const localPath = import_node_path21.default.join(dir, file);
2915
+ const basePath = import_node_path21.default.join(baseDir, file);
2916
+ const remotePath = import_node_path21.default.join(remoteDir, file);
2917
+ const existsLocal = await import_fs_extra19.default.pathExists(localPath);
2918
+ const existsBase = await import_fs_extra19.default.pathExists(basePath);
2919
+ const existsRemote = await import_fs_extra19.default.pathExists(remotePath);
2920
+ const ext = import_node_path21.default.extname(file);
2589
2921
  const isBinary = isBinaryFile(ext);
2590
2922
  if (existsRemote) {
2591
- await import_fs_extra15.default.ensureDir(import_node_path17.default.dirname(localPath));
2923
+ await import_fs_extra19.default.ensureDir(import_node_path21.default.dirname(localPath));
2592
2924
  }
2593
2925
  if (hard) {
2594
2926
  if (existsRemote) {
2595
- await import_fs_extra15.default.copy(remotePath, localPath, { overwrite: true });
2927
+ await import_fs_extra19.default.copy(remotePath, localPath, { overwrite: true });
2596
2928
  debug(`Hard update: Overwrote ${file}`);
2597
2929
  } else if (existsLocal) {
2598
- await import_fs_extra15.default.remove(localPath);
2930
+ await import_fs_extra19.default.remove(localPath);
2599
2931
  debug(`Hard update: Removed ${file}`);
2600
2932
  }
2601
2933
  continue;
@@ -2604,29 +2936,29 @@ async function updateFromRemote({
2604
2936
  if (existsLocal) {
2605
2937
  if (isBinary) {
2606
2938
  debug(`Binary collision: ${file}, overwriting.`);
2607
- await import_fs_extra15.default.copy(remotePath, localPath, { overwrite: true });
2939
+ await import_fs_extra19.default.copy(remotePath, localPath, { overwrite: true });
2608
2940
  logWarningSection(`Overwrote binary file collision: ${file}`);
2609
2941
  } else {
2610
- const emptyBase = import_node_path17.default.join(baseDir, `${file}.empty`);
2611
- await import_fs_extra15.default.ensureFile(emptyBase);
2942
+ const emptyBase = import_node_path21.default.join(baseDir, `${file}.empty`);
2943
+ await import_fs_extra19.default.ensureFile(emptyBase);
2612
2944
  const result = await git.mergeFile(localPath, emptyBase, remotePath);
2613
2945
  if (!result) {
2614
2946
  hasConflicts2 = true;
2615
2947
  conflictFiles.push(file);
2616
2948
  }
2617
- await import_fs_extra15.default.remove(emptyBase);
2949
+ await import_fs_extra19.default.remove(emptyBase);
2618
2950
  }
2619
2951
  } else {
2620
- await import_fs_extra15.default.copy(remotePath, localPath);
2952
+ await import_fs_extra19.default.copy(remotePath, localPath);
2621
2953
  }
2622
2954
  continue;
2623
2955
  }
2624
2956
  if (existsBase && !existsRemote) {
2625
2957
  if (existsLocal) {
2626
- const localBuffer = await import_fs_extra15.default.readFile(localPath);
2627
- const baseBuffer = await import_fs_extra15.default.readFile(basePath);
2958
+ const localBuffer = await import_fs_extra19.default.readFile(localPath);
2959
+ const baseBuffer = await import_fs_extra19.default.readFile(basePath);
2628
2960
  if (localBuffer.equals(baseBuffer)) {
2629
- await import_fs_extra15.default.remove(localPath);
2961
+ await import_fs_extra19.default.remove(localPath);
2630
2962
  } else {
2631
2963
  logWarningSection(
2632
2964
  `File ${file} was deleted in remote but modified locally. Kept local version.`
@@ -2637,7 +2969,7 @@ async function updateFromRemote({
2637
2969
  }
2638
2970
  if (existsBase && existsRemote) {
2639
2971
  if (!existsLocal) {
2640
- await import_fs_extra15.default.copy(remotePath, localPath);
2972
+ await import_fs_extra19.default.copy(remotePath, localPath);
2641
2973
  logWarningSection(
2642
2974
  `File restored: ${file}`,
2643
2975
  `This file was deleted locally but updated in the remote block.
@@ -2646,7 +2978,7 @@ It has been recreated to apply upstream changes.`
2646
2978
  continue;
2647
2979
  }
2648
2980
  if (isBinary) {
2649
- await import_fs_extra15.default.copy(remotePath, localPath, { overwrite: true });
2981
+ await import_fs_extra19.default.copy(remotePath, localPath, { overwrite: true });
2650
2982
  logWarningSection(`Updated binary file: ${file} (overwritten)`);
2651
2983
  } else {
2652
2984
  const result = await git.mergeFile(localPath, basePath, remotePath);
@@ -2686,6 +3018,7 @@ async function updateApp({
2686
3018
  ignore: ignore3,
2687
3019
  hard = false
2688
3020
  }) {
3021
+ let updated = false;
2689
3022
  await runTask({ start: "Update App", end: "Updated App" }, async () => {
2690
3023
  const template = templates[templateDef.name];
2691
3024
  if (!template) {
@@ -2699,12 +3032,13 @@ async function updateApp({
2699
3032
  hard
2700
3033
  });
2701
3034
  if (!toAppCommit) return;
3035
+ updated = true;
2702
3036
  if (!templateDef.bases?.length) return;
2703
3037
  for (const block of usedBlocks) {
2704
3038
  const blockRegistryData = availableBlocks[block.name];
2705
3039
  if (!blockRegistryData) return;
2706
3040
  await git.updateRemote(block.name, blockRegistryData.source);
2707
- const blockPath = import_node_path18.default.join(blocksDir, block.name);
3041
+ const blockPath = import_node_path22.default.join(blocksDir, block.name);
2708
3042
  const currentBloxFile = getBloxFile(blockPath);
2709
3043
  const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
2710
3044
  const blockFromCommit = currentBloxFile.checkpoints?.[block.name]?.commit;
@@ -2719,8 +3053,10 @@ async function updateApp({
2719
3053
  }
2720
3054
  }
2721
3055
  });
3056
+ return updated;
2722
3057
  }
2723
3058
  async function updateAppBases(templateDef, templates, ignore3, hard = false) {
3059
+ let updated = false;
2724
3060
  for (const base of templateDef.bases || []) {
2725
3061
  await runTask(
2726
3062
  { start: `Update App base: ${base.name}`, end: `Updated App base: ${base.name}` },
@@ -2730,27 +3066,40 @@ async function updateAppBases(templateDef, templates, ignore3, hard = false) {
2730
3066
  error("Selected template not available in registries");
2731
3067
  return;
2732
3068
  }
2733
- await updateFromRemote({ name: base.name, source: template.source, ignore: ignore3, hard });
3069
+ const toCommit = await updateFromRemote({
3070
+ name: base.name,
3071
+ source: template.source,
3072
+ ignore: ignore3,
3073
+ hard
3074
+ });
3075
+ if (toCommit) updated = true;
2734
3076
  }
2735
3077
  );
2736
3078
  }
3079
+ return updated;
2737
3080
  }
2738
3081
  async function updateBlock(block, blocks, ignore3, hard = false) {
2739
3082
  const blockRegistryData = blocks[block];
2740
- const blockPath = import_node_path18.default.join(blocksDir, block);
3083
+ const blockPath = import_node_path22.default.join(blocksDir, block);
3084
+ let updated = false;
2741
3085
  await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
2742
3086
  if (!blockRegistryData) {
2743
3087
  error(`Selected block: ${block} not available in registries`, false);
2744
3088
  return;
2745
3089
  }
2746
- await updateFromRemote({
3090
+ const toCommit = await updateFromRemote({
2747
3091
  name: block,
2748
3092
  source: blockRegistryData.source,
2749
3093
  dir: blockPath,
2750
3094
  ignore: ignore3,
2751
3095
  hard
2752
3096
  });
3097
+ if (toCommit) updated = true;
2753
3098
  });
3099
+ if (updated) {
3100
+ await runLifecycleHookWithTask(blockPath, "update", "Run block update");
3101
+ }
3102
+ return updated;
2754
3103
  }
2755
3104
  async function getCurrentCheckpoints() {
2756
3105
  const bloxFile = getBloxFile();
@@ -2792,7 +3141,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
2792
3141
  option("-s, --scope <scope>", "Scope of update").default("all").choices(["app", "bases", "block", "all"])
2793
3142
  ).option("--ignore <list...>", 'Files ignore list scoped by name i.e "repo:file"').option("-b, --block <name>", "Block to update, valid only with scope block").option("--hard", "Hard update (overwrite local changes)", false).action(async (args) => {
2794
3143
  if (await git.hasUncommittedChanges()) {
2795
- import_prompts21.log.warn(fmt.yellow("Make sure to commit any changes first"));
3144
+ import_prompts23.log.warn(fmt.yellow("Make sure to commit any changes first"));
2796
3145
  return;
2797
3146
  }
2798
3147
  await migrateAll(true);
@@ -2815,8 +3164,9 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
2815
3164
  ignoresByName[repo].push(pattern);
2816
3165
  }
2817
3166
  try {
3167
+ let hasUpdate = false;
2818
3168
  if (["app", "all"].includes(args.scope)) {
2819
- await updateApp({
3169
+ const appUpdated = await updateApp({
2820
3170
  templateDef,
2821
3171
  templates,
2822
3172
  usedBlocks,
@@ -2824,23 +3174,26 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
2824
3174
  ignore: ignoresByName[templateDef.name],
2825
3175
  hard: args.hard
2826
3176
  });
3177
+ hasUpdate = hasUpdate || appUpdated;
2827
3178
  }
2828
3179
  if (["bases", "all"].includes(args.scope)) {
2829
- await updateAppBases(
3180
+ const basesUpdated = await updateAppBases(
2830
3181
  templateDef,
2831
3182
  templates,
2832
3183
  ignoresByName[templateDef.name],
2833
3184
  args.hard
2834
3185
  );
3186
+ hasUpdate = hasUpdate || basesUpdated;
2835
3187
  }
2836
3188
  if (args.scope === "all") {
2837
3189
  for (const block of usedBlocks) {
2838
- await updateBlock(
3190
+ const blockUpdated = await updateBlock(
2839
3191
  block.name,
2840
3192
  availableBlocks,
2841
3193
  ignoresByName[block.name],
2842
3194
  args.hard
2843
3195
  );
3196
+ hasUpdate = hasUpdate || blockUpdated;
2844
3197
  }
2845
3198
  }
2846
3199
  if (args.scope === "block") {
@@ -2858,19 +3211,23 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
2858
3211
  error("Selected block not used in app");
2859
3212
  return;
2860
3213
  }
2861
- await updateBlock(
3214
+ const blockUpdated = await updateBlock(
2862
3215
  blockDef.name,
2863
3216
  availableBlocks,
2864
3217
  ignoresByName[blockDef.name],
2865
3218
  args.hard
2866
3219
  );
3220
+ hasUpdate = hasUpdate || blockUpdated;
3221
+ }
3222
+ if (hasUpdate) {
3223
+ await runLifecycleHookWithTask(".", "update", "Run template update");
2867
3224
  }
2868
3225
  await checkVersionsCompatibility();
2869
3226
  const endCheckpoints = await getCurrentCheckpoints();
2870
3227
  await printChangeLog(startCheckpoints, endCheckpoints);
2871
3228
  } catch (e) {
2872
3229
  if (!isDebugMode()) {
2873
- import_prompts21.log.warn("Error happened, Will rollback changes");
3230
+ import_prompts23.log.warn("Error happened, Will rollback changes");
2874
3231
  await git.rollback();
2875
3232
  }
2876
3233
  error(e);
@@ -2890,10 +3247,22 @@ var upgrade = command("upgrade").description("Upgrade blox cli to latest version
2890
3247
  });
2891
3248
 
2892
3249
  // src/commands/index.ts
2893
- var commands = [init2, add2, update2, conf, upgrade, migrateSchema, detach, contribute];
3250
+ var commands = [
3251
+ init2,
3252
+ add2,
3253
+ remove,
3254
+ update2,
3255
+ conf,
3256
+ upgrade,
3257
+ migrateSchema,
3258
+ detach,
3259
+ contribute,
3260
+ skills
3261
+ ];
2894
3262
 
2895
3263
  // bin/run.ts
2896
3264
  async function main() {
3265
+ setBloxCliVersion(version);
2897
3266
  import_extra_typings2.program.name("blox").version(version);
2898
3267
  import_extra_typings2.program.option("-d, --debug", "work in debug mode");
2899
3268
  import_extra_typings2.program.option("-m, --minimal", "work in minimal mode");