@naseej/blox 1.2.2 → 1.3.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.
- package/dist/run.js +65 -29
- 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.
|
|
34
|
+
var version = "1.3.0";
|
|
35
35
|
|
|
36
36
|
// src/commands/add/index.ts
|
|
37
37
|
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
@@ -125,7 +125,7 @@ var logWarningSection = (title, content) => {
|
|
|
125
125
|
const line = fmt.yellow("=".repeat(82));
|
|
126
126
|
console2.log("\n" + line);
|
|
127
127
|
console2.log(fmt.bold(fmt.yellow("\u25B2 " + title)));
|
|
128
|
-
content && console2.log(content);
|
|
128
|
+
content && console2.log("\n" + content);
|
|
129
129
|
console2.log(line + "\n");
|
|
130
130
|
};
|
|
131
131
|
var normalizeLogMessage = (content) => {
|
|
@@ -181,7 +181,11 @@ var clone = (repoUrl, options, shellOptions = {}) => {
|
|
|
181
181
|
var resetToCommit = async (commit2, cwd = ".") => {
|
|
182
182
|
await $("git", ["reset --hard", `${commit2}`], { cwd });
|
|
183
183
|
};
|
|
184
|
+
var updatedRemotes = /* @__PURE__ */ new Set();
|
|
184
185
|
var updateRemote = async (name, source, shellOptions = {}) => {
|
|
186
|
+
const remoteId = `${name}:${source}`;
|
|
187
|
+
if (updatedRemotes.has(remoteId)) return;
|
|
188
|
+
updatedRemotes.add(remoteId);
|
|
185
189
|
debug("updateRemote");
|
|
186
190
|
debug({ name, source });
|
|
187
191
|
try {
|
|
@@ -351,11 +355,6 @@ var text = async (opts) => {
|
|
|
351
355
|
checkIfCanceled(value);
|
|
352
356
|
return value;
|
|
353
357
|
};
|
|
354
|
-
var confirm = async (opts) => {
|
|
355
|
-
const value = await (0, import_prompts3.confirm)(opts);
|
|
356
|
-
checkIfCanceled(value);
|
|
357
|
-
return value;
|
|
358
|
-
};
|
|
359
358
|
var textList = async (opts) => {
|
|
360
359
|
opts.message = `${opts.message} ${fmt.gray('(separated with ",")')}`;
|
|
361
360
|
const value = await (0, import_prompts3.text)(opts);
|
|
@@ -537,7 +536,10 @@ var updateLocalConfig = (config) => {
|
|
|
537
536
|
|
|
538
537
|
// src/services/registry.ts
|
|
539
538
|
var registriesDataPath = import_node_path7.default.join(appPaths.data, "registries");
|
|
539
|
+
var upeToDate = false;
|
|
540
540
|
var syncRegistries = async () => {
|
|
541
|
+
if (upeToDate) return;
|
|
542
|
+
upeToDate = true;
|
|
541
543
|
debug("Sync registries");
|
|
542
544
|
import_fs_extra6.default.ensureDirSync(registriesDataPath);
|
|
543
545
|
const config = getLocalConfig();
|
|
@@ -664,6 +666,9 @@ function updateCheckpoint(name, checkpoint, cwd = ".") {
|
|
|
664
666
|
info.checkpoints[name] = checkpoint;
|
|
665
667
|
saveBloxFile(info, cwd);
|
|
666
668
|
}
|
|
669
|
+
function getUsedBlocksDef() {
|
|
670
|
+
return getUsedBlocks().map((b) => b.definition);
|
|
671
|
+
}
|
|
667
672
|
function getUsedBlocks() {
|
|
668
673
|
debug("Get used blocks");
|
|
669
674
|
const blocks = [];
|
|
@@ -672,8 +677,8 @@ function getUsedBlocks() {
|
|
|
672
677
|
if (!file.isDirectory()) {
|
|
673
678
|
return;
|
|
674
679
|
}
|
|
675
|
-
const blockDef =
|
|
676
|
-
if (blockDef) {
|
|
680
|
+
const blockDef = getBloxFile(import_node_path8.default.join(blocksDir, file.name));
|
|
681
|
+
if (blockDef && blockDef.definition) {
|
|
677
682
|
blocks.push(blockDef);
|
|
678
683
|
}
|
|
679
684
|
});
|
|
@@ -688,11 +693,13 @@ function processDependencyVersion(dep) {
|
|
|
688
693
|
return dep;
|
|
689
694
|
}
|
|
690
695
|
function processTemplate(def) {
|
|
696
|
+
debug("processTemplate");
|
|
691
697
|
if (!def.version) def.version = 0;
|
|
692
698
|
Object.values(def.bases || {}).forEach(processDependencyVersion);
|
|
693
699
|
return def;
|
|
694
700
|
}
|
|
695
701
|
function processBases(info) {
|
|
702
|
+
debug("processBases");
|
|
696
703
|
if (!info || !info.checkpoints) return {};
|
|
697
704
|
Object.values(info.checkpoints).forEach((base) => {
|
|
698
705
|
if (!base.version) base.version = 0;
|
|
@@ -700,6 +707,7 @@ function processBases(info) {
|
|
|
700
707
|
return info.checkpoints;
|
|
701
708
|
}
|
|
702
709
|
function processBlocks(defs) {
|
|
710
|
+
debug("processBlocks");
|
|
703
711
|
defs.forEach((def) => {
|
|
704
712
|
if (!def.version) def.version = 0;
|
|
705
713
|
def.dependencies?.forEach(processDependencyVersion);
|
|
@@ -762,8 +770,9 @@ async function _checkVersionsCompatibility(template, usedBlocks, basesVersion) {
|
|
|
762
770
|
}
|
|
763
771
|
}
|
|
764
772
|
async function checkVersionsCompatibility() {
|
|
773
|
+
debug("checkVersionsCompatibility");
|
|
765
774
|
const template = processTemplate(getTemplateDef());
|
|
766
|
-
const usedBlocks = processBlocks(
|
|
775
|
+
const usedBlocks = processBlocks(getUsedBlocksDef());
|
|
767
776
|
const basesVersion = processBases(getBloxFile());
|
|
768
777
|
basesVersion[template.name] = { version: template.version, commit: "" };
|
|
769
778
|
await _checkVersionsCompatibility(template, usedBlocks, basesVersion);
|
|
@@ -1042,7 +1051,6 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
|
|
|
1042
1051
|
const patchFilePath = import_node_path9.default.join(dir, "diff.patch");
|
|
1043
1052
|
ignore2.push(".blox", "**/.blox");
|
|
1044
1053
|
await git.createPatch(fromCommit, toCommit, patchFilePath, ignore2);
|
|
1045
|
-
const changes = await git.getChangesLog(fromCommit, toCommit);
|
|
1046
1054
|
const deletePatchFile = async () => {
|
|
1047
1055
|
if (!isDebugMode()) {
|
|
1048
1056
|
await import_fs_extra10.default.unlink(patchFilePath);
|
|
@@ -1062,19 +1070,10 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
|
|
|
1062
1070
|
hasMergeConflicts = errorMessage.includes("with conflicts");
|
|
1063
1071
|
}
|
|
1064
1072
|
if (hasMergeConflicts) {
|
|
1065
|
-
|
|
1066
|
-
message: "Please resolve conflicts
|
|
1073
|
+
await select({
|
|
1074
|
+
message: "Please resolve conflicts press enter",
|
|
1075
|
+
options: [{ value: true, label: "continue" }]
|
|
1067
1076
|
});
|
|
1068
|
-
if (!shouldContinue) {
|
|
1069
|
-
await deletePatchFile();
|
|
1070
|
-
throw new Error("Failed to solve conflicts");
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
if (changes.trim() !== "") {
|
|
1074
|
-
logWarningSection(
|
|
1075
|
-
"These is the changes from last update, make sure to review for breaking changes",
|
|
1076
|
-
changes.replace(/BREAKING CHANGE/gi, fmt.red("BREAKING CHANGE"))
|
|
1077
|
-
);
|
|
1078
1077
|
}
|
|
1079
1078
|
await deletePatchFile();
|
|
1080
1079
|
bloxFile.checkpoints[name] = { commit: toCommit };
|
|
@@ -1106,6 +1105,7 @@ async function updateApp({
|
|
|
1106
1105
|
ignore: templateDef.ignore
|
|
1107
1106
|
});
|
|
1108
1107
|
if (!toAppCommit) return;
|
|
1108
|
+
if (!templateDef.bases?.length) return;
|
|
1109
1109
|
for (const block of usedBlocks) {
|
|
1110
1110
|
const blockRegistryData = availableBlocks[block.name];
|
|
1111
1111
|
if (!blockRegistryData) return;
|
|
@@ -1113,11 +1113,10 @@ async function updateApp({
|
|
|
1113
1113
|
const blockPath = import_node_path10.default.join(blocksDir, block.name);
|
|
1114
1114
|
const currentBloxFile = getBloxFile(blockPath);
|
|
1115
1115
|
const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
|
|
1116
|
-
const blockFromCommit = currentBloxFile.checkpoints[block.name]?.commit;
|
|
1117
|
-
const blockToCommit = remoteBloxFile.checkpoints[block.name]?.commit;
|
|
1118
|
-
if (!
|
|
1119
|
-
if (blockFromCommit
|
|
1120
|
-
if (await git.isCommitOlder(blockFromCommit, blockToCommit)) {
|
|
1116
|
+
const blockFromCommit = currentBloxFile.checkpoints?.[block.name]?.commit;
|
|
1117
|
+
const blockToCommit = remoteBloxFile.checkpoints?.[block.name]?.commit;
|
|
1118
|
+
if (!blockToCommit || blockFromCommit === blockToCommit) continue;
|
|
1119
|
+
if (!blockFromCommit || await git.isCommitOlder(blockFromCommit, blockToCommit)) {
|
|
1121
1120
|
saveBloxFile(remoteBloxFile, blockPath);
|
|
1122
1121
|
} else {
|
|
1123
1122
|
logWarningSection(
|
|
@@ -1163,6 +1162,40 @@ async function updateBlock(block, blocks) {
|
|
|
1163
1162
|
});
|
|
1164
1163
|
});
|
|
1165
1164
|
}
|
|
1165
|
+
async function getCurrentCheckpoints() {
|
|
1166
|
+
const bloxFile = getBloxFile();
|
|
1167
|
+
let checkpoints = { ...bloxFile.checkpoints };
|
|
1168
|
+
for (const block of getUsedBlocks()) {
|
|
1169
|
+
checkpoints = { ...checkpoints, ...block.checkpoints };
|
|
1170
|
+
}
|
|
1171
|
+
return checkpoints;
|
|
1172
|
+
}
|
|
1173
|
+
async function printChangeLog(startCheckpoints, endCheckpoints) {
|
|
1174
|
+
const allChanges = [];
|
|
1175
|
+
for (const name of Object.keys(startCheckpoints)) {
|
|
1176
|
+
const fromCommit = startCheckpoints[name]?.commit;
|
|
1177
|
+
const toCommit = endCheckpoints[name]?.commit;
|
|
1178
|
+
if (!fromCommit || !toCommit) continue;
|
|
1179
|
+
if (fromCommit === toCommit) continue;
|
|
1180
|
+
const changes = await git.getChangesLog(fromCommit, toCommit);
|
|
1181
|
+
if (changes.trim() !== "") {
|
|
1182
|
+
allChanges.push(`${fmt.bold(fmt.bgYellow(name))}:
|
|
1183
|
+
|
|
1184
|
+
${changes}`);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
if (allChanges.length) {
|
|
1188
|
+
logWarningSection(
|
|
1189
|
+
`ChangeLog, These is the changes from last update, make sure to review for breaking changes`,
|
|
1190
|
+
allChanges.join(`
|
|
1191
|
+
${fmt.gray("-".repeat(82))}
|
|
1192
|
+
|
|
1193
|
+
`).replace(/BREAKING CHANGE/gi, fmt.red("BREAKING CHANGE"))
|
|
1194
|
+
);
|
|
1195
|
+
} else {
|
|
1196
|
+
import_prompts2.log.success("already up to date");
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1166
1199
|
|
|
1167
1200
|
// src/commands/update/index.ts
|
|
1168
1201
|
var update2 = command("update").description("Update app/block").alias("u").addOption(
|
|
@@ -1174,10 +1207,11 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
|
|
|
1174
1207
|
}
|
|
1175
1208
|
await migrateAll(true);
|
|
1176
1209
|
await syncRegistries();
|
|
1210
|
+
const startCheckpoints = await getCurrentCheckpoints();
|
|
1177
1211
|
const templateDef = getTemplateDef();
|
|
1178
1212
|
const availableBlocks = await getAvailableBlocks(templateDef);
|
|
1179
1213
|
const templates = await getAvailableTemplates();
|
|
1180
|
-
const usedBlocks =
|
|
1214
|
+
const usedBlocks = getUsedBlocksDef();
|
|
1181
1215
|
try {
|
|
1182
1216
|
if (["app", "all"].includes(args.scope)) {
|
|
1183
1217
|
await updateApp({ templateDef, templates, usedBlocks, availableBlocks });
|
|
@@ -1208,6 +1242,8 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
|
|
|
1208
1242
|
await updateBlock(blockDef.name, availableBlocks);
|
|
1209
1243
|
}
|
|
1210
1244
|
await checkVersionsCompatibility();
|
|
1245
|
+
const endCheckpoints = await getCurrentCheckpoints();
|
|
1246
|
+
await printChangeLog(startCheckpoints, endCheckpoints);
|
|
1211
1247
|
} catch (e) {
|
|
1212
1248
|
if (!isDebugMode()) {
|
|
1213
1249
|
import_prompts15.log.warn("Error happened, Will rollback changes");
|