Example #1
0
// Auto generate "Motto" module let can run in Javascript VM
func GenerateScriptModule(prefix string, name string, script string) string {
	name = prefix + "_" + name
	motto.AddModule(name, func(vm *motto.Motto) (otto.Value, error) {
		return motto.CreateLoaderFromSource(script, "")(vm)
	})
	return name
}
Example #2
0
func loadNPMModules() {
	config := util.GetConfig()
	npmPath := config.GetString("extension/npm_path", ".")
	files, _ := ioutil.ReadDir(npmPath + "/node_modules/")
	for _, f := range files {
		if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
			module, err := motto.FindFileModule(f.Name(), npmPath, nil)
			if err != nil {
				log.Error("Finding module failed %s in %s", err, f.Name())
				break
			}
			if !strings.HasSuffix(module, ".js") {
				module = module + "/index.js"
			}
			loader := motto.CreateLoaderFromFile(module)
			motto.AddModule(f.Name(), loader)
		}
	}
}
Example #3
0
func init() {
	motto.AddModule("underscore", underscore)
}
Example #4
0
// Initialize package
func init() {

	// Setup motto module
	motto.AddModule("plurk", plurkModuleLoader)
}