refactor(commands): separate commands and its core into two folders (#32)
- I think it would be better if one for commands only, one for the spec handling core logic so people won't be confused by the core logic inside the commands folder (cleaner I guess) - Regen docs
This commit is contained in:
+14
-14
@@ -5,14 +5,14 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func NpmScriptGenerator(tokens []string, _ string, _ string) []core.Suggestion {
|
||||
cwd := core.GetCWD()
|
||||
func NpmScriptGenerator(tokens []string, _ string, _ string) []spec.Suggestion {
|
||||
cwd := spec.GetCWD()
|
||||
data, err := os.ReadFile(filepath.Join(cwd, "package.json"))
|
||||
if err != nil {
|
||||
return []core.Suggestion{
|
||||
return []spec.Suggestion{
|
||||
{Cmd: "dev", Desc: "development server"},
|
||||
{Cmd: "build", Desc: "build for production"},
|
||||
{Cmd: "start", Desc: "start application"},
|
||||
@@ -30,18 +30,18 @@ func NpmScriptGenerator(tokens []string, _ string, _ string) []core.Suggestion {
|
||||
|
||||
priority := []string{"dev", "start", "build", "test", "lint", "preview", "typecheck", "format"}
|
||||
seen := make(map[string]bool)
|
||||
var results []core.Suggestion
|
||||
var results []spec.Suggestion
|
||||
|
||||
for _, name := range priority {
|
||||
if cmd, ok := pkg.Scripts[name]; ok {
|
||||
results = append(results, core.Suggestion{Cmd: name, Desc: cmd})
|
||||
results = append(results, spec.Suggestion{Cmd: name, Desc: cmd})
|
||||
seen[name] = true
|
||||
}
|
||||
}
|
||||
|
||||
for name, cmd := range pkg.Scripts {
|
||||
if !seen[name] {
|
||||
results = append(results, core.Suggestion{Cmd: name, Desc: cmd})
|
||||
results = append(results, spec.Suggestion{Cmd: name, Desc: cmd})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,36 +49,36 @@ func NpmScriptGenerator(tokens []string, _ string, _ string) []core.Suggestion {
|
||||
}
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "npm",
|
||||
Description: "node packages",
|
||||
Subcommands: []core.Subcommand{
|
||||
{Name: "install", Description: "install packages", Options: []core.Option{
|
||||
Subcommands: []spec.Subcommand{
|
||||
{Name: "install", Description: "install packages", Options: []spec.Option{
|
||||
{Name: "--save-dev", Description: "save as devDependency"},
|
||||
{Name: "--save-exact", Description: "exact version"},
|
||||
{Name: "--legacy-peer-deps", Description: "skip peer deps"},
|
||||
}},
|
||||
{Name: "run", Description: "run script", Generator: NpmScriptGenerator},
|
||||
{Name: "test", Description: "run tests"},
|
||||
{Name: "init", Description: "create package.json", Options: []core.Option{
|
||||
{Name: "init", Description: "create package.json", Options: []spec.Option{
|
||||
{Name: "-y", Description: "skip prompts"},
|
||||
}},
|
||||
{Name: "publish", Description: "publish package"},
|
||||
{Name: "update", Description: "update packages"},
|
||||
{Name: "uninstall", Description: "remove package"},
|
||||
{Name: "ls", Description: "list installed"},
|
||||
{Name: "audit", Description: "security audit", Options: []core.Option{
|
||||
{Name: "audit", Description: "security audit", Options: []spec.Option{
|
||||
{Name: "fix", Description: "auto fix"},
|
||||
}},
|
||||
{Name: "ci", Description: "clean install from lockfile"},
|
||||
{Name: "pack", Description: "create tarball"},
|
||||
{Name: "link", Description: "symlink package"},
|
||||
{Name: "cache", Description: "manage cache", Subcommands: []core.Subcommand{
|
||||
{Name: "cache", Description: "manage cache", Subcommands: []spec.Subcommand{
|
||||
{Name: "clean", Description: "clear cache"},
|
||||
{Name: "verify", Description: "verify cache"},
|
||||
}},
|
||||
},
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "--prefix", Description: "set working directory"},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user