netgusto / nodebook

Nodebook - Multi-Lang Web REPL + CLI Code runner
ISC License
1.63k stars 84 forks source link

install and first run are hard to get right #77

Open talkingtab opened 4 years ago

talkingtab commented 4 years ago

ubuntu 19:10


` Ready. --- Running... internal/modules/cjs/loader.js:895 throw err; ^ Error: Cannot find module '/other/clones/nodebook/notebook/Waspbutter Robin/notebook/Waspbutter Robin/index.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15) at Function.Module._load (internal/modules/cjs/loader.js:785:27) at Function.Module.runMain (internal/modules/cjs/loader.js:1143:12) at internal/main/run_main_module.js:16:11 { code: 'MODULE_NOT_FOUND', requireStack: [] } exit status 1 --- Done.

`

talkingtab commented 4 years ago

Command line was . ./nbk web ./books but it works with ./nbk web /other/work/nbk/books

netgusto commented 4 years ago

Yes, I agree, something has to be done there. For cli mode; It'd also be nice to be able to:

talkingtab commented 4 years ago

A patch to use the absolute path. In your code the possible error was wrapped but I did not do that so you might want to modify that

diff --git a/src/core/baseservices.go b/src/core/baseservices.go
index f5e56bb..1330570 100644
--- a/src/core/baseservices.go
+++ b/src/core/baseservices.go
@@ -3,6 +3,7 @@ package core
 import (
        "fmt"
        "os"
+    "path/filepath"

        "github.com/netgusto/nodebook/src/core/shared/recipe"
        "github.com/netgusto/nodebook/src/core/shared/service"
@@ -14,8 +15,14 @@ func baseServices(notebooksPath string) (*service.RecipeRegistry, *service.Noteb
        recipeRegistry := service.NewRecipeRegistry()
        recipe.AddRecipesToRegistry(recipeRegistry)

+    absBookPath, err := filepath.Abs(notebooksPath)
+    if err != nil {
+        fmt.Println("Could not get absolute path")
+        os.Exit(1)
+    }
+
        // Notebook registry
-       nbRegistry := service.NewNotebookRegistry(notebooksPath, recipeRegistry)
+       nbRegistry := service.NewNotebookRegistry(absBookPath, recipeRegistry)

        // Find notebooks
        notebooks, err := nbRegistry.FindNotebooks(nbRegistry.GetNotebooksPath())