@kokiito0926/oneshot 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +22 -1
  2. package/index.js +8 -7
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,27 @@
1
1
  ## oneshot
2
2
 
3
- oneshotは、パイプから流し込まれたHTMLをブラウザで表示できるコマンドラインのツールです。
3
+ oneshotは、標準入力から流し込まれたHTMLをブラウザで表示できるコマンドラインのツールです。
4
+ Expressのサーバーを一時的に立ち上げ、ブラウザがページを読み込むと同時にサーバーを終了します。
5
+
6
+ ## インストール
7
+
8
+ ```bash
9
+ $ npm install --global @kokiito0926/oneshot
10
+ ```
11
+
12
+ ## 使用方法
13
+
14
+ curlのコマンドでHTMLを取得して、ブラウザで一時的に確認することもできます。
15
+
16
+ ```bash
17
+ $ curl -sSL https://example.com/ | oneshot
18
+ ```
19
+
20
+ --portのオプションを用いれば、ポート番号を変更することができます。
21
+
22
+ ```bash
23
+ $ cat example.html | oneshot --port 8080
24
+ ```
4
25
 
5
26
  ## ライセンス
6
27
 
package/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // >> $ curl -sSL https://example.com/ | ./index.js
4
4
 
5
5
  import open from "open";
6
- import { stdin } from "zx";
6
+ import { stdin, argv } from "zx";
7
7
  import express from "express";
8
8
 
9
9
  if (process.stdin.isTTY) {
@@ -15,19 +15,20 @@ if (!html) {
15
15
  process.exit(1);
16
16
  }
17
17
 
18
+ const port = argv.port || 3000;
19
+
18
20
  const app = express();
19
- const server = app.listen(3000, async () => {
20
- const port = server.address().port;
21
+ const server = app.listen(port, async () => {
21
22
  const url = `http://localhost:${port}`;
22
23
 
23
24
  app.get("/", (req, res) => {
24
- res.send(html);
25
-
26
- setTimeout(() => {
25
+ res.on("finish", () => {
27
26
  server.close(() => {
28
27
  process.exit(0);
29
28
  });
30
- }, 300);
29
+ });
30
+
31
+ res.send(html);
31
32
  });
32
33
 
33
34
  await open(url);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@kokiito0926/oneshot",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "private": false,
5
- "description": "パイプから流し込まれたHTMLをブラウザで表示できるコマンドラインのツールです。",
5
+ "description": "標準入力から流し込まれたHTMLをブラウザで表示できるコマンドラインのツールです。",
6
6
  "keywords": [
7
7
  "cli",
8
8
  "bash",