Skip to content

Create go version #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f382d40
initial file
raulfdm Feb 9, 2024
bdd110a
start the main program
raulfdm Feb 9, 2024
03c8e53
implement the basic API
raulfdm Feb 9, 2024
eb19bb8
remove schema ts
raulfdm Feb 9, 2024
252ec10
start writing the commands
raulfdm Feb 10, 2024
73f22c6
update go mod
raulfdm Feb 10, 2024
d9cbf1e
remove biome.json
raulfdm Feb 10, 2024
6b1e724
add commands and flags
raulfdm Feb 10, 2024
1e26b6c
Add node-versions CLI functionality and API integration
raulfdm Feb 10, 2024
38ce419
implement GetAll and simplify NodeVersions
raulfdm Feb 10, 2024
6d6534e
fix data binding
raulfdm Feb 10, 2024
650e8cd
print all versions
raulfdm Feb 10, 2024
9d65c76
remove settings for vscode
raulfdm Feb 10, 2024
22d4485
comment implemented code
raulfdm Feb 10, 2024
d1c52b7
Add GetLatest() method to NodeVersions
raulfdm Feb 10, 2024
1d2cc8c
run go mod tidy
raulfdm Feb 10, 2024
813770a
Add support for parsing LTS versions in NodeVersion struct
raulfdm Feb 10, 2024
826f0f3
Refactor CLI command actions to use consistent variable names
raulfdm Feb 10, 2024
684954c
Refactor NodeVersion struct and Lts type
raulfdm Feb 10, 2024
e7d5f0d
add debug command
raulfdm Feb 10, 2024
65d021f
remove bin
raulfdm Feb 10, 2024
5b96387
Refactor CLI flag in main.go
raulfdm Feb 10, 2024
448c314
add semver dependency
raulfdm Feb 10, 2024
1c94be2
Refactor CLI usage and add option to get latest version of a specific…
raulfdm Feb 10, 2024
f9ea821
drop TS
raulfdm Feb 10, 2024
405a0e0
update deps
raulfdm Feb 10, 2024
cda823b
add ci file
raulfdm Feb 11, 2024
e0cc68a
Update package.json and .gitignore, add .goreleaser.yaml
raulfdm Feb 11, 2024
0b67188
Refactor CI workflow and update Go version
raulfdm Feb 11, 2024
b412ee3
try goreleaser
raulfdm Feb 11, 2024
94915c2
add GITHUB_TOKEN
raulfdm Feb 11, 2024
8f391ce
fix release command
raulfdm Feb 11, 2024
418de9e
use goreleaser action
raulfdm Feb 11, 2024
4b4eaf0
remove pull_request from release
raulfdm Feb 11, 2024
76f2470
update go
raulfdm Feb 11, 2024
84b9819
only push on tags
raulfdm Feb 11, 2024
b4e5b96
run CI on PR and push to main branch
raulfdm Feb 11, 2024
a30b9cb
remove package lock
raulfdm Feb 11, 2024
ad36e92
ignore dist file
raulfdm Feb 11, 2024
06b2ec5
remove package.json
raulfdm Feb 11, 2024
d24514e
start scripting to generate npm package
raulfdm Feb 11, 2024
05be9ce
Add releaser metadata and update package.json template
raulfdm Feb 11, 2024
4eef7e4
update package.json template
raulfdm Feb 11, 2024
5253259
add install manager script
raulfdm Feb 11, 2024
f25c604
Add file copy functionality and update URL format in package.json
raulfdm Feb 11, 2024
589c530
fix name
raulfdm Feb 11, 2024
1c7938a
Add bin.mjs and update package.json
raulfdm Feb 11, 2024
18f53d5
add release to npm
raulfdm Feb 11, 2024
352ebfe
add npmrc
raulfdm Feb 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
name: CI

on:
push:
branches:
- main

pull_request:
push:
branches:
- main

jobs:
test:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
- uses: actions/checkout@v4
name: Checkout repository

- name: Setup Go
uses: actions/setup-go@v4
with:
bun-version: 1.0.25
go-version: 1.21.7

