@naseej/blox 1.3.4 → 1.4.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 +35 -20
- 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.4.0";
|
|
35
35
|
|
|
36
36
|
// src/commands/add/index.ts
|
|
37
37
|
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
@@ -480,7 +480,6 @@ var deletePattern = async (cwd, patterns = []) => {
|
|
|
480
480
|
// src/services/registry.ts
|
|
481
481
|
var import_node_path7 = __toESM(require("path"));
|
|
482
482
|
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
483
|
-
var import_klaw2 = __toESM(require("klaw"));
|
|
484
483
|
var import_merge = __toESM(require("lodash/merge"));
|
|
485
484
|
|
|
486
485
|
// src/shared/spinner.ts
|
|
@@ -563,11 +562,11 @@ var syncRegistries = async () => {
|
|
|
563
562
|
var getAvailableTemplates = async () => {
|
|
564
563
|
debug("Get available templates");
|
|
565
564
|
const templates = {};
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
if (
|
|
570
|
-
const data = import_fs_extra6.default.readJSONSync(
|
|
565
|
+
const registries = import_fs_extra6.default.readdirSync(registriesDataPath);
|
|
566
|
+
for (const registry of registries) {
|
|
567
|
+
const indexPath = import_node_path7.default.join(registriesDataPath, registry, "index.json");
|
|
568
|
+
if (import_fs_extra6.default.existsSync(indexPath)) {
|
|
569
|
+
const data = import_fs_extra6.default.readJSONSync(indexPath);
|
|
571
570
|
Object.entries(data.templates || {}).forEach(([templateName, template]) => {
|
|
572
571
|
if (!template.source) {
|
|
573
572
|
template.source = `/template-${templateName}`;
|
|
@@ -606,12 +605,22 @@ var getAvailableBlocks = async (templateInfo) => {
|
|
|
606
605
|
debug({ blocks });
|
|
607
606
|
return blocks;
|
|
608
607
|
};
|
|
609
|
-
var getAvailableVersions = async (
|
|
608
|
+
var getAvailableVersions = async (source) => {
|
|
610
609
|
const registries = import_fs_extra6.default.readdirSync(registriesDataPath);
|
|
611
610
|
for (const registry of registries) {
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
611
|
+
const registryPath = import_node_path7.default.join(registriesDataPath, registry);
|
|
612
|
+
const indexPath = import_node_path7.default.join(registryPath, "index.json");
|
|
613
|
+
if (!import_fs_extra6.default.existsSync(indexPath)) continue;
|
|
614
|
+
const registryData = import_fs_extra6.default.readJSONSync(indexPath);
|
|
615
|
+
const versionDirPath = import_node_path7.default.join(registryPath, "versions");
|
|
616
|
+
const versionsFilePaths = [
|
|
617
|
+
import_node_path7.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
|
|
618
|
+
import_node_path7.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
|
|
619
|
+
];
|
|
620
|
+
for (const versionsFile of versionsFilePaths) {
|
|
621
|
+
if (import_fs_extra6.default.existsSync(versionsFile)) {
|
|
622
|
+
return import_fs_extra6.default.readJSONSync(versionsFile);
|
|
623
|
+
}
|
|
615
624
|
}
|
|
616
625
|
}
|
|
617
626
|
};
|
|
@@ -620,7 +629,7 @@ var getAvailableVersions = async (id) => {
|
|
|
620
629
|
var import_node_path8 = __toESM(require("path"));
|
|
621
630
|
var import_ejs = __toESM(require("ejs"));
|
|
622
631
|
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
623
|
-
var
|
|
632
|
+
var import_klaw2 = __toESM(require("klaw"));
|
|
624
633
|
var NON_RENDERABLE_FILES = [
|
|
625
634
|
".png",
|
|
626
635
|
".jpg",
|
|
@@ -641,7 +650,7 @@ var NON_RENDERABLE_FILES = [
|
|
|
641
650
|
];
|
|
642
651
|
async function replacePlaceholders(dir, context) {
|
|
643
652
|
debug("Replace placeholders");
|
|
644
|
-
for await (const file of (0,
|
|
653
|
+
for await (const file of (0, import_klaw2.default)(dir)) {
|
|
645
654
|
if (!file.stats.isFile()) continue;
|
|
646
655
|
const ext = import_node_path8.default.extname(file.path).toLowerCase();
|
|
647
656
|
if (NON_RENDERABLE_FILES.includes(ext)) {
|
|
@@ -808,8 +817,8 @@ async function checkVersionsCompatibility() {
|
|
|
808
817
|
}
|
|
809
818
|
|
|
810
819
|
// src/services/versions/select.ts
|
|
811
|
-
async function selectVersion(
|
|
812
|
-
const versionsData = await getAvailableVersions(
|
|
820
|
+
async function selectVersion(source, fromCommit) {
|
|
821
|
+
const versionsData = await getAvailableVersions(source);
|
|
813
822
|
if (!versionsData) return;
|
|
814
823
|
const versions = [];
|
|
815
824
|
for (const [v, { lastCommit }] of Object.entries(versionsData)) {
|
|
@@ -856,8 +865,9 @@ var addBlock = async (block, blocks) => {
|
|
|
856
865
|
await runTask(
|
|
857
866
|
{ start: `Fetching block: ${block}`, end: `Added block: ${block}` },
|
|
858
867
|
async () => {
|
|
859
|
-
|
|
860
|
-
|
|
868
|
+
const blockSource = blockRegistryData?.source || "";
|
|
869
|
+
await git.clone(blockSource, blockPath);
|
|
870
|
+
let commit2 = await selectVersion(blockSource);
|
|
861
871
|
if (commit2) {
|
|
862
872
|
await git.resetToCommit(commit2, blockPath);
|
|
863
873
|
} else {
|
|
@@ -881,6 +891,10 @@ var addBlock = async (block, blocks) => {
|
|
|
881
891
|
}
|
|
882
892
|
};
|
|
883
893
|
var add2 = command("add").description("Add block to app").alias("a").argument("[block]", "Block to be added").action(async (block) => {
|
|
894
|
+
if (await git.hasUncommittedChanges()) {
|
|
895
|
+
import_prompts2.log.warn(fmt.yellow("Make sure to commit any changes first"));
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
884
898
|
await migrateAll();
|
|
885
899
|
await syncRegistries();
|
|
886
900
|
try {
|
|
@@ -997,8 +1011,9 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
997
1011
|
}
|
|
998
1012
|
const task = spinner();
|
|
999
1013
|
task.start(`Fetch template`);
|
|
1000
|
-
|
|
1001
|
-
|
|
1014
|
+
const templateSource = templates[template]?.source || "";
|
|
1015
|
+
await git.clone(templateSource, name);
|
|
1016
|
+
let commit2 = await selectVersion(templateSource);
|
|
1002
1017
|
if (commit2) {
|
|
1003
1018
|
await git.resetToCommit(commit2, name);
|
|
1004
1019
|
} else {
|
|
@@ -1052,7 +1067,7 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
|
|
|
1052
1067
|
debug("Skip update, no fromCommit found");
|
|
1053
1068
|
return;
|
|
1054
1069
|
}
|
|
1055
|
-
let toCommit = await selectVersion(
|
|
1070
|
+
let toCommit = await selectVersion(source, fromCommit);
|
|
1056
1071
|
if (!toCommit) {
|
|
1057
1072
|
toCommit = await git.getLatestCommitFromRemote(name);
|
|
1058
1073
|
}
|