@naseej/blox 1.6.2 → 1.7.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 +318 -198
- package/package.json +5 -2
- package/readme.md +235 -178
package/dist/run.js
CHANGED
|
@@ -57,6 +57,8 @@ var defaultConfig = {
|
|
|
57
57
|
var bloxFilePath = ".blox";
|
|
58
58
|
var blocksDir = "blocks";
|
|
59
59
|
var defaultBranch = "main";
|
|
60
|
+
var CURRENT_SCHEMA_VERSION = 1;
|
|
61
|
+
var SCHEMA_BASE_URL = "https://raw.githubusercontent.com/Naseej-its/blox/main/schemas";
|
|
60
62
|
|
|
61
63
|
// src/shared/logger.ts
|
|
62
64
|
var console2 = __toESM(require("console"));
|
|
@@ -199,18 +201,69 @@ var checkForCliUpdate = async (currentVersion, argv = []) => {
|
|
|
199
201
|
};
|
|
200
202
|
|
|
201
203
|
// package.json
|
|
202
|
-
var version = "1.
|
|
204
|
+
var version = "1.7.0";
|
|
203
205
|
|
|
204
206
|
// src/commands/add/index.ts
|
|
205
|
-
var
|
|
207
|
+
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
206
208
|
|
|
207
209
|
// src/migrations/index.ts
|
|
208
|
-
var
|
|
209
|
-
var
|
|
210
|
+
var import_node_path11 = __toESM(require("path"));
|
|
211
|
+
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
212
|
+
|
|
213
|
+
// src/migrations/updateSchemaUrls.ts
|
|
214
|
+
var import_node_path3 = __toESM(require("path"));
|
|
215
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
216
|
+
async function updateSchemaUrls(cwd = ".") {
|
|
217
|
+
const locations = [
|
|
218
|
+
{ filePath: import_node_path3.default.join(cwd, bloxFilePath), type: "template" },
|
|
219
|
+
...readBlockPaths(cwd).map((filePath) => ({ filePath, type: "block" }))
|
|
220
|
+
];
|
|
221
|
+
let anyChanged = false;
|
|
222
|
+
for (const { filePath, type } of locations) {
|
|
223
|
+
const changed = rewriteIfStale(filePath, type);
|
|
224
|
+
anyChanged = anyChanged || changed;
|
|
225
|
+
}
|
|
226
|
+
if (anyChanged) {
|
|
227
|
+
import_prompts2.log.warn(fmt.yellow("Schema URLs updated to v" + CURRENT_SCHEMA_VERSION));
|
|
228
|
+
}
|
|
229
|
+
return anyChanged;
|
|
230
|
+
}
|
|
231
|
+
function readBlockPaths(cwd) {
|
|
232
|
+
const dir = import_node_path3.default.join(cwd, blocksDir);
|
|
233
|
+
if (!import_fs_extra3.default.existsSync(dir)) return [];
|
|
234
|
+
return import_fs_extra3.default.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => import_node_path3.default.join(dir, e.name, bloxFilePath));
|
|
235
|
+
}
|
|
236
|
+
function rewriteIfStale(filePath, type) {
|
|
237
|
+
if (!import_fs_extra3.default.existsSync(filePath)) return false;
|
|
238
|
+
let raw;
|
|
239
|
+
try {
|
|
240
|
+
raw = import_fs_extra3.default.readJSONSync(filePath);
|
|
241
|
+
} catch {
|
|
242
|
+
debug(`updateSchemaUrls: skipping unreadable file ${filePath}`);
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
const existingSchema = raw["$schema"];
|
|
246
|
+
const schemaVersion = typeof raw["schemaVersion"] === "number" ? raw["schemaVersion"] : CURRENT_SCHEMA_VERSION;
|
|
247
|
+
const expectedSchemaUrl = buildSchemaUrl(type, schemaVersion);
|
|
248
|
+
if (existingSchema === expectedSchemaUrl) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
const { $schema: _previousSchema, ...rest } = raw;
|
|
252
|
+
const updated = {
|
|
253
|
+
$schema: expectedSchemaUrl,
|
|
254
|
+
...rest
|
|
255
|
+
};
|
|
256
|
+
import_fs_extra3.default.writeFileSync(filePath, JSON.stringify(updated, null, 2));
|
|
257
|
+
debug(`updateSchemaUrls: updated ${filePath} \u2192 ${expectedSchemaUrl}`);
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
function buildSchemaUrl(type, generation = CURRENT_SCHEMA_VERSION) {
|
|
261
|
+
return `${SCHEMA_BASE_URL}/v${generation}/${type}.json`;
|
|
262
|
+
}
|
|
210
263
|
|
|
211
264
|
// src/migrations/utils.ts
|
|
212
|
-
var
|
|
213
|
-
var
|
|
265
|
+
var import_node_path10 = __toESM(require("path"));
|
|
266
|
+
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
214
267
|
|
|
215
268
|
// src/migrations/list/v1.ts
|
|
216
269
|
var v1 = {
|
|
@@ -247,8 +300,8 @@ var migrationsList = [v1];
|
|
|
247
300
|
|
|
248
301
|
// src/services/git.ts
|
|
249
302
|
var import_node_os = __toESM(require("os"));
|
|
250
|
-
var
|
|
251
|
-
var
|
|
303
|
+
var import_node_path9 = __toESM(require("path"));
|
|
304
|
+
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
252
305
|
|
|
253
306
|
// src/services/shell.ts
|
|
254
307
|
var import_cross_spawn = __toESM(require("cross-spawn"));
|
|
@@ -337,14 +390,14 @@ var looksLikeDirectory = (pattern) => {
|
|
|
337
390
|
};
|
|
338
391
|
|
|
339
392
|
// src/shared/utils/gitignoreMatcher.ts
|
|
340
|
-
var
|
|
393
|
+
var import_node_path4 = __toESM(require("path"));
|
|
341
394
|
var import_ignore = __toESM(require("ignore"));
|
|
342
395
|
var createGitignoreMatcher = (patterns) => {
|
|
343
396
|
const cleaned = patterns.map((p) => p.trim()).filter((p) => p && !p.startsWith("#"));
|
|
344
397
|
return (0, import_ignore.default)().add(cleaned);
|
|
345
398
|
};
|
|
346
399
|
var toIgnorePath = (repoRelativePath) => {
|
|
347
|
-
let p = repoRelativePath.split(
|
|
400
|
+
let p = repoRelativePath.split(import_node_path4.default.sep).join("/");
|
|
348
401
|
if (p.startsWith("./")) p = p.slice(2);
|
|
349
402
|
return p;
|
|
350
403
|
};
|
|
@@ -401,9 +454,9 @@ function openUrlInBrowser(url) {
|
|
|
401
454
|
}
|
|
402
455
|
|
|
403
456
|
// src/shared/utils/isBloxConfigFile.ts
|
|
404
|
-
var
|
|
457
|
+
var import_node_path5 = __toESM(require("path"));
|
|
405
458
|
function isBloxConfigFile(file) {
|
|
406
|
-
const normalized = file.split(
|
|
459
|
+
const normalized = file.split(import_node_path5.default.sep).join("/");
|
|
407
460
|
return normalized === bloxFilePath || normalized.endsWith(`/${bloxFilePath}`);
|
|
408
461
|
}
|
|
409
462
|
|
|
@@ -423,40 +476,40 @@ function omitKeys(value, keysToOmit) {
|
|
|
423
476
|
var normalizeCommitRef = (commit2) => commit2.trim().replace(/\r/g, "").replace(/^"+|"+$/g, "");
|
|
424
477
|
|
|
425
478
|
// src/shared/utils/isBlockDirectory.ts
|
|
426
|
-
var
|
|
427
|
-
var
|
|
479
|
+
var import_node_path6 = __toESM(require("path"));
|
|
480
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
428
481
|
function isBlockDirectory(blockDir) {
|
|
429
|
-
const bloxPath =
|
|
430
|
-
if (!
|
|
482
|
+
const bloxPath = import_node_path6.default.join(blockDir, bloxFilePath);
|
|
483
|
+
if (!import_fs_extra4.default.existsSync(bloxPath)) {
|
|
431
484
|
return false;
|
|
432
485
|
}
|
|
433
486
|
try {
|
|
434
|
-
return
|
|
487
|
+
return import_fs_extra4.default.statSync(bloxPath).isFile();
|
|
435
488
|
} catch {
|
|
436
489
|
return false;
|
|
437
490
|
}
|
|
438
491
|
}
|
|
439
492
|
|
|
440
493
|
// src/services/template.ts
|
|
441
|
-
var
|
|
494
|
+
var import_node_path7 = __toESM(require("path"));
|
|
442
495
|
var import_ejs = __toESM(require("ejs"));
|
|
443
|
-
var
|
|
496
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
444
497
|
var import_klaw = __toESM(require("klaw"));
|
|
445
498
|
async function replacePlaceholders(dir, context) {
|
|
446
499
|
debug("Replace placeholders");
|
|
447
500
|
for await (const file of (0, import_klaw.default)(dir)) {
|
|
448
501
|
if (!file.stats.isFile()) continue;
|
|
449
|
-
const ext =
|
|
502
|
+
const ext = import_node_path7.default.extname(file.path).toLowerCase();
|
|
450
503
|
if (isBinaryFile(ext)) {
|
|
451
504
|
continue;
|
|
452
505
|
}
|
|
453
|
-
const templateContent =
|
|
506
|
+
const templateContent = import_fs_extra5.default.readFileSync(file.path, "utf8");
|
|
454
507
|
if (!templateContent.includes("<%")) {
|
|
455
508
|
continue;
|
|
456
509
|
}
|
|
457
510
|
try {
|
|
458
511
|
const rendered = import_ejs.default.render(templateContent, context);
|
|
459
|
-
|
|
512
|
+
import_fs_extra5.default.writeFileSync(file.path, rendered, "utf8");
|
|
460
513
|
} catch (err) {
|
|
461
514
|
console.error("\u274C Error rendering EJS for file:", file.path);
|
|
462
515
|
throw err;
|
|
@@ -477,7 +530,7 @@ function getBlockDef(cwd = ".") {
|
|
|
477
530
|
}
|
|
478
531
|
function getBloxFile(cwd = ".") {
|
|
479
532
|
try {
|
|
480
|
-
const file =
|
|
533
|
+
const file = import_fs_extra5.default.readJSONSync(import_node_path7.default.join(cwd, bloxFilePath));
|
|
481
534
|
if (!file.checkpoints) {
|
|
482
535
|
file.checkpoints = {};
|
|
483
536
|
}
|
|
@@ -488,7 +541,7 @@ function getBloxFile(cwd = ".") {
|
|
|
488
541
|
}
|
|
489
542
|
function saveBloxFile(info, cwd = ".") {
|
|
490
543
|
debug("Save info");
|
|
491
|
-
|
|
544
|
+
import_fs_extra5.default.writeFileSync(import_node_path7.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
|
|
492
545
|
}
|
|
493
546
|
function updateCheckpoint(name, checkpoint, cwd = ".") {
|
|
494
547
|
const info = getBloxFile(cwd);
|
|
@@ -504,12 +557,12 @@ function getUsedBlocksDef() {
|
|
|
504
557
|
function getUsedBlocks() {
|
|
505
558
|
debug("Get used blocks");
|
|
506
559
|
const blocks = [];
|
|
507
|
-
if (
|
|
508
|
-
|
|
560
|
+
if (import_fs_extra5.default.existsSync(blocksDir)) {
|
|
561
|
+
import_fs_extra5.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
509
562
|
if (!file.isDirectory()) {
|
|
510
563
|
return;
|
|
511
564
|
}
|
|
512
|
-
const blockDef = getBloxFile(
|
|
565
|
+
const blockDef = getBloxFile(import_node_path7.default.join(blocksDir, file.name));
|
|
513
566
|
if (blockDef && blockDef.definition) {
|
|
514
567
|
blocks.push(blockDef);
|
|
515
568
|
}
|
|
@@ -577,9 +630,9 @@ async function runLifecycleHookWithTask(cwd, hook, message) {
|
|
|
577
630
|
}
|
|
578
631
|
|
|
579
632
|
// src/services/path.ts
|
|
580
|
-
var
|
|
633
|
+
var import_node_path8 = __toESM(require("path"));
|
|
581
634
|
var normalizePath = (_path) => {
|
|
582
|
-
return _path.split(
|
|
635
|
+
return _path.split(import_node_path8.default.sep).join("/");
|
|
583
636
|
};
|
|
584
637
|
|
|
585
638
|
// src/services/git.ts
|
|
@@ -610,16 +663,16 @@ var getRemoteWorktree = async (remote, commit2) => {
|
|
|
610
663
|
return remoteWorktrees.get(key);
|
|
611
664
|
}
|
|
612
665
|
const tmpDir = import_node_os.default.tmpdir();
|
|
613
|
-
const worktreeDir =
|
|
666
|
+
const worktreeDir = import_node_path9.default.join(tmpDir, "blox-cli-worktrees", remote, commit2);
|
|
614
667
|
try {
|
|
615
668
|
await $("git", ["worktree", "prune"]);
|
|
616
669
|
} catch {
|
|
617
670
|
}
|
|
618
|
-
if (await
|
|
671
|
+
if (await import_fs_extra6.default.pathExists(worktreeDir)) {
|
|
619
672
|
try {
|
|
620
673
|
await $("git", ["worktree", "remove", "--force", worktreeDir]);
|
|
621
674
|
} catch {
|
|
622
|
-
await
|
|
675
|
+
await import_fs_extra6.default.remove(worktreeDir);
|
|
623
676
|
try {
|
|
624
677
|
await $("git", ["worktree", "prune"]);
|
|
625
678
|
} catch {
|
|
@@ -735,8 +788,8 @@ var update = (shellOptions = {}) => {
|
|
|
735
788
|
var getLatestCommitFromRemote = async (remote, branch) => {
|
|
736
789
|
return getLatestCommit(`${remote}/${branch}`);
|
|
737
790
|
};
|
|
738
|
-
var getLatestCommitFromPath = async (
|
|
739
|
-
return getLatestCommit("HEAD",
|
|
791
|
+
var getLatestCommitFromPath = async (path24) => {
|
|
792
|
+
return getLatestCommit("HEAD", path24);
|
|
740
793
|
};
|
|
741
794
|
var getLatestCommit = async (rev, cwd = ".") => {
|
|
742
795
|
debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
|
|
@@ -760,7 +813,7 @@ var getChangesLog = async (fromCommit, toCommit) => {
|
|
|
760
813
|
};
|
|
761
814
|
var unInit = (cwd) => {
|
|
762
815
|
debug("UnInit");
|
|
763
|
-
return
|
|
816
|
+
return import_fs_extra6.default.remove(import_node_path9.default.join(cwd, ".git"));
|
|
764
817
|
};
|
|
765
818
|
var init = async (cwd) => {
|
|
766
819
|
debug("Init");
|
|
@@ -877,11 +930,11 @@ var createBranch = async (branch, from, cwd = ".") => {
|
|
|
877
930
|
var push = async (remote, branch, cwd = ".") => {
|
|
878
931
|
await $("git", ["push", "--progress", remote, `refs/heads/${branch}`], { cwd });
|
|
879
932
|
};
|
|
880
|
-
var checkoutFile = async (
|
|
933
|
+
var checkoutFile = async (path24, ref, cwd = ".") => {
|
|
881
934
|
const args = ["checkout"];
|
|
882
935
|
if (ref) args.push(ref);
|
|
883
936
|
else args.push("HEAD");
|
|
884
|
-
args.push("--",
|
|
937
|
+
args.push("--", path24);
|
|
885
938
|
await $("git", args, { cwd });
|
|
886
939
|
};
|
|
887
940
|
var pathExistsAsBlobInRev = async (rev, filePath, cwd = ".") => {
|
|
@@ -922,6 +975,16 @@ var listCommits = async (limit, skip, cwd = ".") => {
|
|
|
922
975
|
return { hash, subject: subjectRaw.trim() };
|
|
923
976
|
});
|
|
924
977
|
};
|
|
978
|
+
var listCommitsOldestFirst = async (cwd = ".") => {
|
|
979
|
+
let out = "";
|
|
980
|
+
await $("git", ["log", "--reverse", "--pretty=format:%H", "HEAD"], {
|
|
981
|
+
cwd,
|
|
982
|
+
onStdout: (text2) => {
|
|
983
|
+
out += text2;
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
return out.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
987
|
+
};
|
|
925
988
|
var fetchCommit = async (fromRepo, commit2, cwd = ".") => {
|
|
926
989
|
const ref = normalizeCommitRef(commit2);
|
|
927
990
|
await $("git", ["fetch", fromRepo, `+${ref}:FETCH_HEAD`], { cwd });
|
|
@@ -933,10 +996,10 @@ var cherryPick = async (commitHash, subtree, noCommit, cwd = ".") => {
|
|
|
933
996
|
args.push(normalizeCommitRef(commitHash));
|
|
934
997
|
await $("git", args, { cwd });
|
|
935
998
|
};
|
|
936
|
-
var reset = async (
|
|
999
|
+
var reset = async (path24, hard, cwd = ".") => {
|
|
937
1000
|
const args = ["reset"];
|
|
938
1001
|
if (hard) args.push("--hard");
|
|
939
|
-
if (
|
|
1002
|
+
if (path24) args.push(path24);
|
|
940
1003
|
await $("git", args, { cwd });
|
|
941
1004
|
};
|
|
942
1005
|
var commitAll = async (message, cwd = ".") => {
|
|
@@ -1000,6 +1063,7 @@ var git = {
|
|
|
1000
1063
|
checkoutFile,
|
|
1001
1064
|
revertPathToHead,
|
|
1002
1065
|
listCommits,
|
|
1066
|
+
listCommitsOldestFirst,
|
|
1003
1067
|
fetchCommit,
|
|
1004
1068
|
cherryPick,
|
|
1005
1069
|
reset,
|
|
@@ -1118,26 +1182,28 @@ async function migrate(name, { getPath = (f) => f, read, write }) {
|
|
|
1118
1182
|
}
|
|
1119
1183
|
function migrateOnLocal(name, cwd = ".") {
|
|
1120
1184
|
return migrate(name, {
|
|
1121
|
-
getPath: (file) =>
|
|
1122
|
-
read:
|
|
1123
|
-
write:
|
|
1185
|
+
getPath: (file) => import_node_path10.default.join(cwd, file),
|
|
1186
|
+
read: import_fs_extra7.default.readJson,
|
|
1187
|
+
write: import_fs_extra7.default.writeFile
|
|
1124
1188
|
});
|
|
1125
1189
|
}
|
|
1126
1190
|
function migrateOnRemote(name, commit2, cwd) {
|
|
1127
1191
|
return migrate(name, {
|
|
1128
1192
|
read: (file) => git.readJsonFromCommit(commit2, file),
|
|
1129
|
-
getPath: cwd ? (file) =>
|
|
1193
|
+
getPath: cwd ? (file) => import_node_path10.default.join(cwd, file) : void 0
|
|
1130
1194
|
});
|
|
1131
1195
|
}
|
|
1132
1196
|
|
|
1133
1197
|
// src/migrations/index.ts
|
|
1134
1198
|
async function migrateAll(autoCommit) {
|
|
1135
1199
|
let filesChanged = (await migrateOnLocal("app")).filesChanged;
|
|
1136
|
-
const blocks =
|
|
1200
|
+
const blocks = import_fs_extra8.default.existsSync(blocksDir) ? import_fs_extra8.default.readdirSync(blocksDir) : [];
|
|
1137
1201
|
for (const block of blocks) {
|
|
1138
|
-
const res = await migrateOnLocal(block,
|
|
1202
|
+
const res = await migrateOnLocal(block, import_node_path11.default.join(blocksDir, block));
|
|
1139
1203
|
filesChanged = filesChanged || res.filesChanged;
|
|
1140
1204
|
}
|
|
1205
|
+
const urlsChanged = await updateSchemaUrls(".");
|
|
1206
|
+
filesChanged = filesChanged || urlsChanged;
|
|
1141
1207
|
if (autoCommit && filesChanged && await git.hasUncommittedChanges()) {
|
|
1142
1208
|
import_prompts2.log.warn(fmt.yellow(`Migrations done and will be commited`));
|
|
1143
1209
|
await git.add(".");
|
|
@@ -1146,8 +1212,8 @@ async function migrateAll(autoCommit) {
|
|
|
1146
1212
|
}
|
|
1147
1213
|
|
|
1148
1214
|
// src/services/fs.ts
|
|
1149
|
-
var
|
|
1150
|
-
var
|
|
1215
|
+
var import_node_path12 = __toESM(require("path"));
|
|
1216
|
+
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
1151
1217
|
var import_ignore2 = __toESM(require("ignore"));
|
|
1152
1218
|
var import_klaw2 = __toESM(require("klaw"));
|
|
1153
1219
|
var filterBlacklisted = (item) => {
|
|
@@ -1156,44 +1222,51 @@ var filterBlacklisted = (item) => {
|
|
|
1156
1222
|
var deletePattern = async (cwd, patterns = []) => {
|
|
1157
1223
|
const ig = (0, import_ignore2.default)().add(patterns);
|
|
1158
1224
|
for await (const file of (0, import_klaw2.default)(cwd, { filter: filterBlacklisted })) {
|
|
1159
|
-
const relativePath =
|
|
1225
|
+
const relativePath = import_node_path12.default.relative(cwd, file.path);
|
|
1160
1226
|
if (relativePath && ig.ignores(relativePath)) {
|
|
1161
|
-
if (!await
|
|
1227
|
+
if (!await import_fs_extra9.default.exists(file.path)) {
|
|
1162
1228
|
continue;
|
|
1163
1229
|
}
|
|
1164
1230
|
debug(`deleting: ${relativePath}`);
|
|
1165
|
-
await
|
|
1231
|
+
await import_fs_extra9.default.remove(file.path);
|
|
1166
1232
|
}
|
|
1167
1233
|
}
|
|
1168
1234
|
};
|
|
1169
1235
|
|
|
1170
1236
|
// src/services/registry.ts
|
|
1171
|
-
var
|
|
1172
|
-
var
|
|
1237
|
+
var import_node_path13 = __toESM(require("path"));
|
|
1238
|
+
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
1173
1239
|
var import_merge = __toESM(require("lodash/merge"));
|
|
1174
|
-
var registriesDataPath =
|
|
1240
|
+
var registriesDataPath = import_node_path13.default.join(appPaths.data, "registries");
|
|
1175
1241
|
var upeToDate = false;
|
|
1176
1242
|
var cacheDirNameForRegistry = (registry) => {
|
|
1177
1243
|
return encodeURIComponent(registry).replace(/%/g, "_");
|
|
1178
1244
|
};
|
|
1245
|
+
var getConfiguredRegistryDirs = () => {
|
|
1246
|
+
const config = getLocalConfig();
|
|
1247
|
+
return config.registries.map((registry) => ({
|
|
1248
|
+
registry,
|
|
1249
|
+
dir: import_node_path13.default.join(registriesDataPath, cacheDirNameForRegistry(registry))
|
|
1250
|
+
}));
|
|
1251
|
+
};
|
|
1179
1252
|
var syncRegistries = async (branch) => {
|
|
1180
1253
|
if (upeToDate) return;
|
|
1181
1254
|
upeToDate = true;
|
|
1182
1255
|
debug("Sync registries");
|
|
1183
|
-
|
|
1256
|
+
import_fs_extra10.default.ensureDirSync(registriesDataPath);
|
|
1184
1257
|
const config = getLocalConfig();
|
|
1185
1258
|
return await runTask("Update registries", async () => {
|
|
1186
1259
|
await Promise.all(
|
|
1187
1260
|
config.registries.map(async (registry) => {
|
|
1188
1261
|
debug(`update registry: ${registry}`);
|
|
1189
1262
|
const repoName = cacheDirNameForRegistry(registry);
|
|
1190
|
-
const repoDir =
|
|
1191
|
-
if (!
|
|
1263
|
+
const repoDir = import_node_path13.default.join(registriesDataPath, repoName);
|
|
1264
|
+
if (!import_fs_extra10.default.existsSync(repoDir)) {
|
|
1192
1265
|
await git.clone(registry, repoName, branch, {
|
|
1193
1266
|
cwd: registriesDataPath,
|
|
1194
1267
|
depth: 1
|
|
1195
1268
|
});
|
|
1196
|
-
} else if (
|
|
1269
|
+
} else if (import_fs_extra10.default.existsSync(import_node_path13.default.join(repoDir, ".git"))) {
|
|
1197
1270
|
await git.update({ cwd: repoDir });
|
|
1198
1271
|
} else {
|
|
1199
1272
|
debug(`local registry`);
|
|
@@ -1205,11 +1278,10 @@ var syncRegistries = async (branch) => {
|
|
|
1205
1278
|
var getAvailableTemplates = async () => {
|
|
1206
1279
|
debug("Get available templates");
|
|
1207
1280
|
const templates = {};
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
const data = import_fs_extra9.default.readJSONSync(indexPath);
|
|
1281
|
+
for (const { dir } of getConfiguredRegistryDirs()) {
|
|
1282
|
+
const indexPath = import_node_path13.default.join(dir, "index.json");
|
|
1283
|
+
if (import_fs_extra10.default.existsSync(indexPath)) {
|
|
1284
|
+
const data = import_fs_extra10.default.readJSONSync(indexPath);
|
|
1213
1285
|
Object.entries(data.templates || {}).forEach(([templateName, template]) => {
|
|
1214
1286
|
if (!template.source) {
|
|
1215
1287
|
template.source = `/template-${templateName}`;
|
|
@@ -1249,20 +1321,18 @@ var getAvailableBlocks = async (templateInfo) => {
|
|
|
1249
1321
|
return blocks;
|
|
1250
1322
|
};
|
|
1251
1323
|
var getAvailableVersions = async (source) => {
|
|
1252
|
-
const
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
const registryData = import_fs_extra9.default.readJSONSync(indexPath);
|
|
1258
|
-
const versionDirPath = import_node_path12.default.join(registryPath, "versions");
|
|
1324
|
+
for (const { dir } of getConfiguredRegistryDirs()) {
|
|
1325
|
+
const indexPath = import_node_path13.default.join(dir, "index.json");
|
|
1326
|
+
if (!import_fs_extra10.default.existsSync(indexPath)) continue;
|
|
1327
|
+
const registryData = import_fs_extra10.default.readJSONSync(indexPath);
|
|
1328
|
+
const versionDirPath = import_node_path13.default.join(dir, "versions");
|
|
1259
1329
|
const versionsFilePaths = [
|
|
1260
|
-
|
|
1261
|
-
|
|
1330
|
+
import_node_path13.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
|
|
1331
|
+
import_node_path13.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
|
|
1262
1332
|
];
|
|
1263
1333
|
for (const versionsFile of versionsFilePaths) {
|
|
1264
|
-
if (
|
|
1265
|
-
return
|
|
1334
|
+
if (import_fs_extra10.default.existsSync(versionsFile)) {
|
|
1335
|
+
return import_fs_extra10.default.readJSONSync(versionsFile);
|
|
1266
1336
|
}
|
|
1267
1337
|
}
|
|
1268
1338
|
}
|
|
@@ -1399,7 +1469,7 @@ var addBlock = async (block, blocks, branch, destination) => {
|
|
|
1399
1469
|
}
|
|
1400
1470
|
const blockPath = `blocks/${destination}`;
|
|
1401
1471
|
let newBlockAdded = false;
|
|
1402
|
-
if (!
|
|
1472
|
+
if (!import_fs_extra11.default.existsSync(blockPath)) {
|
|
1403
1473
|
newBlockAdded = true;
|
|
1404
1474
|
await runTask(
|
|
1405
1475
|
{ start: `Fetching block: ${block}`, end: `Added block: ${block}` },
|
|
@@ -1528,7 +1598,7 @@ var ContributionTargetType = /* @__PURE__ */ ((ContributionTargetType2) => {
|
|
|
1528
1598
|
})(ContributionTargetType || {});
|
|
1529
1599
|
|
|
1530
1600
|
// src/services/contribute/utils/bloxCheckpoint.ts
|
|
1531
|
-
var
|
|
1601
|
+
var import_node_path14 = __toESM(require("path"));
|
|
1532
1602
|
function getCheckpointForTarget(cwd, target) {
|
|
1533
1603
|
const bloxDir = getBloxDirForTarget(cwd, target);
|
|
1534
1604
|
const blox = getBloxFile(bloxDir);
|
|
@@ -1538,7 +1608,7 @@ function getCheckpointForTarget(cwd, target) {
|
|
|
1538
1608
|
}
|
|
1539
1609
|
function getBloxDirForTarget(cwd, target) {
|
|
1540
1610
|
if (target.type === "block" /* BLOCK */) {
|
|
1541
|
-
return
|
|
1611
|
+
return import_node_path14.default.join(cwd, blocksDir, target.name);
|
|
1542
1612
|
}
|
|
1543
1613
|
return cwd;
|
|
1544
1614
|
}
|
|
@@ -1590,7 +1660,7 @@ var ContributionWorkflow = class {
|
|
|
1590
1660
|
await this.assertAppRepoClean();
|
|
1591
1661
|
const target = await this.targetSelector.selectTargetInteractive();
|
|
1592
1662
|
const mode = flags.existing ? "existing" : "new";
|
|
1593
|
-
const { title, description } = await this.
|
|
1663
|
+
const { title, description } = await this.promptContributionMeta(flags);
|
|
1594
1664
|
const commits = await this.resolveCommitsFromFlags(flags);
|
|
1595
1665
|
const branch = await this.resolveContributionBranch({ mode, target, title });
|
|
1596
1666
|
return this.run({
|
|
@@ -1677,19 +1747,17 @@ var ContributionWorkflow = class {
|
|
|
1677
1747
|
);
|
|
1678
1748
|
}
|
|
1679
1749
|
}
|
|
1680
|
-
async
|
|
1681
|
-
let title = flags.title;
|
|
1682
|
-
let description = flags.description;
|
|
1683
|
-
if (
|
|
1684
|
-
|
|
1685
|
-
title
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
description = await text({ message: "Description (optional)", defaultValue: "" });
|
|
1692
|
-
}
|
|
1750
|
+
async promptContributionMeta(flags) {
|
|
1751
|
+
let title = flags.title?.trim();
|
|
1752
|
+
let description = flags.description?.trim();
|
|
1753
|
+
if (!title) {
|
|
1754
|
+
title = await text({
|
|
1755
|
+
message: "Contribution title (conventional commit style recommended)",
|
|
1756
|
+
validate: (v) => v.trim() ? void 0 : "Title is required"
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
if (description === void 0) {
|
|
1760
|
+
description = await text({ message: "Description (optional)", defaultValue: "" });
|
|
1693
1761
|
}
|
|
1694
1762
|
return { title, description };
|
|
1695
1763
|
}
|
|
@@ -1810,28 +1878,28 @@ ${prUrl}` : "\nPush completed.")
|
|
|
1810
1878
|
};
|
|
1811
1879
|
|
|
1812
1880
|
// src/services/contribute/services/CommitApplierService.ts
|
|
1813
|
-
var
|
|
1814
|
-
var
|
|
1881
|
+
var import_node_path16 = __toESM(require("path"));
|
|
1882
|
+
var import_fs_extra13 = __toESM(require("fs-extra"));
|
|
1815
1883
|
|
|
1816
1884
|
// src/services/contribute/config/index.ts
|
|
1817
1885
|
var tempRepoName = "tmp";
|
|
1818
1886
|
var bloxConfigControlledKeys = ["checkpoints", "project"];
|
|
1819
1887
|
|
|
1820
1888
|
// src/services/contribute/utils/getExcludedPrefixesForTarget.ts
|
|
1821
|
-
var
|
|
1822
|
-
var
|
|
1889
|
+
var import_node_path15 = __toESM(require("path"));
|
|
1890
|
+
var import_fs_extra12 = __toESM(require("fs-extra"));
|
|
1823
1891
|
function getExcludedPrefixesForTarget(target, cwd) {
|
|
1824
1892
|
if (target.type === "block" /* BLOCK */) {
|
|
1825
1893
|
return [];
|
|
1826
1894
|
}
|
|
1827
1895
|
const excluded = [];
|
|
1828
|
-
const blocksPath =
|
|
1829
|
-
if (
|
|
1830
|
-
const entries =
|
|
1896
|
+
const blocksPath = import_node_path15.default.join(cwd, blocksDir);
|
|
1897
|
+
if (import_fs_extra12.default.existsSync(blocksPath)) {
|
|
1898
|
+
const entries = import_fs_extra12.default.readdirSync(blocksPath, { withFileTypes: true });
|
|
1831
1899
|
for (const entry of entries) {
|
|
1832
1900
|
if (!entry.isDirectory()) continue;
|
|
1833
|
-
const blockBloxFile =
|
|
1834
|
-
if (
|
|
1901
|
+
const blockBloxFile = import_node_path15.default.join(blocksPath, entry.name, bloxFilePath);
|
|
1902
|
+
if (import_fs_extra12.default.existsSync(blockBloxFile)) {
|
|
1835
1903
|
excluded.push(normalizePath(`${blocksDir}/${entry.name}/`));
|
|
1836
1904
|
}
|
|
1837
1905
|
}
|
|
@@ -1847,6 +1915,23 @@ function getPathPrefixToStrip(target) {
|
|
|
1847
1915
|
return "";
|
|
1848
1916
|
}
|
|
1849
1917
|
|
|
1918
|
+
// src/services/contribute/utils/orderCommitsOldestToNewest.ts
|
|
1919
|
+
var orderCommitsOldestToNewest = (commits, history) => {
|
|
1920
|
+
const historyIndex = new Map(history.map((commit2, index) => [commit2, index]));
|
|
1921
|
+
const uniqueCommits = [...new Set(commits)];
|
|
1922
|
+
const missingCommits = uniqueCommits.filter((commit2) => !historyIndex.has(commit2));
|
|
1923
|
+
if (missingCommits.length) {
|
|
1924
|
+
throw new Error(
|
|
1925
|
+
`Unable to order commits because these hashes were not found in repo history: ${missingCommits.join(", ")}`
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
return uniqueCommits.sort((left, right) => {
|
|
1929
|
+
const leftIndex = historyIndex.get(left);
|
|
1930
|
+
const rightIndex = historyIndex.get(right);
|
|
1931
|
+
return leftIndex - rightIndex;
|
|
1932
|
+
});
|
|
1933
|
+
};
|
|
1934
|
+
|
|
1850
1935
|
// src/services/contribute/utils/shouldExcludeFile.ts
|
|
1851
1936
|
function shouldExcludeFile(file, excludedPrefixes) {
|
|
1852
1937
|
const f = normalizePath(file);
|
|
@@ -1873,7 +1958,8 @@ var CommitApplierService = class {
|
|
|
1873
1958
|
projectIgnore
|
|
1874
1959
|
});
|
|
1875
1960
|
prepareSpinner.stop("Prepared apply commits");
|
|
1876
|
-
const
|
|
1961
|
+
const history = await git.listCommitsOldestFirst(opts.appRepoCwd);
|
|
1962
|
+
const orderedCommits = orderCommitsOldestToNewest(opts.commits, history);
|
|
1877
1963
|
for (const commit2 of orderedCommits) {
|
|
1878
1964
|
await this.applySingleCommit(
|
|
1879
1965
|
opts,
|
|
@@ -1991,8 +2077,8 @@ ${e instanceof Error ? e.message : String(e)}`);
|
|
|
1991
2077
|
}
|
|
1992
2078
|
const withoutGovernedKeys = omitKeys(stagedJson, bloxConfigControlledKeys);
|
|
1993
2079
|
try {
|
|
1994
|
-
const outPath =
|
|
1995
|
-
await
|
|
2080
|
+
const outPath = import_node_path16.default.join(tmpRepoCwd, file);
|
|
2081
|
+
await import_fs_extra13.default.outputFile(outPath, JSON.stringify(withoutGovernedKeys, null, 2));
|
|
1996
2082
|
await git.add(file, tmpRepoCwd);
|
|
1997
2083
|
} catch (e) {
|
|
1998
2084
|
this.logger.warn("apply.commit.blox_merge_fallback", {
|
|
@@ -2106,13 +2192,13 @@ var CommitSelectorService = class {
|
|
|
2106
2192
|
};
|
|
2107
2193
|
|
|
2108
2194
|
// src/services/contribute/utils/discoverContributionTargets.ts
|
|
2109
|
-
var
|
|
2110
|
-
var
|
|
2195
|
+
var import_node_path17 = __toESM(require("path"));
|
|
2196
|
+
var import_fs_extra14 = __toESM(require("fs-extra"));
|
|
2111
2197
|
var readBloxFileIfExists = (cwd) => {
|
|
2112
|
-
const p =
|
|
2113
|
-
if (!
|
|
2198
|
+
const p = import_node_path17.default.join(cwd, bloxFilePath);
|
|
2199
|
+
if (!import_fs_extra14.default.existsSync(p)) return;
|
|
2114
2200
|
try {
|
|
2115
|
-
return
|
|
2201
|
+
return import_fs_extra14.default.readJSONSync(p);
|
|
2116
2202
|
} catch {
|
|
2117
2203
|
return;
|
|
2118
2204
|
}
|
|
@@ -2140,13 +2226,13 @@ var discoverContributionTargets = (cwd) => {
|
|
|
2140
2226
|
});
|
|
2141
2227
|
}
|
|
2142
2228
|
}
|
|
2143
|
-
const blocksPath =
|
|
2144
|
-
if (
|
|
2145
|
-
const entries =
|
|
2229
|
+
const blocksPath = import_node_path17.default.join(cwd, blocksDir);
|
|
2230
|
+
if (import_fs_extra14.default.existsSync(blocksPath)) {
|
|
2231
|
+
const entries = import_fs_extra14.default.readdirSync(blocksPath, { withFileTypes: true });
|
|
2146
2232
|
for (const entry of entries) {
|
|
2147
2233
|
if (!entry.isDirectory()) continue;
|
|
2148
2234
|
const blockName = entry.name;
|
|
2149
|
-
const blockBlox = readBloxFileIfExists(
|
|
2235
|
+
const blockBlox = readBloxFileIfExists(import_node_path17.default.join(blocksPath, blockName));
|
|
2150
2236
|
if (!blockBlox?.definition?.name) continue;
|
|
2151
2237
|
const def = blockBlox.definition;
|
|
2152
2238
|
const templateName = def.templates?.[0]?.name || appTemplateName;
|
|
@@ -2429,8 +2515,8 @@ ${fmt.cyan(createPageUrl)}
|
|
|
2429
2515
|
|
|
2430
2516
|
// src/services/contribute/services/TmpRepoService.ts
|
|
2431
2517
|
var import_node_os2 = require("os");
|
|
2432
|
-
var
|
|
2433
|
-
var
|
|
2518
|
+
var import_node_path18 = __toESM(require("path"));
|
|
2519
|
+
var import_fs_extra15 = __toESM(require("fs-extra"));
|
|
2434
2520
|
var TmpRepoService = class {
|
|
2435
2521
|
constructor(logger) {
|
|
2436
2522
|
this.logger = logger;
|
|
@@ -2447,7 +2533,7 @@ var TmpRepoService = class {
|
|
|
2447
2533
|
}
|
|
2448
2534
|
async getTmpDir(target) {
|
|
2449
2535
|
const slug = `${target.type}-${target.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-");
|
|
2450
|
-
return
|
|
2536
|
+
return import_node_path18.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
|
|
2451
2537
|
}
|
|
2452
2538
|
async prepare(opts) {
|
|
2453
2539
|
const taskSpinner = spinner();
|
|
@@ -2459,7 +2545,7 @@ var TmpRepoService = class {
|
|
|
2459
2545
|
repoUrl: opts.repoUrl,
|
|
2460
2546
|
branch: opts.branch
|
|
2461
2547
|
});
|
|
2462
|
-
if (await
|
|
2548
|
+
if (await import_fs_extra15.default.pathExists(dir)) {
|
|
2463
2549
|
this.logger.debug(`${tempRepoName} reuse_tmp_local_repo`, { dir });
|
|
2464
2550
|
try {
|
|
2465
2551
|
await this.refreshExistingTmpRepo(dir, opts.branch);
|
|
@@ -2470,10 +2556,10 @@ var TmpRepoService = class {
|
|
|
2470
2556
|
dir,
|
|
2471
2557
|
message: e instanceof Error ? e.message : String(e)
|
|
2472
2558
|
});
|
|
2473
|
-
await
|
|
2559
|
+
await import_fs_extra15.default.remove(dir);
|
|
2474
2560
|
}
|
|
2475
2561
|
}
|
|
2476
|
-
await
|
|
2562
|
+
await import_fs_extra15.default.ensureDir(import_node_path18.default.dirname(dir));
|
|
2477
2563
|
await git.clone(opts.repoUrl, dir, opts.branch);
|
|
2478
2564
|
taskSpinner.stop("Prepared tmp repo");
|
|
2479
2565
|
return dir;
|
|
@@ -2561,7 +2647,7 @@ var detach = command("detach").description("Migrate blox schema").option("--basi
|
|
|
2561
2647
|
});
|
|
2562
2648
|
|
|
2563
2649
|
// src/commands/init/index.ts
|
|
2564
|
-
var
|
|
2650
|
+
var import_fs_extra16 = __toESM(require("fs-extra"));
|
|
2565
2651
|
var init2 = command("init").description("Init new app").alias("i").option("-n, --name <name>", "App name").option("-t, --template <template>", "Template to use").option("--branch <name>", "branch name").action(async ({ name, template, branch }) => {
|
|
2566
2652
|
await syncRegistries();
|
|
2567
2653
|
try {
|
|
@@ -2602,8 +2688,8 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
2602
2688
|
task.stop(`App initialized in ${name}`);
|
|
2603
2689
|
await runLifecycleHookWithTask(name || "", "init", "Run template init");
|
|
2604
2690
|
} catch (e) {
|
|
2605
|
-
if (name &&
|
|
2606
|
-
await
|
|
2691
|
+
if (name && import_fs_extra16.default.existsSync(name)) {
|
|
2692
|
+
await import_fs_extra16.default.remove(name);
|
|
2607
2693
|
}
|
|
2608
2694
|
error(e);
|
|
2609
2695
|
}
|
|
@@ -2623,30 +2709,30 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
|
|
|
2623
2709
|
});
|
|
2624
2710
|
|
|
2625
2711
|
// src/commands/remove/index.ts
|
|
2626
|
-
var
|
|
2627
|
-
var
|
|
2628
|
-
var blocksAbsolutePath = () =>
|
|
2712
|
+
var import_node_path19 = __toESM(require("path"));
|
|
2713
|
+
var import_fs_extra17 = __toESM(require("fs-extra"));
|
|
2714
|
+
var blocksAbsolutePath = () => import_node_path19.default.resolve(process.cwd(), blocksDir);
|
|
2629
2715
|
function listInstalledBlockRelPaths() {
|
|
2630
2716
|
const root = blocksAbsolutePath();
|
|
2631
|
-
if (!
|
|
2717
|
+
if (!import_fs_extra17.default.existsSync(root)) {
|
|
2632
2718
|
return [];
|
|
2633
2719
|
}
|
|
2634
2720
|
const paths2 = [];
|
|
2635
|
-
for (const entry of
|
|
2721
|
+
for (const entry of import_fs_extra17.default.readdirSync(root, { withFileTypes: true })) {
|
|
2636
2722
|
if (!entry.isDirectory()) {
|
|
2637
2723
|
continue;
|
|
2638
2724
|
}
|
|
2639
|
-
const abs =
|
|
2725
|
+
const abs = import_node_path19.default.join(root, entry.name);
|
|
2640
2726
|
if (!isBlockDirectory(abs)) {
|
|
2641
2727
|
continue;
|
|
2642
2728
|
}
|
|
2643
|
-
paths2.push(
|
|
2729
|
+
paths2.push(import_node_path19.default.join(blocksDir, entry.name));
|
|
2644
2730
|
}
|
|
2645
2731
|
return paths2;
|
|
2646
2732
|
}
|
|
2647
2733
|
function getInstalledBlockSelectOptions() {
|
|
2648
2734
|
return listInstalledBlockRelPaths().map((rel) => {
|
|
2649
|
-
const folder =
|
|
2735
|
+
const folder = import_node_path19.default.basename(rel);
|
|
2650
2736
|
const def = getBlockDef(rel);
|
|
2651
2737
|
const label = def?.name && def.name !== folder ? `${def.name} (${folder})` : folder;
|
|
2652
2738
|
return { value: folder, label, hint: def?.name };
|
|
@@ -2654,7 +2740,7 @@ function getInstalledBlockSelectOptions() {
|
|
|
2654
2740
|
}
|
|
2655
2741
|
function assertNoDependents(blockPathAbs, targetBlockName) {
|
|
2656
2742
|
for (const rel of listInstalledBlockRelPaths()) {
|
|
2657
|
-
const abs =
|
|
2743
|
+
const abs = import_node_path19.default.resolve(process.cwd(), rel);
|
|
2658
2744
|
if (abs === blockPathAbs) {
|
|
2659
2745
|
continue;
|
|
2660
2746
|
}
|
|
@@ -2670,19 +2756,19 @@ function assertNoDependents(blockPathAbs, targetBlockName) {
|
|
|
2670
2756
|
}
|
|
2671
2757
|
function assertUnderBlocksRoot(blockPathAbs) {
|
|
2672
2758
|
const root = blocksAbsolutePath();
|
|
2673
|
-
const rel =
|
|
2674
|
-
if (!rel || rel.startsWith("..") ||
|
|
2759
|
+
const rel = import_node_path19.default.relative(root, blockPathAbs);
|
|
2760
|
+
if (!rel || rel.startsWith("..") || import_node_path19.default.isAbsolute(rel)) {
|
|
2675
2761
|
throw new Error("Block path escapes the blocks directory");
|
|
2676
2762
|
}
|
|
2677
2763
|
}
|
|
2678
2764
|
async function removeBlock(block, blocks, force = false) {
|
|
2679
2765
|
const reg = blocks[block];
|
|
2680
2766
|
const destination = reg ? reg.destination ?? block : block;
|
|
2681
|
-
const blockPathRel =
|
|
2682
|
-
const blockPathAbs =
|
|
2767
|
+
const blockPathRel = import_node_path19.default.join(blocksDir, destination);
|
|
2768
|
+
const blockPathAbs = import_node_path19.default.resolve(process.cwd(), blockPathRel);
|
|
2683
2769
|
assertUnderBlocksRoot(blockPathAbs);
|
|
2684
|
-
if (!
|
|
2685
|
-
throw new Error(`Block is not installed at ${
|
|
2770
|
+
if (!import_fs_extra17.default.existsSync(blockPathAbs) || !isBlockDirectory(blockPathAbs)) {
|
|
2771
|
+
throw new Error(`Block is not installed at ${import_node_path19.default.relative(process.cwd(), blockPathAbs)}`);
|
|
2686
2772
|
}
|
|
2687
2773
|
const targetDef = getBlockDef(blockPathRel);
|
|
2688
2774
|
if (!targetDef?.name) {
|
|
@@ -2694,7 +2780,7 @@ async function removeBlock(block, blocks, force = false) {
|
|
|
2694
2780
|
await runLifecycleHookWithTask(blockPathRel, "remove", "Run block remove");
|
|
2695
2781
|
await runTask("Remove block files", async () => {
|
|
2696
2782
|
assertUnderBlocksRoot(blockPathAbs);
|
|
2697
|
-
await
|
|
2783
|
+
await import_fs_extra17.default.remove(blockPathAbs);
|
|
2698
2784
|
});
|
|
2699
2785
|
return true;
|
|
2700
2786
|
}
|
|
@@ -2752,17 +2838,17 @@ var remove = command("remove").description("Remove block from app").alias("rm").
|
|
|
2752
2838
|
// src/commands/skills/index.ts
|
|
2753
2839
|
var import_node_crypto = require("crypto");
|
|
2754
2840
|
var import_node_os3 = __toESM(require("os"));
|
|
2755
|
-
var
|
|
2841
|
+
var import_node_path21 = __toESM(require("path"));
|
|
2756
2842
|
var import_cross_spawn2 = __toESM(require("cross-spawn"));
|
|
2757
|
-
var
|
|
2843
|
+
var import_fs_extra19 = __toESM(require("fs-extra"));
|
|
2758
2844
|
|
|
2759
2845
|
// src/commands/skills/constants.ts
|
|
2760
2846
|
var SKILLS_REPO_URL = "https://tfs.aas.com.sa/Medad/BLOX/_git/cli";
|
|
2761
2847
|
var SKILLS_TEMP_ROOT_PREFIX = "blox-skills";
|
|
2762
2848
|
|
|
2763
2849
|
// src/commands/skills/utils/cliCompatibility.ts
|
|
2764
|
-
var
|
|
2765
|
-
var
|
|
2850
|
+
var import_node_path20 = __toESM(require("path"));
|
|
2851
|
+
var import_fs_extra18 = __toESM(require("fs-extra"));
|
|
2766
2852
|
var import_semver = __toESM(require("semver"));
|
|
2767
2853
|
var SKILLS_CLI_COMPATIBILITY_COMMANDS = ["add", "update"];
|
|
2768
2854
|
function getSkillscommandIndex(args, subcommand) {
|
|
@@ -2786,18 +2872,18 @@ function getAddCommandIndex(args) {
|
|
|
2786
2872
|
return getSkillscommandIndex(args, "add");
|
|
2787
2873
|
}
|
|
2788
2874
|
async function loadSkillsData(cloneRoot) {
|
|
2789
|
-
const skillsDir =
|
|
2790
|
-
if (!await
|
|
2875
|
+
const skillsDir = import_node_path20.default.join(cloneRoot, "skills");
|
|
2876
|
+
if (!await import_fs_extra18.default.pathExists(skillsDir)) {
|
|
2791
2877
|
return [];
|
|
2792
2878
|
}
|
|
2793
|
-
const entries = await
|
|
2879
|
+
const entries = await import_fs_extra18.default.readdir(skillsDir, { withFileTypes: true });
|
|
2794
2880
|
const manifests = await Promise.all(
|
|
2795
2881
|
entries.filter((entry) => entry.isDirectory()).map(async (entry) => {
|
|
2796
|
-
const filePath =
|
|
2797
|
-
if (!await
|
|
2882
|
+
const filePath = import_node_path20.default.join(skillsDir, entry.name, "skill.json");
|
|
2883
|
+
if (!await import_fs_extra18.default.pathExists(filePath)) {
|
|
2798
2884
|
return null;
|
|
2799
2885
|
}
|
|
2800
|
-
const raw = await
|
|
2886
|
+
const raw = await import_fs_extra18.default.readJson(filePath);
|
|
2801
2887
|
const range = raw.cliCompatibility?.trim();
|
|
2802
2888
|
if (!range) {
|
|
2803
2889
|
return null;
|
|
@@ -2848,8 +2934,8 @@ var skills = command("skills").description("Install, update, and manage BLOX CLI
|
|
|
2848
2934
|
async function runSkills() {
|
|
2849
2935
|
const idx = process.argv.indexOf("skills");
|
|
2850
2936
|
const args = idx === -1 ? [] : process.argv.slice(idx + 1);
|
|
2851
|
-
const tempDir =
|
|
2852
|
-
await
|
|
2937
|
+
const tempDir = import_node_path21.default.join(import_node_os3.default.tmpdir(), `${SKILLS_TEMP_ROOT_PREFIX}-${(0, import_node_crypto.randomUUID)()}`);
|
|
2938
|
+
await import_fs_extra19.default.mkdir(tempDir);
|
|
2853
2939
|
let exitCode = 1;
|
|
2854
2940
|
try {
|
|
2855
2941
|
await git.clone(SKILLS_REPO_URL, tempDir);
|
|
@@ -2868,11 +2954,11 @@ async function runSkills() {
|
|
|
2868
2954
|
}
|
|
2869
2955
|
}
|
|
2870
2956
|
}
|
|
2871
|
-
const finalArgs = injectRepoPathIfAdd(args,
|
|
2957
|
+
const finalArgs = injectRepoPathIfAdd(args, import_node_path21.default.resolve(tempDir));
|
|
2872
2958
|
exitCode = await runSkillsCommand(finalArgs, process.cwd());
|
|
2873
2959
|
} finally {
|
|
2874
2960
|
try {
|
|
2875
|
-
await
|
|
2961
|
+
await import_fs_extra19.default.remove(tempDir);
|
|
2876
2962
|
} catch {
|
|
2877
2963
|
debug(`Failed to cleanup temp dir: ${tempDir}`);
|
|
2878
2964
|
}
|
|
@@ -2906,11 +2992,11 @@ function runSkillsCommand(args, cwd) {
|
|
|
2906
2992
|
var import_prompts23 = require("@clack/prompts");
|
|
2907
2993
|
|
|
2908
2994
|
// src/commands/update/utils.ts
|
|
2909
|
-
var
|
|
2995
|
+
var import_node_path23 = __toESM(require("path"));
|
|
2910
2996
|
|
|
2911
2997
|
// src/services/updater.ts
|
|
2912
|
-
var
|
|
2913
|
-
var
|
|
2998
|
+
var import_node_path22 = __toESM(require("path"));
|
|
2999
|
+
var import_fs_extra20 = __toESM(require("fs-extra"));
|
|
2914
3000
|
var import_klaw3 = __toESM(require("klaw"));
|
|
2915
3001
|
async function updateFromRemote({
|
|
2916
3002
|
name,
|
|
@@ -2957,9 +3043,9 @@ async function updateFromRemote({
|
|
|
2957
3043
|
const remoteIgnore = remoteBloxFile.definition?.ignore || [];
|
|
2958
3044
|
const projectIgnore = bloxFile.project?.ignore || [];
|
|
2959
3045
|
ignore3.push(...remoteIgnore, ...projectIgnore, bloxFilePath, `**/${bloxFilePath}`);
|
|
2960
|
-
const gitIgnorePath =
|
|
2961
|
-
if (await
|
|
2962
|
-
const gitIgnoreContent = await
|
|
3046
|
+
const gitIgnorePath = import_node_path22.default.join(dir, ".gitignore");
|
|
3047
|
+
if (await import_fs_extra20.default.pathExists(gitIgnorePath)) {
|
|
3048
|
+
const gitIgnoreContent = await import_fs_extra20.default.readFile(gitIgnorePath, "utf8");
|
|
2963
3049
|
const gitIgnorePatterns = gitIgnoreContent.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
2964
3050
|
ignore3.push(...gitIgnorePatterns);
|
|
2965
3051
|
debug(`Added ${gitIgnorePatterns.length} patterns from .gitignore`);
|
|
@@ -2971,14 +3057,14 @@ async function updateFromRemote({
|
|
|
2971
3057
|
if (hard) {
|
|
2972
3058
|
const getAllFiles = async (d) => {
|
|
2973
3059
|
const files = [];
|
|
2974
|
-
if (await
|
|
3060
|
+
if (await import_fs_extra20.default.pathExists(d)) {
|
|
2975
3061
|
for await (const file of (0, import_klaw3.default)(d)) {
|
|
2976
3062
|
if (file.path.includes("/.git/") || file.path.endsWith("/.git") || file.path.includes("\\.git\\") || file.path.endsWith("\\.git"))
|
|
2977
3063
|
continue;
|
|
2978
3064
|
if (file.path.includes("/node_modules/") || file.path.includes("\\node_modules\\"))
|
|
2979
3065
|
continue;
|
|
2980
3066
|
if (file.stats.isFile()) {
|
|
2981
|
-
files.push(
|
|
3067
|
+
files.push(import_node_path22.default.relative(d, file.path));
|
|
2982
3068
|
}
|
|
2983
3069
|
}
|
|
2984
3070
|
}
|
|
@@ -2997,23 +3083,23 @@ async function updateFromRemote({
|
|
|
2997
3083
|
for (const file of filesToProcess) {
|
|
2998
3084
|
if (file === ".git" || file.startsWith(".git/") || file.startsWith(".git\\")) continue;
|
|
2999
3085
|
if (ignoredMatcher.ignores(toIgnorePath(file))) continue;
|
|
3000
|
-
const localPath =
|
|
3001
|
-
const basePath =
|
|
3002
|
-
const remotePath =
|
|
3003
|
-
const existsLocal = await
|
|
3004
|
-
const existsBase = await
|
|
3005
|
-
const existsRemote = await
|
|
3006
|
-
const ext =
|
|
3086
|
+
const localPath = import_node_path22.default.join(dir, file);
|
|
3087
|
+
const basePath = import_node_path22.default.join(baseDir, file);
|
|
3088
|
+
const remotePath = import_node_path22.default.join(remoteDir, file);
|
|
3089
|
+
const existsLocal = await import_fs_extra20.default.pathExists(localPath);
|
|
3090
|
+
const existsBase = await import_fs_extra20.default.pathExists(basePath);
|
|
3091
|
+
const existsRemote = await import_fs_extra20.default.pathExists(remotePath);
|
|
3092
|
+
const ext = import_node_path22.default.extname(file);
|
|
3007
3093
|
const isBinary = isBinaryFile(ext);
|
|
3008
3094
|
if (existsRemote) {
|
|
3009
|
-
await
|
|
3095
|
+
await import_fs_extra20.default.ensureDir(import_node_path22.default.dirname(localPath));
|
|
3010
3096
|
}
|
|
3011
3097
|
if (hard) {
|
|
3012
3098
|
if (existsRemote) {
|
|
3013
|
-
await
|
|
3099
|
+
await import_fs_extra20.default.copy(remotePath, localPath, { overwrite: true });
|
|
3014
3100
|
debug(`Hard update: Overwrote ${file}`);
|
|
3015
3101
|
} else if (existsLocal) {
|
|
3016
|
-
await
|
|
3102
|
+
await import_fs_extra20.default.remove(localPath);
|
|
3017
3103
|
debug(`Hard update: Removed ${file}`);
|
|
3018
3104
|
}
|
|
3019
3105
|
continue;
|
|
@@ -3022,29 +3108,29 @@ async function updateFromRemote({
|
|
|
3022
3108
|
if (existsLocal) {
|
|
3023
3109
|
if (isBinary) {
|
|
3024
3110
|
debug(`Binary collision: ${file}, overwriting.`);
|
|
3025
|
-
await
|
|
3111
|
+
await import_fs_extra20.default.copy(remotePath, localPath, { overwrite: true });
|
|
3026
3112
|
logWarningSection(`Overwrote binary file collision: ${file}`);
|
|
3027
3113
|
} else {
|
|
3028
|
-
const emptyBase =
|
|
3029
|
-
await
|
|
3114
|
+
const emptyBase = import_node_path22.default.join(baseDir, `${file}.empty`);
|
|
3115
|
+
await import_fs_extra20.default.ensureFile(emptyBase);
|
|
3030
3116
|
const result = await git.mergeFile(localPath, emptyBase, remotePath);
|
|
3031
3117
|
if (!result) {
|
|
3032
3118
|
hasConflicts2 = true;
|
|
3033
3119
|
conflictFiles.push(file);
|
|
3034
3120
|
}
|
|
3035
|
-
await
|
|
3121
|
+
await import_fs_extra20.default.remove(emptyBase);
|
|
3036
3122
|
}
|
|
3037
3123
|
} else {
|
|
3038
|
-
await
|
|
3124
|
+
await import_fs_extra20.default.copy(remotePath, localPath);
|
|
3039
3125
|
}
|
|
3040
3126
|
continue;
|
|
3041
3127
|
}
|
|
3042
3128
|
if (existsBase && !existsRemote) {
|
|
3043
3129
|
if (existsLocal) {
|
|
3044
|
-
const localBuffer = await
|
|
3045
|
-
const baseBuffer = await
|
|
3130
|
+
const localBuffer = await import_fs_extra20.default.readFile(localPath);
|
|
3131
|
+
const baseBuffer = await import_fs_extra20.default.readFile(basePath);
|
|
3046
3132
|
if (localBuffer.equals(baseBuffer)) {
|
|
3047
|
-
await
|
|
3133
|
+
await import_fs_extra20.default.remove(localPath);
|
|
3048
3134
|
} else {
|
|
3049
3135
|
logWarningSection(
|
|
3050
3136
|
`File ${file} was deleted in remote but modified locally. Kept local version.`
|
|
@@ -3055,7 +3141,7 @@ async function updateFromRemote({
|
|
|
3055
3141
|
}
|
|
3056
3142
|
if (existsBase && existsRemote) {
|
|
3057
3143
|
if (!existsLocal) {
|
|
3058
|
-
await
|
|
3144
|
+
await import_fs_extra20.default.copy(remotePath, localPath);
|
|
3059
3145
|
logWarningSection(
|
|
3060
3146
|
`File restored: ${file}`,
|
|
3061
3147
|
`This file was deleted locally but updated in the remote block.
|
|
@@ -3064,7 +3150,7 @@ It has been recreated to apply upstream changes.`
|
|
|
3064
3150
|
continue;
|
|
3065
3151
|
}
|
|
3066
3152
|
if (isBinary) {
|
|
3067
|
-
await
|
|
3153
|
+
await import_fs_extra20.default.copy(remotePath, localPath, { overwrite: true });
|
|
3068
3154
|
logWarningSection(`Updated binary file: ${file} (overwritten)`);
|
|
3069
3155
|
} else {
|
|
3070
3156
|
const result = await git.mergeFile(localPath, basePath, remotePath);
|
|
@@ -3096,6 +3182,12 @@ It has been recreated to apply upstream changes.`
|
|
|
3096
3182
|
}
|
|
3097
3183
|
|
|
3098
3184
|
// src/commands/update/utils.ts
|
|
3185
|
+
async function confirmContinueWhenMissing(itemType, name) {
|
|
3186
|
+
return confirm({
|
|
3187
|
+
message: `${itemType}: ${name} does not exist in registries. Continue updating remaining parts?`,
|
|
3188
|
+
initialValue: true
|
|
3189
|
+
});
|
|
3190
|
+
}
|
|
3099
3191
|
async function updateApp({
|
|
3100
3192
|
templateDef,
|
|
3101
3193
|
templates,
|
|
@@ -3105,10 +3197,14 @@ async function updateApp({
|
|
|
3105
3197
|
hard = false
|
|
3106
3198
|
}) {
|
|
3107
3199
|
let updated = false;
|
|
3200
|
+
let shouldContinue = true;
|
|
3108
3201
|
await runTask({ start: "Update App", end: "Updated App" }, async () => {
|
|
3109
3202
|
const template = templates[templateDef.name];
|
|
3110
3203
|
if (!template) {
|
|
3111
|
-
|
|
3204
|
+
shouldContinue = await confirmContinueWhenMissing(
|
|
3205
|
+
"template" /* TEMPLATE */,
|
|
3206
|
+
templateDef.name
|
|
3207
|
+
);
|
|
3112
3208
|
return;
|
|
3113
3209
|
}
|
|
3114
3210
|
const toAppCommit = await updateFromRemote({
|
|
@@ -3122,9 +3218,16 @@ async function updateApp({
|
|
|
3122
3218
|
if (!templateDef.bases?.length) return;
|
|
3123
3219
|
for (const block of usedBlocks) {
|
|
3124
3220
|
const blockRegistryData = availableBlocks[block.name];
|
|
3125
|
-
if (!blockRegistryData)
|
|
3221
|
+
if (!blockRegistryData) {
|
|
3222
|
+
shouldContinue = await confirmContinueWhenMissing(
|
|
3223
|
+
"block" /* BLOCK */,
|
|
3224
|
+
block.name
|
|
3225
|
+
);
|
|
3226
|
+
if (!shouldContinue) return;
|
|
3227
|
+
continue;
|
|
3228
|
+
}
|
|
3126
3229
|
await git.updateRemote(block.name, blockRegistryData.source);
|
|
3127
|
-
const blockPath =
|
|
3230
|
+
const blockPath = import_node_path23.default.join(blocksDir, block.name);
|
|
3128
3231
|
const currentBloxFile = getBloxFile(blockPath);
|
|
3129
3232
|
const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
|
|
3130
3233
|
const blockFromCommit = currentBloxFile.checkpoints?.[block.name]?.commit;
|
|
@@ -3139,17 +3242,21 @@ async function updateApp({
|
|
|
3139
3242
|
}
|
|
3140
3243
|
}
|
|
3141
3244
|
});
|
|
3142
|
-
return updated;
|
|
3245
|
+
return { updated, shouldContinue };
|
|
3143
3246
|
}
|
|
3144
3247
|
async function updateAppBases(templateDef, templates, ignore3, hard = false) {
|
|
3145
3248
|
let updated = false;
|
|
3249
|
+
let shouldContinue = true;
|
|
3146
3250
|
for (const base of templateDef.bases || []) {
|
|
3147
3251
|
await runTask(
|
|
3148
3252
|
{ start: `Update App base: ${base.name}`, end: `Updated App base: ${base.name}` },
|
|
3149
3253
|
async () => {
|
|
3150
3254
|
const template = templates[base.name];
|
|
3151
3255
|
if (!template) {
|
|
3152
|
-
|
|
3256
|
+
shouldContinue = await confirmContinueWhenMissing(
|
|
3257
|
+
"base" /* BASE */,
|
|
3258
|
+
base.name
|
|
3259
|
+
);
|
|
3153
3260
|
return;
|
|
3154
3261
|
}
|
|
3155
3262
|
const toCommit = await updateFromRemote({
|
|
@@ -3161,16 +3268,18 @@ async function updateAppBases(templateDef, templates, ignore3, hard = false) {
|
|
|
3161
3268
|
if (toCommit) updated = true;
|
|
3162
3269
|
}
|
|
3163
3270
|
);
|
|
3271
|
+
if (!shouldContinue) break;
|
|
3164
3272
|
}
|
|
3165
|
-
return updated;
|
|
3273
|
+
return { updated, shouldContinue };
|
|
3166
3274
|
}
|
|
3167
3275
|
async function updateBlock(block, blocks, ignore3, hard = false) {
|
|
3168
3276
|
const blockRegistryData = blocks[block];
|
|
3169
|
-
const blockPath =
|
|
3277
|
+
const blockPath = import_node_path23.default.join(blocksDir, block);
|
|
3170
3278
|
let updated = false;
|
|
3279
|
+
let shouldContinue = true;
|
|
3171
3280
|
await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
|
|
3172
3281
|
if (!blockRegistryData) {
|
|
3173
|
-
|
|
3282
|
+
shouldContinue = await confirmContinueWhenMissing("block" /* BLOCK */, block);
|
|
3174
3283
|
return;
|
|
3175
3284
|
}
|
|
3176
3285
|
const toCommit = await updateFromRemote({
|
|
@@ -3185,7 +3294,7 @@ async function updateBlock(block, blocks, ignore3, hard = false) {
|
|
|
3185
3294
|
if (updated) {
|
|
3186
3295
|
await runLifecycleHookWithTask(blockPath, "update", "Run block update");
|
|
3187
3296
|
}
|
|
3188
|
-
return updated;
|
|
3297
|
+
return { updated, shouldContinue };
|
|
3189
3298
|
}
|
|
3190
3299
|
async function getCurrentCheckpoints() {
|
|
3191
3300
|
const bloxFile = getBloxFile();
|
|
@@ -3251,8 +3360,9 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
|
|
|
3251
3360
|
}
|
|
3252
3361
|
try {
|
|
3253
3362
|
let hasUpdate = false;
|
|
3363
|
+
let shouldContinue = true;
|
|
3254
3364
|
if (["app", "all"].includes(args.scope)) {
|
|
3255
|
-
const
|
|
3365
|
+
const appResult = await updateApp({
|
|
3256
3366
|
templateDef,
|
|
3257
3367
|
templates,
|
|
3258
3368
|
usedBlocks,
|
|
@@ -3260,29 +3370,35 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
|
|
|
3260
3370
|
ignore: ignoresByName[templateDef.name],
|
|
3261
3371
|
hard: args.hard
|
|
3262
3372
|
});
|
|
3263
|
-
hasUpdate = hasUpdate ||
|
|
3373
|
+
hasUpdate = hasUpdate || appResult.updated;
|
|
3374
|
+
shouldContinue = appResult.shouldContinue;
|
|
3264
3375
|
}
|
|
3265
|
-
if (["bases", "all"].includes(args.scope)) {
|
|
3266
|
-
const
|
|
3376
|
+
if (shouldContinue && ["bases", "all"].includes(args.scope)) {
|
|
3377
|
+
const basesResult = await updateAppBases(
|
|
3267
3378
|
templateDef,
|
|
3268
3379
|
templates,
|
|
3269
3380
|
ignoresByName[templateDef.name],
|
|
3270
3381
|
args.hard
|
|
3271
3382
|
);
|
|
3272
|
-
hasUpdate = hasUpdate ||
|
|
3383
|
+
hasUpdate = hasUpdate || basesResult.updated;
|
|
3384
|
+
shouldContinue = basesResult.shouldContinue;
|
|
3273
3385
|
}
|
|
3274
|
-
if (args.scope === "all") {
|
|
3386
|
+
if (shouldContinue && args.scope === "all") {
|
|
3275
3387
|
for (const block of usedBlocks) {
|
|
3276
|
-
const
|
|
3388
|
+
const blockResult = await updateBlock(
|
|
3277
3389
|
block.name,
|
|
3278
3390
|
availableBlocks,
|
|
3279
3391
|
ignoresByName[block.name],
|
|
3280
3392
|
args.hard
|
|
3281
3393
|
);
|
|
3282
|
-
hasUpdate = hasUpdate ||
|
|
3394
|
+
hasUpdate = hasUpdate || blockResult.updated;
|
|
3395
|
+
if (!blockResult.shouldContinue) {
|
|
3396
|
+
shouldContinue = false;
|
|
3397
|
+
break;
|
|
3398
|
+
}
|
|
3283
3399
|
}
|
|
3284
3400
|
}
|
|
3285
|
-
if (args.scope === "block") {
|
|
3401
|
+
if (shouldContinue && args.scope === "block") {
|
|
3286
3402
|
if (!args.block) {
|
|
3287
3403
|
args.block = await select({
|
|
3288
3404
|
message: "Select block to be updated",
|
|
@@ -3297,13 +3413,17 @@ var update2 = command("update").description("Update app/block").alias("u").addOp
|
|
|
3297
3413
|
error("Selected block not used in app");
|
|
3298
3414
|
return;
|
|
3299
3415
|
}
|
|
3300
|
-
const
|
|
3416
|
+
const blockResult = await updateBlock(
|
|
3301
3417
|
blockDef.name,
|
|
3302
3418
|
availableBlocks,
|
|
3303
3419
|
ignoresByName[blockDef.name],
|
|
3304
3420
|
args.hard
|
|
3305
3421
|
);
|
|
3306
|
-
hasUpdate = hasUpdate ||
|
|
3422
|
+
hasUpdate = hasUpdate || blockResult.updated;
|
|
3423
|
+
shouldContinue = blockResult.shouldContinue;
|
|
3424
|
+
}
|
|
3425
|
+
if (!shouldContinue) {
|
|
3426
|
+
import_prompts23.log.warn(fmt.yellow("Stopped updating remaining parts by user choice"));
|
|
3307
3427
|
}
|
|
3308
3428
|
if (hasUpdate) {
|
|
3309
3429
|
await runLifecycleHookWithTask(".", "update", "Run template update");
|