@naseej/blox 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/run.js +392 -161
  2. package/package.json +1 -1
  3. package/readme.md +24 -10
package/dist/run.js CHANGED
@@ -180,17 +180,17 @@ var checkForCliUpdate = async (currentVersion) => {
180
180
  };
181
181
 
182
182
  // package.json
183
- var version = "1.5.0";
183
+ var version = "1.5.1";
184
184
 
185
185
  // src/commands/add/index.ts
186
186
  var import_fs_extra9 = __toESM(require("fs-extra"));
187
187
 
188
188
  // src/migrations/index.ts
189
- var import_node_path7 = __toESM(require("path"));
189
+ var import_node_path8 = __toESM(require("path"));
190
190
  var import_fs_extra5 = __toESM(require("fs-extra"));
191
191
 
192
192
  // src/migrations/utils.ts
193
- var import_node_path6 = __toESM(require("path"));
193
+ var import_node_path7 = __toESM(require("path"));
194
194
  var import_fs_extra4 = __toESM(require("fs-extra"));
195
195
 
196
196
  // src/migrations/list/v1.ts
@@ -228,18 +228,18 @@ var migrationsList = [v1];
228
228
 
229
229
  // src/services/git.ts
230
230
  var import_node_os = __toESM(require("os"));
231
- var import_node_path5 = __toESM(require("path"));
231
+ var import_node_path6 = __toESM(require("path"));
232
232
  var import_fs_extra3 = __toESM(require("fs-extra"));
233
233
 
234
234
  // src/services/shell.ts
