| 
3 | 3 | import com.algolia.codegen.AlgoliaJavascriptGenerator;  | 
4 | 4 | import com.algolia.codegen.exceptions.GeneratorException;  | 
5 | 5 | import com.algolia.codegen.utils.*;  | 
 | 6 | +import com.fasterxml.jackson.databind.*;  | 
6 | 7 | import java.util.*;  | 
7 | 8 | import org.openapitools.codegen.SupportingFile;  | 
8 | 9 | 
 
  | 
@@ -43,30 +44,32 @@ public void addSnippetsSupportingFiles(List<SupportingFile> supportingFiles, Str  | 
43 | 44 | 
 
  | 
44 | 45 |   @Override  | 
45 | 46 |   public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {  | 
46 |  | -    bundle.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common"));  | 
47 |  | -    bundle.put("algoliasearchVersion", Helpers.getPackageJsonVersion("algoliasearch"));  | 
48 |  | -    bundle.put("initMethod", "init" + Helpers.capitalize(Helpers.camelize(client)));  | 
 | 47 | +    Optional<Map<String, Object>> clientPkg = Helpers.getClientConfigList("javascript", "clients")  | 
 | 48 | +      .stream()  | 
 | 49 | +      .filter(pkg -> ((String) pkg.get("name")).contains(client))  | 
 | 50 | +      .findFirst();  | 
 | 51 | +    if (!clientPkg.isPresent()) {  | 
 | 52 | +      throw new GeneratorException("Cannot find client " + client + " in config/clients.config.json for javascript");  | 
 | 53 | +    }  | 
 | 54 | + | 
 | 55 | +    boolean isStandaloneClient = (boolean) clientPkg.get().getOrDefault("isStandaloneClient", false);  | 
 | 56 | +    bundle.put("isStandaloneClient", isStandaloneClient || client.contains("search"));  | 
49 | 57 | 
 
  | 
50 |  | -    switch (client) {  | 
51 |  | -      case "composition":  | 
52 |  | -        bundle.put("clientName", "compositionClient");  | 
53 |  | -        bundle.put("importPackage", "@algolia/composition");  | 
54 |  | -        break;  | 
55 |  | -      case "composition-full":  | 
56 |  | -        bundle.put("clientName", "compositionClient");  | 
57 |  | -        bundle.put("importPackage", "@algolia/client-composition");  | 
58 |  | -        break;  | 
59 |  | -      case "realtime-personalization":  | 
60 |  | -        bundle.put("clientName", "realtimePersonalizationClient");  | 
61 |  | -        bundle.put("importPackage", "@algolia/client-realtime-personalization");  | 
62 |  | -        break;  | 
63 |  | -      case "algoliasearch":  | 
64 |  | -        bundle.put("clientName", "liteClient");  | 
65 |  | -        bundle.put("importPackage", "algoliasearch/lite");  | 
66 |  | -        break;  | 
67 |  | -      default:  | 
68 |  | -        bundle.put("clientName", "algoliasearch");  | 
69 |  | -        bundle.put("importPackage", "algoliasearch");  | 
 | 58 | +    if (client.equals("algoliasearch")) {  | 
 | 59 | +      bundle.put("clientName", "liteClient");  | 
 | 60 | +      bundle.put("importPackage", "algoliasearch/lite");  | 
 | 61 | +    } else if (isStandaloneClient) {  | 
 | 62 | +      bundle.put("clientName", (String) clientPkg.get().getOrDefault("clientName", Helpers.camelize(client)) + Helpers.API_SUFFIX);  | 
 | 63 | + | 
 | 64 | +      JsonNode packageJson = Helpers.readJsonFile(clientPkg.get().get("output") + "/package.json");  | 
 | 65 | +      bundle.put("importPackage", packageJson.get("name").asText());  | 
 | 66 | +    } else {  | 
 | 67 | +      bundle.put("initMethod", "init" + Helpers.capitalize(Helpers.camelize(client)));  | 
 | 68 | +      bundle.put("clientName", "algoliasearch");  | 
 | 69 | +      bundle.put("importPackage", "algoliasearch");  | 
70 | 70 |     }  | 
 | 71 | + | 
 | 72 | +    bundle.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common"));  | 
 | 73 | +    bundle.put("algoliasearchVersion", Helpers.getPackageJsonVersion("algoliasearch"));  | 
71 | 74 |   }  | 
72 | 75 | }  | 
0 commit comments