mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-18 05:09:26 +00:00
ADD win_ext to URL template variables
This commit is contained in:
13
README.md
13
README.md
@@ -1,16 +1,16 @@
|
|||||||
## Go NPM
|
## Go NPM
|
||||||
### Distribute cross-platform Go binaries via NPM
|
### Distribute cross-platform Go binaries via NPM
|
||||||
|
|
||||||
Applications written in Golang are portable - you can easily cross-compile binaries that work on Windows, Mac, and Linux. But how do you distribute the binaries to customers? When you publish new releases, how do they update the binary?
|
Applications written in Golang are portable - you can easily cross-compile binaries that work on Windows, Mac, and Linux. But how do you distribute the binaries to customers? When you publish new releases, how do they update the binary?
|
||||||
|
|
||||||
**Use NPM to distribute cross-platform Go binaries**
|
**Use NPM to distribute cross-platform Go binaries**
|
||||||
|
|
||||||
## Kidding me! Why NPM?
|
## Kidding me! Why NPM?
|
||||||
* **Cross-platform**: NPM is the only popular package manager that works cross-platform.
|
* **Cross-platform**: NPM is the only popular package manager that works cross-platform.
|
||||||
* **Lower barier to entry**: Most developers have NPM installed already.
|
* **Lower barier to entry**: Most developers have NPM installed already.
|
||||||
* **Pain free publishing**: It just takes one command to publish - `npm publish`
|
* **Pain free publishing**: It just takes one command to publish - `npm publish`
|
||||||
* **Dead simple install & update story**: `npm install/update -g your-awesome-app`
|
* **Dead simple install & update story**: `npm install/update -g your-awesome-app`
|
||||||
* **Adds $PATH**: NPM will automatically add your binary location to $PATH and generate .cmd file for Windows. Your app just works after installation!
|
* **Adds $PATH**: NPM will automatically add your binary location to $PATH and generate .cmd file for Windows. Your app just works after installation!
|
||||||
|
|
||||||
## Okay, tell me how?
|
## Okay, tell me how?
|
||||||
### 1. Publish your binaries
|
### 1. Publish your binaries
|
||||||
@@ -76,7 +76,7 @@ You need to tell `go-npm` where to download the binaries from, and where to inst
|
|||||||
"url": "https://github.com/user/my-go-package/releases/download/v{{version}}/myGoPackage_{{version}}_{{platform}}_{{arch}}.tar.gz"
|
"url": "https://github.com/user/my-go-package/releases/download/v{{version}}/myGoPackage_{{version}}_{{platform}}_{{arch}}.tar.gz"
|
||||||
```
|
```
|
||||||
|
|
||||||
* *name*: Name of the command users will use to run your binary.
|
* *name*: Name of the command users will use to run your binary.
|
||||||
* *path*: Temporary path where binaries will be downloaded to
|
* *path*: Temporary path where binaries will be downloaded to
|
||||||
* *url*: HTTP Web server where binaries are hosted.
|
* *url*: HTTP Web server where binaries are hosted.
|
||||||
|
|
||||||
@@ -84,6 +84,7 @@ Following variables are available to customize the URL:
|
|||||||
* `{{version}}`: Version number read from `package.json` file. When you publish your package to NPM, it will use this version number. Ex: 0.0.1
|
* `{{version}}`: Version number read from `package.json` file. When you publish your package to NPM, it will use this version number. Ex: 0.0.1
|
||||||
* `{{platform}}`: `$GOOS` value for the platform
|
* `{{platform}}`: `$GOOS` value for the platform
|
||||||
* `{{arch}}`: `$GOARCH` value for the architecture
|
* `{{arch}}`: `$GOARCH` value for the architecture
|
||||||
|
* `{{ win_ext }}`: optional `.exe` extension for windows assets.
|
||||||
|
|
||||||
If you use `goreleaser` to publish your modules, it will automatically set the right architecture & platform in your URL.
|
If you use `goreleaser` to publish your modules, it will automatically set the right architecture & platform in your URL.
|
||||||
|
|
||||||
@@ -106,4 +107,4 @@ To Update:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
With ❤️ to the community by [Sanath Kumar Ramesh](http://twitter.com/sanathkr_)
|
With ❤️ to the community by [Sanath Kumar Ramesh](http://twitter.com/sanathkr_)
|
||||||
|
|||||||
@@ -129,7 +129,11 @@ function parsePackageJson() {
|
|||||||
|
|
||||||
// Binary name on Windows has .exe suffix
|
// Binary name on Windows has .exe suffix
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
binName += ".exe"
|
binName += ".exe";
|
||||||
|
|
||||||
|
url = url.replace(/{{win_ext}}/g, '.exe');
|
||||||
|
} else {
|
||||||
|
url = url.replace(/{{win_ext}}/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interpolate variables in URL, if necessary
|
// Interpolate variables in URL, if necessary
|
||||||
@@ -143,7 +147,7 @@ function parsePackageJson() {
|
|||||||
binPath: binPath,
|
binPath: binPath,
|
||||||
url: url,
|
url: url,
|
||||||
version: version
|
version: version
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user