@naseej/blox 0.1.9 → 0.1.11

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 +49 -20
  2. package/package.json +1 -1
  3. package/readme.md +16 -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.9";
34
+ var version = "0.1.11";
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,10 +560,10 @@ 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);
@@ -559,7 +573,7 @@ async function updateFromRemote(name, source = "", destPath = ".") {
559
573
  const changes = await git.getChangesLog(fromCommit, toCommit);
560
574
  const deletePatchFile = async () => {
561
575
  if (!isDebugMode()) {
562
- await import_fs_extra6.default.unlink(patchFilePath);
576
+ await import_fs_extra7.default.unlink(patchFilePath);
563
577
  }
564
578
  debug("make sure to delete the patch file after you're done with it.");
565
579
  };
@@ -613,13 +627,28 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
613
627
  blockInfo.source,
614
628
  import_node_path6.default.join(blocksDir, block.name)
615
629
  );
630
+ if (blockInfo.dependencies?.length) {
631
+ import_prompts2.log.warn(
632
+ `${block.name} has deps ${JSON.stringify(blockInfo.dependencies)}, may need to be updated`
633
+ );
634
+ }
616
635
  });
617
636
  }
618
637
  }
619
638
  });
620
639
 
640
+ // src/commands/upgrade/index.ts
641
+ var upgrade = command("upgrade").description("Upgrade blox cli to latest version").action(async () => {
642
+ try {
643
+ await $("npm", ["i", "-g", "@naseej/blox"]);
644
+ import_prompts2.log.success("Blox updated successfully.");
645
+ } catch (e) {
646
+ error(e);
647
+ }
648
+ });
649
+
621
650
  // src/commands/index.ts
622
- var commands = [init2, add, update2, sync, conf];
651
+ var commands = [init2, add, update2, sync, conf, upgrade];
623
652
 
624
653
  // bin/run.ts
625
654
  import_extra_typings2.program.name("blox").version(version);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"
package/readme.md CHANGED
@@ -51,6 +51,7 @@ Options:
51
51
  * [update](#update)
52
52
  * [sync](#sync)
53
53
  * [conf](#conf)
54
+ * [upgrade](#upgrade)
54
55
 
55
56
  #### init
56
57
 
@@ -112,6 +113,9 @@ Options:
112
113
  blox sync
113
114
 
114
115
  Sync local registry with remote updates
116
+
117
+ Options:
118
+ -f, --force Force update [boolean] [default: "false"]
115
119
  ```
116
120
 
117
121
  #### conf
@@ -129,6 +133,18 @@ Options:
129
133
  -r, --registries Remote registries urls
130
134
  ```
131
135
 
136
+ #### upgrade
137
+
138
+ ```sh
139
+ blox upgrade
140
+ ```
141
+
142
+ ```
143
+ blox upgrade
144
+
145
+ Upgrade blox cli to latest version
146
+ ```
147
+
132
148
  ### Docs
133
149
 
134
150
  - [Design](./docs/design.md)