-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5e03888
Showing
16 changed files
with
556 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: npm | ||
|
||
env: | ||
DENO_VERSION: 1.x | ||
NODE_VERSION: 16.x | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: denoland/setup-deno@main | ||
with: | ||
deno-version: ${{ env.DENO_VERSION }} | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Build | ||
run: make build-npm | ||
- name: Publish | ||
run: | | ||
cd npm | ||
npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Test | ||
|
||
env: | ||
DENO_VERSION: 1.x | ||
|
||
on: | ||
schedule: | ||
- cron: "0 7 * * 0" | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: denoland/setup-deno@main | ||
with: | ||
deno-version: ${{ env.DENO_VERSION }} | ||
- name: Lint | ||
run: make lint | ||
|
||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: denoland/setup-deno@main | ||
with: | ||
deno-version: ${{ env.DENO_VERSION }} | ||
- name: Format | ||
run: make fmt-check | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: denoland/setup-deno@main | ||
with: | ||
deno-version: ${{ env.DENO_VERSION }} | ||
- name: Test | ||
run: make test | ||
timeout-minutes: 5 | ||
|
||
typecheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: denoland/setup-deno@main | ||
with: | ||
deno-version: ${{ env.DENO_VERSION }} | ||
- name: Type check | ||
run: make type-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Update | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
udd: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: "1.x" | ||
- name: Update dependencies | ||
run: | | ||
make deps > ../output.txt | ||
env: | ||
NO_COLOR: 1 | ||
- name: Read ../output.txt | ||
id: log | ||
uses: juliangruber/read-file-action@v1 | ||
with: | ||
path: ../output.txt | ||
- name: Commit changes | ||
run: | | ||
git config user.name '${{ github.actor }}' | ||
git config user.email '${{ github.actor }}@users.noreply.github.com' | ||
git commit -a -F- <<EOM | ||
:package: Update Deno dependencies | ||
Update dependencies by udd: | ||
${{ steps.log.outputs.content }} | ||
EOM | ||
- uses: peter-evans/create-pull-request@v3 | ||
with: | ||
title: ":package: Update Deno dependencies" | ||
body: | | ||
The output of `make update` is | ||
``` | ||
${{ steps.log.outputs.content }} | ||
``` | ||
labels: automation | ||
branch: automation/update-dependencies | ||
delete-branch: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright 2022 Fixpoint, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
TARGETS := $$(find . \( -name '*.ts' -or -name '*.md' \) -not -path './npm/*' -not -path './scripts/*' -not -path './example/*') | ||
VERSION := $$(git describe --tags --always --dirty) | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
help: | ||
@cat $(MAKEFILE_LIST) | \ | ||
perl -ne 'print if /^\w+.*##/;' | \ | ||
perl -pe 's/(.*):.*##\s*/sprintf("%-20s",$$1)/eg;' | ||
|
||
fmt: FORCE ## Format code | ||
@deno fmt ${TARGETS} | ||
|
||
fmt-check: FORCE ## Format check | ||
@deno fmt --check ${TARGETS} | ||
|
||
lint: FORCE ## Lint code | ||
@deno lint ${TARGETS} | ||
|
||
type-check: FORCE ## Type check | ||
@deno test --unstable --no-run ${TARGETS} | ||
|
||
test: FORCE ## Test | ||
@deno test --unstable -A ${TARGETS} | ||
|
||
deps: FORCE ## Update dependencies | ||
@deno run -A https://deno.land/x/[email protected]/main.ts ${TARGETS} | ||
@make fmt | ||
|
||
build-npm: FORCE ## Build npm package | ||
@deno run -A scripts/build_npm.ts ${VERSION} | ||
|
||
FORCE: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# replutil | ||
|
||
[![npm](http://img.shields.io/badge/available%20on-npm-lightgrey.svg?logo=npm&logoColor=white)](https://www.npmjs.com/package/replutil) | ||
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/replutil) | ||
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/replutil/mod.ts) | ||
[![Test](https://github.com/lambdalisue/deno-replutil/workflows/Test/badge.svg)](https://github.com/lambdalisue/deno-replutil/actions?query=workflow%3ATest) | ||
[![npm version](https://badge.fury.io/js/replutil.svg)](https://badge.fury.io/js/replutil) | ||
|
||
REPL (Read-eval-print loop) utilities. | ||
|
||
## Usage | ||
|
||
Use `Sender` to send message to REPL and `Receiver` to receive message from | ||
REPL. | ||
|
||
##### SSH | ||
|
||
```typescript | ||
import { Receiver, Sender } from "../mod.ts"; | ||
|
||
const proc = Deno.run({ | ||
cmd: ["ssh", "-tt", "localhost", "/bin/sh"], | ||
stdin: "piped", | ||
stdout: "piped", | ||
}); | ||
const receiver = new Receiver(proc.stdout); | ||
const sender = new Sender(proc.stdin); | ||
const prompt = /.*\$ $/; | ||
await receiver.wait(prompt); | ||
await sender.send("ls -al\n"); | ||
const received = await receiver.recv(prompt); | ||
await sender.send("exit\n"); | ||
await proc.status(); | ||
proc.close(); | ||
|
||
console.log("-".repeat(80)); | ||
console.log(received); | ||
console.log("-".repeat(80)); | ||
``` | ||
|
||
##### Telnet | ||
|
||
```typescript | ||
import { Receiver, Sender } from "../mod.ts"; | ||
|
||
const username = "johntitor"; | ||
const password = "steinsgate"; | ||
|
||
const proc = Deno.run({ | ||
cmd: ["telnet", "localhost"], | ||
stdin: "piped", | ||
stdout: "piped", | ||
}); | ||
const receiver = new Receiver(proc.stdout); | ||
const sender = new Sender(proc.stdin); | ||
|
||
await receiver.wait(/login: $/); | ||
await sender.send(`${username}\n`); | ||
|
||
await receiver.wait(/Password:$/); | ||
await sender.send(`${password}\n`); | ||
|
||
const prompt = /.* % /; | ||
await receiver.wait(prompt); | ||
await sender.send("ls -al\n"); | ||
const received = await receiver.recv(prompt); | ||
await sender.send("exit\n"); | ||
await proc.status(); | ||
proc.close(); | ||
|
||
console.log("-".repeat(80)); | ||
console.log(received); | ||
console.log("-".repeat(80)); | ||
``` | ||
|
||
## Development | ||
|
||
Lint code like: | ||
|
||
```text | ||
make lint | ||
``` | ||
|
||
Format code like | ||
|
||
```text | ||
make fmt | ||
``` | ||
|
||
Check types like | ||
|
||
```text | ||
make type-check | ||
``` | ||
|
||
Run tests like: | ||
|
||
```text | ||
make test | ||
``` | ||
|
||
## License | ||
|
||
The code follows MIT license written in [LICENSE](./LICENSE). Contributors need | ||
to agree that any modifications sent in this repository follow the license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
export * as io from "https://deno.land/[email protected]/io/mod.ts"; | ||
export { delay } from "https://deno.land/[email protected]/async/mod.ts"; | ||
export * as streams from "https://deno.land/[email protected]/streams/mod.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Receiver, Sender } from "../mod.ts"; | ||
|
||
const proc = Deno.run({ | ||
cmd: ["ssh", "-tt", "localhost", "/bin/sh"], | ||
stdin: "piped", | ||
stdout: "piped", | ||
}); | ||
const receiver = new Receiver(proc.stdout); | ||
const sender = new Sender(proc.stdin); | ||
const prompt = /.*\$ $/; | ||
await receiver.wait(prompt); | ||
await sender.send("ls -al\n"); | ||
const received = await receiver.recv(prompt); | ||
await sender.send("exit\n"); | ||
await proc.status(); | ||
proc.close(); | ||
|
||
console.log("-".repeat(80)); | ||
console.log(received); | ||
console.log("-".repeat(80)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Receiver, Sender } from "../mod.ts"; | ||
|
||
const username = "johntitor"; | ||
const password = "steinsgate"; | ||
|
||
const proc = Deno.run({ | ||
cmd: ["telnet", "localhost"], | ||
stdin: "piped", | ||
stdout: "piped", | ||
}); | ||
const receiver = new Receiver(proc.stdout); | ||
const sender = new Sender(proc.stdin); | ||
|
||
await receiver.wait(/login: $/); | ||
await sender.send(`${username}\n`); | ||
|
||
await receiver.wait(/Password:$/); | ||
await sender.send(`${password}\n`); | ||
|
||
const prompt = /.* % /; | ||
await receiver.wait(prompt); | ||
await sender.send("ls -al\n"); | ||
const received = await receiver.recv(prompt); | ||
await sender.send("exit\n"); | ||
await proc.status(); | ||
proc.close(); | ||
|
||
console.log("-".repeat(80)); | ||
console.log(received); | ||
console.log("-".repeat(80)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./receiver.ts"; | ||
export * from "./sender.ts"; |
Oops, something went wrong.