@md-lark-converter/cli 1.0.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/index.js ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ import { program } from 'commander';
3
+ import chalk from 'chalk';
4
+ import { readFileSync, existsSync, writeFileSync } from 'fs';
5
+ import { fileURLToPath } from 'url';
6
+ import { dirname } from 'path';
7
+ import { MarkdownToLarkConverter, generateHtml } from '@md-lark-converter/core';
8
+ import { writeHtmlToClipboard } from '@md-lark-converter/core/node';
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+ program
12
+ .name('md-to-lark')
13
+ .description('Convert Markdown to Lark (飞书) clipboard format')
14
+ .version('1.0.0')
15
+ .argument('[input]', 'Input markdown file path or stdin')
16
+ .option('-o, --output <file>', 'Output JSON file path')
17
+ .option('--stdin', 'Read from stdin')
18
+ .option('--copy', 'Copy to system clipboard directly')
19
+ .option('--verbose', 'Show detailed output')
20
+ .action((input, options) => {
21
+ run(input, options);
22
+ });
23
+ async function run(input, options) {
24
+ try {
25
+ let markdown = '';
26
+ // Read input
27
+ if (options.stdin) {
28
+ if (options.verbose) {
29
+ console.log(chalk.yellow('Reading from stdin...'));
30
+ }
31
+ markdown = await readStdin();
32
+ }
33
+ else if (input) {
34
+ if (options.verbose) {
35
+ console.log(chalk.yellow(`Reading from file: ${input}`));
36
+ }
37
+ if (!existsSync(input)) {
38
+ console.error(chalk.red(`Error: File not found: ${input}`));
39
+ process.exit(1);
40
+ }
41
+ markdown = readFileSync(input, 'utf-8');
42
+ }
43
+ else {
44
+ console.error(chalk.red('Error: Please provide input file or use --stdin'));
45
+ program.help();
46
+ process.exit(1);
47
+ }
48
+ // Convert
49
+ if (options.verbose) {
50
+ console.log(chalk.yellow('Converting markdown to Lark format...'));
51
+ }
52
+ const converter = new MarkdownToLarkConverter();
53
+ const result = await converter.convert(markdown);
54
+ // Output
55
+ if (options.output) {
56
+ writeFileSync(options.output, JSON.stringify(result, null, 2), 'utf-8');
57
+ if (options.verbose) {
58
+ console.log(chalk.green(`✓ Output written to: ${options.output}`));
59
+ }
60
+ }
61
+ else if (options.copy) {
62
+ // 使用 core 包的 generateHtml 函数
63
+ const html = generateHtml(result);
64
+ try {
65
+ // 尝试写入富文本格式
66
+ await writeHtmlToClipboard(html);
67
+ if (options.verbose) {
68
+ console.log(chalk.green('✓ Copied rich text to clipboard! Paste directly to Lark document'));
69
+ }
70
+ else {
71
+ console.log(chalk.green('✓ Copied to clipboard!'));
72
+ }
73
+ }
74
+ catch (htmlError) {
75
+ // 如果富文本失败,显示错误信息
76
+ if (options.verbose) {
77
+ console.warn(chalk.yellow('⚠ Rich text copy failed, HTML content printed below:'));
78
+ console.warn(chalk.dim(htmlError.message));
79
+ }
80
+ else {
81
+ console.warn(chalk.yellow('⚠ Rich text clipboard not supported on this platform'));
82
+ }
83
+ // 输出 HTML 到控制台
84
+ console.log(html);
85
+ }
86
+ }
87
+ else {
88
+ // Default: pretty print
89
+ console.log(JSON.stringify(result, null, 2));
90
+ }
91
+ if (options.verbose) {
92
+ console.log(chalk.green('✓ Conversion completed successfully!'));
93
+ }
94
+ }
95
+ catch (error) {
96
+ console.error(chalk.red('Error:'), error.message);
97
+ if (options.verbose) {
98
+ console.error(error.stack);
99
+ }
100
+ process.exit(1);
101
+ }
102
+ }
103
+ function readStdin() {
104
+ return new Promise((resolve, reject) => {
105
+ let data = '';
106
+ process.stdin.setEncoding('utf-8');
107
+ process.stdin.on('data', (chunk) => {
108
+ data += chunk;
109
+ });
110
+ process.stdin.on('end', () => {
111
+ resolve(data);
112
+ });
113
+ process.stdin.on('error', reject);
114
+ });
115
+ }
116
+ program.parse();
117
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CA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C,CAAC,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;QAC7D,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAE,KAAe,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YACzC,IAAI,IAAI,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,OAAO,CAAC,KAAK,EAAE,CAAC"}
package/index.ts ADDED
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from 'commander';
4
+ import chalk from 'chalk';
5
+ import { readFileSync, existsSync, writeFileSync } from 'fs';
6
+ import { fileURLToPath } from 'url';
7
+ import { dirname } from 'path';
8
+ import { MarkdownToLarkConverter, generateHtml } from '@md-lark-converter/core';
9
+ import { writeHtmlToClipboard } from '@md-lark-converter/core/node';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+
14
+ interface Options {
15
+ output?: string;
16
+ stdin?: boolean;
17
+ copy?: boolean;
18
+ verbose?: boolean;
19
+ }
20
+
21
+ program
22
+ .name('md-to-lark')
23
+ .description('Convert Markdown to Lark (飞书) clipboard format')
24
+ .version('1.0.0')
25
+ .argument('[input]', 'Input markdown file path or stdin')
26
+ .option('-o, --output <file>', 'Output JSON file path')
27
+ .option('--stdin', 'Read from stdin')
28
+ .option('--copy', 'Copy to system clipboard directly')
29
+ .option('--verbose', 'Show detailed output')
30
+ .action((input: string, options: Options) => {
31
+ run(input, options);
32
+ });
33
+
34
+ async function run(input: string, options: Options): Promise<void> {
35
+ try {
36
+ let markdown = '';
37
+
38
+ // Read input
39
+ if (options.stdin) {
40
+ if (options.verbose) {
41
+ console.log(chalk.yellow('Reading from stdin...'));
42
+ }
43
+ markdown = await readStdin();
44
+ } else if (input) {
45
+ if (options.verbose) {
46
+ console.log(chalk.yellow(`Reading from file: ${input}`));
47
+ }
48
+ if (!existsSync(input)) {
49
+ console.error(chalk.red(`Error: File not found: ${input}`));
50
+ process.exit(1);
51
+ }
52
+ markdown = readFileSync(input, 'utf-8');
53
+ } else {
54
+ console.error(chalk.red('Error: Please provide input file or use --stdin'));
55
+ program.help();
56
+ process.exit(1);
57
+ }
58
+
59
+ // Convert
60
+ if (options.verbose) {
61
+ console.log(chalk.yellow('Converting markdown to Lark format...'));
62
+ }
63
+ const converter = new MarkdownToLarkConverter();
64
+ const result = await converter.convert(markdown);
65
+
66
+ // Output
67
+ if (options.output) {
68
+ writeFileSync(options.output, JSON.stringify(result, null, 2), 'utf-8');
69
+ if (options.verbose) {
70
+ console.log(chalk.green(`✓ Output written to: ${options.output}`));
71
+ }
72
+ } else if (options.copy) {
73
+ // 使用 core 包的 generateHtml 函数
74
+ const html = generateHtml(result);
75
+
76
+ try {
77
+ // 尝试写入富文本格式
78
+ await writeHtmlToClipboard(html);
79
+ if (options.verbose) {
80
+ console.log(chalk.green('✓ Copied rich text to clipboard! Paste directly to Lark document'));
81
+ } else {
82
+ console.log(chalk.green('✓ Copied to clipboard!'));
83
+ }
84
+ } catch (htmlError) {
85
+ // 如果富文本失败,显示错误信息
86
+ if (options.verbose) {
87
+ console.warn(chalk.yellow('⚠ Rich text copy failed, HTML content printed below:'));
88
+ console.warn(chalk.dim((htmlError as Error).message));
89
+ } else {
90
+ console.warn(chalk.yellow('⚠ Rich text clipboard not supported on this platform'));
91
+ }
92
+ // 输出 HTML 到控制台
93
+ console.log(html);
94
+ }
95
+ } else {
96
+ // Default: pretty print
97
+ console.log(JSON.stringify(result, null, 2));
98
+ }
99
+
100
+ if (options.verbose) {
101
+ console.log(chalk.green('✓ Conversion completed successfully!'));
102
+ }
103
+ } catch (error) {
104
+ console.error(chalk.red('Error:'), (error as Error).message);
105
+ if (options.verbose) {
106
+ console.error((error as Error).stack);
107
+ }
108
+ process.exit(1);
109
+ }
110
+ }
111
+
112
+ function readStdin(): Promise<string> {
113
+ return new Promise((resolve, reject) => {
114
+ let data = '';
115
+ process.stdin.setEncoding('utf-8');
116
+ process.stdin.on('data', (chunk: string) => {
117
+ data += chunk;
118
+ });
119
+ process.stdin.on('end', () => {
120
+ resolve(data);
121
+ });
122
+ process.stdin.on('error', reject);
123
+ });
124
+ }
125
+
126
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@md-lark-converter/cli",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool for converting Markdown to Lark",
5
+ "type": "module",
6
+ "bin": {
7
+ "md-to-lark": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "tsc --watch",
12
+ "start": "node dist/index.js"
13
+ },
14
+ "keywords": [
15
+ "markdown",
16
+ "lark",
17
+ "feishu",
18
+ "cli",
19
+ "converter"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/iceprosurface/md-lark-converter.git",
24
+ "directory": "packages/cli"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/iceprosurface/md-lark-converter/issues"
28
+ },
29
+ "homepage": "https://github.com/iceprosurface/md-lark-converter#readme",
30
+ "author": "icepro",
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "@md-lark-converter/core": "workspace:*",
34
+ "chalk": "^5.0.0",
35
+ "commander": "^12.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^20.19.28",
39
+ "typescript": "^5.0.0"
40
+ }
41
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "lib": ["ES2022"],
6
+ "moduleResolution": "bundler",
7
+ "outDir": "./dist",
8
+ "rootDir": "./",
9
+ "declaration": false,
10
+ "sourceMap": true,
11
+ "strict": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "allowSyntheticDefaultImports": true,
16
+ "resolveJsonModule": true,
17
+ "moduleDetection": "force"
18
+ },
19
+ "include": ["index.ts"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }