Skip to content

Commit

Permalink
Create runnable node.js code with https://github.com/denoland/dnt
Browse files Browse the repository at this point in the history
To create a publishable build:

```sh
cd deno
deno task build-npm-package
cd ../npm/
npm publish
```
  • Loading branch information
marc136 committed May 22, 2023
1 parent 9a01bb8 commit 0c0c09a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
elm-stuff
elm-home
npm
bun
compare
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/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

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
1 change: 1 addition & 0 deletions deno/deno.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
41 changes: 41 additions & 0 deletions deno/scripts/build_npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { build, emptyDir } from "https://deno.land/x/[email protected]/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"));
},
});

0 comments on commit 0c0c09a

Please sign in to comment.