mirror of
https://github.com/jesseduffield/lazynpm.git
synced 2026-01-09 06:21:11 +08:00
switch to new dependency when changing type
This commit is contained in:
parent
0b0463a3e0
commit
d0aa2213b7
@ -54,12 +54,12 @@ func (gui *Gui) linkPathMap() map[string]bool {
|
||||
|
||||
func (gui *Gui) handleDepInstall(dep *commands.Dependency) error {
|
||||
cmdStr := fmt.Sprintf("npm install %s", dep.Name)
|
||||
return gui.newMainCommand(cmdStr, dep.ID())
|
||||
return gui.newMainCommand(cmdStr, dep.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleDepUpdate(dep *commands.Dependency) error {
|
||||
cmdStr := fmt.Sprintf("npm update %s", dep.Name)
|
||||
return gui.newMainCommand(cmdStr, dep.ID())
|
||||
return gui.newMainCommand(cmdStr, dep.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleOpenDepPackageConfig(dep *commands.Dependency) error {
|
||||
@ -81,7 +81,7 @@ func (gui *Gui) handleDepUninstall(dep *commands.Dependency) error {
|
||||
{
|
||||
displayStrings: []string{"uninstall", utils.ColoredString(uninstallStr, color.FgYellow)},
|
||||
onPress: func() error {
|
||||
return gui.newMainCommand(uninstallStr, dep.ID())
|
||||
return gui.newMainCommand(uninstallStr, dep.ID(), newMainCommandOptions{})
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -99,13 +99,13 @@ func (gui *Gui) handleDepUninstall(dep *commands.Dependency) error {
|
||||
{
|
||||
displayStrings: []string{"uninstall and save", utils.ColoredString(uninstallAndSaveCmdStr, color.FgYellow)},
|
||||
onPress: func() error {
|
||||
return gui.newMainCommand(uninstallAndSaveCmdStr, dep.ID())
|
||||
return gui.newMainCommand(uninstallAndSaveCmdStr, dep.ID(), newMainCommandOptions{})
|
||||
},
|
||||
},
|
||||
{
|
||||
displayStrings: []string{"just uninstall", utils.ColoredString(uninstallCmdStr, color.FgYellow)},
|
||||
onPress: func() error {
|
||||
return gui.newMainCommand(uninstallCmdStr, dep.ID())
|
||||
return gui.newMainCommand(uninstallCmdStr, dep.ID(), newMainCommandOptions{})
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -144,7 +144,15 @@ func (gui *Gui) handleChangeDepType(dep *commands.Dependency) error {
|
||||
menuItems = append(menuItems, &menuItem{
|
||||
displayStrings: []string{kindKeyMap[kindFlag.Kind], utils.ColoredString(cmdStr, color.FgYellow)},
|
||||
onPress: func() error {
|
||||
return gui.newMainCommand(cmdStr, dep.ID())
|
||||
return gui.newMainCommand(cmdStr, dep.ID(), newMainCommandOptions{onSuccess: func() {
|
||||
for i, newDep := range gui.State.Deps {
|
||||
if newDep.Name == dep.Name && newDep.Kind == kindFlag.Kind {
|
||||
gui.State.Panels.Deps.SelectedLine = i
|
||||
gui.refreshDepsView()
|
||||
break
|
||||
}
|
||||
}
|
||||
}})
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -158,7 +166,7 @@ func (gui *Gui) handleAddDependency(dep *commands.Dependency) error {
|
||||
prompt := func(cmdStr string) error {
|
||||
return gui.createPromptPanel(gui.getDepsView(), "enter dependency name", "", func(input string) error {
|
||||
newCmdStr := fmt.Sprintf("%s %s", cmdStr, input)
|
||||
return gui.newMainCommand(newCmdStr, dep.ID())
|
||||
return gui.newMainCommand(newCmdStr, dep.ID(), newMainCommandOptions{})
|
||||
})
|
||||
}
|
||||
|
||||
@ -186,3 +194,8 @@ func (gui *Gui) handleEditDepConstraint(dep *commands.Dependency) error {
|
||||
return gui.finalStep(gui.NpmManager.EditDepConstraint(dep, packageConfigPath, input))
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) refreshDepsView() {
|
||||
displayStrings := presentation.GetDependencyListDisplayStrings(gui.State.Deps, gui.State.CommandViewMap, gui.getLeftSideWidth() > 70)
|
||||
gui.renderDisplayStrings(gui.getDepsView(), displayStrings)
|
||||
}
|
||||
|
||||
@ -69,8 +69,7 @@ func (gui *Gui) refreshListViews() {
|
||||
displayStrings := presentation.GetPackageListDisplayStrings(gui.State.Packages, gui.linkPathMap(), gui.State.CommandViewMap)
|
||||
gui.renderDisplayStrings(gui.getPackagesView(), displayStrings)
|
||||
|
||||
displayStrings = presentation.GetDependencyListDisplayStrings(gui.State.Deps, gui.State.CommandViewMap, gui.getLeftSideWidth() > 70)
|
||||
gui.renderDisplayStrings(gui.getDepsView(), displayStrings)
|
||||
gui.refreshDepsView()
|
||||
|
||||
displayStrings = presentation.GetScriptListDisplayStrings(gui.getScripts(), gui.State.CommandViewMap)
|
||||
gui.renderDisplayStrings(gui.getScriptsView(), displayStrings)
|
||||
@ -147,7 +146,7 @@ func (gui *Gui) handleLinkPackage() error {
|
||||
}
|
||||
}
|
||||
|
||||
return gui.newMainCommand(cmdStr, selectedPkg.ID())
|
||||
return gui.newMainCommand(cmdStr, selectedPkg.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleGlobalLinkPackage(pkg *commands.Package) error {
|
||||
@ -162,7 +161,7 @@ func (gui *Gui) handleGlobalLinkPackage(pkg *commands.Package) error {
|
||||
cmdStr = "npm link"
|
||||
}
|
||||
|
||||
return gui.newMainCommand(cmdStr, pkg.ID())
|
||||
return gui.newMainCommand(cmdStr, pkg.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleInstall(pkg *commands.Package) error {
|
||||
@ -173,7 +172,7 @@ func (gui *Gui) handleInstall(pkg *commands.Package) error {
|
||||
cmdStr = "npm install --prefix " + pkg.Path
|
||||
}
|
||||
|
||||
return gui.newMainCommand(cmdStr, pkg.ID())
|
||||
return gui.newMainCommand(cmdStr, pkg.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleBuild(pkg *commands.Package) error {
|
||||
@ -184,7 +183,7 @@ func (gui *Gui) handleBuild(pkg *commands.Package) error {
|
||||
cmdStr = "npm run build --prefix " + pkg.Path
|
||||
}
|
||||
|
||||
return gui.newMainCommand(cmdStr, pkg.ID())
|
||||
return gui.newMainCommand(cmdStr, pkg.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleOpenPackageConfig(pkg *commands.Package) error {
|
||||
@ -227,7 +226,7 @@ func (gui *Gui) handlePackPackage(pkg *commands.Package) error {
|
||||
cmdStr = fmt.Sprintf("npm pack %s", pkg.Path)
|
||||
}
|
||||
|
||||
return gui.newMainCommand(cmdStr, pkg.ID())
|
||||
return gui.newMainCommand(cmdStr, pkg.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) selectedPackageID() string {
|
||||
@ -252,7 +251,7 @@ func (gui *Gui) handlePublish(name string, scoped bool, id string) error {
|
||||
cmdStr = fmt.Sprintf("%s --tag=%s", cmdStr, tag)
|
||||
}
|
||||
cmdStr = fmt.Sprintf("%s %s", cmdStr, name)
|
||||
return gui.newMainCommand(cmdStr, id)
|
||||
return gui.newMainCommand(cmdStr, id, newMainCommandOptions{})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,11 @@ import (
|
||||
"github.com/jesseduffield/lazynpm/pkg/utils"
|
||||
)
|
||||
|
||||
func (gui *Gui) newMainCommand(cmdStr string, contextKey string) error {
|
||||
type newMainCommandOptions struct {
|
||||
onSuccess func()
|
||||
}
|
||||
|
||||
func (gui *Gui) newMainCommand(cmdStr string, contextKey string, opts newMainCommandOptions) error {
|
||||
cmd := gui.OSCommand.ExecutableFromString(cmdStr)
|
||||
|
||||
mainPanelLeft, mainPanelTop, mainPanelRight, mainPanelBottom, err := gui.getMainViewDimensions()
|
||||
@ -124,7 +128,7 @@ func (gui *Gui) newMainCommand(cmdStr string, contextKey string) error {
|
||||
|
||||
gui.State.CommandViewMap[contextKey] = commandView
|
||||
|
||||
if err := gui.newPtyTask(contextKey, commandView, cmdStr); err != nil {
|
||||
if err := gui.newPtyTask(contextKey, commandView, cmdStr, opts); err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
|
||||
@ -161,7 +165,7 @@ func (gui *Gui) onResize() error {
|
||||
// which is just an io.Reader. the pty package lets us wrap a command in a
|
||||
// pseudo-terminal meaning we'll get the behaviour we want from the underlying
|
||||
// command.
|
||||
func (gui *Gui) newPtyTask(viewName string, commandView *commands.CommandView, cmdStr string) error {
|
||||
func (gui *Gui) newPtyTask(viewName string, commandView *commands.CommandView, cmdStr string, opts newMainCommandOptions) error {
|
||||
go func() {
|
||||
view, err := gui.g.View(viewName)
|
||||
if err != nil {
|
||||
@ -202,6 +206,9 @@ func (gui *Gui) newPtyTask(viewName string, commandView *commands.CommandView, c
|
||||
if commandView.Cancelled {
|
||||
fmt.Fprint(view, utils.ColoredString("\n\ncommand cancelled", color.FgRed))
|
||||
} else if commandView.Cmd.ProcessState.Success() {
|
||||
if opts.onSuccess != nil {
|
||||
opts.onSuccess()
|
||||
}
|
||||
fmt.Fprint(view, utils.ColoredString("\n\ncommand completed successfully", color.FgGreen))
|
||||
} else {
|
||||
fmt.Fprint(view, utils.ColoredString("\n\ncommand failed", color.FgRed))
|
||||
|
||||
@ -37,7 +37,7 @@ func (gui *Gui) handleScriptSelect(g *gocui.Gui, v *gocui.View) error {
|
||||
|
||||
func (gui *Gui) handleRunScript(script *commands.Script) error {
|
||||
return gui.createPromptPanel(gui.getScriptsView(), "run script", fmt.Sprintf("npm run %s", script.Name), func(input string) error {
|
||||
return gui.newMainCommand(input, script.ID())
|
||||
return gui.newMainCommand(input, script.ID(), newMainCommandOptions{})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ func (gui *Gui) handleDeleteTarball(tarball *commands.Tarball) error {
|
||||
|
||||
func (gui *Gui) handleInstallTarball(tarball *commands.Tarball) error {
|
||||
cmdStr := fmt.Sprintf("npm install %s", tarball.Name)
|
||||
return gui.newMainCommand(cmdStr, tarball.ID())
|
||||
return gui.newMainCommand(cmdStr, tarball.ID(), newMainCommandOptions{})
|
||||
}
|
||||
|
||||
func (gui *Gui) handlePublishTarball(tarball *commands.Tarball) error {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user