@naseej/blox 1.3.2 → 1.3.4

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 +74 -42
  2. package/package.json +1 -1
package/dist/run.js CHANGED
@@ -31,7 +31,7 @@ var option = (flags, description) => {
31
31
  };
32
32
 
33
33
  // package.json
34
- var version = "1.3.2";
34
+ var version = "1.3.4";
35
35
 
36
36
  // src/commands/add/index.ts
37
37
  var import_fs_extra8 = __toESM(require("fs-extra"));
@@ -253,7 +253,7 @@ var createPatch = async (fromCommit, toCommit, outputPath, ignore2 = []) => {
253
253
  ">",
254
254
  outputPath,
255
255
  "--",
256
- ...ignore2.map((file) => `':!${file}'`)
256
+ ...ignore2.map((file) => `":(exclude)${file}"`)
257
257
  ]);
258
258
  };
259
259
  var getChangesLog = async (fromCommit, toCommit) => {
@@ -621,13 +621,42 @@ var import_node_path8 = __toESM(require("path"));
621
621
  var import_ejs = __toESM(require("ejs"));
622
622
  var import_fs_extra7 = __toESM(require("fs-extra"));
623
623
  var import_klaw3 = __toESM(require("klaw"));
624
+ var NON_RENDERABLE_FILES = [
625
+ ".png",
626
+ ".jpg",
627
+ ".jpeg",
628
+ ".gif",
629
+ ".svg",
630
+ ".ico",
631
+ ".ttf",
632
+ ".woff",
633
+ ".woff2",
634
+ ".otf",
635
+ ".mp4",
636
+ ".mp3",
637
+ ".zip",
638
+ ".plist",
639
+ ".DS_Store",
640
+ ".bin"
641
+ ];
624
642
  async function replacePlaceholders(dir, context) {
625
643
  debug("Replace placeholders");
626
644
  for await (const file of (0, import_klaw3.default)(dir)) {
627
- if (file.stats.isFile()) {
628
- const template = import_fs_extra7.default.readFileSync(file.path, "utf-8");
629
- const rendered = import_ejs.default.render(template, context);
630
- import_fs_extra7.default.writeFileSync(file.path, rendered, "utf-8");
645
+ if (!file.stats.isFile()) continue;
646
+ const ext = import_node_path8.default.extname(file.path).toLowerCase();
647
+ if (NON_RENDERABLE_FILES.includes(ext)) {
648
+ continue;
649
+ }
650
+ const templateContent = import_fs_extra7.default.readFileSync(file.path, "utf8");
651
+ if (!templateContent.includes("<%")) {
652
+ continue;
653
+ }
654
+ try {
655
+ const rendered = import_ejs.default.render(templateContent, context);
656
+ import_fs_extra7.default.writeFileSync(file.path, rendered, "utf8");
657
+ } catch (err) {
658
+ console.error("\u274C Error rendering EJS for file:", file.path);
659
+ throw err;
631
660
  }
632
661
  }
633
662
  }
@@ -1049,7 +1078,8 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
1049
1078
  }
1050
1079
  }
1051
1080
  const patchFilePath = import_node_path9.default.join(dir, "diff.patch");
1052
- ignore2.push(".blox", "**/.blox");
1081
+ const remoteIgnore = remoteBloxFile.definition?.ignore || [];
1082
+ ignore2.push(...remoteIgnore, ".blox", "**/.blox");
1053
1083
  await git.createPatch(fromCommit, toCommit, patchFilePath, ignore2);
