1
0
Fork 0

Add --monorepo-config CLI mode for unified multi-package generation

This commit is contained in:
Brendan Szymanski 2026-07-01 20:35:56 -04:00
parent 944b7cf670
commit 58aef1a5d4

View file

@ -17,6 +17,51 @@ struct SwiftGtkGenCLI {
return return
} }
if !args.monorepoConfigTOML.isEmpty {
guard FileManager.default.fileExists(atPath: args.monorepoConfigTOML) else {
print("Error: monorepo config file not found: \(args.monorepoConfigTOML)")
exit(1)
}
do {
let tomlContent = try String(contentsOfFile: args.monorepoConfigTOML, encoding: .utf8)
let toml = try TOMLReader.parse(tomlContent)
let monorepoConfig = try MonorepoConfig.from(toml: toml, defaultOutputDir: args.output)
let monorepoAnalyzer = MultiPackageAnalyzer(config: monorepoConfig)
let analysis = try monorepoAnalyzer.analyze()
let generator = CodeGenerator(config: GenerationConfig(
library: "", version: "", girsDirectories: [],
targetDirectory: "", externalLibraries: [],
generate: [], manual: [], ignore: [], objects: []
))
let outputs = try generator.generateMonorepo(analysis: analysis)
for (moduleName, sourceFiles) in outputs {
let sourcesDir = URL(fileURLWithPath: monorepoConfig.outputDir)
.appendingPathComponent("Sources/\(moduleName)/Generated")
try FileManager.default.createDirectory(at: sourcesDir, withIntermediateDirectories: true)
for (fileName, content) in sourceFiles.sorted(by: { $0.key < $1.key }) {
let fileURL = sourcesDir.appendingPathComponent(fileName)
try content.write(to: fileURL, atomically: true, encoding: .utf8)
print("Generated \(fileURL.path)")
}
}
let scaffolding = CodeGenerator.generateMonorepoScaffolding(analysis: analysis)
let outputRoot = URL(fileURLWithPath: monorepoConfig.outputDir)
for (relativePath, content) in scaffolding.sorted(by: { $0.key < $1.key }) {
let fileURL = outputRoot.appendingPathComponent(relativePath)
try FileManager.default.createDirectory(at: fileURL.deletingLastPathComponent(), withIntermediateDirectories: true)
try content.write(to: fileURL, atomically: true, encoding: .utf8)
print("Generated \(fileURL.path)")
}
} catch {
print("Error: \(error)")
exit(1)
}
return
}
guard !args.girFile.isEmpty else { guard !args.girFile.isEmpty else {
print("Error: --gir-file is required") print("Error: --gir-file is required")
exit(1) exit(1)
@ -133,6 +178,7 @@ struct SwiftGtkGenCLI {
var generateAll: Bool = false var generateAll: Bool = false
var manual: [String] = [] var manual: [String] = []
var ignore: [String] = [] var ignore: [String] = []
var monorepoConfigTOML: String = ""
} }
/// Parses command-line arguments. /// Parses command-line arguments.
@ -191,6 +237,9 @@ struct SwiftGtkGenCLI {
case "--ignore": case "--ignore":
guard let val = nextArg(&args, for: flag) else { return CLIArgs(showHelp: true, girFile: "") } guard let val = nextArg(&args, for: flag) else { return CLIArgs(showHelp: true, girFile: "") }
cli.ignore = val.components(separatedBy: ",") cli.ignore = val.components(separatedBy: ",")
case "--monorepo-config":
guard let val = nextArg(&args, for: flag) else { return CLIArgs(showHelp: true, girFile: "") }
cli.monorepoConfigTOML = val
default: default:
break break
} }
@ -292,6 +341,7 @@ struct SwiftGtkGenCLI {
print(" --manual TYPES Comma-separated types to mark manual") print(" --manual TYPES Comma-separated types to mark manual")
print(" --ignore TYPES Comma-separated types to ignore") print(" --ignore TYPES Comma-separated types to ignore")
print(" --emit-single-file Emit a single file instead of per-type files") print(" --emit-single-file Emit a single file instead of per-type files")
print(" --monorepo-config PATH Generate a monorepo using this TOML config")
print(" --help, -h Show this help") print(" --help, -h Show this help")
} }
} }