@naseej/blox 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/run.js +190 -83
  2. package/package.json +3 -2
package/dist/run.js CHANGED
@@ -31,10 +31,10 @@ var option = (flags, description) => {
31
31
  };
32
32
 
33
33
  // package.json
34
- var version = "1.0.0";
34
+ var version = "1.2.0";
35
35
 
36
36
  // src/commands/add/index.ts
37
- var import_fs_extra7 = __toESM(require("fs-extra"));
37
+ var import_fs_extra8 = __toESM(require("fs-extra"));
38
38
 
39
39
  // src/config/runtime.ts
40
40
  var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
@@ -66,6 +66,9 @@ var v1 = {
66
66
  }
67
67
  },
68
68
  run: async ({ packageJson, bloxFile: oldBloxFile }) => {
69
+ if (!packageJson.blox) {
70
+ return {};
71
+ }
69
72
  const bloxFile = {
70
73
  schemaVersion: 1,
71
74
  definition: packageJson.blox,
@@ -224,8 +227,8 @@ var update = (shellOptions = {}) => {
224
227
  var getLatestCommitFromRemote = async (remote) => {
225
228
  return getLatestCommit(`${remote}/main`);
226
229
  };
227
- var getLatestCommitFromPath = async (path10) => {
228
- return getLatestCommit("HEAD", path10);
230
+ var getLatestCommitFromPath = async (path11) => {
231
+ return getLatestCommit("HEAD", path11);
229
232
  };
230
233
  var getLatestCommit = async (rev, cwd = ".") => {
231
234
  debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
@@ -238,7 +241,7 @@ var getLatestCommit = async (rev, cwd = ".") => {
238
241
  });
239
242
  return commit2.replace(/\n/g, "");
240
243
  };
241
- var createPatch = async (fromCommit, toCommit, outputPath, ignore = []) => {
244
+ var createPatch = async (fromCommit, toCommit, outputPath, ignore2 = []) => {
242
245
  return $("git", [
243
246
  "diff",
244
247
  fromCommit,
@@ -246,7 +249,7 @@ var createPatch = async (fromCommit, toCommit, outputPath, ignore = []) => {
246
249
  ">",
247
250
  outputPath,
248
251
  "--",
249
- ...ignore.map((file) => `':!${file}'`)
252
+ ...ignore2.map((file) => `':!${file}'`)
250
253
  ]);
251
254
  };
252
255
  var getChangesLog = async (fromCommit, toCommit) => {
@@ -259,7 +262,7 @@ var getChangesLog = async (fromCommit, toCommit) => {
259
262
  return changes;
260
263
  };
261
264
  var applyPatch = (patch, cwd = ".") => {
262
- const args = ["apply", "-3"];
265
+ const args = ["apply", "-3", "--allow-empty"];
263
266
  if (cwd != ".") {
264
267
  args.push("--directory");
265
268
  args.push(normalizePath(cwd));
@@ -348,6 +351,11 @@ var text = async (opts) => {
348
351
  checkIfCanceled(value);
349
352
  return value;
350
353
  };
354
+ var confirm = async (opts) => {
355
+ const value = await (0, import_prompts3.confirm)(opts);
356
+ checkIfCanceled(value);
357
+ return value;
358
+ };
351
359
  var textList = async (opts) => {
352
360
  opts.message = `${opts.message} ${fmt.gray('(separated with ",")')}`;
353
361
  const value = await (0, import_prompts3.text)(opts);
@@ -370,19 +378,17 @@ function getApplicableMigrations(schemaVersion = 0) {
370
378
  return migrationsList.slice(schemaVersion);
371
379
  }
372
380
  async function migrate(name, { getPath = (f) => f, read, write }) {
373
- let remoteBloxFile;
381
+ let originalBloxFile;
374
382
  try {
375
- remoteBloxFile = await read(getPath(".blox"));
383
+ originalBloxFile = await read(getPath(".blox"));
376
384
  } catch {
377
- remoteBloxFile = {};
378
- }
379
- const migrations = getApplicableMigrations(remoteBloxFile.schemaVersion);
380
- if (migrations.length) {
381
- import_prompts2.log.warn(fmt.yellow(`Migrations found for ${name}, will migrate to latest schema`));
385
+ originalBloxFile = {};
382
386
  }
383
- const currentRev = {
384
- ".blox": remoteBloxFile
387
+ const migrations = getApplicableMigrations(originalBloxFile.schemaVersion);
388
+ let originalRev = {
389
+ ".blox": originalBloxFile
385
390
  };
391
+ const currentRev = { ...originalRev };
386
392
  for (const migration of migrations) {
387
393
  const deps = {};
388
394
  for (const [name2, { location, defaultValue = {} }] of Object.entries(
@@ -401,18 +407,25 @@ async function migrate(name, { getPath = (f) => f, read, write }) {
401
407
  deps[name2] = defaultValue;
402
408
  }
403
409
  }
410
+ originalRev = { ...deps, ...originalRev };
404
411
  const output = await migration.run(deps);
405
412
  for (const [name2, value] of Object.entries(output || {})) {
406
413
  const { location } = migration.dependencies[name2] || {};
407
414
  location && (currentRev[location] = value);
408
415
  }
409
416
  }
417
+ let filesChanged = false;
410
418
  if (write) {
411
419
  for (const [location, value] of Object.entries(currentRev)) {
420
+ if (currentRev[location] === originalRev[location]) continue;
421
+ filesChanged = true;
412
422
  await write(getPath(location), JSON.stringify(value, null, 2));
413
423
  }
414
424
  }
415
- return { output: currentRev, migrationsRan: migrations.length };
425
+ if (filesChanged) {
426
+ import_prompts2.log.warn(fmt.yellow(`Migrations found for ${name}, will migrate to latest schema`));
427
+ }
428
+ return { output: currentRev, filesChanged };
416
429
  }
417
430
  function migrateOnLocal(name, cwd = ".") {
418
431
  return migrate(name, {
@@ -421,30 +434,54 @@ function migrateOnLocal(name, cwd = ".") {
421
434
  write: import_fs_extra2.default.writeFile
422
435
  });
423
436
  }
424
- function migrateOnRemote(name, commit2) {
437
+ function migrateOnRemote(name, commit2, cwd) {
425
438
  return migrate(name, {
426
- read: (file) => git.readJsonFromCommit(commit2, file)
439
+ read: (file) => git.readJsonFromCommit(commit2, file),
440
+ getPath: cwd ? (file) => import_node_path3.default.join(cwd, file) : void 0
427
441
  });
428
442
  }
429
443
 
430
444
  // src/migrations/index.ts
431
445
  async function migrateAll(autoCommit) {
432
- let migrationsRan = (await migrateOnLocal("app")).migrationsRan;
446
+ let filesChanged = (await migrateOnLocal("app")).filesChanged;
433
447
  const blocks = import_fs_extra3.default.existsSync(blocksDir) ? import_fs_extra3.default.readdirSync(blocksDir) : [];
434
448
  for (const block of blocks) {
435
- migrationsRan += (await migrateOnLocal(block, import_node_path4.default.join(blocksDir, block))).migrationsRan;
449
+ const res = await migrateOnLocal(block, import_node_path4.default.join(blocksDir, block));
450
+ filesChanged = filesChanged || res.filesChanged;
436
451
  }
437
- if (autoCommit && migrationsRan) {
452
+ if (autoCommit && filesChanged && await git.hasUncommittedChanges()) {
438
453
  import_prompts2.log.warn(fmt.yellow(`Migrations done and will be commited`));
439
454
  await git.add(".");
440
455
  await git.commit("chore: migrate blox schema");
441
456
  }
442
457
  }
443
458
 
444
- // src/services/registry.ts
445
- var import_node_path6 = __toESM(require("path"));
446
- var import_fs_extra5 = __toESM(require("fs-extra"));
459
+ // src/services/fs.ts
460
+ var import_node_path5 = __toESM(require("path"));
461
+ var import_fs_extra4 = __toESM(require("fs-extra"));
462
+ var import_ignore = __toESM(require("ignore"));
447
463
  var import_klaw = __toESM(require("klaw"));
464
+ var filterBlacklisted = (item) => {
465
+ return !item.includes("node_modules") && !item.includes(".git");
466
+ };
467
+ var deletePattern = async (cwd, patterns = []) => {
468
+ const ig = (0, import_ignore.default)().add(patterns);
469
+ for await (const file of (0, import_klaw.default)(cwd, { filter: filterBlacklisted })) {
470
+ const relativePath = import_node_path5.default.relative(cwd, file.path);
471
+ if (relativePath && ig.ignores(relativePath)) {
472
+ if (!await import_fs_extra4.default.exists(file.path)) {
473
+ continue;
474
+ }
475
+ debug(`deleting: ${relativePath}`);
476
+ await import_fs_extra4.default.remove(file.path);
477
+ }
478
+ }
479
+ };
480
+
481
+ // src/services/registry.ts
482
+ var import_node_path7 = __toESM(require("path"));
483
+ var import_fs_extra6 = __toESM(require("fs-extra"));
484
+ var import_klaw2 = __toESM(require("klaw"));
448
485
  var import_merge = __toESM(require("lodash/merge"));
449
486
 
450
487
  // src/shared/spinner.ts
@@ -479,40 +516,40 @@ async function runTask(message, task) {
479
516
  }
480
517
 
481
518
  // src/services/config.ts
482
- var import_node_path5 = __toESM(require("path"));
519
+ var import_node_path6 = __toESM(require("path"));
483
520
  var import_env_paths = __toESM(require("env-paths"));
484
- var import_fs_extra4 = __toESM(require("fs-extra"));
521
+ var import_fs_extra5 = __toESM(require("fs-extra"));
485
522
  var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
486
- var configFilePath = import_node_path5.default.join(appPaths.config, "config.json");
523
+ var configFilePath = import_node_path6.default.join(appPaths.config, "config.json");
487
524
  var getLocalConfig = () => {
488
525
  try {
489
- return import_fs_extra4.default.readJSONSync(configFilePath);
526
+ return import_fs_extra5.default.readJSONSync(configFilePath);
490
527
  } catch {
491
528
  return defaultConfig;
492
529
  }
493
530
  };
494
531
  var updateLocalConfig = (config) => {
495
532
  debug("Update local config");
496
- import_fs_extra4.default.ensureFileSync(configFilePath);
533
+ import_fs_extra5.default.ensureFileSync(configFilePath);
497
534
  const current = getLocalConfig();
498
- import_fs_extra4.default.writeJsonSync(configFilePath, { ...current, ...config });
535
+ import_fs_extra5.default.writeJsonSync(configFilePath, { ...current, ...config });
499
536
  };
500
537
 
501
538
  // src/services/registry.ts
502
- var registriesDataPath = import_node_path6.default.join(appPaths.data, "registries");
539
+ var registriesDataPath = import_node_path7.default.join(appPaths.data, "registries");
503
540
  var syncRegistries = async () => {
504
541
  debug("Sync registries");
505
- import_fs_extra5.default.ensureDirSync(registriesDataPath);
542
+ import_fs_extra6.default.ensureDirSync(registriesDataPath);
506
543
  const config = getLocalConfig();
507
544
  return await runTask("Update registries", async () => {
508
545
  await Promise.all(
509
546
  config.registries.map(async (registry) => {
510
547
  debug(`update registry: ${registry}`);
511
548
  const repoName = registry.split("/").pop() || "";
512
- const repoDir = import_node_path6.default.join(registriesDataPath, repoName);
513
- if (!import_fs_extra5.default.existsSync(repoDir)) {
549
+ const repoDir = import_node_path7.default.join(registriesDataPath, repoName);
550
+ if (!import_fs_extra6.default.existsSync(repoDir)) {
514
551
  await git.clone(registry, "--depth 1", { cwd: registriesDataPath });
515
- } else if (import_fs_extra5.default.existsSync(import_node_path6.default.join(repoDir, ".git"))) {
552
+ } else if (import_fs_extra6.default.existsSync(import_node_path7.default.join(repoDir, ".git"))) {
516
553
  await git.update({ cwd: repoDir });
517
554
  } else {
518
555
  debug(`local registry`);
@@ -524,11 +561,11 @@ var syncRegistries = async () => {
524
561
  var getAvailableTemplates = async () => {
525
562
  debug("Get available templates");
526
563
  const templates = {};
527
- for await (const file of (0, import_klaw.default)(registriesDataPath, {
564
+ for await (const file of (0, import_klaw2.default)(registriesDataPath, {
528
565
  filter: (item) => !item.includes(".git")
529
566
  })) {
530
567
  if (file.path.endsWith(".json")) {
531
- const data = import_fs_extra5.default.readJSONSync(file.path);
568
+ const data = import_fs_extra6.default.readJSONSync(file.path);
532
569
  Object.entries(data.templates || {}).forEach(([templateName, template]) => {
533
570
  if (!template.source) {
534
571
  template.source = `/template-${templateName}`;
@@ -568,27 +605,27 @@ var getAvailableBlocks = async (templateInfo) => {
568
605
  return blocks;
569
606
  };
570
607
  var getAvailableVersions = async (id) => {
571
- const registries = import_fs_extra5.default.readdirSync(registriesDataPath);
608
+ const registries = import_fs_extra6.default.readdirSync(registriesDataPath);
572
609
  for (const registry of registries) {
573
- const versionsFile = import_node_path6.default.join(registriesDataPath, registry, "versions", `${id}.json`);
574
- if (import_fs_extra5.default.existsSync(versionsFile)) {
575
- return import_fs_extra5.default.readJSONSync(versionsFile);
610
+ const versionsFile = import_node_path7.default.join(registriesDataPath, registry, "versions", `${id}.json`);
611
+ if (import_fs_extra6.default.existsSync(versionsFile)) {
612
+ return import_fs_extra6.default.readJSONSync(versionsFile);
576
613
  }
577
614
  }
578
615
  };
579
616
 
580
617
  // src/services/template.ts
581
- var import_node_path7 = __toESM(require("path"));
618
+ var import_node_path8 = __toESM(require("path"));
582
619
  var import_ejs = __toESM(require("ejs"));
583
- var import_fs_extra6 = __toESM(require("fs-extra"));
584
- var import_klaw2 = __toESM(require("klaw"));
620
+ var import_fs_extra7 = __toESM(require("fs-extra"));
621
+ var import_klaw3 = __toESM(require("klaw"));
585
622
  async function replacePlaceholders(dir, context) {
586
623
  debug("Replace placeholders");
587
- for await (const file of (0, import_klaw2.default)(dir)) {
624
+ for await (const file of (0, import_klaw3.default)(dir)) {
588
625
  if (file.stats.isFile()) {
589
- const template = import_fs_extra6.default.readFileSync(file.path, "utf-8");
626
+ const template = import_fs_extra7.default.readFileSync(file.path, "utf-8");
590
627
  const rendered = import_ejs.default.render(template, context);
591
- import_fs_extra6.default.writeFileSync(file.path, rendered, "utf-8");
628
+ import_fs_extra7.default.writeFileSync(file.path, rendered, "utf-8");
592
629
  }
593
630
  }
594
631
  }
@@ -606,7 +643,7 @@ function getBlockDef(cwd = ".") {
606
643
  }
607
644
  function getBloxFile(cwd = ".") {
608
645
  try {
609
- const file = import_fs_extra6.default.readJSONSync(import_node_path7.default.join(cwd, bloxFilePath));
646
+ const file = import_fs_extra7.default.readJSONSync(import_node_path8.default.join(cwd, bloxFilePath));
610
647
  if (!file.checkpoints) {
611
648
  file.checkpoints = {};
612
649
  }
@@ -617,7 +654,7 @@ function getBloxFile(cwd = ".") {
617
654
  }
618
655
  function saveBloxFile(info, cwd = ".") {
619
656
  debug("Save info");
620
- import_fs_extra6.default.writeFileSync(import_node_path7.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
657
+ import_fs_extra7.default.writeFileSync(import_node_path8.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
621
658
  }
622
659
  function updateCheckpoint(name, checkpoint, cwd = ".") {
623
660
  const info = getBloxFile(cwd);
@@ -630,12 +667,12 @@ function updateCheckpoint(name, checkpoint, cwd = ".") {
630
667
  function getUsedBlocks() {
631
668
  debug("Get used blocks");
632
669
  const blocks = [];
633
- if (import_fs_extra6.default.existsSync(blocksDir)) {
634
- import_fs_extra6.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
670
+ if (import_fs_extra7.default.existsSync(blocksDir)) {
671
+ import_fs_extra7.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
635
672
  if (!file.isDirectory()) {
636
673
  return;
637
674
  }
638
- const blockDef = getBlockDef(import_node_path7.default.join(blocksDir, file.name));
675
+ const blockDef = getBlockDef(import_node_path8.default.join(blocksDir, file.name));
639
676
  if (blockDef) {
640
677
  blocks.push(blockDef);
641
678
  }
@@ -777,7 +814,7 @@ function runInitScript(cwd) {
777
814
  var addBlock = async (block, blocks) => {
778
815
  const blockPath = `blocks/${block}`;
779
816
  const blockRegistryData = blocks[block];
780
- if (!import_fs_extra7.default.existsSync(blockPath)) {
817
+ if (!import_fs_extra8.default.existsSync(blockPath)) {
781
818
  await runTask(
782
819
  { start: `Fetching block: ${block}`, end: `Added block: ${block}` },
783
820
  async () => {
@@ -791,6 +828,8 @@ var addBlock = async (block, blocks) => {
791
828
  await git.unInit(blockPath);
792
829
  await replacePlaceholders(blockPath, {});
793
830
  await migrateAll();
831
+ const def = getBlockDef(blockPath);
832
+ await deletePattern(blockPath, def.ignore);
794
833
  updateCheckpoint(block, { commit: commit2 }, blockPath);
795
834
  }
796
835
  );
@@ -857,7 +896,7 @@ var conf = command("conf").description("Set blox global config").alias("c").opti
857
896
  });
858
897
 
859
898
  // src/commands/init/index.ts
860
- var import_fs_extra8 = __toESM(require("fs-extra"));
899
+ var import_fs_extra9 = __toESM(require("fs-extra"));
861
900
  var init2 = command("init").description("Init new app").alias("i").option("-n, --name <name>", "App name").option("-t, --template <template>", "Template to use").action(async ({ name, template }) => {
862
901
  await syncRegistries();
863
902
  try {
@@ -889,13 +928,17 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
889
928
  }
890
929
  await git.unInit(name);
891
930
  await migrateAll();
931
+ const def = getTemplateDef(name);
932
+ await deletePattern(name, def.ignore);
892
933
  await replacePlaceholders(name, { app: { name } });
893
934
  updateCheckpoint(name, { commit: commit2 }, name);
894
935
  await git.init(name);
895
936
  task.stop(`App initialized in ${name}`);
896
937
  await runTask("Run init script", async () => runInitScript(name || ""));
897
938
  } catch (e) {
898
- name && import_fs_extra8.default.existsSync(name) && import_fs_extra8.default.rmdirSync(name);
939
+ if (name && import_fs_extra9.default.existsSync(name)) {
940
+ await import_fs_extra9.default.remove(name);
941
+ }
899
942
  error(e);
900
943
  }
901
944
  });
@@ -914,18 +957,18 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
914
957
  });
915
958
 
916
959
  // src/commands/update/index.ts
917
- var import_prompts13 = require("@clack/prompts");
960
+ var import_prompts14 = require("@clack/prompts");
918
961
 
919
962
  // src/commands/update/utils.ts
920
- var import_node_path9 = __toESM(require("path"));
963
+ var import_node_path10 = __toESM(require("path"));
921
964
 
922
965
  // src/services/updater.ts
923
- var import_node_path8 = __toESM(require("path"));
924
- var import_fs_extra9 = __toESM(require("fs-extra"));
925
- async function updateFromRemote(name, source = "", ignore = [], destPath = ".") {
966
+ var import_node_path9 = __toESM(require("path"));
967
+ var import_fs_extra10 = __toESM(require("fs-extra"));
968
+ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir = "." }) {
926
969
  debug("Updating from remote");
927
970
  await git.updateRemote(name, source);
928
- const bloxFile = getBloxFile(destPath);
971
+ const bloxFile = getBloxFile(dir);
929
972
  const fromCommit = bloxFile.checkpoints[name]?.commit;
930
973
  if (!fromCommit) {
931
974
  debug("Skip update, no fromCommit found");
@@ -956,18 +999,19 @@ async function updateFromRemote(name, source = "", ignore = [], destPath = ".")
956
999
  );
957
1000
  }
958
1001
  }
959
- const patchFilePath = import_node_path8.default.join(destPath, "diff.patch");
960
- ignore.push("./.blox");
961
- await git.createPatch(fromCommit, toCommit, patchFilePath, ignore);
1002
+ const patchFilePath = import_node_path9.default.join(dir, "diff.patch");
1003
+ ignore2.push(".blox", "**/.blox");
1004
+ await git.createPatch(fromCommit, toCommit, patchFilePath, ignore2);
962
1005
  const changes = await git.getChangesLog(fromCommit, toCommit);
963
1006
  const deletePatchFile = async () => {
964
1007
  if (!isDebugMode()) {
965
- await import_fs_extra9.default.unlink(patchFilePath);
1008
+ await import_fs_extra10.default.unlink(patchFilePath);
966
1009
  }
967
1010
  debug("make sure to delete the patch file after you're done with it.");
968
1011
  };
1012
+ let hasMergeConflicts = false;
969
1013
  try {
970
- await git.applyPatch(patchFilePath, destPath);
1014
+ await git.applyPatch(patchFilePath, dir);
971
1015
  } catch (e) {
972
1016
  const errorMessage = `${e}`;
973
1017
  if (errorMessage.includes("error:")) {
@@ -975,6 +1019,16 @@ async function updateFromRemote(name, source = "", ignore = [], destPath = ".")
975
1019
  console.log(`${e}`.replace("error:", fmt.red("error:")));
976
1020
  throw new Error("Failed to apply changes.");
977
1021
  }
1022
+ hasMergeConflicts = errorMessage.includes("with conflicts");
1023
+ }
1024
+ if (hasMergeConflicts) {
1025
+ const shouldContinue = await confirm({
1026
+ message: "Please resolve conflicts and press yes to continue"
1027
+ });
1028
+ if (!shouldContinue) {
1029
+ await deletePatchFile();
1030
+ throw new Error("Failed to solve conflicts");
1031
+ }
978
1032
  }
979
1033
  if (changes.trim() !== "") {
980
1034
  logWarningSection(
@@ -989,22 +1043,64 @@ async function updateFromRemote(name, source = "", ignore = [], destPath = ".")
989
1043
  } else {
990
1044
  bloxFile.checkpoints[name].version = remoteBloxFile.definition.version;
991
1045
  }
992
- saveBloxFile(bloxFile, destPath);
1046
+ saveBloxFile(bloxFile, dir);
1047
+ return toCommit;
993
1048
  }
994
1049
 
995
1050
  // src/commands/update/utils.ts
996
- async function updateApp(templateInfo, templates) {
1051
+ async function updateAppBlocks({
1052
+ toAppCommit,
1053
+ usedBlocks,
1054
+ availableBlocks
1055
+ }) {
1056
+ for (const block of usedBlocks) {
1057
+ const blockRegistryData = availableBlocks[block.name];
1058
+ if (!blockRegistryData) return;
1059
+ await git.updateRemote(block.name, blockRegistryData.source);
1060
+ const blockPath = import_node_path10.default.join(blocksDir, block.name);
1061
+ const currentBloxFile = getBloxFile(blockPath);
1062
+ const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
1063
+ const blockFromCommit = currentBloxFile.checkpoints[block.name]?.commit;
1064
+ const blockToCommit = remoteBloxFile.checkpoints[block.name]?.commit;
1065
+ if (!blockFromCommit || !blockToCommit) continue;
1066
+ if (blockFromCommit === blockToCommit) continue;
1067
+ if (await git.isCommitOlder(blockFromCommit, blockToCommit)) {
1068
+ saveBloxFile(remoteBloxFile, blockPath);
1069
+ } else {
1070
+ logWarningSection(
1071
+ `${block.name} is newer in project than template, make sure no breaking changes`
1072
+ );
1073
+ }
1074
+ }
1075
+ }
1076
+ async function updateApp({
1077
+ templateDef,
1078
+ templates,
1079
+ usedBlocks,
1080
+ availableBlocks
1081
+ }) {
997
1082
  await runTask({ start: "Update App", end: "Updated App" }, async () => {
998
- const template = templates[templateInfo.name];
1083
+ const template = templates[templateDef.name];
999
1084
  if (!template) {
1000
- error(`Selected template: ${templateInfo.name} not available in registries`);
1085
+ error(`Selected template: ${templateDef.name} not available in registries`);
1001
1086
  return;
1002
1087
  }
1003
- await updateFromRemote(templateInfo.name, template.source, templateInfo.ignore);
1088
+ const toAppCommit = await updateFromRemote({
1089
+ name: templateDef.name,
1090
+ source: template.source,
1091
+ ignore: templateDef.ignore
1092
+ });
1093
+ if (!toAppCommit) return;
1094
+ await updateAppBlocks({ toAppCommit, usedBlocks, availableBlocks });
1004
1095
  });
1005
1096
  }
1006
- async function updateAppBases(templateInfo, templates) {
1007
- for (const base of templateInfo.bases || []) {
1097
+ async function updateAppBases({
1098
+ templateDef,
1099
+ templates,
1100
+ usedBlocks,
1101
+ availableBlocks
1102
+ }) {
1103
+ for (const base of templateDef.bases || []) {
1008
1104
  await runTask(
1009
1105
  { start: `Update App base: ${base.name}`, end: `Updated App base: ${base.name}` },
1010
1106
  async () => {
@@ -1013,20 +1109,31 @@ async function updateAppBases(templateInfo, templates) {
1013
1109
  error("Selected template not available in registries");
1014
1110
  return;
1015
1111
  }
1016
- await updateFromRemote(base.name, template.source, []);
1112
+ const toAppCommit = await updateFromRemote({
1113
+ name: base.name,
1114
+ source: template.source
1115
+ });
1116
+ if (!toAppCommit) return;
1117
+ await updateAppBlocks({ toAppCommit, usedBlocks, availableBlocks });
1017
1118
  }
1018
1119
  );
1019
1120
  }
1020
1121
  }
1021
1122
  async function updateBlock(block, blocks) {
1022
- const blockDef = blocks[block];
1023
- const blockPath = import_node_path9.default.join(blocksDir, block);
1123
+ const blockRegistryData = blocks[block];
1124
+ const blockPath = import_node_path10.default.join(blocksDir, block);
1125
+ const blockDef = getBlockDef(blockPath);
1024
1126
  await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
1025
- if (!blockDef) {
1127
+ if (!blockRegistryData) {
1026
1128
  error(`Selected block: ${block} not available in registries`, false);
1027
1129
  return;
1028
1130
  }
1029
- await updateFromRemote(block, blockDef.source, blockDef.ignore, blockPath);
1131
+ await updateFromRemote({
1132
+ name: block,
1133
+ source: blockRegistryData.source,
1134
+ ignore: blockDef.ignore,
1135
+ dir: blockPath
1136
+ });
1030
1137
  });
1031
1138
  }
1032
1139
 
@@ -1035,7 +1142,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
1035
1142
  option("-s, --scope <scope>", "Scope of update").default("all").choices(["app", "bases", "block", "all"])
1036
1143
  ).option("-b, --block <name>", "Block to update, valid only with scope block").action(async (args) => {
1037
1144
  if (await git.hasUncommittedChanges()) {
1038
- import_prompts13.log.warn("Make sure to commit any changes first");
1145
+ import_prompts14.log.warn(fmt.yellow("Make sure to commit any changes first"));
1039
1146
  return;
1040
1147
  }
1041
1148
  await migrateAll(true);
@@ -1046,10 +1153,10 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
1046
1153
  const usedBlocks = getUsedBlocks();
1047
1154
  try {
1048
1155
  if (["app", "all"].includes(args.scope)) {
1049
- await updateApp(templateDef, templates);
1156
+ await updateApp({ templateDef, templates, usedBlocks, availableBlocks });
1050
1157
  }
1051
1158
  if (["bases", "all"].includes(args.scope)) {
1052
- await updateAppBases(templateDef, templates);
1159
+ await updateAppBases({ templateDef, templates, usedBlocks, availableBlocks });
1053
1160
  }
1054
1161
  if (args.scope === "all") {
1055
1162
  for (const block of usedBlocks) {
@@ -1076,7 +1183,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
1076
1183
  await checkVersionsCompatibility();
1077
1184
  } catch (e) {
1078
1185
  if (!isDebugMode()) {
1079
- import_prompts13.log.warn("Error happened, Will rollback changes");
1186
+ import_prompts14.log.warn("Error happened, Will rollback changes");
1080
1187
  await git.rollback();
1081
1188
  }
1082
1189
  error(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"
@@ -72,6 +72,7 @@
72
72
  "commander": "12.1.0",
73
73
  "ms": "2.1.3",
74
74
  "dayjs": "1.11.13",
75
- "lodash": "^4.17.21"
75
+ "lodash": "^4.17.21",
76
+ "ignore": "^7.0.5"
76
77
  }
77
78
  }