@shikijs/cli 3.21.0 → 3.23.0
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/dist/cli.mjs +40 -5
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import '@shikijs/vscode-textmate';
|
|
|
7
7
|
import 'ansis';
|
|
8
8
|
import 'shiki';
|
|
9
9
|
|
|
10
|
-
const version = "3.
|
|
10
|
+
const version = "3.23.0";
|
|
11
11
|
|
|
12
12
|
function isUrl(path) {
|
|
13
13
|
return path.startsWith("http://") || path.startsWith("https://");
|
|
@@ -15,7 +15,7 @@ function isUrl(path) {
|
|
|
15
15
|
function getExtFromUrl(url) {
|
|
16
16
|
try {
|
|
17
17
|
const pathname = new URL(url).pathname;
|
|
18
|
-
return parse(pathname).ext.slice(1);
|
|
18
|
+
return parse(pathname).ext.slice(1).toLowerCase();
|
|
19
19
|
} catch {
|
|
20
20
|
return "";
|
|
21
21
|
}
|
|
@@ -31,18 +31,53 @@ async function readSource(path) {
|
|
|
31
31
|
return { content, ext };
|
|
32
32
|
} else {
|
|
33
33
|
const content = await fs.readFile(path, "utf-8");
|
|
34
|
-
const ext = parse(path).ext.slice(1);
|
|
34
|
+
const ext = parse(path).ext.slice(1).toLowerCase();
|
|
35
35
|
return { content, ext };
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
async function run(argv = process.argv, log = console.log) {
|
|
39
39
|
const cli = cac("shiki");
|
|
40
|
-
cli.option("--theme <theme>", "Color theme to use", { default: "vitesse-dark" }).option("--lang <lang>", "Programming language").option("--format <format>", "Output format (ansi, html)", { default: "ansi" }).help().version(version);
|
|
40
|
+
cli.option("--theme <theme>", "Color theme to use", { default: "vitesse-dark" }).option("--lang <lang>", "Programming language").option("--format <format>", "Output format (ansi, html)", { default: "ansi" }).option("--list-themes", "List all available themes").option("--list-langs", "List all available languages").help().version(version);
|
|
41
41
|
const { options, args } = cli.parse(argv);
|
|
42
|
+
if (options.listThemes) {
|
|
43
|
+
const { bundledThemes } = await import('shiki');
|
|
44
|
+
for (const theme of Object.keys(bundledThemes))
|
|
45
|
+
log(theme);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (options.listLangs) {
|
|
49
|
+
const { bundledLanguages } = await import('shiki');
|
|
50
|
+
for (const lang of Object.keys(bundledLanguages))
|
|
51
|
+
log(lang);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
42
54
|
const files = args;
|
|
55
|
+
if (files.length === 0) {
|
|
56
|
+
if (!process.stdin.isTTY) {
|
|
57
|
+
const content = await new Promise((resolve, reject) => {
|
|
58
|
+
let data = "";
|
|
59
|
+
process.stdin.on("data", (chunk) => data += chunk);
|
|
60
|
+
process.stdin.on("end", () => resolve(data));
|
|
61
|
+
process.stdin.on("error", reject);
|
|
62
|
+
});
|
|
63
|
+
const lang = options.lang || "text";
|
|
64
|
+
if (options.format === "html") {
|
|
65
|
+
const { codeToHtml } = await import('shiki');
|
|
66
|
+
log(await codeToHtml(content, {
|
|
67
|
+
lang,
|
|
68
|
+
theme: options.theme
|
|
69
|
+
}));
|
|
70
|
+
} else {
|
|
71
|
+
log(await codeToANSI(content, lang, options.theme));
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
cli.outputHelp();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
43
78
|
const codes = await Promise.all(files.map(async (path) => {
|
|
44
79
|
const { content, ext } = await readSource(path);
|
|
45
|
-
const lang = options.lang || ext;
|
|
80
|
+
const lang = (options.lang || ext).toLowerCase();
|
|
46
81
|
if (options.format === "html") {
|
|
47
82
|
const { codeToHtml } = await import('shiki');
|
|
48
83
|
return await codeToHtml(content, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.23.0",
|
|
5
5
|
"description": "Shiki in the command line",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@shikijs/vscode-textmate": "^10.0.2",
|
|
40
40
|
"ansis": "^4.2.0",
|
|
41
41
|
"cac": "^6.7.14",
|
|
42
|
-
"shiki": "3.
|
|
42
|
+
"shiki": "3.23.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "unbuild",
|