func (self *file) Run(ctx scaffolt.Context, dryrun bool) (err error) { source := filepath.Join(ctx.Source(), InterpolateOrDefault(randomString(20), self.desc.Source, ctx)) target := filepath.Join(ctx.Target(), InterpolateOrDefault(randomString(20), self.desc.Target, ctx)) hasContent := self.desc.Content != "" self.l.Printf("Creating file: %s", target) if dryrun { return nil } if self.desc.Interpolate { var str string if hasContent { str, err = Interpolate(randomString(20)+"name", self.desc.Content, ctx) } else { str, err = InterpolateFile(source, ctx) } if err == nil { err = createFileBytes(target, []byte(str), false) } } else { if hasContent { err = createFileBytes(target, []byte(self.desc.Content), false) } else { err = createFile(target, source, false) } } return err }
func (self *engine) Run(path string, ctx scaffolt.Context) error { /*val, err := self.engine.ToValue(ctx) if err != nil { return err }*/ c, _ := self.engine.ToValue(&context{ctx, self.engine}) //self.engine.Set("context", c) value, err := self.engine.Require(path, ctx.Source()) if err != nil { return err } if value.IsFunction() { _, err := value.Call(otto.UndefinedValue(), c) if err != nil { return err } } else if value.IsObject() { v := value.Object() prop := "run" if Contains(v.Keys(), "run") { prop = "run" } else if Contains(v.Keys(), "Run") { prop = "Run" } _, err := v.Call(prop, c) if err != nil { return err } } return nil }