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