Esempio n. 1
0
func addJsClient(pm *PluginManager) {
	//these are internally used for js building
	pm.Add("jsClients", func(config *BuildConfig, options Plugins, c chan bool) {
		for _, pkg := range options.Args {
			var pg Plugins
			pg.Config = make(PluginConfig)
			pg.Tag = "jsClient"
			pg.Config["package"] = pkg
			pg.Args = nil
			pm.Activate(pg, config, c)
		}
	})

	pm.Add("jsClient", func(config *BuildConfig, options Plugins, c chan bool) {
		pkg := options.Config["package"]

		_, jsName := filepath.Split(pkg)

		pkgs := append([]string{}, pkg)
		packages, err := assets.GetAllPackageLists(pkgs)

		if err != nil {
			panic(err)
		}

		dir, err := assets.GetPackageDir(pkg)

		if err != nil {
			panic(err)
		}

		jsbuild := builders.JSLauncher(builders.JSBuildConfig{
			Package:  pkg,
			Folder:   dir,
			FileName: jsName,
			Tags:     options.Args,
			Verbose:  config.Client.UseVerbose,
		})

		jsbuild.React(func(root flux.Reactor, err error, _ interface{}) {
			if err != nil {
				fmt.Printf("--> Js.client.Build complete: Dir: %s \n -----> Error: %s \n", dir, err)
			}
		}, true)

		watcher := fs.WatchSet(fs.WatchSetConfig{
			Path: packages,
			Validator: func(base string, info os.FileInfo) bool {
				if strings.Contains(base, ".git") {
					return false
				}

				if info != nil && info.IsDir() {
					return true
				}

				if filepath.Ext(base) != ".go" {
					return false
				}

				return true
			},
		})

		watcher.React(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
			if ev, ok := data.(fsnotify.Event); ok {
				fmt.Printf("--> Client:File as changed: %+s\n", ev.String())
			}
		}), true)

		watcher.Bind(jsbuild, true)

		jsbuild.Send(true)

		flux.GoDefer("jsClient:kill", func() {
			<-c
			watcher.Close()
			jsbuild.Close()
		})
	})
}
Esempio n. 2
0
func addWatchBuildRun(pm *PluginManager) {
	//these are internally used
	pm.Add("watchBuildRun", func(config *BuildConfig, options Plugins, c chan bool) {
		pwd, _ := os.Getwd()
		_, binName := filepath.Split(config.Package)
		binDir := filepath.Join(pwd, config.Bin)
		binfile := filepath.Join(binDir, binName)

		pkgs := append([]string{}, config.Package, "github.com/influx6/relay/relay", "github.com/influx6/relay/engine")

		packages, err := assets.GetAllPackageLists(pkgs)

		if err != nil {
			panic(err)
		}

		fmt.Printf("--> Retrieved package directories %s \n", config.Package)

		goget := builders.GoInstallerWith("./")
		goget.React(func(root flux.Reactor, err error, data interface{}) {
			if err != nil {
				fmt.Printf("---> goget.Error occured: %s\n", err)
			} else {
				fmt.Printf("--> Sending signal for 'go get'\n")
			}
		}, true)

		buildbin := builders.BinaryBuildLauncher(builders.BinaryBuildConfig{
			Path:    binDir,
			Name:    binName,
			RunArgs: config.BinArgs,
		})

		buildbin.React(func(root flux.Reactor, err error, data interface{}) {
			if err != nil {
				fmt.Printf("---> buildbin.Error occured: %s\n", err)
			} else {
				fmt.Printf("--> Building Binary")
			}
		}, true)

		goget.Bind(buildbin, true)

		fmt.Printf("--> Initializing File Watcher using package dependecies at %d\n", len(packages))

		watcher := fs.WatchSet(fs.WatchSetConfig{
			Path: packages,
			Validator: func(base string, info os.FileInfo) bool {
				if strings.Contains(base, ".git") {
					return false
				}

				if strings.Contains(base, binDir) || base == binDir {
					return false
				}

				if strings.Contains(base, binfile) || base == binfile {
					return false
				}

				if info != nil && info.IsDir() {
					return true
				}

				if filepath.Ext(base) != ".go" {
					return false
				}

				return true
			},
		})

		watcher.React(func(root flux.Reactor, err error, data interface{}) {
			if err != nil {
				fmt.Printf("---> watcher.Error occured: %s\n", err)
			} else {
				if ev, ok := data.(fsnotify.Event); ok {
					fmt.Printf("--> File as changed: %+s\n", ev.String())
				}
			}
		}, true)

		watcher.Bind(buildbin, true)
		watcher.Bind(goget, true)

		//run go installer
		goget.Send(true)

		fmt.Printf("--> Initializing Interrupt Signal  Watcher for %s@%s\n", binName, binfile)

		flux.GoDefer("watchBuildRun:kill", func() {
			<-c
			//close our builders
			watcher.Close()
			goget.Close()
			buildbin.Close()
		})
	})
}
Esempio n. 3
0
func addJSWatchBuild(pm *PluginManager) {
	//these are internally used for js building
	pm.Add("jsWatchBuild", func(config *BuildConfig, options Plugins, c chan bool) {
		pwd, _ := os.Getwd()
		_, binName := filepath.Split(config.Package)
		binDir := filepath.Join(pwd, config.Bin)
		binfile := filepath.Join(binDir, binName)

		pkgs := append([]string{}, config.ClientPackage)

		packages, err := assets.GetAllPackageLists(pkgs)

		if err != nil {
			panic(err)
		}

		// packages = append(packages, pwd)
		fmt.Printf("--> Retrieved js package directories %s \n", config.Package)

		var clientdir string

		outputdir := filepath.Join(pwd, config.Client.StaticDir)

		if config.Client.Dir != "" {
			clientdir = filepath.Join(pwd, config.Client.Dir)
		}

		jsbuild := builders.JSLauncher(builders.JSBuildConfig{
			Package:    config.ClientPackage,
			Folder:     outputdir,
			FileName:   config.Client.Name,
			Tags:       config.Client.BuildTags,
			Verbose:    config.Client.UseVerbose,
			PackageDir: clientdir,
		})

		jsbuild.React(func(root flux.Reactor, err error, _ interface{}) {
			if err != nil {
				fmt.Printf("--> Js.client.Build complete: Dir: %s \n -----> Error: %s \n", clientdir, err)
			}
		}, true)

		fmt.Printf("--> Initializing File Watcher using js package dependecies at %d\n", len(packages))

		watcher := fs.WatchSet(fs.WatchSetConfig{
			Path: packages,
			Validator: func(base string, info os.FileInfo) bool {
				if strings.Contains(base, ".git") {
					return false
				}

				if strings.Contains(base, binDir) || base == binDir {
					return false
				}

				if strings.Contains(base, binfile) || base == binfile {
					return false
				}

				if info != nil && info.IsDir() {
					return true
				}

				if filepath.Ext(base) != ".go" {
					return false
				}

				// log.Printf("allowed: %s", base)
				return true
			},
		})

		watcher.React(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
			if ev, ok := data.(fsnotify.Event); ok {
				fmt.Printf("--> Client:File as changed: %+s\n", ev.String())
			}
		}), true)

		watcher.Bind(jsbuild, true)

		jsbuild.Send(true)

		flux.GoDefer("jsWatchBuild:kill", func() {
			<-c
			//close our builders
			watcher.Close()
			jsbuild.Close()
		})
	})
}