Skip to content

Commit 176cd07

Browse files
committed
chore: generate readme for js clients
1 parent f52621a commit 176cd07

File tree

3 files changed

+82
-38
lines changed

3 files changed

+82
-38
lines changed

clients/algoliasearch-client-javascript/README.md

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ yarn add algoliasearch
4242
npm install algoliasearch
4343
```
4444

45-
Or use a specific package:
46-
47-
```bash
48-
yarn add @algolia/client-search
49-
# or
50-
npm install @algolia/client-search
51-
```
52-
5345
Without a package manager
5446

5547
Add the following JavaScript snippet to the <head> of your website:
@@ -61,35 +53,9 @@ Add the following JavaScript snippet to the <head> of your website:
6153
You can now import the Algolia API client in your project and play with it.
6254

6355
```js
64-
import { searchClient } from '@algolia/client-search';
65-
66-
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
67-
68-
// Add a new record to your Algolia index
69-
const response = await client.saveObject({
70-
indexName: '<YOUR_INDEX_NAME>',
71-
body: { objectID: 'id', test: 'val' },
72-
});
73-
74-
// use typed response
75-
console.log(response);
76-
77-
// Poll the task status to know when it has been indexed
78-
await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID: response.taskID });
79-
80-
// Fetch search results, with typo tolerance
81-
const response = await client.search({
82-
requests: [
83-
{
84-
indexName: '<YOUR_INDEX_NAME>',
85-
query: '<YOUR_QUERY>',
86-
hitsPerPage: 50,
87-
},
88-
],
89-
});
90-
91-
// use typed response
92-
console.log(response);
56+
import { liteClient } from 'algoliasearch';
57+
58+
const client = liteClient('YOUR_APP_ID', 'YOUR_API_KEY');
9359
```
9460

9561
For full documentation, visit the **[Algolia JavaScript API Client](https://www.algolia.com/doc/api-client/getting-started/install/javascript/)**.
@@ -100,4 +66,4 @@ Encountering an issue? Before reaching out to support, we recommend heading to o
10066

10167
## 📄 License
10268

103-
The Algolia JavaScript API Client is an open-sourced software licensed under the [MIT license](LICENSE).
69+
The Algolia JavaScript API Client is an open-sourced software licensed under the [MIT license](LICENSE).

generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void processOpts() {
5959
supportingFiles.add(new SupportingFile("index.mustache", "", "index.js"));
6060
supportingFiles.add(new SupportingFile("index.d.mustache", "", "index.d.ts"));
6161
supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
62+
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
6263

6364
// `client` related files, `algoliasearch` have it's own logic below
6465
if (!isAlgoliasearchClient) {
@@ -72,6 +73,8 @@ public void processOpts() {
7273
}
7374
// `algoliasearch` related files
7475
else {
76+
supportingFiles.add(new SupportingFile("README.mustache", "", "../../README.md"));
77+
7578
// `algoliasearch` builds
7679
supportingFiles.add(new SupportingFile("algoliasearch/builds/browser.mustache", "builds", "browser.ts"));
7780
supportingFiles.add(new SupportingFile("algoliasearch/builds/node.mustache", "builds", "node.ts"));
@@ -147,6 +150,7 @@ private void setDefaultGeneratorOptions() {
147150
additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient);
148151
additionalProperties.put("packageVersion", Helpers.getPackageJsonVersion(packageName));
149152
additionalProperties.put("packageName", packageName);
153+
additionalProperties.put("npmPackageName", isAlgoliasearchClient ? packageName : "@algolia/" + packageName);
150154
additionalProperties.put("nodeSearchHelpers", CLIENT.equals("search") || isAlgoliasearchClient);
151155

152156
if (isAlgoliasearchClient) {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<p align="center">
2+
<a href="https://www.algolia.com">
3+
<img alt="Algolia for JavaScript" src="https://raw.githubusercontent.com/algolia/algoliasearch-client-common/master/banners/javascript.png" >
4+
</a>
5+
6+
<h4 align="center">The perfect starting point to integrate <a href="https://algolia.com" target="_blank">Algolia</a> within your JavaScript project</h4>
7+
8+
<p align="center">
9+
<a href="https://npmjs.org/package/{{npmPackageName}}"><img src="https://img.shields.io/npm/v/{{npmPackageName}}.svg?style=flat-square" alt="NPM version"></img></a>
10+
<a href="http://npm-stat.com/charts.html?package={{npmPackageName}}"><img src="https://img.shields.io/npm/dm/{{npmPackageName}}.svg?style=flat-square" alt="NPM downloads"></a>
11+
<a href="https://www.jsdelivr.com/package/npm/{{npmPackageName}}"><img src="https://data.jsdelivr.com/v1/package/npm/{{npmPackageName}}/badge" alt="jsDelivr Downloads"></img></a>
12+
<a href="LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-green.svg?style=flat-square" alt="License"></a>
13+
</p>
14+
</p>
15+
16+
<p align="center">
17+
<a href="https://www.algolia.com/doc/api-client/getting-started/install/javascript/" target="_blank">Documentation</a> •
18+
<a href="https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/" target="_blank">InstantSearch</a> •
19+
<a href="https://discourse.algolia.com" target="_blank">Community Forum</a> •
20+
<a href="http://stackoverflow.com/questions/tagged/algolia" target="_blank">Stack Overflow</a> •
21+
<a href="https://github.com/algolia/algoliasearch-client-javascript/issues" target="_blank">Report a bug</a> •
22+
<a href="https://www.algolia.com/doc/api-client/troubleshooting/faq/javascript/" target="_blank">FAQ</a> •
23+
<a href="https://alg.li/support" target="_blank">Support</a>
24+
</p>
25+
26+
## ✨ Features
27+
28+
- Thin & **minimal low-level HTTP client** to interact with Algolia's API
29+
- Works both on the **browser** and **node.js**
30+
- **UMD and ESM compatible**, you can use it with any module loader
31+
- Built with TypeScript
32+
33+
## 💡 Getting Started
34+
35+
To get started, you first need to install {{npmPackageName}} (or any other available API client package).
36+
37+
All of our clients comes with type definition, and are available for both browser and node environments.
38+
39+
```bash
40+
yarn add {{npmPackageName}}
41+
# or
42+
npm install {{npmPackageName}}
43+
```
44+
45+
Without a package manager
46+
47+
Add the following JavaScript snippet to the <head> of your website:
48+
49+
```html
50+
<script src="https://cdn.jsdelivr.net/npm/algoliasearch/dist/{{packageName}}.umd.min.js"></script>
51+
```
52+
53+
You can now import the Algolia API client in your project and play with it.
54+
55+
```js
56+
{{^isAlgoliasearchClient}}
57+
import { {{apiName}} } from '{{npmPackageName}}';
58+
{{/isAlgoliasearchClient}}
59+
{{#isAlgoliasearchClient}}
60+
import { algoliasearch } from '{{npmPackageName}}';
61+
{{/isAlgoliasearchClient}}
62+
63+
const client = {{apiName}}('YOUR_APP_ID', 'YOUR_API_KEY');
64+
```
65+
66+
For full documentation, visit the **[Algolia JavaScript API Client](https://www.algolia.com/doc/api-client/getting-started/install/javascript/)**.
67+
68+
## ❓ Troubleshooting
69+
70+
Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/javascript/) where you will find answers for the most common issues and gotchas with the client. You can also open [a GitHub issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=&projects=&template=Bug_report.md)
71+
72+
## 📄 License
73+
74+
The Algolia JavaScript API Client is an open-sourced software licensed under the [MIT license](LICENSE).

0 commit comments

Comments
 (0)