Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cli index name #121

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-chicken-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"composable-cli": patch
---

algolia index name resolving fixed
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
} from "./utility/algolia/algolia"
import { logging } from "@angular-devkit/core"
import { attemptToAddEnvVariables } from "../../../lib/devkit/add-env-variables"
import { resolveIndexName } from "./utility/resolve-index-name"

export function createAlgoliaIntegrationCommand(
ctx: CommandContext,
Expand Down Expand Up @@ -291,9 +292,10 @@ export function createAlgoliaIntegrationCommandHandler(

spinner.succeed(`Published ${catalog.attributes.name} catalog!`)

const algoliaIndexName = `${catalog.attributes.name.replace(" ", "_")}_${
catalog.id.split("-")[0]
}`
const algoliaIndexName = resolveIndexName(
catalog.attributes.name,
catalog.id,
)

const envVarResult = await attemptToAddEnvVariables(ctx, spinner, {
NEXT_PUBLIC_ALGOLIA_INDEX_NAME: algoliaIndexName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { resolveIndexName } from "./resolve-index-name"

describe("resolveIndexName", () => {
it("should resolve index name with escaped catalog name and first block of catalogId", () => {
const catalogName = "Flora standard catalog"
const catalogId = "7b479b7c-05b7-4a25-ae3a-dae4787b0811"

const result = resolveIndexName(catalogName, catalogId)

expect(result).toBe("Flora_standard_catalog_7b479b7c")
})

it("should handle catalog names with leading/trailing spaces", () => {
const catalogName = " Flora catalog with spaces "
const catalogId = "7b479b7c-05b7-4a25-ae3a-dae4787b0811"

const result = resolveIndexName(catalogName, catalogId)

expect(result).toBe("Flora_catalog_with_spaces_7b479b7c")
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function resolveIndexName(
catalogName: string,
catalogId: string,
): string {
const escapedName = escapeCatalogName(catalogName)
const resolvedId = catalogId.split("-")[0]

return `${escapedName}_${resolvedId}`
}

function escapeCatalogName(catalogName: string): string {
// Replace leading and trailing spaces and then replace spaces with underscores
return catalogName.trim().replace(/\s/g, "_")
}
Loading