diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b8b5843 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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}} diff --git a/README.md b/README.md index 2f7cdd5..a35367e 100644 --- a/README.md +++ b/README.md @@ -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).
diff --git a/package.json b/package.json index 7631df1..6580451 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,21 @@ { "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", @@ -15,8 +23,13 @@ "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 (https://itsaydrian.com)", "license": "MIT", "devDependencies": { "@types/node": "^20.4.5", @@ -41,4 +54,4 @@ "dependencies": { "i18next": "^23.2.11" } -} +} \ No newline at end of file