diff --git a/.earthignore b/.earthignore index b2f4b25..8bf40a5 100644 --- a/.earthignore +++ b/.earthignore @@ -1,4 +1,5 @@ # Generate when development node_modules/ dist/ -junit/ \ No newline at end of file +junit/ +docs/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1a28092..5e3f4bd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -58,7 +58,7 @@ jobs: git config user.email github-actions@github.com # npm publish and push updated package.json - - name: Publish + - name: Publish to npm and jsr run: | npm run release -- --VERSION=$VERSION git push origin master diff --git a/.github/workflows/release_test.yml b/.github/workflows/release_test.yml index 4b46b88..7df6a25 100644 --- a/.github/workflows/release_test.yml +++ b/.github/workflows/release_test.yml @@ -28,15 +28,10 @@ jobs: git config user.email github-actions@github.com # npm publish and push updated package.json - - name: PrePublish + - name: prepublish to npm and jsr run: | npm run release:prepublish + git push env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} - - - name: Commit and push changes - run: | - git add package*.json - git commit -m "debug: npm run release:prepublish" - git push diff --git a/.gitignore b/.gitignore index 7751bc1..8fb21d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ dist/ -junit/ \ No newline at end of file +junit/ +docs/ diff --git a/Earthfile b/Earthfile index a43b796..eb72f3f 100644 --- a/Earthfile +++ b/Earthfile @@ -27,8 +27,13 @@ prepublish: RUN rm -rf dist COPY +build/dist dist + # Bump package.json and jsr.json then commit the changes that mimic `npm version` RUN npm version prerelease --no-git-tag-version && \ - npm publish --provenance --tag=beta + npm run jsr:version && \ + git add jsr.json package*.json && \ + jq -r '.version' package.json | xargs -I {} git commit -m "{}" + RUN npm publish --provenance --tag=beta + RUN npm install && npx -y jsr publish publish: BUILD +integate-test @@ -38,4 +43,8 @@ publish: COPY +build/dist dist RUN npm version $VERSION && \ - npm publish --provenance + npm run jsr:version && \ + git add jsr.json package*.json && \ + jq -r '.version' package.json | xargs -I {} git commit -m "{}" + RUN npm publish --provenance + RUN npm install && npx -y jsr publish diff --git a/README.md b/README.md index 8fd720e..aea1236 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # ts-junit2json [![junit2json](https://badgen.net/npm/v/junit2json)](https://www.npmjs.com/package/junit2json) +[![JSR](https://jsr.io/badges/@kesin11/junit2json)](https://jsr.io/@kesin11/junit2json) ![CI](https://github.com/Kesin11/ts-junit2json/workflows/Node%20CI/badge.svg) ts-juni2json provides a converter that convert JUnit XML format to JSON. Also provides TypeScript types definition. diff --git a/jsr.json b/jsr.json new file mode 100644 index 0000000..ce90890 --- /dev/null +++ b/jsr.json @@ -0,0 +1,12 @@ +{ + "name": "@kesin11/junit2json", + "version": "0.1.1", + "exports": "./src/index.ts", + "publish": { + "include": [ + "LICENSE", + "README.md", + "src/**/*.ts" + ] + } +} diff --git a/package.json b/package.json index d849645..44dcbaa 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,12 @@ "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && tsconfig-to-dual-package", "test": "jest", "test:watch": "jest --watch", + "doc": "deno doc --unstable-byonm --unstable-sloppy-imports --html --name=junit2json src", + "doc:lint": "deno doc --unstable-byonm --unstable-sloppy-imports --lint src", "integrate_test": "node --test integrate_tests/", "release:prepublish": "earthly +prepublish", - "release": "earthly +publish" + "release": "earthly +publish", + "jsr:version": "jq -r '.version' package.json | xargs -I {} jq '.version = \"{}\"' jsr.json > temp.json && mv temp.json jsr.json" }, "repository": { "type": "git", diff --git a/src/cli.ts b/src/cli.ts index 4341e11..306029b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,5 +1,5 @@ #!/usr/bin/env node -import fs from 'fs' +import fs from 'node:fs' import yargs from 'yargs' import { hideBin } from 'yargs/helpers' import { parse } from './index.js' @@ -38,4 +38,4 @@ const main = async () => { const output = await parse(xmlString) console.log(JSON.stringify(output, replacer, indent)) } -main() \ No newline at end of file +main() diff --git a/src/index.ts b/src/index.ts index d9c7165..5bcef38 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { parseStringPromise, processors } from 'xml2js' import type { convertableToString, OptionsV2 } from 'xml2js' +/** It represents a `` tag. */ export type TestSuites = { testsuite?: TestSuite[] name?: string @@ -11,6 +12,7 @@ export type TestSuites = { disabled?: number } +/** It represents a `` tag. */ export type TestCase = { name?: string classname?: string @@ -24,6 +26,7 @@ export type TestCase = { "system-err"?: string[] } +/** It represents a `` tag. */ export type TestSuite = { testcase?: TestCase[] name?: string @@ -42,10 +45,39 @@ export type TestSuite = { "system-err"?: string[] } +/** It represents a `` tag. */ export type Property = { name?: string, value?: string } +/** It represents a `` tag. */ export type Skipped = { message?: string } +/** It represents a ` and ` tag. */ export type Details = { message?: string, type?: string, inner?: string } +/** + * Parses the given JUnit XML string into a JavaScript object representation using xml2js library. + * + * @example Basic usage + * ```ts + * import { parse } from 'junit2json' + * + * const junitXmlString = "..." + * const output = await parse(xmlString) + * ``` + * + * If you want to filter some tags like `` or ``, you can use `replacer` function argument in [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). + * + * @example Filter some tags + * ```ts + * import { parse } from 'junit2json' + * + * const junitXmlString = "..." + * const output = await parse(xmlString) + * const replacer = (key: any, value: any) => { + * if (key === 'system-out' || key === 'system-err') return undefined + * return value + * } + * console.log(JSON.stringify(output, replacer, 2)) + * ``` + */ export const parse = async (xmlString: convertableToString, xml2jsOptions?: OptionsV2): Promise => { const options = xml2jsOptions ?? { attrValueProcessors: [processors.parseNumbers]