@kokiito0926/fmeditor 0.0.1 → 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 +6 -2
- package/index.js +61 -34
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -15,11 +15,15 @@ curlなどで取得したマークダウンをパイプでfmeditorに流し込
|
|
|
15
15
|
そうすると、コマンドライン引数の値がセットされたフロントマターとともにマークダウンが出力されます。
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
$ 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
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
$ 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
|
|
23
27
|
```
|
|
24
28
|
|
|
25
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,8 +34,9 @@
|
|
|
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"
|