- name: Install Dependencies
run: bun i
- name: Install dependencies
run: go get .

- name: Build
run: bun run build
run: go build -v .
52 changes: 32 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,47 @@ name: Release

on:
push:
branches:
- main
tags:
- '*'

concurrency: ${{ github.workflow }}-${{ github.ref }}
permissions:
contents: write

jobs:
release:
name: Release
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21.7

- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
bun-version: 1.0.25
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Dependencies
run: bun i
- uses: actions/setup-node@v4
name: Setup Node
with:
node-version: 20

- name: Install pnpm
run: bun i -g pnpm
- name: Generate NPM files
run: |
go run ./scripts/npm.go

- name: Create Release Pull Request
uses: changesets/action@v1
with:
publish: bun run scripts/release.ts
createGithubReleases: true
- name: Publish to NPM
run: |
cd dist-npm
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
npm publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,6 @@ dist

# Finder (MacOS) folder config
.DS_Store

dist/
dist-npm/
51 changes: 51 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
github:
owner: raulfdm
name: node-versions-cli
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go",
"args": ["lts"]
},
]
}
11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

36 changes: 36 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package api

import (
"encoding/json"
"errors"
"io"
"net/http"
"node-versions-cli/data"
)

const nodeVersionURL = "https://nodejs.org/dist/index.json"

func GetNodeVersions() (*data.NodeVersions, error) {
response, err := http.Get(nodeVersionURL)

if err != nil {
return nil, err
}

if response.StatusCode == http.StatusOK {
var nodeVersions data.NodeVersions

bodyBi, error := io.ReadAll(response.Body)

if error != nil {
return nil, error
}

json.Unmarshal(bodyBi, &nodeVersions)

return &nodeVersions, nil
} else {
return nil, errors.New("error fetching node versions")
}

}
3 changes: 0 additions & 3 deletions bin/node-versions

This file was deleted.

12 changes: 0 additions & 12 deletions biome.json

This file was deleted.

Binary file removed bun.lockb
Binary file not shown.
83 changes: 83 additions & 0 deletions data/node_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package data

import (
"errors"
"strconv"

"github.com/Masterminds/semver/v3"
)

type Lts interface{}

type NodeVersion struct {
Version string `json:"version"`
Date string `json:"date"`
Files []string `json:"files"`
Npm string `json:"npm,omitempty"`
V8 string `json:"v8"`
Uv string `json:"uv,omitempty"`
Zlib string `json:"zlib,omitempty"`
Openssl string `json:"openssl,omitempty"`
Modules string `json:"modules,omitempty"`
Lts Lts `json:"lts"`
Security bool `json:"security"`
}

func (n NodeVersion) IsLts() bool {
switch n.Lts.(type) {
case bool:
return false
default:
return true
}
}

type NodeVersions []NodeVersion

func (n NodeVersions) GetAll() []string {
var allVersions []string

for _, version := range n {
allVersions = append(allVersions, version.Version)
}

return allVersions
}

func (n NodeVersions) GetLatest() string {
return n[0].Version
}

func (n NodeVersions) GetLatestOf(majorVersionNumber string) (*string, error) {
for _, version := range n {
versionWithoutV := version.Version[1:len(version.Version)]

nodeVersion, _ := semver.NewVersion(versionWithoutV)
majorVersionAsInt, _ := strconv.ParseUint(majorVersionNumber, 10, 64)

if majorVersionAsInt == nodeVersion.Major() {
return &version.Version, nil
}
}

return nil, errors.New("no version found for major version " + majorVersionNumber)
}

func (n NodeVersions) GetCurrentLts() string {

allLts := n.GetAllLts()

return allLts[0]
}

func (n NodeVersions) GetAllLts() []string {
var ltsVersions []string = []string{}

for _, version := range n {
if version.IsLts() {
ltsVersions = append(ltsVersions, version.Version)
}
}

return ltsVersions
}
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module node-versions-cli

go 1.21.7

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/urfave/cli/v2 v2.27.1
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
Loading