forked from netgusto/nodebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe_typescript.go
41 lines (35 loc) · 1.2 KB
/
recipe_typescript.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package recipe
import (
"os"
"path"
"github.com/a112121788/nodebook/src/core/shared/recipe/helper"
"github.com/a112121788/nodebook/src/core/shared/types"
)
func Typescript() types.Recipe {
return helper.StdRecipe(
"typescript", // key
"TypeScript", // name
"TypeScript", // language
"index.ts", // mainfile
"javascript", // cmmode
"docker.io/sandrokeil/typescript:latest",
func(notebook types.Notebook) []string {
if hasTsNode(notebook) {
return []string{"sh", "-c", "node_modules/.bin/ts-node " + notebook.GetRecipe().GetMainfile()}
}
return []string{"sh", "-c", "tsc --allowJs --outFile /tmp/code.js " + notebook.GetRecipe().GetMainfile() + " && node /tmp/code.js"}
},
func(notebook types.Notebook) []string {
if hasTsNode(notebook) {
return []string{"sh", "-c", "node_modules/.bin/ts-node " + notebook.GetRecipe().GetMainfile()}
}
return []string{"sh", "-c", "tsc --allowJs --outFile /tmp/code.js " + notebook.GetRecipe().GetMainfile() + " && node /tmp/code.js"}
},
nil,
nil,
)
}
func hasTsNode(notebook types.Notebook) bool {
info, err := os.Stat(path.Join(notebook.GetAbsdir(), "node_modules", ".bin", "ts-node"))
return err == nil && info.Mode().IsRegular()
}