mutating func run()

in FishyTransport/Sources/FishyActorsGenerator/main.swift [35:66]


  mutating func run() throws {
    // Step 1: Analyze all files looking for `distributed actor` decls
    let analysis = Analysis(sourceDirectory: sourceDirectory, verbose: verbose)
    analysis.run()

    // Optimization: If nothing changed since our last run, just return

    // Step 2: Source generate necessary bits for every decl
    if verbose {
      print("Generate extensions...")
    }

    let sourceGen = SourceGen(buckets: buckets)
    
    // TODO: Don't do this
    // Just make sure all "buckets" exist (don't remove this
    // until you can honor the requested ammount of buckets)
    for i in (0..<buckets) {
      let path = targetFilePath(targetDirectory: targetDirectory, i: i)
      try! "".write(to: path, atomically: true, encoding: .utf8)
    }
    
    for decl in analysis.decls {
      let source = try sourceGen.generate(decl: decl)
      let filePath = targetFilePath(targetDirectory: targetDirectory, i: source.bucket)
      if verbose {
        print("  Generated 'FishyActorTransport' extensions for 'distributed actor \(decl.name)' -> \(filePath)")
      }
      
      try source.text.write(to: filePath, atomically: true, encoding: .utf8)
    }
  }