|
8 | 8 | "fmt" |
9 | 9 | "github.com/cloudimpl/polycode/core" |
10 | 10 | _go "github.com/cloudimpl/polycode/go" |
11 | | - "github.com/fsnotify/fsnotify" |
12 | 11 | "io" |
13 | 12 | "log" |
14 | 13 | "net/http" |
@@ -55,9 +54,6 @@ func main() { |
55 | 54 | case "build": |
56 | 55 | cmdBuild(os.Args[2:]) |
57 | 56 |
|
58 | | - case "run": |
59 | | - cmdRun(os.Args[2:]) |
60 | | - |
61 | 57 | case "extract": |
62 | 58 | cmdExtract(os.Args[2:]) |
63 | 59 |
|
@@ -181,12 +177,10 @@ func cmdBuild(args []string) { |
181 | 177 | var ( |
182 | 178 | appLanguage string |
183 | 179 | outputPath string |
184 | | - watchFlag bool |
185 | 180 | ) |
186 | 181 |
|
187 | 182 | fs.StringVar(&appLanguage, "language", "auto", "Application language (supported: go)") |
188 | 183 | fs.StringVar(&outputPath, "out", "", "Output path for generated code (default: <app-path>/app)") |
189 | | - fs.BoolVar(&watchFlag, "watch", false, "Watch <app-path>/services and rebuild on changes") |
190 | 184 | fs.Usage = func() { |
191 | 185 | fmt.Fprintf(fs.Output(), "Usage:\n polycode build <app-path> [options]\n\nOptions:\n") |
192 | 186 | fs.PrintDefaults() |
@@ -230,107 +224,11 @@ func cmdBuild(args []string) { |
230 | 224 | log.Fatalf("language %q is not supported", appLanguage) |
231 | 225 | } |
232 | 226 |
|
233 | | - if watchFlag { |
234 | | - servicesPath := filepath.Join(appPath, "services") |
235 | | - log.Printf("watching: %s", servicesPath) |
236 | | - watch(servicesPath, func(event fsnotify.Event) { |
237 | | - _ = g.OnChange(appPath, outputPath, event) |
238 | | - }) |
239 | | - return |
240 | | - } |
241 | | - |
242 | 227 | if err := g.Generate(appPath, outputPath); err != nil { |
243 | 228 | log.Fatalf("failed to build: %v", err) |
244 | 229 | } |
245 | 230 | } |
246 | 231 |
|
247 | | -// ========================= run ========================= |
248 | | - |
249 | | -// polycode run <app-path> |
250 | | -// - Builds into <app-path>/app (like build) |
251 | | -// - For Go: builds binary into .polycode/app and runs it |
252 | | -func cmdRun(args []string) { |
253 | | - fs := flag.NewFlagSet("run", flag.ContinueOnError) |
254 | | - fs.SetOutput(os.Stderr) |
255 | | - |
256 | | - var ( |
257 | | - appLanguage string |
258 | | - ) |
259 | | - fs.StringVar(&appLanguage, "language", "auto", "Application language (supported: go)") |
260 | | - fs.Usage = func() { |
261 | | - fmt.Fprintf(fs.Output(), "Usage:\n polycode run <app-path> [options]\n\nOptions:\n") |
262 | | - fs.PrintDefaults() |
263 | | - } |
264 | | - |
265 | | - if err := fs.Parse(args); err != nil { |
266 | | - if err == flag.ErrHelp { |
267 | | - return |
268 | | - } |
269 | | - os.Exit(2) |
270 | | - } |
271 | | - if fs.NArg() < 1 { |
272 | | - fmt.Fprintln(os.Stderr, "missing required <app-path>") |
273 | | - fs.Usage() |
274 | | - os.Exit(2) |
275 | | - } |
276 | | - appPath := fs.Arg(0) |
277 | | - |
278 | | - // detect language |
279 | | - if appLanguage == "" || appLanguage == "auto" { |
280 | | - appLanguage = detectLanguage(appPath) |
281 | | - if appLanguage == "" { |
282 | | - log.Fatalf("unable to detect language for %s — please specify with -language", appPath) |
283 | | - } |
284 | | - fmt.Println("Detected language:", appLanguage) |
285 | | - } |
286 | | - |
287 | | - // 1) build |
288 | | - if err := os.MkdirAll(filepath.Join(appPath, "app"), 0o755); err != nil { |
289 | | - log.Fatalf("failed to create app folder: %v", err) |
290 | | - } |
291 | | - cmdBuild([]string{appPath, "-language", appLanguage}) |
292 | | - |
293 | | - // 2) build & run (language-specific) |
294 | | - switch appLanguage { |
295 | | - case "go": |
296 | | - binDir := filepath.Join(appPath, ".polycode") |
297 | | - _ = os.MkdirAll(binDir, 0o755) |
298 | | - bin := filepath.Join(binDir, "app") |
299 | | - // go mod tidy at root (in case builder added deps) |
300 | | - _ = runCmd(appPath, "go", "mod", "tidy") |
301 | | - // build the generated app |
302 | | - if err := runCmd(appPath, "go", "build", "-o", bin, "./app"); err != nil { |
303 | | - log.Fatalf("build binary failed: %v", err) |
304 | | - } |
305 | | - fmt.Printf("▶ Running %s\n\n", bin) |
306 | | - // exec the app and proxy signals |
307 | | - ctx, cancel := context.WithCancel(context.Background()) |
308 | | - defer cancel() |
309 | | - |
310 | | - cmd := exec.CommandContext(ctx, bin) |
311 | | - cmd.Stdout, cmd.Stderr, cmd.Stdin = os.Stdout, os.Stderr, os.Stdin |
312 | | - if err := cmd.Start(); err != nil { |
313 | | - log.Fatalf("failed to start: %v", err) |
314 | | - } |
315 | | - done := make(chan struct{}) |
316 | | - go func() { |
317 | | - handleSignals(func() { |
318 | | - gracefulStop(cmd.Process) |
319 | | - }) |
320 | | - _ = cmd.Wait() |
321 | | - close(done) |
322 | | - }() |
323 | | - <-done |
324 | | - |
325 | | - case "java": |
326 | | - log.Fatalf("run: java pipeline not implemented yet") |
327 | | - case "python": |
328 | | - log.Fatalf("run: python pipeline not implemented yet") |
329 | | - default: |
330 | | - log.Fatalf("run: unsupported language %q", appLanguage) |
331 | | - } |
332 | | -} |
333 | | - |
334 | 232 | // ========================= extract ========================= |
335 | 233 |
|
336 | 234 | func cmdExtract(args []string) { |
@@ -476,70 +374,6 @@ func runExtractor(client, out, callback, cwd string) { |
476 | 374 |
|
477 | 375 | // ========================= helpers ========================= |
478 | 376 |
|
479 | | -func watch(watchPath string, onChange func(event fsnotify.Event)) { |
480 | | - watcher, err := fsnotify.NewWatcher() |
481 | | - if err != nil { |
482 | | - log.Fatalf("failed to create watcher: %v", err) |
483 | | - } |
484 | | - defer watcher.Close() |
485 | | - |
486 | | - // Handle OS signals for graceful shutdown |
487 | | - done := make(chan struct{}) |
488 | | - |
489 | | - go func() { |
490 | | - defer close(done) |
491 | | - for { |
492 | | - select { |
493 | | - case event, ok := <-watcher.Events: |
494 | | - if !ok { |
495 | | - return |
496 | | - } |
497 | | - |
498 | | - // auto-add new directories |
499 | | - if event.Op&fsnotify.Create == fsnotify.Create { |
500 | | - if info, err := os.Stat(event.Name); err == nil && info.IsDir() { |
501 | | - if err := watcher.Add(event.Name); err != nil { |
502 | | - log.Printf("failed to watch new dir %s: %v", event.Name, err) |
503 | | - } |
504 | | - } |
505 | | - } |
506 | | - |
507 | | - if event.Op&fsnotify.Write == fsnotify.Write { |
508 | | - onChange(event) |
509 | | - } |
510 | | - |
511 | | - case err, ok := <-watcher.Errors: |
512 | | - if !ok { |
513 | | - return |
514 | | - } |
515 | | - log.Printf("watcher error: %v", err) |
516 | | - } |
517 | | - } |
518 | | - }() |
519 | | - |
520 | | - // initial walk |
521 | | - err = filepath.Walk(watchPath, func(p string, info os.FileInfo, err error) error { |
522 | | - if err != nil { |
523 | | - log.Printf("walk error on %s: %v", p, err) |
524 | | - return err |
525 | | - } |
526 | | - if info.IsDir() { |
527 | | - return watcher.Add(p) |
528 | | - } |
529 | | - return nil |
530 | | - }) |
531 | | - if err != nil { |
532 | | - log.Fatalf("failed to initialize watcher: %v", err) |
533 | | - } |
534 | | - |
535 | | - // Block forever; exit on signal |
536 | | - handleSignals(func() { |
537 | | - watcher.Close() |
538 | | - }) |
539 | | - |
540 | | - <-done |
541 | | -} |
542 | | - |
543 | 377 | func handleSignals(onTerm func()) { |
544 | 378 | sig := make(chan os.Signal, 1) |
545 | 379 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) |
@@ -764,27 +598,19 @@ Usage: |
764 | 598 |
|
765 | 599 | Commands: |
766 | 600 | new Create a new project from the getting-started repo |
767 | | - build Build code from an app folder (with optional watch mode) |
768 | | - run Build then run the app (Go supported) |
769 | | - extract Run a client binary and capture its startup POST payload |
| 601 | + build Build code from an app folder |
| 602 | + extract Run app binary and capture its startup POST payload |
770 | 603 |
|
771 | 604 | Run 'polycode <command> -h' for more details. |
772 | 605 |
|
773 | 606 | Examples: |
774 | 607 | # Create a new project |
775 | 608 | polycode new myapp -language go |
776 | | - cd myapp |
777 | | - polycode build . |
778 | | - go run ./app |
779 | 609 |
|
780 | 610 | # Build in-place |
781 | | - polycode build ./myapp -language go -out ./myapp/app |
782 | | - polycode build ./myapp -watch |
783 | | -
|
784 | | - # Run (build + binary + execute) |
785 | | - polycode run ./myapp |
| 611 | + polycode build ./myapp |
786 | 612 |
|
787 | 613 | # Extract startup metadata from an app binary |
788 | | - polycode extract ./bin/myclient -out ./meta.json -callback http://localhost:8080/hook -cwd ./sandbox |
| 614 | + polycode extract ./myapp/app |
789 | 615 | `) |
790 | 616 | } |
0 commit comments