From 832b9b2badd3073234c41882d2dc4124f14ffb5e Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 4 Jul 2026 21:52:08 +0200 Subject: [PATCH] chore: npm best practices --- .config/build.js | 2 +- .gitignore | 2 ++ LICENSE | 21 +++++++++++++++++++++ doctests.config.ts | 1 + package.json | 14 ++++++++------ src/generator.ts | 4 ++-- src/index.ts | 8 ++++++++ 7 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 LICENSE diff --git a/.config/build.js b/.config/build.js index 27f80d5..28b9f16 100644 --- a/.config/build.js +++ b/.config/build.js @@ -2,7 +2,7 @@ import * as esbuild from "esbuild"; const result = await esbuild.build({ entryPoints: ["src/index.ts", "src/config.ts"], - minify: true, + minify: false, bundle: true, outdir: "dist", define: { diff --git a/.gitignore b/.gitignore index a547bf3..5394154 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ dist dist-ssr *.local +tests/generated/ + # Editor directories and files .vscode/* !.vscode/extensions.json diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..54c72e3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 BluePlum + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/doctests.config.ts b/doctests.config.ts index 21fd530..c507f44 100644 --- a/doctests.config.ts +++ b/doctests.config.ts @@ -2,5 +2,6 @@ import { defineConfig } from "./dist/config"; export default defineConfig({ include: ["src/**.ts"], + outDir: "tests/generated", templateHeader: ["console.log('hello, world!');"], }); diff --git a/package.json b/package.json index 4551d5a..8188eab 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,27 @@ { "name": "gen-doctests", + "description": "Tool for generating tests from JSDoc @example:s for various test harnesses", + "keywords": ["tool", "docs", "test", "doctest"], "private": false, - "version": "0.2.1", + "version": "0.2.2", "type": "module", "bin": "dist/index.js", "scripts": { "test": "vitest --run --reporter=tree", "build": "tsc -b && node .config/build.js", - "prepublishOnly": "pnpm build", + "prepack": "pnpm build", "fmt": "prettier --write .", "lint": "eslint .", "preview": "vite preview" }, "exports": { ".": { - "default": "./dist/index.js", - "types": "./dist/index.d.ts" + "types": "./dist/index.d.ts", + "default": "./dist/index.js" }, "./config": { - "default": "./dist/config.js", - "types": "./dist/config.d.ts" + "types": "./dist/config.d.ts", + "default": "./dist/config.js" } }, "devDependencies": { diff --git a/src/generator.ts b/src/generator.ts index 4abc0dd..7a31672 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -188,9 +188,9 @@ export function createGenerator(options: Options) { node = regions[region]; } - const out = fn(src, name) + "\n\n"; + const out = fn(src, name); if (node !== null) node[Symbol()] = out; - else source += out; + else source += out + "\n\n"; } function emitRegions(region: Region): string { diff --git a/src/index.ts b/src/index.ts index e92db51..8ce86ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -104,9 +104,17 @@ async function main() { function parseWithOptions(options: Options) { const doctest = picomatch("**/*" + options.fileExtension + ".*"); + /** + * @example + * Test 1 + */ const files = globSync(options.include) .filter((v) => !doctest(v)) .filter((path) => !lstatSync(path).isDirectory()); + /** + * @example + * Test 2 + */ const parsed = files .map((path) => parseFile(path, options)) .filter((v) => v !== null);