Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
icanzilb committed Jun 15, 2022
1 parent 686fc1b commit 047f80e
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 2 deletions.
32 changes: 32 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// swift-tools-version: 5.7
import PackageDescription

let package = Package(
name: "DoNotDisturbPlugin",
platforms: [.macOS(.v12)],
products: [
.plugin(name: "DoNilDisturbPlugin", targets: ["DoNilDisturb"])
],
targets: [
// Your app or library
.executableTarget(
name: "MyApp",
plugins: [
.plugin(name: "DoNilDisturb")
]
),
// Your plugin's IMPLEMENTATION
.executableTarget(
name: "PluginBinary",
path: "PluginBinary"
),
// Your plugin's INTERFACE
.plugin(
name: "DoNilDisturb",
capability: .buildTool(),
dependencies: [
.target(name: "PluginBinary")
]
)
]
)
29 changes: 29 additions & 0 deletions PluginBinary/PluginBinary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Foundation

extension String: Error { }

@main class PluginBinary {
static func main() throws {
let outputURL = URL(fileURLWithPath: ProcessInfo.processInfo.arguments[1])
let content: String

if (9.0...18.0 ~= Date().time) { // Your 9-6 basically
// Working hours
content = "// All is good, do not disturb is off."
} else {
// DND
content = #"#error("Do not disturb is ON")"#
}

try content.write(to: outputURL, atomically: true, encoding: .utf8)
}
}

// https://stackoverflow.com/a/62616907/208205
// https://creativecommons.org/licenses/by-sa/4.0/
extension Date {
/// time returns a double for which the integer represents the hours from 1 to 24 and the decimal value represents the minutes.
var time: Double {
Double(Calendar.current.component(.hour, from: self)) + Double(Calendar.current.component(.minute, from: self)) / 100
}
}
19 changes: 19 additions & 0 deletions Plugins/DoNilDisturb/DoNotDisturbPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation
import PackagePlugin

@main
struct DoNilDisturb: BuildToolPlugin {

func createBuildCommands(context: PackagePlugin.PluginContext, target: PackagePlugin.Target) async throws -> [PackagePlugin.Command] {
let output = context.pluginWorkDirectory.appending(["DND.swift"])

return [
.buildCommand(
displayName: "Do Not Disturb",
executable: try context.tool(named: "PluginBinary").path,
arguments: [output.string],
outputFiles: [output]
)
]
}
}
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# DoNilDisturbPlugin
A plugin for your Xcode project that stops you from working outside work hours
# DoNilDisturb Swift Plugin

Use Xcode 14+ to make use of this amazing and novel Swift plugin in your package.

The plugin stops you from working on your 9-5 project outside of 9-5 hours:

![Project failing to compile with a message that do not disturb is on](etc/dnd.png)

Add this to your dependencies in your Package.swift:

```swift
.package(url: "https://github.com/icanzilb/DoNilDisturbPlugin.git", from: "0.0.1"),
```

**And then**, add the plugin in your target definition(still in Package.swift:

```swift
.target(
name: "MyTarget",
plugins: [
.plugin(name: "DoNilDisturbPlugin")
]
)
```

That's all. Your target will fail to build outside of working hours.

Enjoy your time off work.

## License

MIT, of course.
9 changes: 9 additions & 0 deletions Sources/MyApp/MyApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

@main
class MyApp {
static func main() throws {
print("My App runs!")
print("But it only builds during workng hours")
}
}
7 changes: 7 additions & 0 deletions Tests/DoNotDisturbPluginTests/DoNotDisturbPluginTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest
@testable import DoNotDisturbPlugin

final class DoNotDisturbPluginTests: XCTestCase {
func testExample() throws {
}
}
Binary file added etc/dnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 047f80e

Please sign in to comment.