Skip to content

Commit

Permalink
[chore] Renamed to XConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhenry committed Nov 2, 2022
1 parent 1e594b1 commit 0ad5d7f
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 59 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions .pre-commit.config.yaml

This file was deleted.

40 changes: 40 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# file options

--exclude Tests/XCTestManifests.swift,DerivedData

# format options

--allman false
--binarygrouping 4,8
--commas always
--comments indent
--decimalgrouping 3,6
--elseposition same-line
--empty void
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--header strip
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef indent
--indent 4
--indentcase false
--importgrouping testable-bottom
--linebreaks lf
--maxwidth none
--octalgrouping 4,8
--operatorfunc spaced
--patternlet hoist
--ranges spaced
--self remove
--semicolons inline
--stripunusedargs always
--swiftversion 5.5
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve

# rules

--enable isEmpty
Empty file added Gemfile
Empty file.
35 changes: 31 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,39 @@
"object": {
"pins": [
{
"package": "SwiftSyntax",
"repositoryURL": "https://github.com/apple/swift-syntax.git",
"package": "CombineCocoa",
"repositoryURL": "https://github.com/CombineCommunity/CombineCocoa",
"state": {
"branch": null,
"revision": "75e60475d9d8fd5bbc16a12e0eaa2cb01b0c322e",
"version": "0.50500.0"
"revision": "4e262c2f9fb1cee1cb3be5717f7e6b55eb823971",
"version": "0.4.0"
}
},
{
"package": "CombineExt",
"repositoryURL": "https://github.com/CombineCommunity/CombineExt",
"state": {
"branch": null,
"revision": "aaf1a0981c05360000af972473034cb952be4ca0",
"version": "1.8.0"
}
},
{
"package": "Highlightr",
"repositoryURL": "https://github.com/raspu/Highlightr",
"state": {
"branch": null,
"revision": "93199b9e434f04bda956a613af8f571933f9f037",
"version": "2.1.2"
}
},
{
"package": "Prettier_swift",
"repositoryURL": "https://github.com/michaelhenry/Prettier.swift",
"state": {
"branch": null,
"revision": "d6e2197469a2d9a9c5f0a9302bb28e155586d36d",
"version": "1.1.1"
}
}
]
Expand Down
30 changes: 18 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@
import PackageDescription

let package = Package(
name: "FeatureFlag",
name: "XConfigs",
platforms: [
.iOS(.v13),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "FeatureFlag",
targets: ["FeatureFlag"]),
name: "XConfigs",
targets: ["XConfigs"]
),
],
dependencies: [
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .exact("0.50500.0")),
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/CombineCommunity/CombineExt", .upToNextMinor(from: "1.8.0")),
.package(url: "https://github.com/CombineCommunity/CombineCocoa", .upToNextMinor(from: "0.4.0")),
.package(url: "https://github.com/michaelhenry/Prettier.swift", .upToNextMajor(from: "1.1.1")),
.package(url: "https://github.com/raspu/Highlightr", from: "2.1.2"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "FeatureFlag",
name: "XConfigs",
dependencies: [
"SwiftSyntax",
]),
.testTarget(
name: "FeatureFlagTests",
dependencies: ["FeatureFlag"]),
.product(name: "CombineExt", package: "CombineExt"),
.product(name: "CombineCocoa", package: "CombineCocoa"),
.product(name: "Prettier_swift", package: "Prettier.swift"),
.product(name: "Highlightr", package: "Highlightr"),
]
),
]
)
77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
# FeatureFlag
<h1 align="center">🛠Configs</h1>
<p align="center">A quick, easy and elegant solution for your remote and dev configuration.</p>
<p align="center">
<a href="https://codecov.io/gh/michaelhenry/XConfigs"><img alt="codecov" src="https://codecov.io/gh/michaelhenry/XConfigs/branch/main/graph/badge.svg?token=WLH8VVA19I"/></a>
<a href="https://github.com/michaelhenry/XConfigs/actions"><img alt="test" src="https://github.com/michaelhenry/XConfigs/workflows/test/badge.svg"></a>
<a href="https://github.com/michaelhenry/XConfigs/releases/latest"><img alt="release" src="https://img.shields.io/github/v/release/michaelhenry/XConfigs.svg"/></a>
<a href="https://developer.apple.com/swift"><img alt="Swift5" src="https://img.shields.io/badge/language-Swift5-orange.svg"></a>
<a href="https://developer.apple.com"><img alt="Platform" src="https://img.shields.io/badge/platform-iOS-green.svg"></a>
<a href="LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-black.svg"></a>
</p>

A description of this package.
---

- [Introduction](#introduction)
- [Getting Started](#getting-started)
- [Example](#example)
- [Other Related](#other-related)
- [License](#license)

---

## Introduction

As part of software development process, we always need to see how our app will react depending on the different scenarios or configurations especially during testing. At the same time, it would be better if we can control some of app configurations on the fly, especially if there are unexpected things happened in our production environment, we can immediately enable or disable certain app functionality.

## Getting Started

Install using SPM

```swift
.package(url: "https://github.com/michaelhenry/XConfigs", .upToNextMinor(from: "1.0.0")),
```

## Example

Similar with logger tool such as [swift-log](https://github.com/apple/swift-log), You can simply create a single global variable or just a singleton, as long as the it conforms to [XConfigSpec](Sources/XConfigs/Protocols/XConfigsSpec.swift) and then use the `@XConfig` property wrapper inside it.

If you have some custom datatype, you can simply conform them to `RawStringValueRepresentable`.

```swift
struct MockConfigs: XConfigSpec {

@XConfig(key: "isOnboardingEnabled", defaultValue: false)
var isOnboardingEnabled: Bool

@XConfig(key: "apiURL", defaultValue: URL(string: "https://google.com")!)
var apiURL: URL

@XConfig(key: "region", defaultValue: .north)
var region: Region

@XConfig(key: "maxRetry", defaultValue: 10)
var maxRetry: Int

@XConfig(key: "threshold", defaultValue: 1)
var threshold: Int

@XConfig(key: "rate", defaultValue: 2.5)
var rate: Double
}

enum Region: String, CaseIterable, RawStringValueRepresentable {
case north
case south
case east
case west
}
```

## Other Related

- [Firebase Remote Config](https://firebase.google.com/docs/remote-config), you can simply backed [XConfigs](https://github.com/michaelhenry/XConfigs) by FirebaseRemoteConfig by simply implmenting [KeyValueProvider](Sources/XConfigs/Protocols/KeyValueProvider.swift) protocol.

## LICENSE

MIT
31 changes: 0 additions & 31 deletions Tests/FeatureFlagTests/FeatureFlagTests.swift

This file was deleted.

5 changes: 5 additions & 0 deletions setup-swiftformat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
brew install swiftformat && \
npm install --global git-format-staged && \
echo '#!/bin/bash\ngit-format-staged --formatter "swiftformat stdin --stdinpath \x27{}\x27" "*.swift"' > '.git/hooks/pre-commit' && \
chmod +x .git/hooks/pre-commit && \
git config --global core.hooksPath '~/.githooks'

0 comments on commit 0ad5d7f

Please sign in to comment.