Skip to content

Commit

Permalink
add camlizedName
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Apr 26, 2022
1 parent d8e0de3 commit b52c935
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ jobs:
with:
path: |
${{ format('{0}/algoliasearch-core/src/com/algolia/api/{1}.java', matrix.client.path, matrix.client.api) }}
${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.name) }}
${{ format('{0}/algoliasearch-core/src/com/algolia/model/{1}/**', matrix.client.path, matrix.client.camelizedName) }}
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand Down
27 changes: 13 additions & 14 deletions scripts/ci/createMatrix.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CLIENTS, GENERATORS } from '../common';
import { createClientName } from '../cts/utils';
import { camelize, createClientName } from '../cts/utils';
import type { Language } from '../types';

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

type ClientMatrix = BaseMatrix & {
config?: string;
api?: string;
capitalizedName?: string;
config: string;
api: string;
capitalizedName: string;
camelizedName: string;
};

type SpecMatrix = BaseMatrix;
Expand Down Expand Up @@ -56,18 +57,16 @@ async function getClientMatrix({
continue;
}

const matchedGenerator: ClientMatrix = {
name: client,
path: output,
};

const clientName = createClientName(client, language);

matchedGenerator.config = `${clientName}Config`;
matchedGenerator.api = `${clientName}Client`;
matchedGenerator.capitalizedName = clientName;

matrix.client.push(matchedGenerator);
matrix.client.push({
name: client,
path: output,
config: `${clientName}Config`,
api: `${clientName}Client`,
capitalizedName: clientName,
camelizedName: camelize(client),
});
}

return matrix;
Expand Down
34 changes: 29 additions & 5 deletions scripts/cts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,47 @@ export async function* walk(
}
}

/**
* Sets the first letter of the given string in capital.
*
* `searchClient` -> `SearchClient`.
*/
export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}

export function createClientName(client: string, language: string): string {
const clientName = client
.split('-')
/**
* Splits a string for a given `delimiter` (defaults to `-`) and capitalize each
* parts except the first letter.
*
* `search-client` -> `searchClient`.
*/
export function camelize(str: string, delimiter: string = '-'): string {
return str
.split(delimiter)
.map((part, i) => {
if (language === 'javascript' && i === 0) {
if (i === 0) {
return part;
}

return capitalize(part);
})
.join('');
}

/**
* Returns the client name with the correct casing for its language.
*
* `search-client`, `java` -> `SearchClient`.
*
* `search-client`, `javascript` -> `searchClient`.
*/
export function createClientName(client: string, language: string): string {
if (language === 'javascript') {
return camelize(client);
}

return clientName;
return capitalize(camelize(client));
}

export async function createOutputDir({
Expand Down

0 comments on commit b52c935

Please sign in to comment.