Path: blob/dev/pkg/js/devtools/bindgen/cmd/bindgen/main.go
2071 views
package main12import (3"flag"4"fmt"5"log"6"path"7"path/filepath"89"github.com/pkg/errors"10generator "github.com/projectdiscovery/nuclei/v3/pkg/js/devtools/bindgen"11fileutil "github.com/projectdiscovery/utils/file"12)1314var (15dir string16generatedDir string17targetModules string18)1920func main() {21flag.StringVar(&dir, "dir", "libs", "directory to process")22flag.StringVar(&generatedDir, "out", "generated", "directory to output generated files")23flag.StringVar(&targetModules, "target", "", "target modules to generate")24flag.Parse()25log.SetFlags(0)26if !fileutil.FolderExists(dir) {27log.Fatalf("directory %s does not exist", dir)28}29if err := process(); err != nil {30log.Fatal(err)31}32}3334func process() error {35modules, err := generator.GetLibraryModules(dir)36if err != nil {37return errors.Wrap(err, "could not get library modules")38}39if len(modules) == 0 && fileutil.FolderExists(dir) {40// if no modules are found, then given directory is the module itself41targetModules = path.Base(dir)42modules = append(modules, targetModules)43dir = filepath.Dir(dir)44}45for _, module := range modules {46log.Printf("[module] Generating %s", module)4748data, err := generator.CreateTemplateData(filepath.Join(dir, module), "github.com/projectdiscovery/nuclei/v3/pkg/js/libs/")49if err != nil {50return fmt.Errorf("could not create template data: %v", err)51}5253prefixed := "lib" + module54// if !goOnly {55// err = data.WriteJSTemplate(filepath.Join(generatedDir, "js/"+prefixed), module)56// if err != nil {57// return fmt.Errorf("could not write js template: %v", err)58// }59// }60err = data.WriteGoTemplate(path.Join(generatedDir, "go/"+prefixed), module)61if err != nil {62return fmt.Errorf("could not write go template: %v", err)63}64// disabled for now since we have static website for docs65// err = data.WriteMarkdownLibraryDocumentation(path.Join(generatedDir, "markdown/"), module)66// if err != nil {67// return fmt.Errorf("could not write markdown template: %v", err)68// }6970// err = data.WriteMarkdownIndexTemplate(path.Join(generatedDir, "markdown/"))71// if err != nil {72// return fmt.Errorf("could not write markdown index template: %v", err)73// }74data.InitNativeScripts()75}76return nil77}787980