@naseej/blox 1.3.3 → 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 +68 -24
- 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,14 +629,43 @@ 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"));
|
|
633
|
+
var NON_RENDERABLE_FILES = [
|
|
634
|
+
".png",
|
|
635
|
+
".jpg",
|
|
636
|
+
".jpeg",
|
|
637
|
+
".gif",
|
|
638
|
+
".svg",
|
|
639
|
+
".ico",
|
|
640
|
+
".ttf",
|
|
641
|
+
".woff",
|
|
642
|
+
".woff2",
|
|
643
|
+
".otf",
|
|
644
|
+
".mp4",
|
|
645
|
+
".mp3",
|
|
646
|
+
".zip",
|
|
647
|
+
".plist",
|
|
648
|
+
".DS_Store",
|
|
649
|
+
".bin"
|
|
650
|
+
];
|
|
624
651
|
async function replacePlaceholders(dir, context) {
|
|
625
652
|
debug("Replace placeholders");
|
|
626
|
-
for await (const file of (0,
|
|
627
|
-
if (file.stats.isFile())
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
653
|
+
for await (const file of (0, import_klaw2.default)(dir)) {
|
|
654
|
+
if (!file.stats.isFile()) continue;
|
|
655
|
+
const ext = import_node_path8.default.extname(file.path).toLowerCase();
|
|
656
|
+
if (NON_RENDERABLE_FILES.includes(ext)) {
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
const templateContent = import_fs_extra7.default.readFileSync(file.path, "utf8");
|
|
660
|
+
if (!templateContent.includes("<%")) {
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
try {
|
|
664
|
+
const rendered = import_ejs.default.render(templateContent, context);
|
|
665
|
+
import_fs_extra7.default.writeFileSync(file.path, rendered, "utf8");
|
|
666
|
+
} catch (err) {
|
|
667
|
+
console.error("\u274C Error rendering EJS for file:", file.path);
|
|
668
|
+
throw err;
|
|
631
669
|
}
|
|
632
670
|
}
|
|
633
671
|
}
|
|
@@ -779,8 +817,8 @@ async function checkVersionsCompatibility() {
|
|
|
779
817
|
}
|
|
780
818
|
|
|
781
819
|
// src/services/versions/select.ts
|
|
782
|
-
async function selectVersion(
|
|
783
|
-
const versionsData = await getAvailableVersions(
|
|
820
|
+
async function selectVersion(source, fromCommit) {
|
|
821
|
+
const versionsData = await getAvailableVersions(source);
|
|
784
822
|
if (!versionsData) return;
|
|
785
823
|
const versions = [];
|
|
786
824
|
for (const [v, { lastCommit }] of Object.entries(versionsData)) {
|
|
@@ -827,8 +865,9 @@ var addBlock = async (block, blocks) => {
|
|
|
827
865
|
await runTask(
|
|
828
866
|
{ start: `Fetching block: ${block}`, end: `Added block: ${block}` },
|
|
829
867
|
async () => {
|
|
830
|
-
|
|
831
|
-
|
|
868
|
+
const blockSource = blockRegistryData?.source || "";
|
|
869
|
+
await git.clone(blockSource, blockPath);
|
|
870
|
+
let commit2 = await selectVersion(blockSource);
|
|
832
871
|
if (commit2) {
|
|
833
872
|
await git.resetToCommit(commit2, blockPath);
|
|
834
873
|
} else {
|
|
@@ -852,6 +891,10 @@ var addBlock = async (block, blocks) => {
|
|
|
852
891
|
}
|
|
853
892
|
};
|
|
854
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
|
+
}
|
|
855
898
|
await migrateAll();
|
|
856
899
|
await syncRegistries();
|
|
857
900
|
try {
|
|
@@ -968,8 +1011,9 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
968
1011
|
}
|
|
969
1012
|
const task = spinner();
|
|
970
1013
|
task.start(`Fetch template`);
|
|
971
|
-
|
|
972
|
-
|
|
1014
|
+
const templateSource = templates[template]?.source || "";
|
|
1015
|
+
await git.clone(templateSource, name);
|
|
1016
|
+
let commit2 = await selectVersion(templateSource);
|
|
973
1017
|
if (commit2) {
|
|
974
1018
|
await git.resetToCommit(commit2, name);
|
|
975
1019
|
} else {
|
|
@@ -1023,7 +1067,7 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
|
|
|
1023
1067
|
debug("Skip update, no fromCommit found");
|
|
1024
1068
|
return;
|
|
1025
1069
|
}
|
|
1026
|
-
let toCommit = await selectVersion(
|
|
1070
|
+
let toCommit = await selectVersion(source, fromCommit);
|
|
1027
1071
|
if (!toCommit) {
|
|
1028
1072
|
toCommit = await git.getLatestCommitFromRemote(name);
|
|
1029
1073
|
}
|