Skip to content

Commit

Permalink
updated README and created publish github action
Browse files Browse the repository at this point in the history
  • Loading branch information
aydrian committed Jul 26, 2023
1 parent 1570a35 commit 7cf9fec
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 5 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: 📦 Publish

on:
release:
types: [published]
push:
branches: main
pull_request: {}

jobs:
lint:
name: ⬣ ESLint
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1

- name: 🔬 Lint
run: npm run lint

typecheck:
name: ʦ TypeScript
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1

- name: 🔎 Type check
run: npm run typecheck --if-present

publish:
name: 📦 Publish
runs-on: ubuntu-latest
needs: [lint, typecheck]
if: ${{github.event_name == 'release'}}
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://registry.npmjs.org/

- name: ⚙️ Install dependencies
run: npm ci

- name: 👷 Build
run: npm run build

- name: 📦 Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,84 @@
# i18next Prisma backend plugin

A backend plugin for [i18next](https://www.i18next.com/) that supports using [Prisma](https://www.prisma.io/) to load resources from the data source specified in the `schema.prisma` configuration file.

## Getting Started

### Install packages

This package expects the Prisma Client as a peer dependency.

npm

```shell
npm install @prisma/client i18next-prisma-backend
```

yarn

```shell
yarn add @prisma/client i18next-prisma-backend
```

### Update your Schema

Update your `schema.prisma` files to include the following model with a minimum of the following fields:

```
model i18n {
namespace String
language String
key String
translation String
@@id([key, language])
@@index([language, translation])
}
```

You may use `@@map` and `@map` to specify the underlying database table and field names respectively. The plugin will expect this model to exist.

Apply the schema changes to your database.

## Usage

This library supports ESM and CommonJS.

ESM

```javascript
import i18next from "i18next";
import Backend from "i18next-prisma-backend";

i18next.use(Backend).init({
// Backend Options
backend: options
});
```

CommonJS

```javascript
const i18next = require("i18next");
const Backend = require("i18next-prisma-backend");

i18next.use(Backend).init({
// Backend Options
backend: options
});
```

## Backend Options

```javascript
{
// Optional: If you have an existing client instance,
// you can specifiy it here. Otherwise a new instance
// will be instanciated.
client: prisma; // PrismaClient() instance
}
```

## 📝 License

Copyright © 2023 [Aydrian Howard](https://itsaydrian.com). <br />
Expand Down
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
{
"name": "i18next-prisma-backend",
"version": "0.0.1",
"description": "",
"description": "Use i18next with Prisma ORM as backend",
"homepage": "https://github.com/aydrian/i18next-prisma-backend",
"repository": {
"type": "git",
"url": "https://github.com/aydrian/i18next-prisma-backend"
},
"bugs": {
"url": "https://github.com/aydrian/i18next-prisma-backend/issues"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"ts-types": "tsc",
"typecheck": "tsc",
"dev": "rimraf dist && tsup --watch",
"build": "rimraf dist && env NODE_ENV=production tsup",
"lint:fix": "eslint ./src --ext .ts,.tsx --quiet --fix --ignore-path ./.gitignore",
"lint:format": "prettier --loglevel warn --write \"./**/*.{ts,tsx,css,md,json}\" ",
"lint": "npm run lint:format && npm run lint:fix",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Aydrian Howard",
"keywords": [
"i18next",
"prisma",
"i18next-backend",
"i18next-prisma-backend"
],
"author": "Aydrian Howard <[email protected]> (https://itsaydrian.com)",
"license": "MIT",
"devDependencies": {
"@types/node": "^20.4.5",
Expand All @@ -41,4 +54,4 @@
"dependencies": {
"i18next": "^23.2.11"
}
}
}

0 comments on commit 7cf9fec

Please sign in to comment.