Skip to content

Commit 80390fb

Browse files
committed
Release 0.0.1
0 parents  commit 80390fb

18 files changed

Lines changed: 619 additions & 0 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Examples Test
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
workflow_dispatch:
8+
9+
jobs:
10+
ExamplesTest:
11+
name: Run `ExamplesTest.sh`
12+
strategy:
13+
matrix:
14+
os:
15+
- macOS-latest
16+
- ubuntu-latest
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
- run: brew install swift-sh
21+
- run: sh ./Scripts/ExamplesTest.sh

.github/workflows/danger.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: SwiftLint
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
# .swiftファイルが変更にない場合は実行しない
7+
paths:
8+
- '**.swift'
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Danger
16+
uses: docker://ghcr.io/danger/danger-swift-with-swiftlint:3.12.3
17+
with:
18+
args: --failOnErrors --no-publish-check
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/swift.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: swift test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test-on-mac:
11+
name: Test on macOS
12+
strategy:
13+
matrix:
14+
xcode-version:
15+
- /Applications/Xcode_13.2.1.app
16+
- /Applications/Xcode_12.5.1.app
17+
runs-on: macOS-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- run: sudo xcode-select -s "${{ matrix.xcode-version }}"
21+
- run: swift --version
22+
- run: swift test
23+
24+
test-on-ubuntu:
25+
name: Test on Ubuntu
26+
strategy:
27+
matrix:
28+
swift-version: ["5.3", "5.4", "5.5"]
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Setup swiftenv
33+
run: |
34+
git clone https://github.com/kylef/swiftenv.git ~/.swiftenv
35+
export SWIFTENV_ROOT="$HOME/.swiftenv"
36+
export PATH="$SWIFTENV_ROOT/bin:$PATH"
37+
eval "$(swiftenv init -)"
38+
echo "$PATH" >> $GITHUB_PATH
39+
- name: Install Swift
40+
run: swiftenv install "${{ matrix.swift-version }}" --skip-existing
41+
- run: swift --version
42+
- run: swift test --enable-test-discovery

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc
10+
.swiftpm

.swiftlint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
included:
2+
- Sources/
3+
- Tests/
4+
- Package.swift

Examples/echo.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/swift sh
2+
3+
import ScriptSwift // KS1019/Script.swift ~> main
4+
5+
Script()
6+
.exec(#"echo "testing""#)
7+
.stdout()

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Kotaro Suto
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.resolved

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// swift-tools-version:5.3
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "Script.swift",
8+
products: [
9+
// Products define the executables and libraries a package produces, and make them visible to other packages.
10+
.library(
11+
name: "ScriptSwift",
12+
targets: ["ScriptSwift"])
13+
],
14+
dependencies: [
15+
// Dependencies declare other packages that this package depends on.
16+
// .package(url: /* package url */, from: "1.0.0"),
17+
.package(url: "https://github.com/JohnSundell/ShellOut.git", from: "2.0.0"),
18+
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0")
19+
],
20+
targets: [
21+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
22+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
23+
.target(
24+
name: "ScriptSwift",
25+
dependencies: ["ShellOut", "Files"]),
26+
.testTarget(
27+
name: "ScriptSwiftTests",
28+
dependencies: ["ScriptSwift"])
29+
]
30+
)

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Script.swift
2+
Script.swift is a small library that lets you write a Swift script with ease by using method chaining, inspired by [bitfield/script](https://github.com/bitfield/script).
3+
4+
## Install
5+
**Via Swift Package Manager**
6+
7+
Add this line in `dependencies` of your `Package.swift`.
8+
```swift
9+
.package(url: "https://github.com/KS1019/Script.swift", from: "0.0.1")
10+
```
11+
12+
**Via [`swift-sh`](https://github.com/mxcl/swift-sh)**
13+
14+
Add this line at the top of your Swift script. Refer to swift-sh documentation for more details.
15+
```swift
16+
import ScriptSwift // KS1019/Script.swift ~> 0.0.1
17+
```
18+
## Usage
19+
20+
| Method | Contents |
21+
| ------ | -------- |
22+
| `exec` | Executes commands |
23+
| `ifExists` | Continues only if a file exists |
24+
| `write` | Writes data to a file |
25+
| `read` | Reads data from a file |
26+
| `countLines` | Returns the number of lines |
27+
| `concat` | Returns an array of string representation of files |
28+
| `asArray` | Returns lines of a string as an array |
29+
30+
See [documentation](https://ks1019.github.io/Script.swift/documentation/ScriptSwift/) for more details.
31+
32+
### Using `Script.swift` with [`swift-sh`](https://github.com/mxcl/swift-sh)
33+
When you want a script, you typically want it in a single file. With usual setup using Swift Package Manager to interact with external libraries, you would end up a directory with `Package.swift`, which is bit much as a script.
34+
35+
By using `swift-sh`, you only have to take care of a single Swift file for your script, which makes your Swift script as portable as possible.
36+
## Examples
37+
<table>
38+
<thead>
39+
<tr>
40+
<th>Source</th>
41+
<th>Script</th>
42+
</tr>
43+
</thead>
44+
<tbody>
45+
<tr>
46+
<td>
47+
48+
[`echo.swift`](https://github.com/KS1019/Script.swift/Examples/echo.swift)
49+
50+
</td>
51+
<td>
52+
53+
```swift
54+
Script()
55+
.exec(#"echo "testing""#)
56+
.stdout()
57+
```
58+
59+
</td>
60+
61+
</tr>
62+
</tbody>
63+
</table>
64+
65+
## Acknowledgements
66+
- [JohnSundell/Files](https://github.com/johnsundell/files)
67+
- [JohnSundell/ShellOut](https://github.com/johnsundell/shellout)
68+
- [mxcl/swift-sh](https://github.com/mxcl/swift-sh)
69+
- [bitfield/script](https://github.com/bitfield/script)

0 commit comments

Comments
 (0)