示例#1
0
文件: initialise.go 项目: kego/ke
func Initialise(ctx context.Context, overrides OptionsInterface) (context.Context, context.CancelFunc, error) {
	if overrides == nil {
		overrides = Flags{}
	}
	options := overrides.getOptions()

	ctx, cancel := context.WithCancel(ctx)
	ctx = jsonctx.AutoContext(ctx)
	ctx = wgctx.NewContext(ctx)
	ctx = sysctx.NewContext(ctx)

	cmd := &cmdctx.Cmd{}

	vos := vosctx.FromContext(ctx)

	path := ""
	cmd.Edit = options.Edit
	cmd.Validate = options.Validate
	cmd.Update = options.Update
	cmd.Log = options.Log
	cmd.Debug = options.Debug
	cmd.Port = options.Port
	if options.Path == "" {
		dir, err := vos.Getwd()
		if err != nil {
			return nil, nil, kerr.Wrap("OKOLXAMBSJ", err)
		}
		p, err := packages.GetPackageFromDir(ctx, dir)
		if err != nil {
			return nil, nil, kerr.Wrap("ADNJKTLAWY", err)
		}
		path = p
	} else {
		path = options.Path
	}

	ctx = cmdctx.NewContext(ctx, cmd)

	pcache, err := parser.Parse(ctx, path)
	if err != nil {
		return nil, nil, kerr.Wrap("EBMBIBIKUF", err)
	}

	ctx = envctx.NewContext(ctx, pcache.Env)

	return ctx, cancel, nil
}
示例#2
0
func NewContext(ctx context.Context, path string, aliases map[string]string) context.Context {
	ctx = envctx.NewContext(ctx, &envctx.Env{Path: path, Aliases: aliases})
	ctx = jsonctx.AutoContext(ctx)
	return ctx
}
示例#3
0
文件: client.go 项目: kego/ke
func Start() error {

	loc := dom.GetWindow().Location()
	addr := fmt.Sprintf("ws://%s:%s/_rpc", loc.Hostname, loc.Port)
	ws, err := websocket.Dial(addr)
	if err != nil {
		return kerr.Wrap("HNQFLPFAJD", err)
	}

	app := &stores.App{
		Conn: connection.New(rpc.NewClient(ws)),
		Fail: make(chan error),
	}

	// We parse the info attribute from the body tag
	info, err := getInfo(getRawInfo())
	if err != nil {
		return kerr.Wrap("MGLVIQIDDY", err)
	}

	var ctx context.Context
	ctx = context.Background()
	ctx = envctx.NewContext(ctx, &envctx.Env{Path: info.Path, Aliases: info.Aliases})
	ctx = sysctx.NewContext(ctx)
	ctx = jsonctx.AutoContext(ctx)
	ctx = stores.NewContext(ctx, app)
	ctx = clientctx.NewContext(ctx)

	app.Init(ctx)

	// Don't do this. Implement the Editable interface instead. We can't do
	// this for system types so we use this method instead.
	editors.Register(ctx)

	if _, err := registerTypes(ctx, info.Path, info.Imports); err != nil {
		return kerr.Wrap("MMJDDOBAUK", err)
	}

	p := views.NewPage(ctx)
	vecty.RenderBody(p)

	// TODO: work out why I can't seem to call this without using eval
	js.Global.Get("window").Call("eval", "Split(['#tree', '#main'], {sizes:[25, 75]});")

	app.Dispatch(&actions.InitialState{
		Info: info,
	})

	go func() {
		err, open := <-app.Fail
		if !open {
			// Channel has been closed, so app should gracefully exit.
			fmt.Println("Server disconnected")
		} else {
			// Error received, so app should display error.
			fmt.Println(err.Error())
		}
	}()

	return nil
}