A helper cli which takes one or more binaries for different platforms and wraps them into an npm package for distribution.
Opt1: Run directly from JSR
deno run --allow-read='.' --allow-write='.' jsr:@bjesuiter/bin2npm --config ./bin2npm.toml
Opt2: Install globally on your host machine from JSR
deno install --global --allow-read='.' --allow-write='.' -n bin2npm jsr:@bjesuiter/bin2npm
Package URL: https://www.npmjs.com/package/bin2npm
Opt1: Run directly from npm
# with config file search
npx bin2npm
# with explicit config file
npx bin2npm --config ./bin2npm.toml
Opt2: Install on your host machine from npm
# global install
npm i -g bin2npm
# local install
npm i -D bin2npm
Package URL: https://www.npmjs.com/package/bin2npm
Opt1: Run directly from bun
bunx bin2npm --config ./bin2npm.toml
Opt2: Install globally on your host machine from bun
# global install
bun i -g bin2npm
# local install
bun i -D bin2npm
- Write a config file (see: example config file)
- Run
bin2npm
(only works when installed globally, alternatively use npx, bunx, or direct running via jsr) => It will search for all bin2npm.toml files inside your CWD - Alternatively, run
bin2npm --config ./bin2npm.toml
to specify a config file directly - Finished! If your config was correct, then your output npm package should be in your configured output dir!
If you have any issues, please open an Issue at: https://github.com/bjesuiter/bin2npm/issues
# File: bin2npm.toml
bin2NpmVersion = "0"
outDir = "npm"
[targetPackageJson]
name = "bin2npm"
version = "0.0.6"
description = "A cli tool by @bjesuiter which takes one or more binaries for different platforms and wraps them into an npm package for distribution. Can also be used via bin2npm package on npmjs.org"
[[binaries]]
# path to the binary you want to wrap, based on the cwd where you run bin2npm
path = "compiled/bin2npm_linux_x64"
# platform should be one of nodejs's os.platform() values:
# for Node 16 LTS: 'aix', 'darwin', 'freebsd','linux', 'openbsd', 'sunos', and 'win32'
# see https://nodejs.org/docs/latest-v16.x/api/os.html#osplatform
# These are only the allowed values. You have to provide the correct binary for this to work.
platform = "linux"
# arch should be one of nodejs's os.arch() values:
# for Node 16 LTS: 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64'
# see https://nodejs.org/docs/latest-v16.x/api/os.html#osarch
# These are only the allowed values. You have to provide the correct binary for this to work.
arch = "x64"
[[binaries]]
path = "compiled/bin2npm_macos_x64"
platform = "darwin"
arch = "x64"
[[binaries]]
path = "compiled/bin2npm_macos_arm"
platform = "darwin"
arch = "arm64"
[[binaries]]
path = "compiled/bin2npm_windows_x64.exe"
platform = "win32"
arch = "x64"
# copy extra files from the current directory into the npm package
[[extraAssets]]
from = "Readme.md"
to = "Readme.md"
Use asset-builder
from (https://jsr.io/@codemonument/asset-builder) to have the template folder available to the deno cli.
Run deno task pack-assets
to pack the files in /template
into src/gen/assets.ts
Must be used in the npm AND the deno variant of this package, otherwise this cli will not work when installed from jsr.io!
- Increase versions:
- In
cli.ts
for the bin2npm cli --version command - In
deno.jsonc
for the JSR deployment of this package - Of target npm package by updating the version in
./bin2npm.toml
- In Changelog here at the bottom of the readme
- In
- Run
deno task pack-assets
- Commit all changes
- Add a new git tag for your new version and push it => will trigger the deploy-npm.yml github workflow and the publish-jsr workflow
-
deno task compile
to compile the deno scripts with the deno executable into self-contained executables -
deno task assemble-npm
=> This runs bin2npm on the compiled output of itself! (Great, isn't it?!?) -
deno task publish-npm
to publish on npm
- add config example to readme
- fix bin field formatting in package.json generated by bin2npm => this might fix the build error of the publish-npm workflow on Github Actions
- Update dependencies and add jsr deployment
- First Version built by Github Actions
- Fix missing assets for both deno.land/x and npm, by inlining the assets as base64
- Fixing stdin of wrapped child processes, was not attached to process.stdin before, so selecting the config to use was not possible!
- initial release