Skip to content

Commit c4b20b8

Browse files
authored
fix: move files to new folders (#5)
Move the source file into `Sources/PluginName` and tests into `Tests/PluginNameTests` as configured in the `Package.swift` closes #1
1 parent 1fd6888 commit c4b20b8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Sources/cap2spm.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct Cap2SPM: ParsableCommand {
5151
guard let capPlugin = capacitorPluginPackage.oldPlugin?.capacitorPlugin else { return }
5252

5353
try modifySwiftFile(at: swiftFileURL, plugin: capPlugin)
54+
try moveItemCreatingIntermediaryDirectories(at: swiftFileURL, to: capacitorPluginPackage.iosSrcDirectoryURL.appending(path: "Sources").appending(path: capPlugin.identifier).appending(path: swiftFileURL.lastPathComponent))
55+
try moveItemCreatingIntermediaryDirectories(at: capacitorPluginPackage.iosSrcDirectoryURL.appending(path: "PluginTests"), to: capacitorPluginPackage.iosSrcDirectoryURL.appending(path: "Tests").appending(path: "\(capPlugin.identifier)Tests"))
5456
try generatePackageSwiftFile(at: packageSwiftFileURL, plugin: capPlugin)
5557

5658
let fileList = [mFileURL, hFileURL]
@@ -102,4 +104,13 @@ struct Cap2SPM: ParsableCommand {
102104

103105
try packageFileString.write(to: packageFileURL, atomically: true, encoding: .utf8)
104106
}
107+
108+
private func moveItemCreatingIntermediaryDirectories(at: URL, to: URL) throws {
109+
print("Moving \(at.path()) to \(to.path())...")
110+
let parentPath = to.deletingLastPathComponent()
111+
if !FileManager.default.fileExists(atPath: parentPath.path) {
112+
try FileManager.default.createDirectory(at: parentPath, withIntermediateDirectories: true, attributes: nil)
113+
}
114+
try FileManager.default.moveItem(at: at, to: to)
115+
}
105116
}

0 commit comments

Comments
 (0)