@naseej/blox 0.1.18 → 0.1.20

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 +150 -127
  2. package/package.json +1 -1
package/dist/run.js CHANGED
@@ -31,14 +31,46 @@ var option = (flags, description) => {
31
31
  };
32
32
 
33
33
  // package.json
34
- var version = "0.1.17";
34
+ var version = "0.1.20";
35
35
 
36
36
  // src/commands/add/index.ts
37
- var import_fs_extra6 = __toESM(require("fs-extra"));
37
+ var import_fs_extra7 = __toESM(require("fs-extra"));
38
+
39
+ // src/commands/update/utils.ts
40
+ var import_node_path7 = __toESM(require("path"));
41
+
42
+ // src/config/index.ts
43
+ var defaultConfig = {
44
+ syncFrequency: "1d",
45
+ registries: ["https://tfs.aas.com.sa/Medad/BLOX/_git/default-registry"]
46
+ };
47
+ var basedOnFile = ".blox";
48
+ var blocksDir = "blocks";
49
+
50
+ // src/services/registry.ts
51
+ var import_node_path4 = __toESM(require("path"));
52
+ var import_dayjs = __toESM(require("dayjs"));
53
+ var import_fs_extra4 = __toESM(require("fs-extra"));
54
+ var import_klaw = __toESM(require("klaw"));
55
+ var import_ms = __toESM(require("ms"));
56
+
57
+ // src/config/runtime.ts
58
+ var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
59
+ var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
60
+
61
+ // src/services/fs.ts
62
+ var import_fs_extra = __toESM(require("fs-extra"));
63
+ var readJsonFile = (path8, defaultValue = {}) => {
64
+ try {
65
+ return import_fs_extra.default.readJSONSync(path8);
66
+ } catch {
67
+ return defaultValue;
68
+ }
69
+ };
38
70
 
39
71
  // src/services/git.ts
40
72
  var import_node_path2 = __toESM(require("path"));
41
- var import_fs_extra = __toESM(require("fs-extra"));
73
+ var import_fs_extra2 = __toESM(require("fs-extra"));
42
74
 
43
75
  // src/services/path.ts
44
76
  var import_node_path = __toESM(require("path"));
@@ -53,10 +85,6 @@ var import_node_child_process = require("child_process");
53
85
  var console2 = __toESM(require("console"));
54
86
  var import_prompts = require("@clack/prompts");
55
87
 
56
- // src/config/runtime.ts
57
- var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
58
- var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
59
-
60
88
  // src/shared/terminal/index.ts
61
89
  var import_ansis = __toESM(require("ansis"));
62
90
  var fmt = import_ansis.default;
@@ -163,8 +191,15 @@ var getLatestCommit = async (rev, cwd = ".") => {
163
191
  });
164
192
  return commit.replace(/\n/g, "");
165
193
  };
