diff --git a/Examples/LocalDebugging/Shared/Package.swift b/Examples/LocalDebugging/Shared/Package.swift index 2ac36e03..12d5eb9f 100644 --- a/Examples/LocalDebugging/Shared/Package.swift +++ b/Examples/LocalDebugging/Shared/Package.swift @@ -10,6 +10,12 @@ let package = Package( ], dependencies: [], targets: [ - .target(name: "Shared", dependencies: []) + .target( + name: "Shared", + dependencies: [], + resources: [ + .process("Resources") + ] + ) ] ) diff --git a/Examples/LocalDebugging/Shared/Sources/Shared/Resources/test.json b/Examples/LocalDebugging/Shared/Sources/Shared/Resources/test.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/Examples/LocalDebugging/Shared/Sources/Shared/Resources/test.json @@ -0,0 +1 @@ +{} diff --git a/Plugins/AWSLambdaPackager/Plugin.swift b/Plugins/AWSLambdaPackager/Plugin.swift index 4359ab1d..f342c770 100644 --- a/Plugins/AWSLambdaPackager/Plugin.swift +++ b/Plugins/AWSLambdaPackager/Plugin.swift @@ -133,14 +133,12 @@ struct AWSLambdaPackager: CommandPlugin { // because Examples' Package.swift have a dependency on ../.. // just like Package.swift's examples assume ../.., we assume we are two levels below the root project let slice = packageDirectory.pathComponents.suffix(2) - let beforeLastComponent = packageDirectory.pathComponents[slice.startIndex] - let lastComponent = packageDirectory.pathComponents[slice.endIndex - 1] try Utils.execute( executable: dockerToolPath, arguments: [ "run", "--rm", "--env", "LAMBDA_USE_LOCAL_DEPS=true", "-v", "\(packageDirectory.path())../..:/workspace", "-w", - "/workspace/\(beforeLastComponent)/\(lastComponent)", baseImage, "bash", "-cl", buildCommand, + "/workspace/\(slice.joined(separator: "/"))", baseImage, "bash", "-cl", buildCommand, ], logLevel: verboseLogging ? .debug : .output ) @@ -237,17 +235,26 @@ struct AWSLambdaPackager: CommandPlugin { // add resources var artifactPathComponents = artifactPath.pathComponents - _ = artifactPathComponents.removeLast() - let artifactDirectory = artifactPathComponents.joined(separator: "/") - let resourcesDirectoryName = "\(packageName)_\(product.name).resources" - let resourcesDirectory = artifactDirectory.appending(resourcesDirectoryName) - let relocatedResourcesDirectory = workingDirectory.appending(path: resourcesDirectoryName) - if FileManager.default.fileExists(atPath: resourcesDirectory) { - try FileManager.default.copyItem( - atPath: resourcesDirectory, - toPath: relocatedResourcesDirectory.path() - ) - arguments.append(resourcesDirectoryName) + _ = artifactPathComponents.removeFirst() // Get rid of beginning "/" + _ = artifactPathComponents.removeLast() // Get rid of the name of the package + let artifactDirectory = "/\(artifactPathComponents.joined(separator: "/"))" + for fileInArtifactDirectory in try FileManager.default.contentsOfDirectory(atPath: artifactDirectory) { + guard let artifactURL = URL(string: "\(artifactDirectory)/\(fileInArtifactDirectory)") else { + continue + } + + guard artifactURL.pathExtension == "resources" else { + continue // Not resources, so don't copy + } + let resourcesDirectoryName = artifactURL.lastPathComponent + let relocatedResourcesDirectory = workingDirectory.appending(path: resourcesDirectoryName) + if FileManager.default.fileExists(atPath: artifactURL.path()) { + try FileManager.default.copyItem( + atPath: artifactURL.path(), + toPath: relocatedResourcesDirectory.path() + ) + arguments.append(resourcesDirectoryName) + } } // run the zip tool