@@ -44,6 +44,7 @@ public final class InitPackage {
44
44
case library = " library "
45
45
case executable = " executable "
46
46
case tool = " tool "
47
+ case buildToolPlugin = " build-tool-plugin "
47
48
case commandPlugin = " command-plugin "
48
49
case macro = " macro "
49
50
@@ -271,6 +272,14 @@ public final class InitPackage {
271
272
]),
272
273
]
273
274
"""
275
+ } else if packageType == . buildToolPlugin {
276
+ param += """
277
+ .plugin(
278
+ name: " \( typeName) " ,
279
+ capability: .buildTool()
280
+ ),
281
+ ]
282
+ """
274
283
} else if packageType == . commandPlugin {
275
284
param += """
276
285
.plugin(
@@ -362,7 +371,7 @@ public final class InitPackage {
362
371
363
372
private func writePlugins( ) throws {
364
373
switch packageType {
365
- case . commandPlugin:
374
+ case . buildToolPlugin , . commandPlugin:
366
375
let plugins = destinationPath. appending ( component: " Plugins " )
367
376
guard self . fileSystem. exists ( plugins) == false else {
368
377
return
@@ -376,16 +385,30 @@ public final class InitPackage {
376
385
let sourceFileName = " plugin.swift "
377
386
let sourceFile = try AbsolutePath ( validating: sourceFileName, relativeTo: moduleDir)
378
387
379
- let content = """
388
+ var content = """
380
389
import PackagePlugin
381
390
382
391
@main
383
- struct \( typeName) : CommandPlugin {
384
- func performCommand(context: PluginContext, arguments: [String]) async throws {
385
- print( " Hello, World! " )
392
+ """
393
+ if packageType == . buildToolPlugin {
394
+ content += """
395
+ struct \( typeName) : BuildToolPlugin {
396
+ func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
397
+ print( " Hello, World! " )
398
+ return []
399
+ }
386
400
}
387
- }
388
- """
401
+ """
402
+ }
403
+ else {
404
+ content += """
405
+ struct \( typeName) : CommandPlugin {
406
+ func performCommand(context: PluginContext, arguments: [String]) async throws {
407
+ print( " Hello, World! " )
408
+ }
409
+ }
410
+ """
411
+ }
389
412
390
413
try writePackageFile ( sourceFile) { stream in
391
414
stream. write ( content)
@@ -397,7 +420,7 @@ public final class InitPackage {
397
420
}
398
421
399
422
private func writeSources( ) throws {
400
- if packageType == . empty || packageType == . commandPlugin {
423
+ if packageType == . empty || packageType == . buildToolPlugin || packageType == . commandPlugin {
401
424
return
402
425
}
403
426
@@ -473,7 +496,7 @@ public final class InitPackage {
473
496
public macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: " \( moduleName) Macros " , type: " StringifyMacro " )
474
497
"""
475
498
476
- case . empty, . commandPlugin:
499
+ case . empty, . buildToolPlugin , . commandPlugin:
477
500
throw InternalError ( " invalid packageType \( packageType) " )
478
501
}
479
502
@@ -489,7 +512,7 @@ public final class InitPackage {
489
512
490
513
private func writeTests( ) throws {
491
514
switch packageType {
492
- case . empty, . executable, . tool, . commandPlugin: return
515
+ case . empty, . executable, . tool, . buildToolPlugin , . commandPlugin: return
493
516
default : break
494
517
}
495
518
let tests = destinationPath. appending ( " Tests " )
@@ -635,7 +658,7 @@ public final class InitPackage {
635
658
636
659
let testClassFile = try AbsolutePath ( validating: " \( moduleName) Tests.swift " , relativeTo: testModule)
637
660
switch packageType {
638
- case . empty, . commandPlugin, . executable, . tool: break
661
+ case . empty, . buildToolPlugin , . commandPlugin, . executable, . tool: break
639
662
case . library:
640
663
try writeLibraryTestsFile ( testClassFile)
641
664
case . macro:
0 commit comments