-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into changeset-release/main
- Loading branch information
Showing
24 changed files
with
296 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@mheob/check-package-manager': major | ||
--- | ||
|
||
switch to golang to speed up the execution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Release Go project | ||
|
||
on: | ||
push: | ||
tags: | ||
- "@mheob/check-package-manager@*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ">=1.19" | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v3 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
workdir: ./packages/check-package-manager | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
run: | ||
timeout: 5m | ||
modules-download-mode: readonly | ||
go: "1.19" | ||
|
||
linters: | ||
enable: | ||
- errcheck | ||
- goimports | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- nakedret | ||
- revive | ||
- staticcheck | ||
- typecheck | ||
- unused | ||
|
||
linters-settings: | ||
nakedret: | ||
# Aggressively disallow naked returns | ||
max-func-lines: 3 | ||
|
||
issues: | ||
exclude-use-default: false | ||
max-issues-per-linter: 0 | ||
max-same-issues: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
builds: | ||
- binary: check-package-manager | ||
goos: | ||
- windows | ||
- darwin | ||
- linux | ||
goarch: | ||
- amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Package cmd holds the root cobra command | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
pm "check-package-manager/packageManager" | ||
"check-package-manager/utils" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "check-package-manager", | ||
Version: "1.0.0", | ||
Short: "A simple check of the usage of the correct package manager", | ||
Long: `Check if the correct package manager is used. | ||
Available are 'NPM', 'Yarn' and 'PNPM'.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
chosenPackageManager := pm.GetSelectedPackageManager(args) | ||
errors := pm.GetCheckLockFilesErrors(chosenPackageManager) | ||
hasErrors := len(errors) > 0 | ||
|
||
if hasErrors { | ||
utils.PrintInvalidMessage() | ||
|
||
for _, err := range errors { | ||
fmt.Println(err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
utils.PrintValidMessage() | ||
}, | ||
} | ||
|
||
// Execute executes the root command | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
rootCmd.Flags().BoolP(pm.NPM.Name, pm.NPM.ShortFlag, false, pm.NPM.Description) | ||
rootCmd.Flags().BoolP(pm.PNPM.Name, pm.PNPM.ShortFlag, false, pm.PNPM.Description) | ||
rootCmd.Flags().BoolP(pm.YARN.Name, pm.YARN.ShortFlag, false, pm.YARN.Description) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module check-package-manager | ||
|
||
go 1.19 | ||
|
||
require github.com/spf13/cobra v1.6.1 | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.0.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= | ||
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= | ||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= | ||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= | ||
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= | ||
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Package main provides the entry point for the CLI. | ||
package main | ||
|
||
import "check-package-manager/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Package packageManager holds the package manager related functions | ||
package packageManager | ||
|
||
import "check-package-manager/utils" | ||
|
||
// GetSelectedPackageManager returns the selected package manager; default is PNPM | ||
func GetSelectedPackageManager(args []string) PackageManager { | ||
if len(args) == 0 { | ||
return PNPM | ||
} | ||
|
||
switch args[0] { | ||
case NPM.Name: | ||
return NPM | ||
case YARN.Name: | ||
return YARN | ||
default: | ||
return PNPM | ||
} | ||
} | ||
|
||
// GetCheckLockFilesErrors returns a list of errors if the lock files are not correct | ||
func GetCheckLockFilesErrors(selectedPackageManager PackageManager) []string { | ||
var errors []string | ||
|
||
for _, packageManager := range []PackageManager{NPM, PNPM, YARN} { | ||
if packageManager.Name == selectedPackageManager.Name { | ||
if !utils.FileExists(packageManager.LockFile) { | ||
errors = append(errors, utils.GetMissingLockFileMessage(packageManager.LockFile)) | ||
} | ||
} else { | ||
if utils.FileExists(packageManager.LockFile) { | ||
errors = append( | ||
errors, | ||
utils.GetInvalidFileMessage(packageManager.LockFile, selectedPackageManager.LockFile), | ||
) | ||
} | ||
} | ||
} | ||
|
||
return errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package packageManager | ||
|
||
// PackageManager structure of possible package manager | ||
type PackageManager struct { | ||
Name string | ||
Description string | ||
ShortFlag string | ||
LockFile string | ||
} | ||
|
||
// NPM Package Manager | ||
var NPM = PackageManager{ | ||
Name: "npm", | ||
Description: "Use NPM as package manager", | ||
ShortFlag: "n", | ||
LockFile: "package-lock.json", | ||
} | ||
|
||
// PNPM Package Manager | ||
var PNPM = PackageManager{ | ||
Name: "pnpm", | ||
Description: "Use PNPM as package manager", | ||
ShortFlag: "p", | ||
LockFile: "pnpm-lock.yaml", | ||
} | ||
|
||
// YARN Package Manager | ||
var YARN = PackageManager{ | ||
Name: "yarn", | ||
Description: "Use YARN as package manager", | ||
ShortFlag: "y", | ||
LockFile: "yarn.lock", | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.