@naseej/blox 1.0.0 → 1.1.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 +83 -54
  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.1.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;
@@ -224,8 +224,8 @@ var update = (shellOptions = {}) => {
224
224
  var getLatestCommitFromRemote = async (remote) => {
225
225
  return getLatestCommit(`${remote}/main`);
226
226
  };
227
- var getLatestCommitFromPath = async (path10) => {
228
- return getLatestCommit("HEAD", path10);
227
+ var getLatestCommitFromPath = async (path11) => {
228
+ return getLatestCommit("HEAD", path11);
229
229
  };
230
230
  var getLatestCommit = async (rev, cwd = ".") => {
231
231
  debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
@@ -238,7 +238,7 @@ var getLatestCommit = async (rev, cwd = ".") => {
238
238
  });
239
239
  return commit2.replace(/\n/g, "");
240
240
  };
241
- var createPatch = async (fromCommit, toCommit, outputPath, ignore = []) => {
241
+ var createPatch = async (fromCommit, toCommit, outputPath, ignore2 = []) => {
242
242
  return $("git", [
243
243
  "diff",
244
244
  fromCommit,
@@ -246,7 +246,7 @@ var createPatch = async (fromCommit, toCommit, outputPath, ignore = []) => {
246
246
  ">",
247
247
  outputPath,
248
248
  "--",
249
- ...ignore.map((file) => `':!${file}'`)
249
+ ...ignore2.map((file) => `':!${file}'`)
250
250
  ]);
251
251
  };
252
252
  var getChangesLog = async (fromCommit, toCommit) => {
@@ -259,7 +259,7 @@ var getChangesLog = async (fromCommit, toCommit) => {
259
259
  return changes;
260
260
  };
261
261
  var applyPatch = (patch, cwd = ".") => {
262
- const args = ["apply", "-3"];
262
+ const args = ["apply", "-3", "--allow-empty"];
263
263
  if (cwd != ".") {
264
264
  args.push("--directory");
265
265
  args.push(normalizePath(cwd));
@@ -441,10 +441,32 @@ async function migrateAll(autoCommit) {
441
441
  }
442
442
  }
443
443
 
444
- // src/services/registry.ts
445
- var import_node_path6 = __toESM(require("path"));
446
- var import_fs_extra5 = __toESM(require("fs-extra"));
444
+ // src/services/fs.ts
445
+ var import_node_path5 = __toESM(require("path"));
446
+ var import_fs_extra4 = __toESM(require("fs-extra"));
447
+ var import_ignore = __toESM(require("ignore"));
447
448
  var import_klaw = __toESM(require("klaw"));
449
+ var filterBlacklisted = (item) => {
450
+ return !item.includes("node_modules") && !item.includes(".git");
451
+ };
452
+ var deletePattern = async (cwd, patterns = []) => {
453
+ const ig = (0, import_ignore.default)().add(patterns);
454
+ for await (const file of (0, import_klaw.default)(cwd, { filter: filterBlacklisted })) {
455
+ const relativePath = import_node_path5.default.relative(cwd, file.path);
456
+ if (relativePath && ig.ignores(relativePath)) {
457
+ if (!await import_fs_extra4.default.exists(file.path)) {
458
+ continue;
459
+ }
460
+ debug(`deleting: ${relativePath}`);
461
+ await import_fs_extra4.default.remove(file.path);
462
+ }
463
+ }
464
+ };
465
+
466
+ // src/services/registry.ts
467
+ var import_node_path7 = __toESM(require("path"));
468
+ var import_fs_extra6 = __toESM(require("fs-extra"));
469
+ var import_klaw2 = __toESM(require("klaw"));
448
470
  var import_merge = __toESM(require("lodash/merge"));
449
471
 
450
472
  // src/shared/spinner.ts
@@ -479,40 +501,40 @@ async function runTask(message, task) {
479
501
  }
480
502
 
481
503
  // src/services/config.ts
482
- var import_node_path5 = __toESM(require("path"));
504
+ var import_node_path6 = __toESM(require("path"));
483
505
  var import_env_paths = __toESM(require("env-paths"));
484
- var import_fs_extra4 = __toESM(require("fs-extra"));
506
+ var import_fs_extra5 = __toESM(require("fs-extra"));
485
507
  var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
486
- var configFilePath = import_node_path5.default.join(appPaths.config, "config.json");
508
+ var configFilePath = import_node_path6.default.join(appPaths.config, "config.json");
487
509
  var getLocalConfig = () => {
488
510
  try {
489
- return import_fs_extra4.default.readJSONSync(configFilePath);
511
+ return import_fs_extra5.default.readJSONSync(configFilePath);
490
512
  } catch {
491
513
  return defaultConfig;
492
514
  }
493
515
  };
494
516
  var updateLocalConfig = (config) => {
495
517
  debug("Update local config");
496
- import_fs_extra4.default.ensureFileSync(configFilePath);
518
+ import_fs_extra5.default.ensureFileSync(configFilePath);
497
519
  const current = getLocalConfig();
498
- import_fs_extra4.default.writeJsonSync(configFilePath, { ...current, ...config });
520
+ import_fs_extra5.default.writeJsonSync(configFilePath, { ...current, ...config });
499
521
  };
500
522
 
501
523
  // src/services/registry.ts
502
- var registriesDataPath = import_node_path6.default.join(appPaths.data, "registries");
524
+ var registriesDataPath = import_node_path7.default.join(appPaths.data, "registries");
503
525
  var syncRegistries = async () => {
504
526
  debug("Sync registries");
505
- import_fs_extra5.default.ensureDirSync(registriesDataPath);
527
+ import_fs_extra6.default.ensureDirSync(registriesDataPath);
506
528
  const config = getLocalConfig();
507
529
  return await runTask("Update registries", async () => {
508
530
  await Promise.all(
509
531
  config.registries.map(async (registry) => {
510
532
  debug(`update registry: ${registry}`);
511
533
  const repoName = registry.split("/").pop() || "";
512
- const repoDir = import_node_path6.default.join(registriesDataPath, repoName);
513
- if (!import_fs_extra5.default.existsSync(repoDir)) {
534
+ const repoDir = import_node_path7.default.join(registriesDataPath, repoName);
535
+ if (!import_fs_extra6.default.existsSync(repoDir)) {
514
536
  await git.clone(registry, "--depth 1", { cwd: registriesDataPath });
515
- } else if (import_fs_extra5.default.existsSync(import_node_path6.default.join(repoDir, ".git"))) {
537
+ } else if (import_fs_extra6.default.existsSync(import_node_path7.default.join(repoDir, ".git"))) {
516
538
  await git.update({ cwd: repoDir });
517
539
  } else {
518
540
  debug(`local registry`);
@@ -524,11 +546,11 @@ var syncRegistries = async () => {
524
546
  var getAvailableTemplates = async () => {
525
547
  debug("Get available templates");
526
548
  const templates = {};
527
- for await (const file of (0, import_klaw.default)(registriesDataPath, {
549
+ for await (const file of (0, import_klaw2.default)(registriesDataPath, {
528
550
  filter: (item) => !item.includes(".git")
529
551
  })) {
530
552
  if (file.path.endsWith(".json")) {
531
- const data = import_fs_extra5.default.readJSONSync(file.path);
553
+ const data = import_fs_extra6.default.readJSONSync(file.path);
532
554
  Object.entries(data.templates || {}).forEach(([templateName, template]) => {
533
555
  if (!template.source) {
534
556
  template.source = `/template-${templateName}`;
@@ -568,27 +590,27 @@ var getAvailableBlocks = async (templateInfo) => {
568
590
  return blocks;
569
591
  };
570
592
  var getAvailableVersions = async (id) => {
571
- const registries = import_fs_extra5.default.readdirSync(registriesDataPath);
593
+ const registries = import_fs_extra6.default.readdirSync(registriesDataPath);
572
594
  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);
595
+ const versionsFile = import_node_path7.default.join(registriesDataPath, registry, "versions", `${id}.json`);
596
+ if (import_fs_extra6.default.existsSync(versionsFile)) {
597
+ return import_fs_extra6.default.readJSONSync(versionsFile);
576
598
  }
577
599
  }
578
600
  };
579
601
 
580
602
  // src/services/template.ts
581
- var import_node_path7 = __toESM(require("path"));
603
+ var import_node_path8 = __toESM(require("path"));
582
604
  var import_ejs = __toESM(require("ejs"));
583
- var import_fs_extra6 = __toESM(require("fs-extra"));
584
- var import_klaw2 = __toESM(require("klaw"));
605
+ var import_fs_extra7 = __toESM(require("fs-extra"));
606
+ var import_klaw3 = __toESM(require("klaw"));
585
607
  async function replacePlaceholders(dir, context) {
586
608
  debug("Replace placeholders");
587
- for await (const file of (0, import_klaw2.default)(dir)) {
609
+ for await (const file of (0, import_klaw3.default)(dir)) {
588
610
  if (file.stats.isFile()) {
589
- const template = import_fs_extra6.default.readFileSync(file.path, "utf-8");
611
+ const template = import_fs_extra7.default.readFileSync(file.path, "utf-8");
590
612
  const rendered = import_ejs.default.render(template, context);
591
- import_fs_extra6.default.writeFileSync(file.path, rendered, "utf-8");
613
+ import_fs_extra7.default.writeFileSync(file.path, rendered, "utf-8");
592
614
  }
593
615
  }
594
616
  }
@@ -606,7 +628,7 @@ function getBlockDef(cwd = ".") {
606
628
  }
607
629
  function getBloxFile(cwd = ".") {
608
630
  try {
609
- const file = import_fs_extra6.default.readJSONSync(import_node_path7.default.join(cwd, bloxFilePath));
631
+ const file = import_fs_extra7.default.readJSONSync(import_node_path8.default.join(cwd, bloxFilePath));
610
632
  if (!file.checkpoints) {
611
633
  file.checkpoints = {};
612
634
  }
@@ -617,7 +639,7 @@ function getBloxFile(cwd = ".") {
617
639
  }
618
640
  function saveBloxFile(info, cwd = ".") {
619
641
  debug("Save info");
620
- import_fs_extra6.default.writeFileSync(import_node_path7.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
642
+ import_fs_extra7.default.writeFileSync(import_node_path8.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
621
643
  }
622
644
  function updateCheckpoint(name, checkpoint, cwd = ".") {
623
645
  const info = getBloxFile(cwd);
@@ -630,12 +652,12 @@ function updateCheckpoint(name, checkpoint, cwd = ".") {
630
652
  function getUsedBlocks() {
631
653
  debug("Get used blocks");
632
654
  const blocks = [];
633
- if (import_fs_extra6.default.existsSync(blocksDir)) {
634
- import_fs_extra6.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
655
+ if (import_fs_extra7.default.existsSync(blocksDir)) {
656
+ import_fs_extra7.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
635
657
  if (!file.isDirectory()) {
636
658
  return;
637
659
  }
638
- const blockDef = getBlockDef(import_node_path7.default.join(blocksDir, file.name));
660
+ const blockDef = getBlockDef(import_node_path8.default.join(blocksDir, file.name));
639
661
  if (blockDef) {
640
662
  blocks.push(blockDef);
641
663
  }
@@ -777,7 +799,7 @@ function runInitScript(cwd) {
777
799
  var addBlock = async (block, blocks) => {
778
800
  const blockPath = `blocks/${block}`;
779
801
  const blockRegistryData = blocks[block];
780
- if (!import_fs_extra7.default.existsSync(blockPath)) {
802
+ if (!import_fs_extra8.default.existsSync(blockPath)) {
781
803
  await runTask(
782
804
  { start: `Fetching block: ${block}`, end: `Added block: ${block}` },
783
805
  async () => {
@@ -791,6 +813,8 @@ var addBlock = async (block, blocks) => {
791
813
  await git.unInit(blockPath);
792
814
  await replacePlaceholders(blockPath, {});
793
815
  await migrateAll();
816
+ const def = getBlockDef(blockPath);
817
+ await deletePattern(blockPath, def.ignore);
794
818
  updateCheckpoint(block, { commit: commit2 }, blockPath);
795
819
  }
796
820
  );
@@ -857,7 +881,7 @@ var conf = command("conf").description("Set blox global config").alias("c").opti
857
881
  });
858
882
 
859
883
  // src/commands/init/index.ts
860
- var import_fs_extra8 = __toESM(require("fs-extra"));
884
+ var import_fs_extra9 = __toESM(require("fs-extra"));
861
885
  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
886
  await syncRegistries();
863
887
  try {
@@ -889,13 +913,17 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
889
913
  }
890
914
  await git.unInit(name);
891
915
  await migrateAll();
916
+ const def = getTemplateDef(name);
917
+ await deletePattern(name, def.ignore);
892
918
  await replacePlaceholders(name, { app: { name } });
893
919
  updateCheckpoint(name, { commit: commit2 }, name);
894
920
  await git.init(name);
895
921
  task.stop(`App initialized in ${name}`);
896
922
  await runTask("Run init script", async () => runInitScript(name || ""));
897
923
  } catch (e) {
898
- name && import_fs_extra8.default.existsSync(name) && import_fs_extra8.default.rmdirSync(name);
924
+ if (name && import_fs_extra9.default.existsSync(name)) {
925
+ await import_fs_extra9.default.remove(name);
926
+ }
899
927
  error(e);
900
928
  }
901
929
  });
@@ -917,12 +945,12 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
917
945
  var import_prompts13 = require("@clack/prompts");
918
946
 
919
947
  // src/commands/update/utils.ts
920
- var import_node_path9 = __toESM(require("path"));
948
+ var import_node_path10 = __toESM(require("path"));
921
949
 
922
950
  // 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 = ".") {
951
+ var import_node_path9 = __toESM(require("path"));
952
+ var import_fs_extra10 = __toESM(require("fs-extra"));
953
+ async function updateFromRemote(name, source = "", ignore2 = [], destPath = ".") {
926
954
  debug("Updating from remote");
927
955
  await git.updateRemote(name, source);
928
956
  const bloxFile = getBloxFile(destPath);
@@ -956,13 +984,13 @@ async function updateFromRemote(name, source = "", ignore = [], destPath = ".")
956
984
  );
957
985
  }
958
986
  }
959
- const patchFilePath = import_node_path8.default.join(destPath, "diff.patch");
960
- ignore.push("./.blox");
961
- await git.createPatch(fromCommit, toCommit, patchFilePath, ignore);
987
+ const patchFilePath = import_node_path9.default.join(destPath, "diff.patch");
988
+ ignore2.push("./.blox");
989
+ await git.createPatch(fromCommit, toCommit, patchFilePath, ignore2);
962
990
  const changes = await git.getChangesLog(fromCommit, toCommit);
963
991
  const deletePatchFile = async () => {
964
992
  if (!isDebugMode()) {
965
- await import_fs_extra9.default.unlink(patchFilePath);
993
+ await import_fs_extra10.default.unlink(patchFilePath);
966
994
  }
967
995
  debug("make sure to delete the patch file after you're done with it.");
968
996
  };
@@ -1019,14 +1047,15 @@ async function updateAppBases(templateInfo, templates) {
1019
1047
  }
1020
1048
  }
1021
1049
  async function updateBlock(block, blocks) {
1022
- const blockDef = blocks[block];
1023
- const blockPath = import_node_path9.default.join(blocksDir, block);
1050
+ const blockRegistryData = blocks[block];
1051
+ const blockPath = import_node_path10.default.join(blocksDir, block);
1052
+ const blockDef = getBlockDef(blockPath);
1024
1053
  await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
1025
- if (!blockDef) {
1054
+ if (!blockRegistryData) {
1026
1055
  error(`Selected block: ${block} not available in registries`, false);
1027
1056
  return;
1028
1057
  }
1029
- await updateFromRemote(block, blockDef.source, blockDef.ignore, blockPath);
1058
+ await updateFromRemote(block, blockRegistryData.source, blockDef.ignore, blockPath);
1030
1059
  });
1031
1060
  }
1032
1061
 
@@ -1035,7 +1064,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
1035
1064
  option("-s, --scope <scope>", "Scope of update").default("all").choices(["app", "bases", "block", "all"])
1036
1065
  ).option("-b, --block <name>", "Block to update, valid only with scope block").action(async (args) => {
1037
1066
  if (await git.hasUncommittedChanges()) {
1038
- import_prompts13.log.warn("Make sure to commit any changes first");
1067
+ import_prompts13.log.warn(fmt.yellow("Make sure to commit any changes first"));
1039
1068
  return;
1040
1069
  }
1041
1070
  await migrateAll(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "1.0.0",
3
+ "version": "1.1.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
  }