Skip to content

Commit

Permalink
fix i18n types
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Dec 28, 2023
1 parent d36f7de commit df1304d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ jobs:

- name: Unit test
run: pnpm test

# https://github.com/arethetypeswrong/arethetypeswrong.github.io
- name: 'arethetypeswrong test'
run: pnpm -F artalk attw
38 changes: 18 additions & 20 deletions ui/artalk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
"require": {
"types": "./dist/main.d.cts",
"default": "./dist/Artalk.cjs"
},
"default": {
"types": "./dist/main.d.ts",
"default": "./dist/ArtalkLite.js"
}
},
"./dist/ArtalkLite": {
Expand All @@ -41,21 +37,27 @@
"require": {
"types": "./dist/main.d.cts",
"default": "./dist/ArtalkLite.cjs"
},
"default": {
"types": "./dist/main.d.ts",
"default": "./dist/ArtalkLite.js"
}
},
"./dist/i18n/jp": {
"import": "./dist/i18n/jp.mjs",
"require": "./dist/i18n/jp.cjs",
"default": "./dist/i18n/jp.js"
"import": {
"types": "./dist/i18n/jp.d.ts",
"default": "./dist/i18n/jp.mts"
},
"require": {
"types": "./dist/i18n/jp.d.cts",
"default": "./dist/i18n/jp.cjs"
}
},
"./dist/i18n/zh-TW": {
"import": "./dist/i18n/zh-TW.mjs",
"require": "./dist/i18n/zh-TW.cjs",
"default": "./dist/i18n/zh-TW.js"
"import": {
"types": "./dist/i18n/zh-TW.d.ts",
"default": "./dist/i18n/zh-TW.mts"
},
"require": {
"types": "./dist/i18n/zh-TW.d.cts",
"default": "./dist/i18n/zh-TW.cjs"
}
},
"./dist/i18n/*": "./dist/i18n/*",
"./dist/*.css": {
Expand All @@ -66,18 +68,13 @@
},
"typesVersions": {
"*": {
"dist/main.d.ts": [
"./dist/main.d.ts"
],
"dist/ArtalkLite": [
"./dist/main.d.ts"
]
}
},
"main": "./dist/Artalk.js",
"jsdelivr": "./dist/Artalk.iife.js",
"unpkg": "./dist/Artalk.iife.js",
"module": "./dist/Artalk.es.js",
"module": "./dist/Artalk.mjs",
"types": "./dist/main.d.ts",
"files": [
"dist"
Expand All @@ -93,6 +90,7 @@
"test": "vitest",
"coverage": "vitest run --coverage",
"lint": "eslint './src/**/*.{js,ts}'",
"attw": "pnpx @arethetypeswrong/cli --pack .",
"serve": "vite preview",
"test:e2e": "playwright test",
"test:report": "playwright show-report"
Expand Down
10 changes: 6 additions & 4 deletions ui/artalk/scripts/build-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ fs.readdirSync(i18nPath).forEach(f => {
libraries.push({
entry: filename,
name: lang,
fileName: (format) => {
console.log(lang)
return getFileName(lang, format)
},
fileName: (format) => getFileName(lang, format),
})
})

Expand All @@ -47,4 +44,9 @@ libraries.forEach(async (lib) => {
},
configFile: false, // prevent load any vite config file
})

// crete d.ts file
const dts = `import type { I18n } from '../main.d.cts'\nexport = I18n`
fs.writeFileSync(path.join(outDir, `${lib.name!}.d.ts`), dts)
fs.writeFileSync(path.join(outDir, `${lib.name!}.d.cts`), dts)
})
7 changes: 6 additions & 1 deletion ui/artalk/src/i18n/en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
const en = {
/* Editor */
placeholder: 'Leave a comment',
noComment: 'No Comment',
Expand Down Expand Up @@ -83,3 +83,8 @@ export default {
ignore: 'Ignore',
open: 'Open'
}

export type I18n = typeof en
export type I18nKeys = keyof I18n

export default en
5 changes: 2 additions & 3 deletions ui/artalk/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import en from './en'
import en, { I18n, I18nKeys } from './en'
import zhCN from './zh-CN'
import { GLOBAL_LOCALES_KEY } from './external'

export type I18n = typeof en
export type I18nKeys = keyof I18n
export type * from './en'

// @note the key of language is followed by `ISO 639`
// https://en.wikipedia.org/wiki/ISO_639
Expand Down
4 changes: 3 additions & 1 deletion ui/artalk/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Artalk from './artalk'
import * as ArtalkType from './types'
import type * as ArtalkType from './types'

export type * from './types'
export { ArtalkType }

export default Artalk

// Expose the static methods from the Artalk class
Expand Down
15 changes: 8 additions & 7 deletions ui/artalk/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export * from './config'
export * from './data'
export * from './context'
export * from './editor'
export * from './event'
export * from './plugin'
export * from './sidebar'
export type * from './config'
export type * from './data'
export type * from './context'
export type * from './editor'
export type * from './event'
export type * from './plugin'
export type * from './sidebar'
export type { I18n, I18nKeys } from '../i18n'

0 comments on commit df1304d

Please sign in to comment.