@llmist/cli 8.0.0 → 8.1.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/cli.js CHANGED
@@ -843,11 +843,39 @@ function isExternalPackageSpecifier(specifier) {
843
843
  function parseGadgetSpecifier(specifier) {
844
844
  if (specifier.startsWith("git+")) {
845
845
  const url = specifier.slice(4);
846
- const [baseUrl, ref] = url.split("#");
846
+ let baseUrl;
847
+ let ref;
848
+ let preset;
849
+ if (url.includes("#")) {
850
+ const hashIndex = url.indexOf("#");
851
+ baseUrl = url.slice(0, hashIndex);
852
+ const refAndPreset = url.slice(hashIndex + 1);
853
+ if (refAndPreset.includes(":")) {
854
+ const colonIndex = refAndPreset.indexOf(":");
855
+ ref = refAndPreset.slice(0, colonIndex);
856
+ preset = refAndPreset.slice(colonIndex + 1);
857
+ } else {
858
+ ref = refAndPreset;
859
+ }
860
+ } else {
861
+ const gitExtIndex = url.indexOf(".git");
862
+ if (gitExtIndex !== -1) {
863
+ const afterGit = url.slice(gitExtIndex + 4);
864
+ if (afterGit.startsWith(":")) {
865
+ baseUrl = url.slice(0, gitExtIndex + 4);
866
+ preset = afterGit.slice(1);
867
+ } else {
868
+ baseUrl = url;
869
+ }
870
+ } else {
871
+ baseUrl = url;
872
+ }
873
+ }
847
874
  return {
848
875
  type: "git",
849
876
  package: baseUrl,
850
- version: ref
877
+ version: ref,
878
+ preset
851
879
  };
852
880
  }
853
881
  const npmMatch = specifier.match(
@@ -1019,7 +1047,41 @@ async function loadExternalGadgets(specifier, forceInstall = false) {
1019
1047
  const message = error instanceof Error ? error.message : String(error);
1020
1048
  throw new Error(`Failed to import '${specifier}': ${message}`);
1021
1049
  }
1022
- let gadgets = extractGadgetsFromModule(exports);
1050
+ let gadgets = [];
1051
+ if (manifest?.factory) {
1052
+ const exportsObj = exports;
1053
+ if (spec.preset && typeof exportsObj.createGadgetsByPreset === "function") {
1054
+ const result = await exportsObj.createGadgetsByPreset(
1055
+ spec.preset
1056
+ );
1057
+ gadgets = extractGadgetsFromModule(result);
1058
+ gadgetNames = null;
1059
+ } else if (gadgetNames && typeof exportsObj.createGadgetsByName === "function") {
1060
+ const result = await exportsObj.createGadgetsByName(
1061
+ gadgetNames
1062
+ );
1063
+ gadgets = extractGadgetsFromModule(result);
1064
+ gadgetNames = null;
1065
+ } else {
1066
+ const factoryNames = [
1067
+ "createGadgets",
1068
+ "createDhalsimGadgets",
1069
+ "createAllGadgets",
1070
+ "gadgets",
1071
+ "default"
1072
+ ];
1073
+ for (const name of factoryNames) {
1074
+ if (typeof exportsObj[name] === "function") {
1075
+ const result = await exportsObj[name]();
1076
+ gadgets = extractGadgetsFromModule(result);
1077
+ if (gadgets.length > 0) break;
1078
+ }
1079
+ }
1080
+ }
1081
+ }
1082
+ if (gadgets.length === 0) {
1083
+ gadgets = extractGadgetsFromModule(exports);
1084
+ }
1023
1085
  if (gadgetNames) {
1024
1086
  const gadgetSet = new Set(gadgetNames.map((n) => n.toLowerCase()));
1025
1087
  gadgets = gadgets.filter((g) => {