@naseej/blox 0.1.10 → 0.1.12

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 +42 -19
  2. package/package.json +1 -1
  3. package/readme.md +3 -0
package/dist/run.js CHANGED
@@ -31,7 +31,10 @@ var option = (flags, description) => {
31
31
  };
32
32
 
33
33
  // package.json
34
- var version = "0.1.10";
34
+ var version = "0.1.12";
35
+
36
+ // src/commands/add/index.ts
37
+ var import_fs_extra6 = __toESM(require("fs-extra"));
35
38
 
36
39
  // src/services/git.ts
37
40
  var import_node_path = __toESM(require("path"));
@@ -277,7 +280,7 @@ var updateLocalConfig = (config) => {
277
280
  // src/services/registry.ts
278
281
  var registriesDataPath = import_node_path3.default.join(appPaths.data, "registries");
279
282
  var registriesStatPath = import_node_path3.default.join(registriesDataPath, "stats.json");
280
- var syncRegistries = async (logProgress = true) => {
283
+ var syncRegistries = async (force, logProgress = true) => {
281
284
  debug("Sync registries");
282
285
  logProgress = logProgress || isDebugMode();
283
286
  import_fs_extra4.default.ensureDirSync(registriesDataPath);
@@ -299,7 +302,7 @@ var syncRegistries = async (logProgress = true) => {
299
302
  if (!import_fs_extra4.default.existsSync(repoDir)) {
300
303
  await git.clone(registry, "--depth 1", { cwd: registriesDataPath });
301
304
  registriesStat[repoName].lastUpdated = now.format();
302
- } else if (shouldUpdate) {
305
+ } else if (force || shouldUpdate) {
303
306
  await git.update({ cwd: repoDir });
304
307
  registriesStat[repoName].lastUpdated = now.format();
305
308
  } else {
@@ -434,8 +437,27 @@ var textList = async (opts) => {
434
437
  };
435
438
 
436
439
  // src/commands/add/index.ts
440
+ var addBlock = async (block, blocks) => {
441
+ const blockPath = `blocks/${block}`;
442
+ const blockDef = blocks[block];
443
+ if (!import_fs_extra6.default.existsSync(blockPath)) {
444
+ const task = spinner();
445
+ task.start(`Fetch block`);
446
+ await git.clone(blockDef?.source || "", blockPath);
447
+ const commit = await git.getLatestCommitFromPath(blockPath);
448
+ await git.unInit(blockPath);
449
+ await replacePlaceholders(blockPath, {});
450
+ saveBasedOnInfo({ commit }, blockPath);
451
+ task.stop(`Block ${block} added`);
452
+ } else {
453
+ import_prompts2.log.warn(`${block} already exists, may need to be updated`);
454
+ }
455
+ for (const dep of blockDef?.dependencies || []) {
456
+ await addBlock(dep, blocks);
457
+ }
458
+ };
437
459
  var add = command("add").description("Add block to app").alias("a").argument("[block]", "Block to be added").action(async (block) => {
438
- await syncRegistries(false);
460
+ await syncRegistries(false, false);
439
461
  try {
440
462
  const templateInfo = getTemplateInfo();
441
463
  const blocks = await getAvailableBlocks(templateInfo.name);
@@ -452,15 +474,7 @@ var add = command("add").description("Add block to app").alias("a").argument("[b
452
474
  if (!blocks[block]) {
453
475
  error("Selected block not available, try to sync registries");
454
476
  }
455
- const task = spinner();
456
- task.start(`Fetch block`);
457
- const blockPath = `blocks/${block}`;
458
- await git.clone(blocks[block]?.source || "", blockPath);
459
- const commit = await git.getLatestCommitFromPath(blockPath);
460
- await git.unInit(blockPath);
461
- await replacePlaceholders(blockPath, {});
462
- saveBasedOnInfo({ commit }, blockPath);
463
- task.stop(`Block ${block} added`);
477
+ await addBlock(block, blocks);
464
478
  } catch (e) {
465
479
  error(e);
466
480
  }
@@ -498,7 +512,7 @@ var conf = command("conf").description("Set blox global config").alias("c").opti
498
512
 
499
513
  // src/commands/init/index.ts
500
514
  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 }) => {
501
- await syncRegistries(false);
515
+ await syncRegistries(false, false);
502
516
  try {
503
517
  if (!name) {
504
518
  name = await text({ message: "Select app name" });
@@ -532,9 +546,9 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
532
546
  });
533
547
 
534
548
  // src/commands/sync/index.ts
535
- var sync = command("sync").description("Sync local registry with remote updates").alias("s").action(async () => {
549
+ var sync = command("sync").description("Sync local registry with remote updates").alias("s").option("-f, --force", "Force registry update").action(async ({ force = false }) => {
536
550
  try {
537
- await syncRegistries();
551
+ await syncRegistries(force);
538
552
  import_prompts2.log.success("Local registries synced successfully.");
539
553
  } catch (e) {
540
554
  error(e);
@@ -546,20 +560,24 @@ var import_node_path6 = __toESM(require("path"));
546
560
 
547
561
  // src/services/updater.ts
548
562
  var import_node_path5 = __toESM(require("path"));
549
- var import_fs_extra6 = __toESM(require("fs-extra"));
563
+ var import_fs_extra7 = __toESM(require("fs-extra"));
550
564
  async function updateFromRemote(name, source = "", destPath = ".") {
551
565
  debug("Updating from remote");
552
- import_fs_extra6.default.ensureDirSync(appPaths.temp);
566
+ import_fs_extra7.default.ensureDirSync(appPaths.temp);
553
567
  await git.updateRemote(name, source);
554
568
  const fromCommit = getBasedOnInfo(destPath).commit;
555
569
  const toCommit = await git.getLatestCommitFromRemote(name);
556
570
  debug({ fromCommit, toCommit });
571
+ if (fromCommit == toCommit) {
572
+ debug("No new version");
573
+ return;
574
+ }
557
575
  const patchFilePath = import_node_path5.default.join(destPath, "diff.patch");
558
576
  await git.createPatch(fromCommit, toCommit, patchFilePath);
559
577
  const changes = await git.getChangesLog(fromCommit, toCommit);
560
578
  const deletePatchFile = async () => {
561
579
  if (!isDebugMode()) {
562
- await import_fs_extra6.default.unlink(patchFilePath);
580
+ await import_fs_extra7.default.unlink(patchFilePath);
563
581
  }
564
582
  debug("make sure to delete the patch file after you're done with it.");
565
583
  };
@@ -613,6 +631,11 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
613
631
  blockInfo.source,
614
632
  import_node_path6.default.join(blocksDir, block.name)
615
633
  );
634
+ if (blockInfo.dependencies?.length) {
635
+ import_prompts2.log.warn(
636
+ `${block.name} has deps ${JSON.stringify(blockInfo.dependencies)}, may need to be updated`
637
+ );
638
+ }
616
639
  });
617
640
  }
618
641
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"
package/readme.md CHANGED
@@ -113,6 +113,9 @@ Options:
113
113
  blox sync
114
114
 
115
115
  Sync local registry with remote updates
116
+
117
+ Options:
118
+ -f, --force Force update [boolean] [default: "false"]
116
119
  ```
117
120
 
118
121
  #### conf