166
- var createPatch = async (fromCommit, toCommit, outputPath) => {
167
- return $("git", ["diff", fromCommit, toCommit, ">", outputPath]);
194
+ var createPatch = async (fromCommit, toCommit, outputPath, ignore = []) => {
195
+ return $("git", [
196
+ "diff",
197
+ fromCommit,
198
+ toCommit,
199
+ ">",
200
+ outputPath,
201
+ ...ignore.map((file) => `':!${file}'`)
202
+ ]);
168
203
  };
169
204
  var getChangesLog = async (fromCommit, toCommit) => {
170
205
  let changes = "";
@@ -186,7 +221,7 @@ var applyPatch = (patch, cwd = ".") => {
186
221
  };
187
222
  var unInit = (cwd) => {
188
223
  debug("UnInit");
189
- return import_fs_extra.default.remove(import_node_path2.default.join(cwd, ".git"));
224
+ return import_fs_extra2.default.remove(import_node_path2.default.join(cwd, ".git"));
190
225
  };
191
226
  var init = async (cwd) => {
192
227
  debug("Init");
@@ -208,23 +243,6 @@ var git = {
208
243
  updateRemote
209
244
  };
210
245
 
211
- // src/services/registry.ts
212
- var import_node_path4 = __toESM(require("path"));
213
- var import_dayjs = __toESM(require("dayjs"));
214
- var import_fs_extra4 = __toESM(require("fs-extra"));
215
- var import_klaw = __toESM(require("klaw"));
216
- var import_ms = __toESM(require("ms"));
217
-
218
- // src/services/fs.ts
219
- var import_fs_extra2 = __toESM(require("fs-extra"));
220
- var readJsonFile = (path8, defaultValue = {}) => {
221
- try {
222
- return import_fs_extra2.default.readJSONSync(path8);
223
- } catch {
224
- return defaultValue;
225
- }
226
- };
227
-
228
246
  // src/shared/spinner.ts
229
247
  var import_prompts3 = require("@clack/prompts");
230
248
  var spinner = () => {
@@ -242,14 +260,16 @@ var spinner = () => {
242
260
  }
243
261
  };
244
262
  };
245
- async function runTask(name, task) {
263
+ async function runTask(message, task) {
264
+ const startMessage = typeof message === "string" ? message : message.start;
265
+ const endMessage = typeof message === "string" ? message : message.end;
246
266
  const taskSpinner = spinner();
247
- taskSpinner.start(name);
267
+ taskSpinner.start(startMessage);
248
268
  try {
249
269
  await (typeof task === "function" ? task() : task);
250
- taskSpinner.stop(name);
270
+ taskSpinner.stop(endMessage);
251
271
  } catch (e) {
252
- taskSpinner.stop(`Failed: ${name}`, 1);
272
+ taskSpinner.stop(`Failed: ${endMessage}`, 1);
253
273
  throw e;
254
274
  }
255
275
  }
@@ -258,16 +278,6 @@ async function runTask(name, task) {
258
278
  var import_node_path3 = __toESM(require("path"));
259
279
  var import_env_paths = __toESM(require("env-paths"));
260
280
  var import_fs_extra3 = __toESM(require("fs-extra"));
261
-
262
- // src/config/index.ts
263
- var defaultConfig = {
264
- syncFrequency: "1d",
265
- registries: ["https://tfs.aas.com.sa/Medad/BLOX/_git/default-registry"]
266
- };
267
- var basedOnFile = ".blox";
268
- var blocksDir = "blocks";
269
-
270
- // src/services/config.ts
271
281
  var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
272
282
  var configFilePath = import_node_path3.default.join(appPaths.config, "config.json");
273
283
  var getLocalConfig = () => {
@@ -358,6 +368,10 @@ var getAvailableBlocks = async (templateName) => {
358
368
  return blocks;
359
369
  };
360
370
 
371
+ // src/services/updater.ts
372
+ var import_node_path6 = __toESM(require("path"));
373
+ var import_fs_extra6 = __toESM(require("fs-extra"));
374
+
361
375
  // src/services/template.ts
362
376
  var import_node_path5 = __toESM(require("path"));
363
377
  var import_ejs = __toESM(require("ejs"));
@@ -443,6 +457,85 @@ var textList = async (opts) => {
443
457
  return value.split(",");
444
458
  };
445
459
 
460
+ // src/services/updater.ts
461
+ async function updateFromRemote(name, source = "", ignore = [], destPath = ".") {
462
+ debug("Updating from remote");
463
+ import_fs_extra6.default.ensureDirSync(appPaths.temp);
464
+ await git.updateRemote(name, source);
465
+ const fromCommit = getBasedOnInfo(destPath).commit;
466
+ const toCommit = await git.getLatestCommitFromRemote(name);
467
+ debug({ fromCommit, toCommit });
468
+ if (fromCommit == toCommit) {
469
+ debug("No new version");
470
+ return;
471
+ }
472
+ const patchFilePath = import_node_path6.default.join(destPath, "diff.patch");
473
+ await git.createPatch(fromCommit, toCommit, patchFilePath, ignore);
474
+ const changes = await git.getChangesLog(fromCommit, toCommit);
475
+ const deletePatchFile = async () => {
476
+ if (!isDebugMode()) {
477
+ await import_fs_extra6.default.unlink(patchFilePath);
478
+ }
479
+ debug("make sure to delete the patch file after you're done with it.");
480
+ };
481
+ try {
482
+ await git.applyPatch(patchFilePath, destPath);
483
+ } catch (e) {
484
+ const errorMessage = `${e}`;
485
+ if (errorMessage.includes("error:")) {
486
+ await deletePatchFile();
487
+ console.log(`${e}`.replace("error:", fmt.red("error:")));
488
+ error("Failed to apply changes.");
489
+ }
490
+ }
491
+ if (changes.trim() !== "") {
492
+ logWarningSection(
493
+ "These is the changes from last update, make sure to review for breaking changes",
494
+ changes
495
+ );
496
+ }
497
+ await deletePatchFile();
498
+ updateBasedOnInfo({ commit: toCommit }, destPath);
499
+ }
500
+
501
+ // src/commands/update/utils.ts
502
+ async function updateAPP(templateInfo) {
503
+ await runTask({ start: "Update App", end: "Updated App" }, async () => {
504
+ const templates = await getAvailableTemplates();
505
+ const template = templates[templateInfo.name];
506
+ if (!template) {
507
+ error("Selected template not available, try to sync registries");
508
+ return;
509
+ }
510
+ await updateFromRemote(templateInfo.name, template.source, templateInfo.ignore);
511
+ });
512
+ }
513
+ var updatedBlocks = /* @__PURE__ */ new Set();
514
+ async function updateBlock(block, blocks) {
515
+ if (updatedBlocks.has(block)) {
516
+ debug(`${block} already updated`);
517
+ return;
518
+ }
519
+ const blockInfo = blocks[block];
520
+ await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
521
+ if (!blockInfo) {
522
+ error("Selected block not available, try to sync registries", false);
523
+ return;
524
+ }
525
+ await updateFromRemote(
526
+ block,
527
+ blockInfo.source,
528
+ blockInfo.ignore,
529
+ import_node_path7.default.join(blocksDir, block)
530
+ );
531
+ updatedBlocks.add(block);
532
+ });
533
+ for (const dep of blockInfo?.dependencies || []) {
534
+ debug(`${block} has dependency on ${dep}, will be updated`);
535
+ await updateBlock(dep, blocks);
536
+ }
537
+ }
538
+
446
539
  // src/commands/init/utils/index.ts
447
540
  function runInitScript(cwd) {
448
541
  debug(`Run init script in: ${cwd}`);
@@ -456,18 +549,21 @@ function runInitScript(cwd) {
456
549
  var addBlock = async (block, blocks) => {
457
550
  const blockPath = `blocks/${block}`;
458
551
  const blockDef = blocks[block];
459
- if (!import_fs_extra6.default.existsSync(blockPath)) {
460
- const task = spinner();
461
- task.start(`Fetch block`);
462
- await git.clone(blockDef?.source || "", blockPath);
463
- const commit = await git.getLatestCommitFromPath(blockPath);
464
- await git.unInit(blockPath);
465
- await replacePlaceholders(blockPath, {});
466
- saveBasedOnInfo({ commit }, blockPath);
467
- await runInitScript(blockPath);
468
- task.stop(`Block ${block} added`);
552
+ if (!import_fs_extra7.default.existsSync(blockPath)) {
553
+ await runTask(
554
+ { start: `Fetching block: ${block}`, end: `Added block: ${block}` },
555
+ async () => {
556
+ await git.clone(blockDef?.source || "", blockPath);
557
+ const commit = await git.getLatestCommitFromPath(blockPath);
558
+ await git.unInit(blockPath);
559
+ await replacePlaceholders(blockPath, {});
560
+ saveBasedOnInfo({ commit }, blockPath);
561
+ await runInitScript(blockPath);
562
+ }
563
+ );
469
564
  } else {
470
- import_prompts2.log.warn(`${block} already exists, may need to be updated`);
565
+ debug(`${block} already exists, will be updated`);
566
+ await updateBlock(block, blocks);
471
567
  }
472
568
  for (const dep of blockDef?.dependencies || []) {
473
569
  await addBlock(dep, blocks);
@@ -581,79 +677,6 @@ var sync = command("sync").description("Sync local registry with remote updates"
581
677
  }
582
678
  });
583
679
 
584
- // src/commands/update/utils.ts
585
- var import_node_path7 = __toESM(require("path"));
586
-
587
- // src/services/updater.ts
588
- var import_node_path6 = __toESM(require("path"));
589
- var import_fs_extra7 = __toESM(require("fs-extra"));
590
- async function updateFromRemote(name, source = "", destPath = ".") {
591
- debug("Updating from remote");
592
- import_fs_extra7.default.ensureDirSync(appPaths.temp);
593
- await git.updateRemote(name, source);
594
- const fromCommit = getBasedOnInfo(destPath).commit;
595
- const toCommit = await git.getLatestCommitFromRemote(name);
596
- debug({ fromCommit, toCommit });
597
- if (fromCommit == toCommit) {
598
- debug("No new version");
599
- return;
600
- }
601
- const patchFilePath = import_node_path6.default.join(destPath, "diff.patch");
602
- await git.createPatch(fromCommit, toCommit, patchFilePath);
603
- const changes = await git.getChangesLog(fromCommit, toCommit);
604
- const deletePatchFile = async () => {
605
- if (!isDebugMode()) {
606
- await import_fs_extra7.default.unlink(patchFilePath);
607
- }
608
- debug("make sure to delete the patch file after you're done with it.");
609
- };
610
- try {
611
- await git.applyPatch(patchFilePath, destPath);
612
- } catch (e) {
613
- const errorMessage = `${e}`;
614
- if (errorMessage.includes("error:")) {
615
- await deletePatchFile();
616
- console.log(`${e}`.replace("error:", fmt.red("error:")));
617
- error("Failed to apply changes.");
618
- }
619
- }
620
- if (changes.trim() !== "") {
621
- logWarningSection(
622
- "These is the changes from last update, make sure to review for breaking changes",
623
- changes
624
- );
625
- }
626
- await deletePatchFile();
627
- updateBasedOnInfo({ commit: toCommit }, destPath);
628
- }
629
-
630
- // src/commands/update/utils.ts
631
- async function updateAPP(templateInfo) {
632
- await runTask("update app", async () => {
633
- const templates = await getAvailableTemplates();
634
- const template = templates[templateInfo.name];
635
- if (!template) {
636
- error("Selected template not available, try to sync registries");
637
- return;
638
- }
639
- await updateFromRemote(templateInfo.name, template.source);
640
- });
641
- }
642
- async function updateBlock(block, blockInfo) {
643
- await runTask(`update block: ${block.name}`, async () => {
644
- if (!blockInfo) {
645
- error("Selected block not available, try to sync registries", false);
646
- return;
647
- }
648
- await updateFromRemote(block.name, blockInfo.source, import_node_path7.default.join(blocksDir, block.name));
649
- if (blockInfo.dependencies?.length) {
650
- import_prompts2.log.warn(
651
- `${block.name} has deps ${JSON.stringify(blockInfo.dependencies)}, may need to be updated`
652
- );
653
- }
654
- });
655
- }
656
-
657
680
  // src/commands/update/index.ts
658
681
  var update2 = command("update").description("Update app/block").alias("u").addOption(
659
682
  option("-s, --scope <scope>", "Scope of update").default("all").choices(["app", "block", "all"])
@@ -667,7 +690,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
667
690
  const usedBlocks = getUsedBlocks();
668
691
  if (args.scope === "all") {
669
692
  for (const block of usedBlocks) {
670
- await updateBlock(block, availableBlocks[block.name]);
693
+ await updateBlock(block.name, availableBlocks);
671
694
  }
672
695
  }
673
696
  if (args.scope === "block") {
@@ -685,7 +708,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
685
708
  error("Selected block not used in app");
686
709
  return;
687
710
  }
688
- await updateBlock(block, availableBlocks[block.name]);
711
+ await updateBlock(block.name, availableBlocks);
689
712
  }
690
713
  });
691
714
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"