Skip to content

Commit

Permalink
Add typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 11, 2024
1 parent f87ff9a commit 38c68cf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.d.ts
*.d.ts.map
*.log
.DS_Store
dest/
Expand Down
7 changes: 6 additions & 1 deletion crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs/promises'
import {iso6393} from 'iso-639-3'
import {fetch} from 'undici'

/** @type {Record<string, string>} */
const iso6393ToName = {}

let index = -1
Expand All @@ -20,5 +21,9 @@ await fs.writeFile(new URL('src/fixtures.js', import.meta.url), body)

await fs.writeFile(
new URL('src/to-name.js', import.meta.url),
'export const toName = ' + JSON.stringify(iso6393ToName, undefined, 2) + '\n'
[
'/** @type {Record<string, string>} */',
'export const toName = ' + JSON.stringify(iso6393ToName, undefined, 2),
''
].join('\n')
)
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"stylelint": "^14.0.0",
"stylelint-config-prettier": "^9.0.0",
"stylelint-config-standard": "^28.0.0",
"type-coverage": "^2.27.1",
"typescript": "^5.3.3",
"undici": "^6.0.0",
"xo": "^0.56.0"
},
Expand Down Expand Up @@ -48,13 +50,14 @@
},
"repository": "wooorm/franc",
"scripts": {
"build": "tsc --build --clean && tsc --build && type-coverage",
"crawl": "node --conditions development crawl.js",
"format": "remark --frail --output --quiet -- . && prettier . --log-level warn --write && xo --fix && stylelint src/index.css --fix",
"generate:script": "esbuild src/index.js --bundle --minify --outfile=dest/index.nomodule.js --target=es6 && esbuild src/index.js --bundle --format=esm --minify --outfile=dest/index.module.js --target=es2020",
"generate:structure": "rehype -u rehype-preset-minify -u rehype-prevent-favicon-request src -o dest",
"generate:style": "postcss src/index.css > dest/index.css",
"generate": "npm run generate:script && npm run generate:style && npm run generate:structure",
"test": "npm run crawl && npm run format && npm run generate"
"test": "npm run crawl && npm run build && npm run format && npm run generate"
},
"stylelint": {
"extends": [
Expand All @@ -63,6 +66,12 @@
]
},
"type": "module",
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"ignore": [
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env browser */

import debounce from 'debounce'
import {francAll} from 'franc'
import {toName} from './to-name.js'
Expand Down Expand Up @@ -38,7 +39,7 @@ function oninputchange() {
const c2 = document.createElement('td')
c0.append(link)
c1.textContent = toName[code]
c2.textContent = score
c2.textContent = String(score)

$node.append(c0)
$node.append(c1)
Expand Down
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"checkJs": true,
"customConditions": ["development"],
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"exactOptionalPropertyTypes": true,
"jsx": "preserve",
"lib": ["dom", "es2022"],
"module": "node16",
"strict": true,
"target": "es2022"
},
"exclude": ["coverage/", "dest/", "node_modules/"],
"include": ["**/*.js"]
}

0 comments on commit 38c68cf

Please sign in to comment.