Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Icaruk committed Mar 28, 2023
1 parent 30831bd commit 0b6af69
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VERSION = "2.1.0"
APP_NAME = "up-npm"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

dist/
node_modules
.env
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CLI tool written in Go to review and update your NPM dependencies, easy and fast

![](https://i.imgur.com/MzzR05S.png)



# Usage

Go where your `package.json` is located and run:
Expand All @@ -17,3 +19,27 @@ Flags:
- -h, --help help
- -v, --version version
- -d, --dev Update dev dependencies



# Examples

- Update dependencies:
`npm-up`

- Update dependencies including _devDependencies:_
`npm-up --dev` or `npm-up -d`



# Build yourself

- Prerequisites:
- [Go 1.20](https://go.dev/doc/install)
- [Node 18](https://nodejs.org/en/download)
- [Taskfile](https://taskfile.dev)
- Then run:
```bash
task buid
```
- Binaries will be created in `/dist` folder.
6 changes: 4 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

version: '3'

dotenv: [".env"]

vars:
DIST_FOLDER: dist
APPNAME: up-npm
VERSION: 0.0.2
APPNAME: $APP_NAME
VERSION: $VERSION

tasks:
build:
Expand Down
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "up-npm",
"version": "2.0.3",
"version": "2.1.0",
"author": "Icaruk",
"scripts": {
"postinstall": "node ./scripts/setup.js"
Expand Down Expand Up @@ -32,5 +32,8 @@
],
"bin": {
"up-npm": "up-npm"
},
"devDependencies": {
"dotenv": "^16.0.3"
}
}
24 changes: 18 additions & 6 deletions pkg/updater/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type VersionComparisonItem struct {
versionType string
shouldUpdate bool
homepage string
repositoryUrl string
versionPrefix string
isDev bool
}
Expand Down Expand Up @@ -304,6 +305,12 @@ func getCleanVersion(version string) (string, string) {
return prefix, cleanVersion
}

func getRepositoryUrl(url string) string {
re := regexp.MustCompile(`^(git\+)(.*)(.git)$`)
matches := re.FindStringSubmatch(url)
return matches[2]
}

func readDependencies(dependencyList map[string]string, targetMap map[string]VersionComparisonItem, isDev bool, bar *progressbar.ProgressBar) {

if !isDev {
Expand Down Expand Up @@ -334,6 +341,8 @@ func readDependencies(dependencyList map[string]string, targetMap map[string]Ver

distTags := result["dist-tags"].(map[string]interface{})
homepage := result["homepage"].(string)
repository := result["repository"].(map[string]interface{})
repositoryUrl := getRepositoryUrl(repository["url"].(string))

// Get latest version from distTags
var latestVersion string
Expand All @@ -354,6 +363,7 @@ func readDependencies(dependencyList map[string]string, targetMap map[string]Ver
versionType: versionType,
shouldUpdate: false,
homepage: homepage,
repositoryUrl: repositoryUrl,
versionPrefix: versionPrefix,
isDev: isDev,
}
Expand Down Expand Up @@ -446,16 +456,18 @@ func Init(updateDev bool) {

if response == updatePackageOptions.show_changes {
// Open browser url
homepage := value.homepage
var url string

if homepage == "" {
fmt.Println("No homepage found")
if value.repositoryUrl != "" {
url = value.repositoryUrl + "/releases"
} else {
fmt.Println("Opening homepage...")
fmt.Println()
Openbrowser(homepage)
url = value.homepage
}

fmt.Println("Opening...")
fmt.Println()
Openbrowser(url)

}

if response == updatePackageOptions.update {
Expand Down
6 changes: 4 additions & 2 deletions scripts/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('dotenv').config();

const os = require("os");
const fs = require("fs");
const path = require("path");
Expand All @@ -8,8 +10,8 @@ const distPath = path.join(__dirname, "../dist");
const scriptsPath = path.join(__dirname, "../scripts");
const binPath = path.join(__dirname, "..");

const appName = "up-npm";
const version = "0.0.2";
const appName = process.env.APP_NAME;
const version = process.env.VERSION;

let distFilename = "";
let isWindows = false;
Expand Down

0 comments on commit 0b6af69

Please sign in to comment.