diff --git a/.gitignore b/.gitignore index 5f7f0aa..b666104 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ node_modules elm-stuff elm-home +npm +bun +compare diff --git a/README.md b/README.md index e515094..0f713d9 100644 --- a/README.md +++ b/README.md @@ -85,14 +85,19 @@ There are three options when you have [deno](https://deno.land) installed. 3. Compile a huge binary that contains the deno runtime ``` -deno compile --allow-env=ELM_HOME,HOME --allow-read --allow-write --allow-net=github.com,codeload.github.com,api.github.com --output elm-janitor-apply-patches https://raw.githubusercontent.com/elm-janitor/apply-patches/main/deno/cli.ts +❯ deno compile --allow-env=ELM_HOME,HOME --allow-read --allow-write --allow-net=github.com,codeload.github.com,api.github.com --output elm-janitor-apply-patches https://raw.githubusercontent.com/elm-janitor/apply-patches/main/deno/cli.ts ``` ### With node.js -If there ever will be a stable version, use -https://deno.land/manual@v1.32.4/advanced/publishing/dnt to generate a node -module. +The script is also published to +[npm](https://www.npmjs.com/package/elm-janitor-apply-patches). + +You can run it in the node.js runtime for instance like this: + +``` +❯ npx elm-janitor-apply-patches +``` ### By downloading a binary @@ -158,6 +163,11 @@ cd .. Then re-run the tests or compile the example `src/Main.elm` file to see the output of the new `deadEndsToString`. +### Publishing to npm + +For information how to publish this deno code to npm as a node.js script, see +[explanation](https://github.com/elm-janitor/apply-patches/blob/main/deno/README.md#publish-as-an-npm-package) + ## Notes If you rely on local documentation, you can also generate the `docs.json` file diff --git a/deno/README.md b/deno/README.md index 4a566c4..ee295e0 100644 --- a/deno/README.md +++ b/deno/README.md @@ -3,3 +3,13 @@ Look into `./deno.json` for the available shortcuts. Run `deno task update-deps` to refresh the dependency lock file + +## Publish as an npm package + +Bump the version number in `./build_npm.ts` and then execute + +```sh +deno task build-npm-package +cd ../npm +npm publish +``` diff --git a/deno/deno.json b/deno/deno.json index cb304bc..b692677 100644 --- a/deno/deno.json +++ b/deno/deno.json @@ -1,5 +1,6 @@ { "tasks": { + "build-npm-package": "deno run --allow-env --allow-net=deno.land --allow-write=../npm --allow-read --allow-run=npm scripts/build_npm.ts", "update-deps": "deno cache --reload --lock=deno.lock deps.ts" } } diff --git a/deno/scripts/build_npm.ts b/deno/scripts/build_npm.ts new file mode 100644 index 0000000..135807c --- /dev/null +++ b/deno/scripts/build_npm.ts @@ -0,0 +1,41 @@ +import { build, emptyDir } from "https://deno.land/x/dnt@0.35.0/mod.ts"; +import { path } from "../deps.ts"; + +const outDir = "../npm"; +await emptyDir(outDir); + +await build({ + entryPoints: [{ + kind: "bin", + name: "elm-janitor-apply-patches", + path: "./cli.ts", + }], + outDir, + shims: { + // see JS docs for overview and more options + deno: true, + }, + typeCheck: false, + test: false, + declaration: false, + scriptModule: false, + package: { + // package.json properties + name: "elm-janitor-apply-patches", + version: "0.1.0", + description: "Script to apply the elm-janitor patches to ELM_HOME.", + license: "UNLICENSE", + repository: { + type: "git", + url: "git+https://github.com/elm-janitor/apply-patches.git", + }, + bugs: { + url: "https://github.com/elm-janitor/apply-patches/issues", + }, + }, + postBuild() { + // steps to run after building and before running the tests + Deno.copyFileSync("../UNLICENSE", path.join(outDir, "UNLICENSE")); + Deno.copyFileSync("../README.md", path.join(outDir, "README.md")); + }, +});