Skip to content

Commit

Permalink
Remove not working umd bundle and replace with iife and cjs (#471)
Browse files Browse the repository at this point in the history
* Remove not working umd bundle and replace with iife and cjs

Remove unecessary configs

Examples

comment removed

Add version

remove version

Information on imports

* Better readme

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update README.md

Co-authored-by: Clémentine Urquizar <[email protected]>

* Update examples/typescript-browser/public/index.html

Co-authored-by: Clémentine Urquizar <[email protected]>

Co-authored-by: Clémentine Urquizar <[email protected]>
  • Loading branch information
bidoubiwa and curquiza authored Jun 24, 2020
1 parent f0ac9db commit 02aab14
Show file tree
Hide file tree
Showing 29 changed files with 5,642 additions and 85 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
},
plugins: ['jsdoc', '@typescript-eslint'],
rules: {
'@typescript-eslint/return-await': 'off',
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',
'@typescript-eslint/space-before-function-paren': 0,
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## V0.11.1 (released)
## V0.11.1
- Feat: Make IndexInterface generic. createIndex and getIndex generic support #442
- Split bundles into umd and cjs.
- use bundle in package.json `browser` for `umd`
- use bundle in package.json `main` for `cjs`

## V0.11.0 (released)

- BREAKING: Usage of createIndex changed `createIndex(uid: string, options: IndexOptions): Index` #436
- BREAKING: Changes in types
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,45 @@ $ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --m

NB: you can also download MeiliSearch from **Homebrew** or **APT**.

## Import

### Front end or ESmodule

```javascript
import MeiliSearch from 'meilisearch'

const client = new MeiliSearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
})
```

### HTML import

```javascript
<script src="https://cdn.jsdelivr.net/npm/meilisearch@latest/dist/bundles/meilisearch.browser.js"></script>
<script>
const client = new MeiliSearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
})
client.listIndexes().then(res => {
console.log({ res });
})
</script>
```

### Back-End CommonJs

```javascript
const MeiliSearch = require('meilisearch');

const client = new MeiliSearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
})
```

## 🎬 Getting started

Here is a quickstart for a search request
Expand Down
22 changes: 22 additions & 0 deletions examples/browser/webpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
hello
</body>
</html>
<script src="../../dist/bundles/meilisearch.umd.js"></script>
<script>
const client = new window.Meiliearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
})
client.listIndexes().then(res => {
console.log({ res });
})
</script>
30 changes: 30 additions & 0 deletions examples/node/search_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const MeiliSearch = require('../../')
const dataset = require('./small_movies.json')

const config = {
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
}

const client = new MeiliSearch(config)
const uid = 'movies'

const addDataset = async () => {
const index = await client.getOrCreateIndex(uid)
const documents = await index.getDocuments()
if (documents.length === 0) {
const { updateId } = await index.addDocuments(dataset)
await index.waitForPendingUpdate(updateId)
}
}

;(async () => {
await addDataset()
const index = await client.getIndex('movies')
const resp = await index.search('Avengers', {
limit: 1,
attributesToHighlight: 'title',
})
console.log({ resp })
console.log({ hit: resp.hits[0] })
})()
16 changes: 7 additions & 9 deletions examples/small_index.js → examples/node/small_index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
var MeiliSearch = require('../')
const MeiliSearch = require('../../')

const config = {
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
}

var meili = new MeiliSearch(config)
const client = new MeiliSearch(config)

const newIndex = {
uid: 'movies_test',
}
const uid = 'movies_test'

const dataset = [
{ id: 123, title: 'Pride and Prejudice', comment: 'A great book' },
Expand All @@ -31,8 +29,8 @@ const dataset = [

;(async () => {
// This example creates an index with 7 documents
await meili.createIndex(index)
const { updateId } = await meili.getIndex(index.uid).addDocuments(dataset)
const res = await meili.getIndex(index.uid).waitForPendingUpdate(updateId)
console.log({ res });
const index = await client.getOrCreateIndex(uid)
const { updateId } = await index.addDocuments(dataset)
const res = await index.waitForPendingUpdate(updateId)
console.log({ res })
})()
File renamed without changes.
43 changes: 0 additions & 43 deletions examples/search_example.js

This file was deleted.

1 change: 1 addition & 0 deletions examples/typescript-browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public/bundle.js
20 changes: 20 additions & 0 deletions examples/typescript-browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "typescript-demo",
"version": "0.1.0",
"description": "MeiliSearch Typescript Demo",
"main": "index.js",
"scripts": {
"build": "webpack"
},
"keywords": [
"demo",
"meilisearch"
],
"author": "Charlotte Vermandel",
"license": "ISC",
"devDependencies": {
"webpack": "^4.43.0",
"ts-loader": "^7.0.5",
"webpack-cli": "^3.3.12"
}
}
13 changes: 13 additions & 0 deletions examples/typescript-browser/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
hello
</body>
</html>
<script src="./bundle.js"></script>
22 changes: 22 additions & 0 deletions examples/typescript-browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import MeiliSearch, { IndexResponse } from '../../../'

const config = {
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
}

const client = new MeiliSearch(config)
const user = 'MeiliSearch User'

function greeter(person: string) {
return 'Hello, ' + person
}

;(async () => {
const indexes = await client.listIndexes()
console.log({ indexes }, 'hello')
const uids = indexes.map((index: IndexResponse) => index.uid)
document.body.innerHTML = `${greeter(
user
)} this is the list of all your indexes: ${uids.join(', ')}`
})()
4 changes: 4 additions & 0 deletions examples/typescript-browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compilerOptions": {
}
}
26 changes: 26 additions & 0 deletions examples/typescript-browser/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const webpack = require('webpack')
const path = require('path')

let config = {
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, './public'),
filename: './bundle.js',
},
mode: 'production',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
mainFields: ['module', 'browser'], // the `module` field has priority on the browser field
},
}

module.exports = config
Loading

0 comments on commit 02aab14

Please sign in to comment.