@kokiito0926/fmeditor 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.
- package/README.md +9 -4
- package/index.js +61 -34
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
## fmeditor
|
|
2
2
|
|
|
3
3
|
fmeditorは、フロントマターを編集することができるコマンドラインのツールです。
|
|
4
|
-
|
|
4
|
+
マークダウンを標準入力から受け取り、コマンドライン引数に従って、フロントマターを編集します。
|
|
5
5
|
|
|
6
6
|
## インストール
|
|
7
7
|
|
|
@@ -11,14 +11,19 @@ $ npm install --global @kokiito0926/fmeditor
|
|
|
11
11
|
|
|
12
12
|
## 使用方法
|
|
13
13
|
|
|
14
|
-
curlなどで取得したマークダウンをパイプでfmeditorに流し込みます。
|
|
14
|
+
curlなどで取得したマークダウンをパイプでfmeditorに流し込みます。
|
|
15
|
+
そうすると、コマンドライン引数の値がセットされたフロントマターとともにマークダウンが出力されます。
|
|
15
16
|
|
|
16
17
|
```bash
|
|
17
|
-
$ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | fmeditor --draft
|
|
18
|
+
$ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | fmeditor get --title --tags --draft
|
|
18
19
|
```
|
|
19
20
|
|
|
20
21
|
```bash
|
|
21
|
-
$ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | fmeditor --tags '["markdown", "frontmatter", "yaml"]'
|
|
22
|
+
$ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | fmeditor set --tags '["markdown", "frontmatter", "yaml"]'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
$ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | fmeditor remove --title --tags
|
|
22
27
|
```
|
|
23
28
|
|
|
24
29
|
## ライセンス
|
package/index.js
CHANGED
|
@@ -1,34 +1,61 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// >> $ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | ./index.js --draft
|
|
4
|
-
// >> $ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | ./index.js --tags '["markdown", "frontmatter", "yaml"]'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// >> $ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | ./index.js get --title --tags --draft
|
|
4
|
+
// >> $ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | ./index.js set --tags '["markdown", "frontmatter", "yaml"]'
|
|
5
|
+
// >> $ curl -fsSL https://raw.githubusercontent.com/Kernix13/markdown-cheatsheet/refs/heads/master/frontmatter.md | ./index.js remove --title --tags
|
|
6
|
+
|
|
7
|
+
import { stdin, argv } from "zx";
|
|
8
|
+
import matter from "gray-matter";
|
|
9
|
+
import yaml from "js-yaml";
|
|
10
|
+
|
|
11
|
+
if (process.stdin.isTTY) {
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const input = await stdin();
|
|
16
|
+
if (!input) {
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { _, ...flags } = argv;
|
|
21
|
+
const command = _[0] || "set";
|
|
22
|
+
|
|
23
|
+
if (command === "set") {
|
|
24
|
+
const processedData = {};
|
|
25
|
+
for (const [key, value] of Object.entries(flags)) {
|
|
26
|
+
try {
|
|
27
|
+
processedData[key] = JSON.parse(value);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
processedData[key] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const doc = matter(input);
|
|
34
|
+
|
|
35
|
+
doc.data = { ...doc.data, ...processedData };
|
|
36
|
+
|
|
37
|
+
const text = matter.stringify(doc.content, doc.data);
|
|
38
|
+
console.log(text);
|
|
39
|
+
} else if (command === "get") {
|
|
40
|
+
const doc = matter(input);
|
|
41
|
+
|
|
42
|
+
const keys = Object.keys(flags);
|
|
43
|
+
if (keys.length === 0) {
|
|
44
|
+
console.log(yaml.dump(doc.data));
|
|
45
|
+
} else {
|
|
46
|
+
const result = {};
|
|
47
|
+
keys.forEach((k) => {
|
|
48
|
+
if (k in doc.data) result[k] = doc.data[k];
|
|
49
|
+
});
|
|
50
|
+
console.log(yaml.dump(result));
|
|
51
|
+
}
|
|
52
|
+
} else if (command === "remove") {
|
|
53
|
+
const doc = matter(input);
|
|
54
|
+
|
|
55
|
+
Object.keys(flags).forEach((k) => {
|
|
56
|
+
delete doc.data[k];
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const text = matter.stringify(doc.content, doc.data);
|
|
60
|
+
console.log(text);
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokiito0926/fmeditor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "フロントマターを編集することができるコマンドラインのツールです。",
|
|
6
6
|
"keywords": [
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"test": "node --test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"gray-matter": "^4.0.3",
|
|
38
|
+
"js-yaml": "^4.1.1",
|
|
39
|
+
"zx": "^8.8.4"
|
|
39
40
|
},
|
|
40
41
|
"engines": {
|
|
41
42
|
"node": ">=24.0.0"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|