Skip to content

Commit b52c935

Browse files
committed
add camlizedName
1 parent d8e0de3 commit b52c935

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ jobs:
222222
with:
223223
path: |
224224
${{ format('{0}/algoliasearch-core/src/com/algolia/api/{1}.java', matrix.client.path, matrix.client.api) }}
225-
${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.name) }}
225+
${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.camelizedName) }}
226226
key: |
227227
${{ env.CACHE_VERSION }}-${{
228228
hashFiles(

scripts/ci/createMatrix.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CLIENTS, GENERATORS } from '../common';
2-
import { createClientName } from '../cts/utils';
2+
import { camelize, createClientName } from '../cts/utils';
33
import type { Language } from '../types';
44

55
import { getNbGitDiff } from './utils';
@@ -16,9 +16,10 @@ type BaseMatrix = {
1616
};
1717

1818
type ClientMatrix = BaseMatrix & {
19-
config?: string;
20-
api?: string;
21-
capitalizedName?: string;
19+
config: string;
20+
api: string;
21+
capitalizedName: string;
22+
camelizedName: string;
2223
};
2324

2425
type SpecMatrix = BaseMatrix;
@@ -56,18 +57,16 @@ async function getClientMatrix({
5657
continue;
5758
}
5859

59-
const matchedGenerator: ClientMatrix = {
60-
name: client,
61-
path: output,
62-
};
63-
6460
const clientName = createClientName(client, language);
6561

66-
matchedGenerator.config = `${clientName}Config`;
67-
matchedGenerator.api = `${clientName}Client`;
68-
matchedGenerator.capitalizedName = clientName;
69-
70-
matrix.client.push(matchedGenerator);
62+
matrix.client.push({
63+
name: client,
64+
path: output,
65+
config: `${clientName}Config`,
66+
api: `${clientName}Client`,
67+
capitalizedName: clientName,
68+
camelizedName: camelize(client),
69+
});
7170
}
7271

7372
return matrix;

scripts/cts/utils.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,47 @@ export async function* walk(
1414
}
1515
}
1616

17+
/**
18+
* Sets the first letter of the given string in capital.
19+
*
20+
* `searchClient` -> `SearchClient`.
21+
*/
1722
export function capitalize(str: string): string {
1823
return str.charAt(0).toUpperCase() + str.slice(1);
1924
}
2025

21-
export function createClientName(client: string, language: string): string {
22-
const clientName = client
23-
.split('-')
26+
/**
27+
* Splits a string for a given `delimiter` (defaults to `-`) and capitalize each
28+
* parts except the first letter.
29+
*
30+
* `search-client` -> `searchClient`.
31+
*/
32+
export function camelize(str: string, delimiter: string = '-'): string {
33+
return str
34+
.split(delimiter)
2435
.map((part, i) => {
25-
if (language === 'javascript' && i === 0) {
36+
if (i === 0) {
2637
return part;
2738
}
2839

2940
return capitalize(part);
3041
})
3142
.join('');
43+
}
44+
45+
/**
46+
* Returns the client name with the correct casing for its language.
47+
*
48+
* `search-client`, `java` -> `SearchClient`.
49+
*
50+
* `search-client`, `javascript` -> `searchClient`.
51+
*/
52+
export function createClientName(client: string, language: string): string {
53+
if (language === 'javascript') {
54+
return camelize(client);
55+
}
3256

33-
return clientName;
57+
return capitalize(camelize(client));
3458
}
3559

3660
export async function createOutputDir({

0 commit comments

Comments
 (0)