1054
1084
  const deletePatchFile = async () => {
1055
1085
  if (!isDebugMode()) {
@@ -1067,24 +1097,12 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
1067
1097
  console.log(errorMessage.replace("error:", fmt.red("error:")));
1068
1098
  if (errorMessage.includes("does not exist in index")) {
1069
1099
  logWarningSection(
1070
- "These files has changes in remote but were deleted:",
1071
- [
1072
- fmt.cyan(
1073
- JSON.stringify(
1074
- [
1075
- ...errorMessage.matchAll(
1076
- /error: (.*): does not exist in index/g
1077
- )
1078
- ].map((m) => m[1]),
1079
- null,
1080
- 2
1081
- )
1082
- ),
1083
- "Try to",
1084
- `1- temporarily to .blox ignore property for ${name}`,
1085
- "2- commit it and try again",
1086
- "3- remove it after update"
1087
- ].join("\n\n")
1100
+ "Some files has changes in remote but were deleted, \n if you want to skip them pass this arg to update command:",
1101
+ fmt.cyan(
1102
+ `--ignore ${[
1103
+ ...errorMessage.matchAll(/error: (.*): does not exist in index/g)
1104
+ ].map((m) => `"${name}:${m[1]}"`).join(",")}`
1105
+ )
1088
1106
  );
1089
1107
  }
1090
1108
  throw new Error("Failed to apply changes.");
@@ -1113,7 +1131,8 @@ async function updateApp({
1113
1131
  templateDef,
1114
1132
  templates,
1115
1133
  usedBlocks,
1116
- availableBlocks
1134
+ availableBlocks,
1135
+ ignore: ignore2
1117
1136
  }) {
1118
1137
  await runTask({ start: "Update App", end: "Updated App" }, async () => {
1119
1138
  const template = templates[templateDef.name];
@@ -1124,7 +1143,7 @@ async function updateApp({
1124
1143
  const toAppCommit = await updateFromRemote({
1125
1144
  name: templateDef.name,
1126
1145
  source: template.source,
1127
- ignore: templateDef.ignore
1146
+ ignore: ignore2
1128
1147
  });
1129
1148
  if (!toAppCommit) return;
1130
1149
  if (!templateDef.bases?.length) return;
@@ -1148,7 +1167,7 @@ async function updateApp({
1148
1167
  }
1149
1168
  });
1150
1169
  }
1151
- async function updateAppBases(templateDef, templates) {
1170
+ async function updateAppBases(templateDef, templates, ignore2) {
1152
1171
  for (const base of templateDef.bases || []) {
1153
1172
  await runTask(
1154
1173
  { start: `Update App base: ${base.name}`, end: `Updated App base: ${base.name}` },
@@ -1158,19 +1177,14 @@ async function updateAppBases(templateDef, templates) {
1158
1177
  error("Selected template not available in registries");
1159
1178
  return;
1160
1179
  }
1161
- await updateFromRemote({
1162
- name: base.name,
1163
- source: template.source,
1164
- ignore: templateDef.ignore
1165
- });
1180
+ await updateFromRemote({ name: base.name, source: template.source, ignore: ignore2 });
1166
1181
  }
1167
1182
  );
1168
1183
  }
1169
1184
  }
1170
- async function updateBlock(block, blocks) {
1185
+ async function updateBlock(block, blocks, ignore2) {
1171
1186
  const blockRegistryData = blocks[block];
1172
1187
  const blockPath = import_node_path10.default.join(blocksDir, block);
1173
- const blockDef = getBlockDef(blockPath);
1174
1188
  await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
1175
1189
  if (!blockRegistryData) {
1176
1190
  error(`Selected block: ${block} not available in registries`, false);
@@ -1179,8 +1193,8 @@ async function updateBlock(block, blocks) {
1179
1193
  await updateFromRemote({
1180
1194
  name: block,
1181
1195
  source: blockRegistryData.source,
1182
- ignore: blockDef.ignore,
1183
- dir: blockPath
1196
+ dir: blockPath,
1197
+ ignore: ignore2
1184
1198
  });
1185
1199
  });
1186
1200
  }
@@ -1222,7 +1236,7 @@ ${fmt.gray("-".repeat(82))}
1222
1236
  // src/commands/update/index.ts
1223
1237
  var update2 = command("update").description("Update app/block").alias("u").addOption(
1224
1238
  option("-s, --scope <scope>", "Scope of update").default("all").choices(["app", "bases", "block", "all"])
1225
- ).option("-b, --block <name>", "Block to update, valid only with scope block").action(async (args) => {
1239
+ ).option("--ignore <list...>", 'Files ignore list scoped by name i.e "repo:file"').option("-b, --block <name>", "Block to update, valid only with scope block").action(async (args) => {
1226
1240
  if (await git.hasUncommittedChanges()) {
1227
1241
  import_prompts15.log.warn(fmt.yellow("Make sure to commit any changes first"));
1228
1242
  return;
@@ -1234,16 +1248,34 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
1234
1248
  const availableBlocks = await getAvailableBlocks(templateDef);
1235
1249
  const templates = await getAvailableTemplates();
1236
1250
  const usedBlocks = getUsedBlocksDef();
1251
+ const ignoresByName = {};
1252
+ for (const ignore2 of args.ignore || []) {
1253
+ const [repo, pattern] = ignore2.split(":");
1254
+ if (!repo || !pattern) {
1255
+ error("Invalid ignore pattern");
1256
+ return;
1257
+ }
1258
+ if (!ignoresByName[repo]) {
1259
+ ignoresByName[repo] = [];
1260
+ }
1261
+ ignoresByName[repo].push(pattern);
1262
+ }
1237
1263
  try {
1238
1264
  if (["app", "all"].includes(args.scope)) {
1239
- await updateApp({ templateDef, templates, usedBlocks, availableBlocks });
1265
+ await updateApp({
1266
+ templateDef,
1267
+ templates,
1268
+ usedBlocks,
1269
+ availableBlocks,
1270
+ ignore: ignoresByName[templateDef.name]
1271
+ });
1240
1272
  }
1241
1273
  if (["bases", "all"].includes(args.scope)) {
1242
- await updateAppBases(templateDef, templates);
1274
+ await updateAppBases(templateDef, templates, ignoresByName[templateDef.name]);
1243
1275
  }
1244
1276
  if (args.scope === "all") {
1245
1277
  for (const block of usedBlocks) {
1246
- await updateBlock(block.name, availableBlocks);
1278
+ await updateBlock(block.name, availableBlocks, ignoresByName[block.name]);
1247
1279
  }
1248
1280
  }
1249
1281
  if (args.scope === "block") {
@@ -1261,7 +1293,7 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
1261
1293
  error("Selected block not used in app");
1262
1294
  return;
1263
1295
  }
1264
- await updateBlock(blockDef.name, availableBlocks);
1296
+ await updateBlock(blockDef.name, availableBlocks, ignoresByName[blockDef.name]);
1265
1297
  }
1266
1298
  await checkVersionsCompatibility();
1267
1299
  const endCheckpoints = await getCurrentCheckpoints();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"