@@ -27,7 +27,7 @@ struct AWSLambdaPackager: CommandPlugin {
27
27
}
28
28
29
29
// gather file paths
30
- let samDeploymentDescriptorFilePath = " \( context. package . directory) /sam.json "
30
+ let samDeploymentDescriptorFilePath = " \( context. package . directory) /sam.yaml "
31
31
32
32
let swiftExecutablePath = try self . findExecutable ( context: context,
33
33
executableName: " swift " ,
@@ -45,6 +45,7 @@ struct AWSLambdaPackager: CommandPlugin {
45
45
swiftExecutable: swiftExecutablePath,
46
46
samDeploymentDescriptorFilePath: samDeploymentDescriptorFilePath,
47
47
archivePath: configuration. archiveDirectory,
48
+ force: configuration. force,
48
49
verboseLogging: configuration. verboseLogging)
49
50
50
51
@@ -76,6 +77,7 @@ struct AWSLambdaPackager: CommandPlugin {
76
77
swiftExecutable: Path ,
77
78
samDeploymentDescriptorFilePath: String ,
78
79
archivePath: String ,
80
+ force: Bool ,
79
81
verboseLogging: Bool ) throws {
80
82
print ( " ------------------------------------------------------------------------- " )
81
83
print ( " Generating SAM deployment descriptor " )
@@ -131,10 +133,19 @@ struct AWSLambdaPackager: CommandPlugin {
131
133
// logLevel: configuration.verboseLogging ? .debug : .silent)
132
134
try FileManager . default. removeItem ( atPath: helperFilePath)
133
135
134
- // write the generated SAM deployment decsriptor to disk
135
- FileManager . default. createFile ( atPath: samDeploymentDescriptorFilePath,
136
- contents: samDeploymentDescriptor. data ( using: . utf8) )
137
- verboseLogging ? print ( " \( samDeploymentDescriptorFilePath) " ) : nil
136
+ // write the generated SAM deployment descriptor to disk
137
+ if FileManager . default. fileExists ( atPath: samDeploymentDescriptorFilePath) && !force {
138
+
139
+ print ( " SAM deployment descriptor already exists at " )
140
+ print ( " \( samDeploymentDescriptorFilePath) " )
141
+ print ( " use --force option to overwrite it. " )
142
+
143
+ } else {
144
+
145
+ FileManager . default. createFile ( atPath: samDeploymentDescriptorFilePath,
146
+ contents: samDeploymentDescriptor. data ( using: . utf8) )
147
+ verboseLogging ? print ( " Overwriting file at \( samDeploymentDescriptorFilePath) " ) : nil
148
+ }
138
149
139
150
} catch let error as DeployerPluginError {
140
151
print ( " Error while compiling Deploy.swift " )
@@ -271,23 +282,28 @@ REQUIREMENTS: To use this plugin, you must have an AWS account and have `sam` in
271
282
You can install sam with the following command:
272
283
(brew tap aws/tap && brew install aws-sam-cli)
273
284
274
- USAGE: swift package --disable-sandbox deploy [--help] [--verbose] [--nodeploy] [--configuration <configuration>] [--archive-path <archive_path>] [--stack-name <stack-name>]
285
+ USAGE: swift package --disable-sandbox deploy [--help] [--verbose]
286
+ [--archive-path <archive_path>]
287
+ [--configuration <configuration>]
288
+ [--force] [--nodeploy] [--nolist]
289
+ [--stack-name <stack-name>]
275
290
276
291
OPTIONS:
277
292
--verbose Produce verbose output for debugging.
278
- --nodeploy Generates the JSON deployment descriptor, but do not deploy.
279
- --configuration <configuration>
280
- Build for a specific configuration.
281
- Must be aligned with what was used to build and package.
282
- Valid values: [ debug, release ] (default: debug)
283
293
--archive-path <archive-path>
284
294
The path where the archive plugin created the ZIP archive.
285
295
Must be aligned with the value passed to archive --output-path.
286
296
(default: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager)
297
+ --configuration <configuration>
298
+ Build for a specific configuration.
299
+ Must be aligned with what was used to build and package.
300
+ Valid values: [ debug, release ] (default: debug)
301
+ --force Overwrites existing SAM deployment descriptor
302
+ --nodeploy Generates the JSON deployment descriptor, but do not deploy.
303
+ --nolist Do not list endpoints
287
304
--stack-name <stack-name>
288
305
The name of the CloudFormation stack when deploying.
289
306
(default: the project name)
290
- --nolist Do not list endpoints
291
307
--help Show help information.
292
308
""" )
293
309
}
@@ -298,6 +314,7 @@ private struct Configuration: CustomStringConvertible {
298
314
public let help : Bool
299
315
public let noDeploy : Bool
300
316
public let noList : Bool
317
+ public let force : Bool
301
318
public let verboseLogging : Bool
302
319
public let archiveDirectory : String
303
320
public let stackName : String
@@ -316,6 +333,7 @@ private struct Configuration: CustomStringConvertible {
316
333
let nodeployArgument = argumentExtractor. extractFlag ( named: " nodeploy " ) > 0
317
334
let verboseArgument = argumentExtractor. extractFlag ( named: " verbose " ) > 0
318
335
let noListArgument = argumentExtractor. extractFlag ( named: " nolist " ) > 0
336
+ let forceArgument = argumentExtractor. extractFlag ( named: " force " ) > 0
319
337
let configurationArgument = argumentExtractor. extractOption ( named: " configuration " )
320
338
let archiveDirectoryArgument = argumentExtractor. extractOption ( named: " archive-path " )
321
339
let stackNameArgument = argumentExtractor. extractOption ( named: " stackname " )
@@ -324,6 +342,9 @@ private struct Configuration: CustomStringConvertible {
324
342
// help required ?
325
343
self . help = helpArgument
326
344
345
+ // force overwrite the SAM deployment descriptor when it already exists
346
+ self . force = forceArgument
347
+
327
348
// define deployment option
328
349
self . noDeploy = nodeployArgument
329
350
@@ -358,7 +379,7 @@ private struct Configuration: CustomStringConvertible {
358
379
" invalid archive directory: \( self . archiveDirectory) \n the directory does not exists " )
359
380
}
360
381
361
- // infer or consume stackname
382
+ // infer or consume stack name
362
383
if let stackName = stackNameArgument. first {
363
384
self . stackName = stackName
364
385
} else {
0 commit comments