Skip to content

Commit

Permalink
refactor: generate .d.ts from jsdoc (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykzts authored Feb 25, 2023
1 parent ecd783e commit 5818dbb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 45 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
node-version: 18.x
registry-url: https://registry.npmjs.org
- run: pnpm install
- run: pnpm build
- run: pnpm publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"url": "https://github.com/ykzts/edge-sitemap.git"
},
"scripts": {
"build": "tsc",
"format": "prettier -w .",
"lint": "eslint src",
"test": "NODE_OPTIONS=--experimental-vm-modules jest src"
Expand Down
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.d.ts
39 changes: 0 additions & 39 deletions src/index.d.ts

This file was deleted.

20 changes: 15 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

/**
* @typedef {Object} SitemapItem
* @property {SitemapChangeFreq} changefreq
* @property {`${number}-${number}-${number}`} lastmod
* @property {SitemapChangeFreq=} changefreq
* @property {`${number}-${number}-${number}`=} lastmod
* @property {(URL|string)} loc
* @property {number=} priority
*/
Expand All @@ -28,9 +28,14 @@ export class SitemapTransformer {
#indent

/**
* @param {SitemapStreamOptions=} options
* @param {SitemapTransformerOptions=} options
*/
constructor({ baseURL, pretty = false } = {}) {
constructor(
/** @todo https://github.com/microsoft/TypeScript/pull/52880 */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{ baseURL, pretty = false } = {}
) {
this.#baseURL = baseURL
this.#lf = pretty ? '\n' : ''
this.#indent = pretty ? ' ' : ''
Expand Down Expand Up @@ -108,7 +113,12 @@ export class SitemapStream extends TransformStream {
/**
* @param {SitemapStreamOptions=} options
*/
constructor({ baseURL, pretty = false } = {}) {
constructor(
/** @todo https://github.com/microsoft/TypeScript/pull/52880 */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{ baseURL, pretty = false } = {}
) {
super(new SitemapTransformer({ baseURL, pretty }))
}
}
2 changes: 1 addition & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@jest/globals'
import { SitemapStream } from '.'
import { SitemapStream } from './index.js'

/**
* @param {import('.').SitemapItem[]} sitemapItems
Expand Down
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"module": "Node16",
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
},
"exclude": ["./src/**/*.d.ts", "./src/**/*.test.js"],
"include": ["./src/**/*"]
}

0 comments on commit 5818dbb

Please sign in to comment.