From 046ea300902bea9b97658acf904481ecde4065dd Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Thu, 23 Nov 2023 18:01:57 +0900 Subject: [PATCH] Publish to npm --- .github/workflows/build.yaml | 18 +++++++++++++ .gitignore | 1 + CHANGES.md | 3 +++ README.md | 22 ++++++++++++++-- dnt.ts | 51 ++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 dnt.ts diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 369a312..8488d95 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,6 +62,14 @@ jobs: run: '[[ "$VERSION" = "$GITHUB_REF_NAME" ]]' env: VERSION: ${{ steps.determine-version.outputs.version }} + - run: | + set -e + deno run -A dnt.ts "$VERSION" + pushd npm/ + npm pack --dry-run + popd + env: + VERSION: ${{ steps.determine-version.outputs.version }} - run: deno install -Af --unstable https://x.nest.land/eggs@0.3.10/eggs.ts - run: "eggs link '${{ secrets.NEST_API_KEY }}'" - if: github.ref_type == 'tag' @@ -95,3 +103,13 @@ jobs: with: name: eggs-debug.log path: ${{ github.workspace }}/eggs-debug.log + - run: | + set -e + cd npm/ + if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then + npm publish + else + npm publish --tag dev + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} diff --git a/.gitignore b/.gitignore index ffed832..0760d7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .cov/ docs/ +npm/ diff --git a/CHANGES.md b/CHANGES.md index a8d54b3..d3e8e7e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Version 0.5.0 To be released. Unreleased versions are available on [nest.land]. + - Now aitertools is [available on npm]. - Now every submodule is inside *src/* directory. This is a breaking change for users whom import submodules directly. For users whom import from *mod.ts* module, this is not a breaking change. @@ -15,6 +16,8 @@ To be released. Unreleased versions are available on [nest.land]. - Added `range()` function. - Added `Range` class. +[available on npm]: https://www.npmjs.com/package/aitertools + Version 0.4.0 ------------- diff --git a/README.md b/README.md index 5088c47..3ac0b22 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ aitertools ========== [![Latest version][Tag badge]][Deno module] +[![Published on npm][npm badge]][npm] [![Published on nest.land][nest.land badge]][nest.land] [![LGPL 3.0][License badge]](./LICENSE) [![Deno Doc (API references)][Deno Doc badge]][Deno Doc] @@ -12,10 +13,12 @@ aitertools This library provides a [well-tested][Codecov] collection of small utility functions dealing with [async iterables]. You can think of it as .NET LINQ or -Python aitertools for [Deno]. +Python aitertools for [Deno] & Node.js. [Tag badge]: https://img.shields.io/github/v/tag/dahlia/aitertools [Deno module]: https://deno.land/x/aitertools +[npm badge]: https://img.shields.io/npm/v/aitertools +[npm]: https://www.npmjs.com/package/aitertools [nest.land badge]: https://nest.land/badge.svg [nest.land]: https://nest.land/package/aitertools [License badge]: https://img.shields.io/github/license/dahlia/aitertools @@ -80,15 +83,30 @@ In Deno: import * as aitertools from "https://deno.land/x/aitertools/mod.ts"; ~~~ +In Node.js: + +~~~ console +$ npm add aitertools +~~~ + +~~~ typescript +import * as aitertools from "aitertools"; +~~~ Changelog --------- See *[CHANGES.md](CHANGES.md)* file. Note that unreleased versions are also -available on [nest.land]: +available on [nest.land] for Deno: ~~~ typescript import * as aitertools from "https://x.nest.land/aitertools@0.4.0-dev.15+3f191d7/mod.ts"; ~~~ + +… and on [npm] with `dev` tag for Node.js: + +~~~ console +$ npm add aitertools@dev +~~~ diff --git a/dnt.ts b/dnt.ts new file mode 100644 index 0000000..b919b7a --- /dev/null +++ b/dnt.ts @@ -0,0 +1,51 @@ +import { build, emptyDir } from "https://deno.land/x/dnt@0.39.0/mod.ts"; + +await emptyDir("./npm"); + +const version = Deno.args[0]; + +await build({ + entryPoints: ["./mod.ts"], + outDir: "./npm", + package: { + // package.json properties + name: "aitertools", + version, + description: "Well-tested utility functions dealing with async iterables", + keywords: [ + "iterable", + "iterator", + "async", + "stream", + "async-iterable", + "async-iterator", + ], + license: "LGPL-3.0-or-later", + author: { + name: "Hong Minhee", + email: "hong@minhee.org", + url: "https://hongminhee.org/", + }, + homepage: "https://github.com/dahlia/aitertools", + repository: { + type: "git", + url: "git+https://github.com/dahlia/aitertools.git", + }, + bugs: { + url: "https://github.com/dahlia/aitertools/issues", + }, + }, + shims: { + deno: true, + }, + typeCheck: "both", + test: true, + declaration: "separate", + esModule: true, + rootTestDir: "./tests", +}); + +// post build steps +Deno.copyFileSync("LICENSE", "npm/LICENSE"); +Deno.copyFileSync("README.md", "npm/README.md"); +Deno.copyFileSync("CHANGES.md", "npm/CHANGES.md");