235
- var import_node_child_process = require("child_process");
236
- var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
235
+ var import_cross_spawn = __toESM(require("cross-spawn"));
236
+ var $ = async (bin, options = [], { cwd, onStdout, shell = false } = {}) => {
237
237
  debug(`Command executed: "${bin} ${options.join(" ")}" with cwd = ${cwd}`);
238
238
  return new Promise(function(resolve, reject) {
239
- const child = (0, import_node_child_process.spawn)(bin, options, { cwd, shell: true, stdio: ["pipe", "pipe", "pipe"] });
239
+ const child = (0, import_cross_spawn.default)(bin, options, { cwd, shell, stdio: ["pipe", "pipe", "pipe"] });
240
240
  let stdout = "";
241
241
  let stderr = "";
242
- child.stdout.on("data", (data) => {
242
+ child.stdout?.on("data", (data) => {
243
243
  const str = data.toString();
244
244
  stdout += str;
245
245
  try {
@@ -248,7 +248,7 @@ var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
248
248
  reject(e);
249
249
  }
250
250
  });
251
- child.stderr.on("data", (data) => {
251
+ child.stderr?.on("data", (data) => {
252
252
  stderr += data.toString();
253
253
  });
254
254
  child.on("close", function(code) {
@@ -353,10 +353,60 @@ function isBinaryFile(ext) {
353
353
  return BINARY_EXTENSIONS.has(ext);
354
354
  }
355
355
 
356
- // src/services/path.ts
356
+ // src/shared/utils/openUrlInBrowser.ts
357
+ var import_node_child_process = require("child_process");
358
+ function openUrlInBrowser(url) {
359
+ return new Promise((resolve, reject) => {
360
+ try {
361
+ let cmd;
362
+ let args;
363
+ if (process.platform === "win32") {
364
+ cmd = "cmd";
365
+ args = ["/c", "start", "", url];
366
+ } else if (process.platform === "darwin") {
367
+ cmd = "open";
368
+ args = [url];
369
+ } else {
370
+ cmd = "xdg-open";
371
+ args = [url];
372
+ }
373
+ const child = (0, import_node_child_process.execFile)(cmd, args, { windowsHide: true });
374
+ child.on("error", (err) => {
375
+ reject(err);
376
+ });
377
+ resolve();
378
+ } catch (err) {
379
+ reject(err);
380
+ }
381
+ });
382
+ }
383
+
384
+ // src/shared/utils/isBloxConfigFile.ts
357
385
  var import_node_path4 = __toESM(require("path"));
386
+ function isBloxConfigFile(file) {
387
+ const normalized = file.split(import_node_path4.default.sep).join("/");
388
+ return normalized === bloxFilePath || normalized.endsWith(`/${bloxFilePath}`);
389
+ }
390
+
391
+ // src/shared/utils/omitKeys.ts
392
+ function omitKeys(value, keysToOmit) {
393
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
394
+ return value;
395
+ }
396
+ const result = { ...value };
397
+ for (const key of keysToOmit) {
398
+ delete result[key];
399
+ }
400
+ return result;
401
+ }
402
+
403
+ // src/shared/utils/normalizeCommitRef.ts
404
+ var normalizeCommitRef = (commit2) => commit2.trim().replace(/\r/g, "").replace(/^"+|"+$/g, "");
405
+
406
+ // src/services/path.ts
407
+ var import_node_path5 = __toESM(require("path"));
358
408
  var normalizePath = (_path) => {
359
- return _path.split(import_node_path4.default.sep).join("/");
409
+ return _path.split(import_node_path5.default.sep).join("/");
360
410
  };
361
411
 
362
412
  // src/services/git.ts
@@ -387,7 +437,7 @@ var getRemoteWorktree = async (remote, commit2) => {
387
437
  return remoteWorktrees.get(key);
388
438
  }
389
439
  const tmpDir = import_node_os.default.tmpdir();
390
- const worktreeDir = import_node_path5.default.join(tmpDir, "blox-cli-worktrees", remote, commit2);
440
+ const worktreeDir = import_node_path6.default.join(tmpDir, "blox-cli-worktrees", remote, commit2);
391
441
  try {
392
442
  await $("git", ["worktree", "prune"]);
393
443
  } catch {
@@ -430,14 +480,20 @@ var checkAuth = (message) => {
430
480
  var defaultShellOptions = {
431
481
  onStdout: checkAuth
432
482
  };
433
- var clone = (repoUrl, options, branch = defaultBranch, shellOptions = {}) => {
434
- return $("git", ["clone", "--progress", repoUrl, "--branch", branch, options], {
483
+ var clone = (repoUrl, dir, branch = defaultBranch, options = {}) => {
484
+ const { depth, ...shellOptions } = options;
485
+ const args = ["clone", "--progress"];
486
+ if (depth != null && depth > 0) {
487
+ args.push("--depth", String(depth));
488
+ }
489
+ args.push(repoUrl, "--branch", branch, dir);
490
+ return $("git", args, {
435
491
  ...defaultShellOptions,
436
492
  ...shellOptions
437
493
  });
438
494
  };
439
495
  var resetToCommit = async (commit2, cwd = ".") => {
440
- await $("git", ["reset --hard", `${commit2}`], { cwd });
496
+ await $("git", ["reset", "--hard", commit2], { cwd });
441
497
  };
442
498
  var updatedRemotes = /* @__PURE__ */ new Set();
443
499
  var updateRemote = async (name, source, shellOptions = {}) => {
@@ -459,10 +515,12 @@ var updateRemote = async (name, source, shellOptions = {}) => {
459
515
  });
460
516
  await $("git", ["fetch", name], { ...defaultShellOptions, ...shellOptions });
461
517
  };
462
- var readJsonFromCommit = async (commit2, file) => {
518
+ var readJsonFromCommit = async (commit2, file, cwd = ".") => {
463
519
  try {
464
520
  let content = "";
465
- await $("git", ["show", `${commit2}:${file}`], {
521
+ const p = normalizePath(file);
522
+ await $("git", ["show", `${commit2}:${p}`], {
523
+ cwd,
466
524
  onStdout: (text2) => {
467
525
  content = text2;
468
526
  }
@@ -472,12 +530,27 @@ var readJsonFromCommit = async (commit2, file) => {
472
530
  return {};
473
531
  }
474
532
  };
533
+ var readJsonFromIndex = async (file, cwd = ".") => {
534
+ try {
535
+ let content = "";
536
+ const p = normalizePath(file);
537
+ await $("git", ["show", `:0:${p}`], {
538
+ cwd,
539
+ onStdout: (text2) => {
540
+ content = text2;
541
+ }
542
+ });
543
+ return JSON.parse(content);
544
+ } catch {
545
+ return null;
546
+ }
547
+ };
475
548
  var readJsonFromRemote = async (remote, file, branch = defaultBranch, commit2) => {
476
549
  return readJsonFromCommit(commit2 || `${remote}/${branch}`, file);
477
550
  };
478
551
  var isCommitOlder = async (a, b) => {
479
552
  try {
480
- await $("git", ["merge-base --is-ancestor", a, b]);
553
+ await $("git", ["merge-base", "--is-ancestor", a, b]);
481
554
  return true;
482
555
  } catch {
483
556
  return false;
@@ -489,8 +562,8 @@ var update = (shellOptions = {}) => {
489
562
  var getLatestCommitFromRemote = async (remote, branch) => {
490
563
  return getLatestCommit(`${remote}/${branch}`);
491
564
  };
492
- var getLatestCommitFromPath = async (path17) => {
493
- return getLatestCommit("HEAD", path17);
565
+ var getLatestCommitFromPath = async (path19) => {
566
+ return getLatestCommit("HEAD", path19);
494
567
  };
495
568
  var getLatestCommit = async (rev, cwd = ".") => {
496
569
  debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
@@ -501,7 +574,7 @@ var getLatestCommit = async (rev, cwd = ".") => {
501
574
  commit2 = text2;
502
575
  }
503
576
  });
504
- return commit2.replace(/\n/g, "");
577
+ return commit2.replace(/\r?\n/g, "").trim();
505
578
  };
506
579
  var getChangesLog = async (fromCommit, toCommit) => {
507
580
  let changes = "";
@@ -514,7 +587,7 @@ var getChangesLog = async (fromCommit, toCommit) => {
514
587
  };
515
588
  var unInit = (cwd) => {
516
589
  debug("UnInit");
517
- return import_fs_extra3.default.remove(import_node_path5.default.join(cwd, ".git"));
590
+ return import_fs_extra3.default.remove(import_node_path6.default.join(cwd, ".git"));
518
591
  };
519
592
  var init = async (cwd) => {
520
593
  debug("Init");
@@ -529,7 +602,7 @@ var add = async (toAdd, cwd = ".") => {
529
602
  };
530
603
  var commit = async (msg, cwd = ".") => {
531
604
  debug(`Git commit: ${msg}`);
532
- await $("git", ["commit", "--no-verify", "-m", `"${msg}"`], { cwd });
605
+ await $("git", ["commit", "--no-verify", "-m", msg], { cwd });
533
606
  };
534
607
  var rollback = async () => {
535
608
  debug("Rollback");
@@ -631,11 +704,11 @@ var createBranch = async (branch, from, cwd = ".") => {
631
704
  var push = async (remote, branch, cwd = ".") => {
632
705
  await $("git", ["push", "--progress", remote, `refs/heads/${branch}`], { cwd });
633
706
  };
634
- var checkoutFile = async (path17, ref, cwd = ".") => {
707
+ var checkoutFile = async (path19, ref, cwd = ".") => {
635
708
  const args = ["checkout"];
636
709
  if (ref) args.push(ref);
637
710
  else args.push("HEAD");
638
- args.push("--", path17);
711
+ args.push("--", path19);
639
712
  await $("git", args, { cwd });
640
713
  };
641
714
  var pathExistsAsBlobInRev = async (rev, filePath, cwd = ".") => {
@@ -659,7 +732,7 @@ var listCommits = async (limit, skip, cwd = ".") => {
659
732
  let out = "";
660
733
  await $(
661
734
  "git",
662
- ["log", '--pretty=format:"%H|%s"', "-n", String(limit), "--skip", String(skip), "HEAD"],
735
+ ["log", "--pretty=format:%H|%s", "-n", String(limit), "--skip", String(skip), "HEAD"],
663
736
  {
664
737
  cwd,
665
738
  onStdout: (text2) => {
@@ -667,28 +740,30 @@ var listCommits = async (limit, skip, cwd = ".") => {
667
740
  }
668
741
  }
669
742
  );
670
- const lines = out.split("\n").filter(Boolean);
743
+ const lines = out.split(/\r?\n/).filter(Boolean);
671
744
  return lines.map((line) => {
672
745
  const pipe = line.indexOf("|");
673
- const hash = pipe >= 0 ? line.slice(0, pipe) : line;
674
- const subject = pipe >= 0 ? line.slice(pipe + 1) : "";
675
- return { hash: hash.trim(), subject: subject.trim() };
746
+ const hashRaw = pipe >= 0 ? line.slice(0, pipe) : line;
747
+ const subjectRaw = pipe >= 0 ? line.slice(pipe + 1) : "";
748
+ const hash = hashRaw.trim().replace(/^"+|"+$/g, "");
749
+ return { hash, subject: subjectRaw.trim() };
676
750
  });
677
751
  };
678
752
  var fetchCommit = async (fromRepo, commit2, cwd = ".") => {
679
- await $("git", ["fetch", fromRepo, commit2], { cwd });
753
+ const ref = normalizeCommitRef(commit2);
754
+ await $("git", ["fetch", fromRepo, `+${ref}:FETCH_HEAD`], { cwd });
680
755
  };
681
756
  var cherryPick = async (commitHash, subtree, noCommit, cwd = ".") => {
682
757
  const args = ["cherry-pick"];
683
758
  if (noCommit) args.push("--no-commit");
684
759
  if (subtree) args.push(`-Xsubtree=${subtree}`);
685
- args.push(commitHash);
760
+ args.push(normalizeCommitRef(commitHash));
686
761
  await $("git", args, { cwd });
687
762
  };
688
- var reset = async (path17, hard, cwd = ".") => {
763
+ var reset = async (path19, hard, cwd = ".") => {
689
764
  const args = ["reset"];
690
765
  if (hard) args.push("--hard");
691
- if (path17) args.push(path17);
766
+ if (path19) args.push(path19);
692
767
  await $("git", args, { cwd });
693
768
  };
694
769
  var commitAll = async (message, cwd = ".") => {
@@ -728,6 +803,7 @@ var git = {
728
803
  getChangesLog,
729
804
  updateRemote,
730
805
  readJsonFromCommit,
806
+ readJsonFromIndex,
731
807
  readJsonFromRemote,
732
808
  isCommitOlder,
733
809
  rollback,
@@ -869,7 +945,7 @@ async function migrate(name, { getPath = (f) => f, read, write }) {
869
945
  }
870
946
  function migrateOnLocal(name, cwd = ".") {
871
947
  return migrate(name, {
872
- getPath: (file) => import_node_path6.default.join(cwd, file),
948
+ getPath: (file) => import_node_path7.default.join(cwd, file),
873
949
  read: import_fs_extra4.default.readJson,
874
950
  write: import_fs_extra4.default.writeFile
875
951
  });
@@ -877,7 +953,7 @@ function migrateOnLocal(name, cwd = ".") {
877
953
  function migrateOnRemote(name, commit2, cwd) {
878
954
  return migrate(name, {
879
955
  read: (file) => git.readJsonFromCommit(commit2, file),
880
- getPath: cwd ? (file) => import_node_path6.default.join(cwd, file) : void 0
956
+ getPath: cwd ? (file) => import_node_path7.default.join(cwd, file) : void 0
881
957
  });
882
958
  }
883
959
 
@@ -886,7 +962,7 @@ async function migrateAll(autoCommit) {
886
962
  let filesChanged = (await migrateOnLocal("app")).filesChanged;
887
963
  const blocks = import_fs_extra5.default.existsSync(blocksDir) ? import_fs_extra5.default.readdirSync(blocksDir) : [];
888
964
  for (const block of blocks) {
889
- const res = await migrateOnLocal(block, import_node_path7.default.join(blocksDir, block));
965
+ const res = await migrateOnLocal(block, import_node_path8.default.join(blocksDir, block));
890
966
  filesChanged = filesChanged || res.filesChanged;
891
967
  }
892
968
  if (autoCommit && filesChanged && await git.hasUncommittedChanges()) {
@@ -897,7 +973,7 @@ async function migrateAll(autoCommit) {
897
973
  }
898
974
 
899
975
  // src/services/fs.ts
900
- var import_node_path8 = __toESM(require("path"));
976
+ var import_node_path9 = __toESM(require("path"));
901
977
  var import_fs_extra6 = __toESM(require("fs-extra"));
902
978
  var import_ignore2 = __toESM(require("ignore"));
903
979
  var import_klaw = __toESM(require("klaw"));
@@ -907,7 +983,7 @@ var filterBlacklisted = (item) => {
907
983
  var deletePattern = async (cwd, patterns = []) => {
908
984
  const ig = (0, import_ignore2.default)().add(patterns);
909
985
  for await (const file of (0, import_klaw.default)(cwd, { filter: filterBlacklisted })) {
910
- const relativePath = import_node_path8.default.relative(cwd, file.path);
986
+ const relativePath = import_node_path9.default.relative(cwd, file.path);
911
987
  if (relativePath && ig.ignores(relativePath)) {
912
988
  if (!await import_fs_extra6.default.exists(file.path)) {
913
989
  continue;
@@ -919,7 +995,7 @@ var deletePattern = async (cwd, patterns = []) => {
919
995
  };
920
996
 
921
997
  // src/services/registry.ts
922
- var import_node_path9 = __toESM(require("path"));
998
+ var import_node_path10 = __toESM(require("path"));
923
999
  var import_fs_extra7 = __toESM(require("fs-extra"));
924
1000
  var import_merge = __toESM(require("lodash/merge"));
925
1001
 
@@ -955,7 +1031,7 @@ async function runTask(message, task) {
955
1031
  }
956
1032
 
957
1033
  // src/services/registry.ts
958
- var registriesDataPath = import_node_path9.default.join(appPaths.data, "registries");
1034
+ var registriesDataPath = import_node_path10.default.join(appPaths.data, "registries");
959
1035
  var upeToDate = false;
960
1036
  var syncRegistries = async (branch) => {
961
1037
  if (upeToDate) return;
@@ -968,10 +1044,13 @@ var syncRegistries = async (branch) => {
968
1044
  config.registries.map(async (registry) => {
969
1045
  debug(`update registry: ${registry}`);
970
1046
  const repoName = registry.split("/").pop() || "";
971
- const repoDir = import_node_path9.default.join(registriesDataPath, repoName);
1047
+ const repoDir = import_node_path10.default.join(registriesDataPath, repoName);
972
1048
  if (!import_fs_extra7.default.existsSync(repoDir)) {
973
- await git.clone(registry, "--depth 1", branch, { cwd: registriesDataPath });
974
- } else if (import_fs_extra7.default.existsSync(import_node_path9.default.join(repoDir, ".git"))) {
1049
+ await git.clone(registry, repoName, branch, {
1050
+ cwd: registriesDataPath,
1051
+ depth: 1
1052
+ });
1053
+ } else if (import_fs_extra7.default.existsSync(import_node_path10.default.join(repoDir, ".git"))) {
975
1054
  await git.update({ cwd: repoDir });
976
1055
  } else {
977
1056
  debug(`local registry`);
@@ -985,7 +1064,7 @@ var getAvailableTemplates = async () => {
985
1064
  const templates = {};
986
1065
  const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
987
1066
  for (const registry of registries) {
988
- const indexPath = import_node_path9.default.join(registriesDataPath, registry, "index.json");
1067
+ const indexPath = import_node_path10.default.join(registriesDataPath, registry, "index.json");
989
1068
  if (import_fs_extra7.default.existsSync(indexPath)) {
990
1069
  const data = import_fs_extra7.default.readJSONSync(indexPath);
991
1070
  Object.entries(data.templates || {}).forEach(([templateName, template]) => {
@@ -1029,14 +1108,14 @@ var getAvailableBlocks = async (templateInfo) => {
1029
1108
  var getAvailableVersions = async (source) => {
1030
1109
  const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
1031
1110
  for (const registry of registries) {
1032
- const registryPath = import_node_path9.default.join(registriesDataPath, registry);
1033
- const indexPath = import_node_path9.default.join(registryPath, "index.json");
1111
+ const registryPath = import_node_path10.default.join(registriesDataPath, registry);
1112
+ const indexPath = import_node_path10.default.join(registryPath, "index.json");
1034
1113
  if (!import_fs_extra7.default.existsSync(indexPath)) continue;
1035
1114
  const registryData = import_fs_extra7.default.readJSONSync(indexPath);
1036
- const versionDirPath = import_node_path9.default.join(registryPath, "versions");
1115
+ const versionDirPath = import_node_path10.default.join(registryPath, "versions");
1037
1116
  const versionsFilePaths = [
1038
- import_node_path9.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
1039
- import_node_path9.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
1117
+ import_node_path10.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
1118
+ import_node_path10.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
1040
1119
  ];
1041
1120
  for (const versionsFile of versionsFilePaths) {
1042
1121
  if (import_fs_extra7.default.existsSync(versionsFile)) {
@@ -1047,7 +1126,7 @@ var getAvailableVersions = async (source) => {
1047
1126
  };
1048
1127
 
1049
1128
  // src/services/template.ts
1050
- var import_node_path10 = __toESM(require("path"));
1129
+ var import_node_path11 = __toESM(require("path"));
1051
1130
  var import_ejs = __toESM(require("ejs"));
1052
1131
  var import_fs_extra8 = __toESM(require("fs-extra"));
1053
1132
  var import_klaw2 = __toESM(require("klaw"));
@@ -1055,7 +1134,7 @@ async function replacePlaceholders(dir, context) {
1055
1134
  debug("Replace placeholders");
1056
1135
  for await (const file of (0, import_klaw2.default)(dir)) {
1057
1136
  if (!file.stats.isFile()) continue;
1058
- const ext = import_node_path10.default.extname(file.path).toLowerCase();
1137
+ const ext = import_node_path11.default.extname(file.path).toLowerCase();
1059
1138
  if (isBinaryFile(ext)) {
1060
1139
  continue;
1061
1140
  }
@@ -1086,7 +1165,7 @@ function getBlockDef(cwd = ".") {
1086
1165
  }
1087
1166
  function getBloxFile(cwd = ".") {
1088
1167
  try {
1089
- const file = import_fs_extra8.default.readJSONSync(import_node_path10.default.join(cwd, bloxFilePath));
1168
+ const file = import_fs_extra8.default.readJSONSync(import_node_path11.default.join(cwd, bloxFilePath));
1090
1169
  if (!file.checkpoints) {
1091
1170
  file.checkpoints = {};
1092
1171
  }
@@ -1097,7 +1176,7 @@ function getBloxFile(cwd = ".") {
1097
1176
  }
1098
1177
  function saveBloxFile(info, cwd = ".") {
1099
1178
  debug("Save info");
1100
- import_fs_extra8.default.writeFileSync(import_node_path10.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
1179
+ import_fs_extra8.default.writeFileSync(import_node_path11.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
1101
1180
  }
1102
1181
  function updateCheckpoint(name, checkpoint, cwd = ".") {
1103
1182
  const info = getBloxFile(cwd);
@@ -1118,7 +1197,7 @@ function getUsedBlocks() {
1118
1197
  if (!file.isDirectory()) {
1119
1198
  return;
1120
1199
  }
1121
- const blockDef = getBloxFile(import_node_path10.default.join(blocksDir, file.name));
1200
+ const blockDef = getBloxFile(import_node_path11.default.join(blocksDir, file.name));
1122
1201
  if (blockDef && blockDef.definition) {
1123
1202
  blocks.push(blockDef);
1124
1203
  }
@@ -1256,7 +1335,7 @@ function runInitScript(cwd) {
1256
1335
  debug(`Run init script in: ${cwd}`);
1257
1336
  const info = getTemplateDef(cwd);
1258
1337
  if (info.init) {
1259
- return $(info.init, [], { cwd });
1338
+ return $(info.init, [], { cwd, shell: true });
1260
1339
  }
1261
1340
  }
1262
1341
 
@@ -1380,7 +1459,7 @@ var ContributionTargetType = /* @__PURE__ */ ((ContributionTargetType2) => {
1380
1459
  })(ContributionTargetType || {});
1381
1460
 
1382
1461
  // src/services/contribute/utils/bloxCheckpoint.ts
1383
- var import_node_path11 = __toESM(require("path"));
1462
+ var import_node_path12 = __toESM(require("path"));
1384
1463
  function getCheckpointForTarget(cwd, target) {
1385
1464
  const bloxDir = getBloxDirForTarget(cwd, target);
1386
1465
  const blox = getBloxFile(bloxDir);
@@ -1390,7 +1469,7 @@ function getCheckpointForTarget(cwd, target) {
1390
1469
  }
1391
1470
  function getBloxDirForTarget(cwd, target) {
1392
1471
  if (target.type === "block" /* BLOCK */) {
1393
- return import_node_path11.default.join(cwd, blocksDir, target.name);
1472
+ return import_node_path12.default.join(cwd, blocksDir, target.name);
1394
1473
  }
1395
1474
  return cwd;
1396
1475
  }
@@ -1420,11 +1499,6 @@ var getTargetRepoUrl = async (target) => {
1420
1499
  return blockSource;
1421
1500
  };
1422
1501
 
1423
- // src/services/contribute/utils/sleep.ts
1424
- async function sleep(ms2) {
1425
- await new Promise((r) => setTimeout(r, ms2));
1426
- }
1427
-
1428
1502
  // src/services/contribute/utils/slugifyTitle.ts
1429
1503
  function slugifyTitle(title) {
1430
1504
  const s = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
@@ -1497,14 +1571,28 @@ var ContributionWorkflow = class {
1497
1571
  title,
1498
1572
  description
1499
1573
  });
1500
- await this.pushWithRetry(tmpCwd, "origin", branch);
1501
- const pr = await this.pullRequest.printPullRequestInstructions({
1574
+ await this.pullRequest.pushBranch({
1575
+ cwd: tmpCwd,
1576
+ remote: "origin",
1577
+ branch,
1578
+ onAttemptFailed: ({ attempt, error: error2 }) => this.logger.warn("push.failed", { attempt, error: error2 })
1579
+ });
1580
+ this.logger.info("branch.pushed", {
1581
+ branch,
1582
+ remote: repoUrl
1583
+ });
1584
+ this.pullRequest.printPushSummary({
1502
1585
  repoUrl,
1503
1586
  sourceBranch: branch,
1504
1587
  targetBranch: remoteBranch,
1505
1588
  title,
1506
1589
  description
1507
1590
  });
1591
+ const pr = await this.pullRequest.openPullRequestPage({
1592
+ repoUrl,
1593
+ sourceBranch: branch,
1594
+ targetBranch: remoteBranch
1595
+ });
1508
1596
  this.logCompletion(pr.prUrl);
1509
1597
  return {
1510
1598
  branch,
@@ -1638,50 +1726,34 @@ Expected remote ${remoteHead}, local checkpoint ${checkpoint.commit}.`
1638
1726
  logCompletion(prUrl) {
1639
1727
  import_prompts2.log.success(
1640
1728
  fmt.green("Contribution flow completed.") + (prUrl ? `
1641
- PR URL:
1642
- ${prUrl}` : "\nPush completed. Create the PR using the instructions above.")
1729
+ Pull Request (new):
1730
+ ${prUrl}` : "\nPush completed.")
1643
1731
  );
1644
1732
  }
1645
- async pushWithRetry(cwd, remote, branch) {
1646
- const maxAttempts = 3;
1647
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
1648
- try {
1649
- await git.push(remote, branch, cwd);
1650
- return;
1651
- } catch (e) {
1652
- this.logger.warn("push.failed", {
1653
- attempt,
1654
- error: e instanceof Error ? e.message : String(e)
1655
- });
1656
- if (attempt === maxAttempts) {
1657
- throw new Error(
1658
- `git push failed after ${maxAttempts} attempts: ${e instanceof Error ? e.message : String(e)}`
1659
- );
1660
- }
1661
- await sleep(500 * attempt);
1662
- }
1663
- }
1664
- }
1665
1733
  };
1666
1734
 
1735
+ // src/services/contribute/services/CommitApplierService.ts
1736
+ var import_node_path14 = __toESM(require("path"));
1737
+ var import_fs_extra11 = __toESM(require("fs-extra"));
1738
+
1667
1739
  // src/services/contribute/config/index.ts
1668
1740
  var tempRepoName = "tmp";
1669
- var alwaysSkipPatterns = [/\.blox$/];
1741
+ var bloxConfigControlledKeys = ["checkpoints"];
1670
1742
 
1671
1743
  // src/services/contribute/utils/getExcludedPrefixesForTarget.ts
1672
- var import_node_path12 = __toESM(require("path"));
1744
+ var import_node_path13 = __toESM(require("path"));
1673
1745
  var import_fs_extra10 = __toESM(require("fs-extra"));
1674
1746
  function getExcludedPrefixesForTarget(target, cwd) {
1675
1747
  if (target.type === "block" /* BLOCK */) {
1676
1748
  return [];
1677
1749
  }
1678
1750
  const excluded = [];
1679
- const blocksPath = import_node_path12.default.join(cwd, blocksDir);
1751
+ const blocksPath = import_node_path13.default.join(cwd, blocksDir);
1680
1752
  if (import_fs_extra10.default.existsSync(blocksPath)) {
1681
1753
  const entries = import_fs_extra10.default.readdirSync(blocksPath, { withFileTypes: true });
1682
1754
  for (const entry of entries) {
1683
1755
  if (!entry.isDirectory()) continue;
1684
- const blockBloxFile = import_node_path12.default.join(blocksPath, entry.name, bloxFilePath);
1756
+ const blockBloxFile = import_node_path13.default.join(blocksPath, entry.name, bloxFilePath);
1685
1757
  if (import_fs_extra10.default.existsSync(blockBloxFile)) {
1686
1758
  excluded.push(normalizePath(`${blocksDir}/${entry.name}/`));
1687
1759
  }
@@ -1736,7 +1808,7 @@ var CommitApplierService = class {
1736
1808
  message: e instanceof Error ? e.message : String(e)
1737
1809
  });
1738
1810
  }
1739
- await this.revertExcludedStagedFiles(opts.tmpRepoCwd, commit2, exclusion);
1811
+ await this.revertExcludedStagedFiles(opts.tmpRepoCwd, commit2, exclusion, opts.target);
1740
1812
  const remainingConflicts = await git.getUnmergedFiles(opts.tmpRepoCwd);
1741
1813
  if (remainingConflicts.length) {
1742
1814
  this.logger.error("apply.commit.conflicts", {
@@ -1756,23 +1828,72 @@ Resolve manually in the temp repo:
1756
1828
  ${e instanceof Error ? e.message : String(e)}`);
1757
1829
  }
1758
1830
  }
1759
- async revertExcludedStagedFiles(tmpRepoCwd, commit2, exclusion) {
1831
+ async revertExcludedStagedFiles(tmpRepoCwd, commit2, exclusion, target) {
1760
1832
  const stagedFiles = await git.getStagedFiles(tmpRepoCwd);
1761
1833
  const unmergedFiles = await git.getUnmergedFiles(tmpRepoCwd);
1762
1834
  const allTouchedFiles = [.../* @__PURE__ */ new Set([...stagedFiles, ...unmergedFiles])];
1763
1835
  for (const file of allTouchedFiles) {
1764
- const isAlwaysSkipped = alwaysSkipPatterns.some((p) => p.test(file));
1836
+ const isBloxFile = isBloxConfigFile(file);
1765
1837
  const isExcludedByTarget = shouldExcludeFile(file, exclusion);
1766
- if (isAlwaysSkipped || isExcludedByTarget) {
1767
- this.logger.warn("apply.commit.skip_file", {
1768
- commit: commit2.slice(0, 7),
1769
- file,
1770
- reason: isAlwaysSkipped ? "always-skip" : "target-exclusion"
1771
- });
1838
+ if (isExcludedByTarget) {
1839
+ this.logger.warn("apply.commit.skip_file", { file });
1772
1840
  await git.revertPathToHead(file, tmpRepoCwd);
1841
+ continue;
1842
+ }
1843
+ if (isBloxFile) {
1844
+ await this.applyBloxConfigFileRevertPolicy(
1845
+ file,
1846
+ tmpRepoCwd,
1847
+ commit2,
1848
+ unmergedFiles,
1849
+ target
1850
+ );
1851
+ continue;
1773
1852
  }
1774
1853
  }
1775
1854
  }
1855
+ async applyBloxConfigFileRevertPolicy(file, tmpRepoCwd, commit2, unmergedFiles, target) {
1856
+ if (target.type === "base" /* BASE */) {
1857
+ this.logger.warn(
1858
+ "[.blox] revert policy: You cannot contribute the .blox file of a base from a template."
1859
+ );
1860
+ await git.revertPathToHead(file, tmpRepoCwd);
1861
+ return;
1862
+ }
1863
+ if (unmergedFiles.includes(file)) {
1864
+ this.logger.debug("apply.commit.blox_merge_fallback", { file });
1865
+ await git.revertPathToHead(file, tmpRepoCwd);
1866
+ return;
1867
+ }
1868
+ const headJson = await git.readJsonFromCommit("HEAD", file, tmpRepoCwd);
1869
+ const headObj = headJson !== null && typeof headJson === "object" && !Array.isArray(headJson) ? headJson : null;
1870
+ const headDefinesAllGovernedKeys = bloxConfigControlledKeys.every(
1871
+ (key) => headObj !== null && Object.prototype.hasOwnProperty.call(headObj, key)
1872
+ );
1873
+ if (headDefinesAllGovernedKeys) {
1874
+ return;
1875
+ }
1876
+ const stagedJson = await git.readJsonFromIndex(file, tmpRepoCwd);
1877
+ if (stagedJson === null) {
1878
+ this.logger.debug("apply.commit.blox_merge_fallback", { file });
1879
+ await git.revertPathToHead(file, tmpRepoCwd);
1880
+ return;
1881
+ }
1882
+ const withoutGovernedKeys = omitKeys(stagedJson, bloxConfigControlledKeys);
1883
+ try {
1884
+ const outPath = import_node_path14.default.join(tmpRepoCwd, file);
1885
+ await import_fs_extra11.default.outputFile(outPath, JSON.stringify(withoutGovernedKeys, null, 2));
1886
+ await git.add(file, tmpRepoCwd);
1887
+ } catch (e) {
1888
+ this.logger.warn("apply.commit.blox_merge_fallback", {
1889
+ commit: commit2.slice(0, 7),
1890
+ file,
1891
+ reason: "write-failed",
1892
+ message: e instanceof Error ? e.message : String(e)
1893
+ });
1894
+ await git.revertPathToHead(file, tmpRepoCwd);
1895
+ }
1896
+ }
1776
1897
  async waitUntilUserResolvesConflicts(tmpRepoCwd, commit2) {
1777
1898
  let remainingConflicts = await git.getUnmergedFiles(tmpRepoCwd);
1778
1899
  while (remainingConflicts.length) {
@@ -1843,7 +1964,7 @@ var CommitSelectorService = class {
1843
1964
  break;
1844
1965
  }
1845
1966
  const value = await multiselect({
1846
- message: `Select commits ${fmt.gray(`(page ${page + 1})`)}`,
1967
+ message: `Select commits (Press <space> to select, <enter> to continue) ${fmt.gray(`(page ${page + 1})`)}`,
1847
1968
  options: commits.map((c) => ({
1848
1969
  value: c.hash,
1849
1970
  label: `${c.hash.slice(0, 7)} ${c.subject}`
@@ -1878,13 +1999,13 @@ var CommitSelectorService = class {
1878
1999
  };
1879
2000
 
1880
2001
  // src/services/contribute/utils/discoverContributionTargets.ts
1881
- var import_node_path13 = __toESM(require("path"));
1882
- var import_fs_extra11 = __toESM(require("fs-extra"));
2002
+ var import_node_path15 = __toESM(require("path"));
2003
+ var import_fs_extra12 = __toESM(require("fs-extra"));
1883
2004
  var readBloxFileIfExists = (cwd) => {
1884
- const p = import_node_path13.default.join(cwd, bloxFilePath);
1885
- if (!import_fs_extra11.default.existsSync(p)) return;
2005
+ const p = import_node_path15.default.join(cwd, bloxFilePath);
2006
+ if (!import_fs_extra12.default.existsSync(p)) return;
1886
2007
  try {
1887
- return import_fs_extra11.default.readJSONSync(p);
2008
+ return import_fs_extra12.default.readJSONSync(p);
1888
2009
  } catch {
1889
2010
  return;
1890
2011
  }
@@ -1912,13 +2033,13 @@ var discoverContributionTargets = (cwd) => {
1912
2033
  });
1913
2034
  }
1914
2035
  }
1915
- const blocksPath = import_node_path13.default.join(cwd, blocksDir);
1916
- if (import_fs_extra11.default.existsSync(blocksPath)) {
1917
- const entries = import_fs_extra11.default.readdirSync(blocksPath, { withFileTypes: true });
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 });
1918
2039
  for (const entry of entries) {
1919
2040
  if (!entry.isDirectory()) continue;
1920
2041
  const blockName = entry.name;
1921
- const blockBlox = readBloxFileIfExists(import_node_path13.default.join(blocksPath, blockName));
2042
+ const blockBlox = readBloxFileIfExists(import_node_path15.default.join(blocksPath, blockName));
1922
2043
  if (!blockBlox?.definition?.name) continue;
1923
2044
  const def = blockBlox.definition;
1924
2045
  const templateName = def.templates?.[0]?.name || appTemplateName;
@@ -2056,47 +2177,157 @@ ${fmt.gray(
2056
2177
  }
2057
2178
  };
2058
2179
 
2180
+ // src/services/contribute/utils/buildPullRequestUrl.ts
2181
+ function buildPullRequestUrl(parsed, sourceBranch, targetBranch) {
2182
+ const repo = encodeURIComponent(parsed.repositoryId);
2183
+ const base = `${parsed.projectApiRootUrl}/_git/${repo}/pullrequestcreate`;
2184
+ const q = new URLSearchParams({
2185
+ sourceRef: sourceBranch,
2186
+ targetRef: targetBranch
2187
+ });
2188
+ return `${base}?${q.toString()}`;
2189
+ }
2190
+
2191
+ // src/services/contribute/utils/extractAzureRepoInfoFromGit.ts
2192
+ function extractAzureRepoInfoFromGit(rawUrl) {
2193
+ const trimmed = rawUrl.trim().replace(/\.git$/i, "");
2194
+ const ssh = trimmed.match(/^git@ssh\.dev\.azure\.com:v3\/([^/]+)\/([^/]+)\/(.+)$/i);
2195
+ if (ssh?.[1] && ssh[2] && ssh[3]) {
2196
+ const organization = decodeURIComponent(ssh[1]);
2197
+ const project = decodeURIComponent(ssh[2]);
2198
+ const repositoryId2 = decodeURIComponent(ssh[3]);
2199
+ const pathPrefix2 = `/${encodeURIComponent(organization)}/${encodeURIComponent(project)}`;
2200
+ return {
2201
+ projectApiRootUrl: joinProjectRoot("https://dev.azure.com", pathPrefix2),
2202
+ repositoryId: repositoryId2
2203
+ };
2204
+ }
2205
+ let parsed;
2206
+ try {
2207
+ parsed = new URL(trimmed);
2208
+ } catch {
2209
+ return null;
2210
+ }
2211
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
2212
+ return null;
2213
+ }
2214
+ const pathname = (parsed.pathname || "/").replace(/\/+$/, "") || "/";
2215
+ const lower = pathname.toLowerCase();
2216
+ const marker = "/_git/";
2217
+ const gitAt = lower.indexOf(marker);
2218
+ if (gitAt === -1) {
2219
+ return null;
2220
+ }
2221
+ const pathPrefix = pathname.slice(0, gitAt);
2222
+ const repoPath = pathname.slice(gitAt + marker.length);
2223
+ if (!pathPrefix || pathPrefix === "/" || !repoPath) {
2224
+ return null;
2225
+ }
2226
+ const depth = pathPrefix.split("/").filter(Boolean).length;
2227
+ if (depth < 2) {
2228
+ return null;
2229
+ }
2230
+ const repositoryId = decodeURIComponent(repoPath.split("/").filter(Boolean).join("/"));
2231
+ if (!repositoryId) {
2232
+ return null;
2233
+ }
2234
+ return {
2235
+ projectApiRootUrl: joinProjectRoot(parsed.origin, pathPrefix),
2236
+ repositoryId
2237
+ };
2238
+ }
2239
+ function joinProjectRoot(origin, pathPrefix) {
2240
+ const prefix = pathPrefix.startsWith("/") ? pathPrefix : `/${pathPrefix}`;
2241
+ return `${origin.replace(/\/$/, "")}${prefix}`.replace(/\/$/, "");
2242
+ }
2243
+
2244
+ // src/services/contribute/utils/sleep.ts
2245
+ async function sleep(ms2) {
2246
+ await new Promise((r) => setTimeout(r, ms2));
2247
+ }
2248
+
2059
2249
  // src/services/contribute/services/PullRequestService.ts
2060
2250
  var PullRequestService = class {
2061
2251
  constructor(logger) {
2062
2252
  this.logger = logger;
2063
2253
  }
2064
- async printPullRequestInstructions(opts) {
2065
- this.logger.debug("pr.instructions", opts);
2066
- const header = fmt.bold(fmt.cyan("NEXT STEPS: CREATE YOUR PULL REQUEST "));
2067
- const subHeader = fmt.gray(" Push successful! Please finalize the PR in Azure DevOps. ");
2254
+ async pushBranch(opts) {
2255
+ const maxAttempts = opts.maxAttempts ?? 3;
2256
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
2257
+ try {
2258
+ await git.push(opts.remote, opts.branch, opts.cwd);
2259
+ return;
2260
+ } catch (e) {
2261
+ const message = e instanceof Error ? e.message : String(e);
2262
+ opts.onAttemptFailed?.({ attempt, error: message });
2263
+ if (attempt === maxAttempts) {
2264
+ throw new Error(`git push failed after ${maxAttempts} attempts: ${message}`);
2265
+ }
2266
+ await sleep(500 * attempt);
2267
+ }
2268
+ }
2269
+ }
2270
+ printPushSummary(opts) {
2068
2271
  const line = "\u2501".repeat(60);
2272
+ const header = fmt.bold(fmt.cyan("BRANCH PUSHED"));
2069
2273
  import_prompts2.log.message(
2070
2274
  `
2071
2275
  ${fmt.cyan("\u25E2")}${line}${fmt.cyan("\u25E3")}
2072
2276
  ${header}
2073
- ${subHeader}
2074
2277
 
2075
2278
  ${fmt.bold("Target:")} ${fmt.green(opts.targetBranch)}
2076
2279
  ${fmt.bold("Source:")} ${fmt.yellow(opts.sourceBranch)}
2077
- ${fmt.bold("URL:")} ${fmt.blue(opts.repoUrl)}
2280
+ ${fmt.bold("Remote:")} ${fmt.blue(opts.repoUrl)}
2078
2281
  ${fmt.bold("Title:")} ${opts.title}
2079
- ` + (opts.description ? `
2282
+ ` + (opts.description.trim() ? `
2080
2283
  ${fmt.gray("Description:")}
2081
- ${opts.description}
2284
+ ${opts.description.trim()}
2082
2285
  ` : "") + `${fmt.cyan("\u25E5")}${line}${fmt.cyan("\u25E4")}
2083
2286
  `
2084
2287
  );
2085
- return { prUrl: void 0 };
2288
+ }
2289
+ async openPullRequestPage(opts) {
2290
+ const parsed = extractAzureRepoInfoFromGit(opts.repoUrl);
2291
+ if (!parsed) {
2292
+ this.logger.info("pr.skipped", { reason: "remote_not_azure_devops_git" });
2293
+ return { prUrl: void 0 };
2294
+ }
2295
+ this.logger.info("pr.prompt.shown");
2296
+ const wantsPr = await confirm({
2297
+ message: "Do you want to open a Pull Request?",
2298
+ initialValue: true
2299
+ });
2300
+ if (!wantsPr) {
2301
+ this.logger.info("pr.declined");
2302
+ return { prUrl: void 0 };
2303
+ }
2304
+ const createPageUrl = buildPullRequestUrl(parsed, opts.sourceBranch, opts.targetBranch);
2305
+ try {
2306
+ await openUrlInBrowser(createPageUrl);
2307
+ } catch (e) {
2308
+ this.logger.warn("Could not open browser", e);
2309
+ }
2310
+ import_prompts2.log.message(
2311
+ `
2312
+ ${fmt.green("Opening Pull Request creation in your browser.")}
2313
+ ${fmt.cyan(createPageUrl)}
2314
+ `
2315
+ );
2316
+ return { prUrl: createPageUrl };
2086
2317
  }
2087
2318
  };
2088
2319
 
2089
2320
  // src/services/contribute/services/TmpRepoService.ts
2090
2321
  var import_node_os2 = require("os");
2091
- var import_node_path14 = __toESM(require("path"));
2092
- var import_fs_extra12 = __toESM(require("fs-extra"));
2322
+ var import_node_path16 = __toESM(require("path"));
2323
+ var import_fs_extra13 = __toESM(require("fs-extra"));
2093
2324
  var TmpRepoService = class {
2094
2325
  constructor(logger) {
2095
2326
  this.logger = logger;
2096
2327
  }
2097
2328
  async getTmpDir(target) {
2098
2329
  const slug = `${target.type}-${target.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-");
2099
- return import_node_path14.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
2330
+ return import_node_path16.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
2100
2331
  }
2101
2332
  async prepare(opts) {
2102
2333
  const dir = await this.getTmpDir(opts.target);
@@ -2106,11 +2337,11 @@ var TmpRepoService = class {
2106
2337
  branch: opts.branch
2107
2338
  });
2108
2339
  this.logger.info("Prepare for tmp repo");
2109
- if (await import_fs_extra12.default.pathExists(dir)) {
2340
+ if (await import_fs_extra13.default.pathExists(dir)) {
2110
2341
  this.logger.debug(`${tempRepoName}.remove`, { dir });
2111
- await import_fs_extra12.default.remove(dir);
2342
+ await import_fs_extra13.default.remove(dir);
2112
2343
  }
2113
- await import_fs_extra12.default.ensureDir(import_node_path14.default.dirname(dir));
2344
+ await import_fs_extra13.default.ensureDir(import_node_path16.default.dirname(dir));
2114
2345
  await git.clone(opts.repoUrl, dir, opts.branch);
2115
2346
  return dir;
2116
2347
  }
@@ -2193,7 +2424,7 @@ var detach = command("detach").description("Migrate blox schema").option("--basi
2193
2424
  });
2194
2425
 
2195
2426
  // src/commands/init/index.ts
2196
- var import_fs_extra13 = __toESM(require("fs-extra"));
2427
+ var import_fs_extra14 = __toESM(require("fs-extra"));
2197
2428
  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 }) => {
2198
2429
  await syncRegistries();
2199
2430
  try {
@@ -2234,8 +2465,8 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
2234
2465
  task.stop(`App initialized in ${name}`);
2235
2466
  await runTask("Run init script", async () => runInitScript(name || ""));
2236
2467
  } catch (e) {
2237
- if (name && import_fs_extra13.default.existsSync(name)) {
2238
- await import_fs_extra13.default.remove(name);
2468
+ if (name && import_fs_extra14.default.existsSync(name)) {
2469
+ await import_fs_extra14.default.remove(name);
2239
2470
  }
2240
2471
  error(e);
2241
2472
  }
@@ -2255,14 +2486,14 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
2255
2486
  });
2256
2487
 
2257
2488
  // src/commands/update/index.ts
2258
- var import_prompts20 = require("@clack/prompts");
2489
+ var import_prompts21 = require("@clack/prompts");
2259
2490
 
2260
2491
  // src/commands/update/utils.ts
2261
- var import_node_path16 = __toESM(require("path"));
2492
+ var import_node_path18 = __toESM(require("path"));
2262
2493
 
2263
2494
  // src/services/updater.ts
2264
- var import_node_path15 = __toESM(require("path"));
2265
- var import_fs_extra14 = __toESM(require("fs-extra"));
2495
+ var import_node_path17 = __toESM(require("path"));
2496
+ var import_fs_extra15 = __toESM(require("fs-extra"));
2266
2497
  var import_klaw3 = __toESM(require("klaw"));
2267
2498
  async function updateFromRemote({
2268
2499
  name,
@@ -2308,9 +2539,9 @@ async function updateFromRemote({
2308
2539
  }
2309
2540
  const remoteIgnore = remoteBloxFile.definition?.ignore || [];
2310
2541
  ignore3.push(...remoteIgnore, bloxFilePath, `**/${bloxFilePath}`);
2311
- const gitIgnorePath = import_node_path15.default.join(dir, ".gitignore");
2312
- if (await import_fs_extra14.default.pathExists(gitIgnorePath)) {
2313
- const gitIgnoreContent = await import_fs_extra14.default.readFile(gitIgnorePath, "utf8");
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");
2314
2545
  const gitIgnorePatterns = gitIgnoreContent.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
2315
2546
  ignore3.push(...gitIgnorePatterns);
2316
2547
  debug(`Added ${gitIgnorePatterns.length} patterns from .gitignore`);
@@ -2322,14 +2553,14 @@ async function updateFromRemote({
2322
2553
  if (hard) {
2323
2554
  const getAllFiles = async (d) => {
2324
2555
  const files = [];
2325
- if (await import_fs_extra14.default.pathExists(d)) {
2556
+ if (await import_fs_extra15.default.pathExists(d)) {
2326
2557
  for await (const file of (0, import_klaw3.default)(d)) {
2327
2558
  if (file.path.includes("/.git/") || file.path.endsWith("/.git") || file.path.includes("\\.git\\") || file.path.endsWith("\\.git"))
2328
2559
  continue;
2329
2560
  if (file.path.includes("/node_modules/") || file.path.includes("\\node_modules\\"))
2330
2561
  continue;
2331
2562
  if (file.stats.isFile()) {
2332
- files.push(import_node_path15.default.relative(d, file.path));
2563
+ files.push(import_node_path17.default.relative(d, file.path));
2333
2564
  }
2334
2565
  }
2335
2566
  }
@@ -2348,23 +2579,23 @@ async function updateFromRemote({
2348
2579
  for (const file of filesToProcess) {
2349
2580
  if (file === ".git" || file.startsWith(".git/") || file.startsWith(".git\\")) continue;
2350
2581
  if (ignoredMatcher.ignores(toIgnorePath(file))) continue;
2351
- const localPath = import_node_path15.default.join(dir, file);
2352
- const basePath = import_node_path15.default.join(baseDir, file);
2353
- const remotePath = import_node_path15.default.join(remoteDir, file);
2354
- const existsLocal = await import_fs_extra14.default.pathExists(localPath);
2355
- const existsBase = await import_fs_extra14.default.pathExists(basePath);
2356
- const existsRemote = await import_fs_extra14.default.pathExists(remotePath);
2357
- const ext = import_node_path15.default.extname(file);
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);
2358
2589
  const isBinary = isBinaryFile(ext);
2359
2590
  if (existsRemote) {
2360
- await import_fs_extra14.default.ensureDir(import_node_path15.default.dirname(localPath));
2591
+ await import_fs_extra15.default.ensureDir(import_node_path17.default.dirname(localPath));
2361
2592
  }
2362
2593
  if (hard) {
2363
2594
  if (existsRemote) {
2364
- await import_fs_extra14.default.copy(remotePath, localPath, { overwrite: true });
2595
+ await import_fs_extra15.default.copy(remotePath, localPath, { overwrite: true });
2365
2596
  debug(`Hard update: Overwrote ${file}`);
2366
2597
  } else if (existsLocal) {
2367
- await import_fs_extra14.default.remove(localPath);
2598
+ await import_fs_extra15.default.remove(localPath);
2368
2599
  debug(`Hard update: Removed ${file}`);
2369
2600
  }
2370
2601
  continue;
@@ -2373,29 +2604,29 @@ async function updateFromRemote({
2373
2604
  if (existsLocal) {
2374
2605
  if (isBinary) {
2375
2606
  debug(`Binary collision: ${file}, overwriting.`);
2376
- await import_fs_extra14.default.copy(remotePath, localPath, { overwrite: true });
2607
+ await import_fs_extra15.default.copy(remotePath, localPath, { overwrite: true });
2377
2608
  logWarningSection(`Overwrote binary file collision: ${file}`);
2378
2609
  } else {
2379
- const emptyBase = import_node_path15.default.join(baseDir, `${file}.empty`);
2380
- await import_fs_extra14.default.ensureFile(emptyBase);
2610
+ const emptyBase = import_node_path17.default.join(baseDir, `${file}.empty`);
2611
+ await import_fs_extra15.default.ensureFile(emptyBase);
2381
2612
  const result = await git.mergeFile(localPath, emptyBase, remotePath);
2382
2613
  if (!result) {
2383
2614
  hasConflicts2 = true;
2384
2615
  conflictFiles.push(file);
2385
2616
  }
2386
- await import_fs_extra14.default.remove(emptyBase);
2617
+ await import_fs_extra15.default.remove(emptyBase);
2387
2618
  }
2388
2619
  } else {
2389
- await import_fs_extra14.default.copy(remotePath, localPath);
2620
+ await import_fs_extra15.default.copy(remotePath, localPath);
2390
2621
  }
2391
2622
  continue;
2392
2623
  }
2393
2624
  if (existsBase && !existsRemote) {
2394
2625
  if (existsLocal) {
2395
- const localBuffer = await import_fs_extra14.default.readFile(localPath);
2396
- const baseBuffer = await import_fs_extra14.default.readFile(basePath);
2626
+ const localBuffer = await import_fs_extra15.default.readFile(localPath);
2627
+ const baseBuffer = await import_fs_extra15.default.readFile(basePath);
2397
2628
  if (localBuffer.equals(baseBuffer)) {
2398
- await import_fs_extra14.default.remove(localPath);
2629
+ await import_fs_extra15.default.remove(localPath);
2399
2630
  } else {
2400
2631
  logWarningSection(
2401
2632
  `File ${file} was deleted in remote but modified locally. Kept local version.`
@@ -2406,7 +2637,7 @@ async function updateFromRemote({
2406
2637
  }
2407
2638
  if (existsBase && existsRemote) {
2408
2639
  if (!existsLocal) {
2409
- await import_fs_extra14.default.copy(remotePath, localPath);
2640
+ await import_fs_extra15.default.copy(remotePath, localPath);
2410
2641
  logWarningSection(
2411
2642
  `File restored: ${file}`,
2412
2643
  `This file was deleted locally but updated in the remote block.
@@ -2415,7 +2646,7 @@ It has been recreated to apply upstream changes.`
2415
2646
  continue;
2416
2647
  }
2417
2648
  if (isBinary) {
2418
- await import_fs_extra14.default.copy(remotePath, localPath, { overwrite: true });
2649
+ await import_fs_extra15.default.copy(remotePath, localPath, { overwrite: true });
2419
2650
  logWarningSection(`Updated binary file: ${file} (overwritten)`);
2420
2651
  } else {
2421
2652
  const result = await git.mergeFile(localPath, basePath, remotePath);
@@ -2473,7 +2704,7 @@ async function updateApp({
2473
2704
  const blockRegistryData = availableBlocks[block.name];
2474
2705
  if (!blockRegistryData) return;
2475
2706
  await git.updateRemote(block.name, blockRegistryData.source);
2476
- const blockPath = import_node_path16.default.join(blocksDir, block.name);
2707
+ const blockPath = import_node_path18.default.join(blocksDir, block.name);
2477
2708
  const currentBloxFile = getBloxFile(blockPath);
2478
2709
  const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
2479
2710
  const blockFromCommit = currentBloxFile.checkpoints?.[block.name]?.commit;
@@ -2506,7 +2737,7 @@ async function updateAppBases(templateDef, templates, ignore3, hard = false) {
2506
2737
  }
2507
2738
  async function updateBlock(block, blocks, ignore3, hard = false) {
2508
2739
  const blockRegistryData = blocks[block];
2509
- const blockPath = import_node_path16.default.join(blocksDir, block);
2740
+ const blockPath = import_node_path18.default.join(blocksDir, block);
2510
2741
  await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
2511
2742
  if (!blockRegistryData) {
2512
2743
  error(`Selected block: ${block} not available in registries`, false);
@@ -2561,7 +2792,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
2561
2792
  option("-s, --scope <scope>", "Scope of update").default("all").choices(["app", "bases", "block", "all"])
2562
2793
  ).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) => {
2563
2794
  if (await git.hasUncommittedChanges()) {
2564
- import_prompts20.log.warn(fmt.yellow("Make sure to commit any changes first"));
2795
+ import_prompts21.log.warn(fmt.yellow("Make sure to commit any changes first"));
2565
2796
  return;
2566
2797
  }
2567
2798
  await migrateAll(true);
@@ -2639,7 +2870,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
2639
2870
  await printChangeLog(startCheckpoints, endCheckpoints);
2640
2871
  } catch (e) {
2641
2872
  if (!isDebugMode()) {
2642
- import_prompts20.log.warn("Error happened, Will rollback changes");
2873
+ import_prompts21.log.warn("Error happened, Will rollback changes");
2643
2874
  await git.rollback();
2644
2875
  }
2645
2876
  error(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"
package/readme.md CHANGED
@@ -1,9 +1,4 @@
1
- #
2
- ![logo](./assets/blox.png)
3
-
4
- ### Introduction and Goals
5
-
6
- BLOX is started kit built to speed Medad Product development by providing prebuild blocks of code that can be added with all its provided functionalities in one cli command.
1
+ # BLOX CLI
7
2
 
8
3
  ### Prerequisites
9
4
 
@@ -32,6 +27,7 @@ Commands:
32
27
  blox init Init new app [alias: i]
33
28
  blox add Add block to app [alias: a]
34
29
  blox update Update app/block [alias: u]
30
+ blox contribute Contribute changes to template/base/block repos [alias: cb]
35
31
  blox conf Set blox global config [alias: c]
36
32
  blox upgrade Upgrade blox cli to latest version
37
33
  blox migrate Migrate blox schema
@@ -51,6 +47,7 @@ Options:
51
47
  * [init](#init)
52
48
  * [add](#add)
53
49
  * [update](#update)
50
+ * [contribute](#contribute)
54
51
  * [conf](#conf)
55
52
  * [upgrade](#upgrade)
56
53
  * [migrate](#migrate)
@@ -109,6 +106,27 @@ Options:
109
106
 
110
107
  * Note: you may need to resolve merge conflicts if found
111
108
 
109
+ #### contribute
110
+
111
+ ```sh
112
+ blox contribute --help
113
+ ```
114
+
115
+ ```
116
+ blox contribute
117
+
118
+ Contribute changes back to template/base/block repositories
119
+
120
+ Options:
121
+ --existing Add changes to an existing contribution branch
122
+ --title <title> Contribution title
123
+ --description <text> Contribution description
124
+ --commits <commits> Comma-separated commit hashes from the app repo
125
+ --force Bypass safety pre-flight checks
126
+ --type <type> Target: template | base | block
127
+ --name <name> Target name (with --type)
128
+ ```
129
+
112
130
  #### conf
113
131
 
114
132
  ```sh
@@ -146,7 +164,3 @@ blox migrate
146
164
 
147
165
  Migrate blox schema
148
166
  ```
149
-
150
- ### Docs
151
-
152
- - [Design](./docs/design.md)