procoder-cli 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +2 -1
- package/cmd/procoder-return/main.go +2 -1
- package/internal/app/app.go +2 -1
- package/internal/buildinfo/buildinfo.go +16 -0
- package/package.json +1 -1
- package/scripts/postinstall.js +9 -2
package/Makefile
CHANGED
|
@@ -12,7 +12,8 @@ HELPER_CMD_PATH ?= ./cmd/$(HELPER_NAME)
|
|
|
12
12
|
DIST_DIR ?= dist
|
|
13
13
|
BIN_PATH ?= $(DIST_DIR)/$(BIN_NAME)
|
|
14
14
|
HELPER_PATH ?= $(DIST_DIR)/$(HELPER_ASSET)
|
|
15
|
-
|
|
15
|
+
VERSION ?= $(shell node -p "require('./package.json').version" 2>/dev/null)
|
|
16
|
+
LDFLAGS ?= -s -w -X github.com/amxv/procoder/internal/buildinfo.Version=$(if $(VERSION),$(VERSION),dev)
|
|
16
17
|
|
|
17
18
|
.PHONY: help fmt test vet lint check build build-helper build-all install-local clean release-tag
|
|
18
19
|
|
|
@@ -5,12 +5,13 @@ import (
|
|
|
5
5
|
"io"
|
|
6
6
|
"os"
|
|
7
7
|
|
|
8
|
+
"github.com/amxv/procoder/internal/buildinfo"
|
|
8
9
|
"github.com/amxv/procoder/internal/errs"
|
|
9
10
|
"github.com/amxv/procoder/internal/output"
|
|
10
11
|
"github.com/amxv/procoder/internal/returnpkg"
|
|
11
12
|
)
|
|
12
13
|
|
|
13
|
-
var version =
|
|
14
|
+
var version = buildinfo.CurrentVersion()
|
|
14
15
|
var runReturn = returnpkg.Run
|
|
15
16
|
|
|
16
17
|
func main() {
|
package/internal/app/app.go
CHANGED
|
@@ -6,13 +6,14 @@ import (
|
|
|
6
6
|
"strings"
|
|
7
7
|
|
|
8
8
|
"github.com/amxv/procoder/internal/apply"
|
|
9
|
+
"github.com/amxv/procoder/internal/buildinfo"
|
|
9
10
|
"github.com/amxv/procoder/internal/errs"
|
|
10
11
|
"github.com/amxv/procoder/internal/prepare"
|
|
11
12
|
)
|
|
12
13
|
|
|
13
14
|
const commandName = "procoder"
|
|
14
15
|
|
|
15
|
-
var version =
|
|
16
|
+
var version = buildinfo.CurrentVersion()
|
|
16
17
|
var runPrepare = prepare.Run
|
|
17
18
|
var runApplyDryRun = apply.RunDryRun
|
|
18
19
|
var runApply = apply.Run
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package buildinfo
|
|
2
|
+
|
|
3
|
+
import "strings"
|
|
4
|
+
|
|
5
|
+
const defaultVersion = "dev"
|
|
6
|
+
|
|
7
|
+
// Version is overridden at build time via linker flags.
|
|
8
|
+
var Version = defaultVersion
|
|
9
|
+
|
|
10
|
+
func CurrentVersion() string {
|
|
11
|
+
trimmed := strings.TrimSpace(Version)
|
|
12
|
+
if trimmed == "" {
|
|
13
|
+
return defaultVersion
|
|
14
|
+
}
|
|
15
|
+
return trimmed
|
|
16
|
+
}
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -60,6 +60,11 @@ function buildReleaseAssetURL({ repoOwner, repoName, version, assetName }) {
|
|
|
60
60
|
return `https://github.com/${repoOwner}/${repoName}/releases/download/v${version}/${assetName}`;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
function buildLdflags(version) {
|
|
64
|
+
const resolvedVersion = `${version || ""}`.trim() || "dev";
|
|
65
|
+
return `-s -w -X github.com/amxv/procoder/internal/buildinfo.Version=${resolvedVersion}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
function buildInstallPlan({
|
|
64
69
|
pkg,
|
|
65
70
|
cliName,
|
|
@@ -167,6 +172,7 @@ function fallbackBuildOrExit(plan) {
|
|
|
167
172
|
}
|
|
168
173
|
|
|
169
174
|
function buildFallbackBuilds(plan) {
|
|
175
|
+
const ldflags = buildLdflags(plan.version);
|
|
170
176
|
return [
|
|
171
177
|
{
|
|
172
178
|
destination: plan.cli.destination,
|
|
@@ -174,7 +180,7 @@ function buildFallbackBuilds(plan) {
|
|
|
174
180
|
args: [
|
|
175
181
|
"build",
|
|
176
182
|
"-trimpath",
|
|
177
|
-
|
|
183
|
+
`-ldflags=${ldflags}`,
|
|
178
184
|
"-o",
|
|
179
185
|
plan.cli.destination,
|
|
180
186
|
`./cmd/${plan.cli.name}`
|
|
@@ -190,7 +196,7 @@ function buildFallbackBuilds(plan) {
|
|
|
190
196
|
args: [
|
|
191
197
|
"build",
|
|
192
198
|
"-trimpath",
|
|
193
|
-
|
|
199
|
+
`-ldflags=${ldflags}`,
|
|
194
200
|
"-o",
|
|
195
201
|
plan.helper.destination,
|
|
196
202
|
`./cmd/${plan.helper.name}`
|
|
@@ -245,6 +251,7 @@ function downloadToFile(url, destinationPath) {
|
|
|
245
251
|
|
|
246
252
|
module.exports = {
|
|
247
253
|
buildFallbackBuilds,
|
|
254
|
+
buildLdflags,
|
|
248
255
|
buildInstallPlan,
|
|
249
256
|
buildReleaseAssetName,
|
|
250
257
|
buildReleaseAssetURL,
|