@naseej/blox 0.1.20 → 0.1.22

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 +64 -20
  2. package/package.json +4 -2
package/dist/run.js CHANGED
@@ -31,7 +31,7 @@ var option = (flags, description) => {
31
31
  };
32
32
 
33
33
  // package.json
34
- var version = "0.1.20";
34
+ var version = "0.1.22";
35
35
 
36
36
  // src/commands/add/index.ts
37
37
  var import_fs_extra7 = __toESM(require("fs-extra"));
@@ -171,6 +171,19 @@ var updateRemote = async (name, source, shellOptions = {}) => {
171
171
  });
172
172
  await $("git", ["fetch", name], { ...defaultShellOptions, ...shellOptions });
173
173
  };
174
+ var readFileFromRemote = async (remote, file) => {
175
+ try {
176
+ let content = "";
177
+ await $("git", ["show", `${remote}/main:${file}`], {
178
+ onStdout: (text2) => {
179
+ content = text2;
180
+ }
181
+ });
182
+ return JSON.parse(content);
183
+ } catch {
184
+ return {};
185
+ }
186
+ };
174
187
  var update = (shellOptions = {}) => {
175
188
  return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
176
189
  };
@@ -240,7 +253,8 @@ var git = {
240
253
  createPatch,
241
254
  getChangesLog,
242
255
  applyPatch,
243
- updateRemote
256
+ updateRemote,
257
+ readFileFromRemote
244
258
  };
245
259
 
246
260
  // src/shared/spinner.ts
@@ -359,11 +373,15 @@ var getAvailableTemplates = async () => {
359
373
  debug(templates);
360
374
  return templates;
361
375
  };
