go2npm
What is go2npm
Go2npm is a tool that helps you integrate your binary packages into npm;when c、c++、rust or go programs are packaged and compiled, they are usually cross-compiled, we should use different binary packages for different operating systems,go2npm will automatically match the corresponding binary package to the user's operating system,Download it to npm local or global dependencies, supports downloading binaries from public, private repositories.
How to use go2npm
If, for example, you already have successfully released some binary and have them managed in github.
And your binary names should follow this specification:
{{name}}_{{version}}_{{platform}}_{{arch}}.tar.gz
If you use goreleaser package your program, it will automatically write each parameter.
Step one
Create an empty folder and initialize it with the npm init command to make it an npm package
npm init -y
Change the data in package.json to information about the binary tool's info.
Step two
Add a property to package.json called go2npm:
{
"go2npm": {
"username": "[value]",
"repoName": "[value]",
"tagName": "[value]",
"version": "[value]",
"githubToken": "[value]",
"name": "[value]"
}
}
Property | Is required | Description |
---|---|---|
username | true | Github account username |
repoName | true | Your binary repository's name |
tagName | true | Which tag version do you want to download from the golong’s repository |
version | true | Your binary release version which you want to download |
githubToken | false | If your binary's repository is private, need this value |
name | true | Your binary file name, the command use at npm |
Step three
Add two commands to the script property in package.json, and add go2npm to the devDependencies:
{
"script": {
"postinstall": "go2npm install",
"preuninstall": "go2npm uninstall"
},
"devDependencies": {
"go2npm": "^1.2.11"
}
}
Step four
Publish your npm app (includes the binary repository info), you can publish to the official platform or to your own private npm repository
npm publish
Step five
Use npm to install and have fun with your binary application toolkit.
npm install [your npm app name] [-g]
Use yarn
yarn add [your npm app name] [-g]
If you installed in local npm dependency, execute command:
npx [binary-name] [options]
If you installed in global npm dependency, execute command:
[binary-name] [options]
license
MIT