Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: typescript/ESM conversion #95

Merged
merged 9 commits into from Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc
@@ -0,0 +1,21 @@
{
"overrides": [
{
"files": "*.ts",
"parser": "@typescript-eslint/parser",
"rules": {
"no-unused-vars": "off",
"no-useless-constructor": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error"
}
}
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
]
}
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Expand Up @@ -39,3 +39,25 @@ jobs:
- run: npm install
- run: npm test
- run: npm run coverage
esm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14.x'
- run: npm install
- run: npm run test:esm
deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run compile
- uses: denolib/setup-deno@v2
- run: |
deno --version
deno test --allow-read test/deno/y18n-test.ts
32 changes: 31 additions & 1 deletion .github/workflows/release-please.yml
Expand Up @@ -7,8 +7,38 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v1.6.3
- uses: bcoe/release-please-action@v2.0.0
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: y18n
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run compile
- name: push Deno release
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git remote add gh-token "https://${{ secrets.GITHUB_TOKEN}}@github.com/yargs/y18n.git"
git checkout -b deno
git add -f build
git commit -a -m 'chore: ${{ steps.release.outputs.tag_name }} release'
git push origin +deno
git tag -a ${{ steps.release.outputs.tag_name }}-deno -m 'chore: ${{ steps.release.outputs.tag_name }} release'
git push origin ${{ steps.release.outputs.tag_name }}-deno
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: 'https://external-dot-oss-automation.appspot.com/'
if: ${{ steps.release.outputs.release_created }}
- run: npm install
if: ${{ steps.release.outputs.release_created }}
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,5 +1,7 @@
.DS_Store
node_modules
.nyc_output
build
coverage
package-lock.json
example.*
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -47,6 +47,23 @@ output:

`2 fishes foo`

## Deno Example

As of `v5` `y18n` supports [Deno](https://github.com/denoland/deno):

```typescript
import y18n from "https://deno.land/x/y18n/deno.ts";

const __ = y18n({
locale: 'pirate',
directory: './test/locales'
}).__

console.info(__`Hi, ${'Ben'} ${'Coe'}!`)
```

You will need to run with `--allow-read` to load alternative locales.

## JSON Language Files

The JSON language files should be stored in a `./locales` folder.
Expand Down
9 changes: 9 additions & 0 deletions deno.ts
@@ -0,0 +1,9 @@
import { y18n as _y18n } from './build/lib/index.js'
import { Y18NOpts } from './build/lib/index.d.ts'
import shim from './lib/platform-shims/deno.ts'

const y18n = (opts: Y18NOpts) => {
return _y18n(opts, shim)
}

export default y18n
188 changes: 0 additions & 188 deletions index.js

This file was deleted.

8 changes: 8 additions & 0 deletions index.mjs
@@ -0,0 +1,8 @@
import shim from './build/lib/platform-shims/node.js'
import { y18n as _y18n } from './build/lib/index.js'

const y18n = (opts) => {
return _y18n(opts, shim)
}

export default y18n
8 changes: 8 additions & 0 deletions lib/cjs.ts
@@ -0,0 +1,8 @@
import { y18n as _y18n, Y18NOpts } from './index.js'
import nodePlatformShim from './platform-shims/node.js'

const y18n = (opts: Y18NOpts) => {
return _y18n(opts, nodePlatformShim)
}

export default y18n