362
- var getAvailableBlocks = async (templateName) => {
376
+ var getAvailableBlocks = async (templateInfo) => {
363
377
  debug("Get available blocks");
364
378
  const templates = await getAvailableTemplates();
365
- const template = templates[templateName];
379
+ const template = templates[templateInfo.name];
366
380
  const blocks = template?.blocks || {};
381
+ for (const base of templateInfo.bases || []) {
382
+ const baseTemplate = templates[base.name];
383
+ Object.entries(baseTemplate?.blocks || {}).forEach(([k, v]) => blocks[k] = v);
384
+ }
367
385
  debug(blocks);
368
386
  return blocks;
369
387
  };
@@ -371,6 +389,7 @@ var getAvailableBlocks = async (templateName) => {
371
389
  // src/services/updater.ts
372
390
  var import_node_path6 = __toESM(require("path"));
373
391
  var import_fs_extra6 = __toESM(require("fs-extra"));
392
+ var import_merge = __toESM(require("lodash/merge"));
374
393
 
375
394
  // src/services/template.ts
376
395
  var import_node_path5 = __toESM(require("path"));
@@ -401,7 +420,7 @@ function getBasedOnInfo(cwd = ".") {
401
420
  }
402
421
  function saveBasedOnInfo(info, cwd = ".") {
403
422
  debug("Save info");
404
- import_fs_extra5.default.writeJSONSync(import_node_path5.default.join(cwd, basedOnFile), info);
423
+ import_fs_extra5.default.writeFileSync(import_node_path5.default.join(cwd, basedOnFile), JSON.stringify(info, null, 2));
405
424
  }
406
425
  function updateBasedOnInfo(updates, cwd = ".") {
407
426
  const info = getBasedOnInfo(cwd);
@@ -460,9 +479,16 @@ var textList = async (opts) => {
460
479
  // src/services/updater.ts
461
480
  async function updateFromRemote(name, source = "", ignore = [], destPath = ".") {
462
481
  debug("Updating from remote");
463
- import_fs_extra6.default.ensureDirSync(appPaths.temp);
482
+ let basedOnInfo = getBasedOnInfo(destPath);
483
+ const remoteBloxFile = await git.readFileFromRemote(name, ".blox");
484
+ basedOnInfo = (0, import_merge.default)(basedOnInfo, remoteBloxFile);
485
+ const fromBasedCommit = basedOnInfo.bases?.[name]?.commit;
486
+ const fromCommit = fromBasedCommit || basedOnInfo.commit;
487
+ if (!fromCommit) {
488
+ debug("Skip update, no fromCommit found");
489
+ return;
490
+ }
464
491
  await git.updateRemote(name, source);
465
- const fromCommit = getBasedOnInfo(destPath).commit;
466
492
  const toCommit = await git.getLatestCommitFromRemote(name);
467
493
  debug({ fromCommit, toCommit });
468
494
  if (fromCommit == toCommit) {
@@ -470,6 +496,7 @@ async function updateFromRemote(name, source = "", ignore = [], destPath = ".")
470
496
  return;
471
497
  }
472
498
  const patchFilePath = import_node_path6.default.join(destPath, "diff.patch");
499
+ ignore.push("./.blox");
473
500
  await git.createPatch(fromCommit, toCommit, patchFilePath, ignore);
474
501
  const changes = await git.getChangesLog(fromCommit, toCommit);
475
502
  const deletePatchFile = async () => {
@@ -495,13 +522,25 @@ async function updateFromRemote(name, source = "", ignore = [], destPath = ".")
495
522
  );
496
523
  }
497
524
  await deletePatchFile();
498
- updateBasedOnInfo({ commit: toCommit }, destPath);
525
+ if (fromBasedCommit) {
526
+ if (!basedOnInfo.bases) {
527
+ basedOnInfo.bases = {};
528
+ }
529
+ if (!basedOnInfo.bases[name]) {
530
+ basedOnInfo.bases[name] = { commit: toCommit };
531
+ } else {
532
+ basedOnInfo.bases[name].commit = toCommit;
533
+ }
534
+ } else {
535
+ basedOnInfo.commit = toCommit;
536
+ }
537
+ saveBasedOnInfo(basedOnInfo, destPath);
499
538
  }
500
539
 
501
540
  // src/commands/update/utils.ts
502
541
  async function updateAPP(templateInfo) {
542
+ const templates = await getAvailableTemplates();
503
543
  await runTask({ start: "Update App", end: "Updated App" }, async () => {
504
- const templates = await getAvailableTemplates();
505
544
  const template = templates[templateInfo.name];
506
545
  if (!template) {
507
546
  error("Selected template not available, try to sync registries");
@@ -509,6 +548,19 @@ async function updateAPP(templateInfo) {
509
548
  }
510
549
  await updateFromRemote(templateInfo.name, template.source, templateInfo.ignore);
511
550
  });
551
+ for (const base of templateInfo.bases || []) {
552
+ await runTask(
553
+ { start: `Update App base: ${base.name}`, end: `Updated App base: ${base.name}` },
554
+ async () => {
555
+ const template = templates[base.name];
556
+ if (!template) {
557
+ error("Selected template not available, try to sync registries");
558
+ return;
559
+ }
560
+ await updateFromRemote(base.name, template.source, []);
561
+ }
562
+ );
563
+ }
512
564
  }
513
565
  var updatedBlocks = /* @__PURE__ */ new Set();
514
566
  async function updateBlock(block, blocks) {
@@ -573,7 +625,7 @@ var add = command("add").description("Add block to app").alias("a").argument("[b
573
625
  await syncRegistries(false, false);
574
626
  try {
575
627
  const templateInfo = getTemplateInfo();
576
- const blocks = await getAvailableBlocks(templateInfo.name);
628
+ const blocks = await getAvailableBlocks(templateInfo);
577
629
  if (!block) {
578
630
  block = await select({
579
631
  message: "Select template to be used",
@@ -650,15 +702,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
650
702
  const commit = await git.getLatestCommitFromPath(name);
651
703
  await git.unInit(name);
652
704
  await replacePlaceholders(name, { app: { name } });
653
- let basedOnInfo;
654
- try {
655
- basedOnInfo = getBasedOnInfo(name);
656
- } catch (e) {
657
- debug(`${e}`);
658
- }
659
- if (!basedOnInfo?.commit) {
660
- saveBasedOnInfo({ commit }, name);
661
- }
705
+ updateBasedOnInfo({ commit }, name);
662
706
  await git.init(name);
663
707
  await runInitScript(name);
664
708
  task.stop(`App initialized in ${name}`);
@@ -686,7 +730,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
686
730
  await updateAPP(templateInfo);
687
731
  }
688
732
  if (args.scope === "app") return;
689
- const availableBlocks = await getAvailableBlocks(templateInfo.name);
733
+ const availableBlocks = await getAvailableBlocks(templateInfo);
690
734
  const usedBlocks = getUsedBlocks();
691
735
  if (args.scope === "all") {
692
736
  for (const block of usedBlocks) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"
@@ -41,6 +41,7 @@
41
41
  "@types/fs-extra": "11.0.4",
42
42
  "@types/ms": "0.7.34",
43
43
  "@types/ejs": "3.1.5",
44
+ "@types/lodash": "4.17.20",
44
45
  "eslint": "^8.57.0",
45
46
  "vitest": "2.1.8",
46
47
  "prettier": "^3.2.5",
@@ -69,6 +70,7 @@
69
70
  "@commander-js/extra-typings": "12.1.0",
70
71
  "commander": "12.1.0",
71
72
  "ms": "2.1.3",
72
- "dayjs": "1.11.13"
73
+ "dayjs": "1.11.13",
74
+ "lodash": "^4.17.21"
73
75
  }
74
76
  }