Skip to content

Commit 43c80d8

Browse files
committed
feat: copy result to clipboard
1 parent 2d790c4 commit 43c80d8

File tree

5 files changed

+142
-8
lines changed

5 files changed

+142
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"vitest": "^1.3.1"
4848
},
4949
"dependencies": {
50+
"clipboardy": "^2.3.0",
5051
"commander": "^12.0.0",
5152
"picocolors": "^1.1.1"
5253
}

pnpm-lock.yaml

Lines changed: 128 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/handleOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function handleOptions(options: Options) {
2121
let outputString = result
2222
if (fileExistSync(options.output!)) {
2323
// appending mode
24-
outputString = '\n' + result
24+
outputString = '\n```\n' + result + '```'
2525
}
2626
fs.appendFile(options.output!, outputString, (err) => {
2727
if (err) throw err

src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
import { program } from 'commander'
4+
import clipboard from 'clipboardy'
45
import { toTree } from './toTree'
56
import { generate } from './generate'
67
import pkg from '../package.json'
@@ -27,14 +28,21 @@ program
2728
'-o, --output <output>',
2829
'export content into a file, appending mode by default'
2930
)
31+
.option('-c, --clipboard', 'copy the output to clipboard')
3032
.parse(process.argv)
3133

3234
const options = handleOptions(program.opts() as Options)
3335

3436
const root = toTree(options)
3537
const result = generate(root.children, options)
3638

37-
onExits.forEach((onExit) => onExit(result))
39+
onExits.forEach((fn) => fn(result))
3840

39-
console.log(root.path)
40-
console.log(result)
41+
if (options.clipboard) {
42+
clipboard.writeSync(result)
43+
}
44+
45+
if (!options.output && !options.clipboard) {
46+
console.log(root.path)
47+
console.log(result)
48+
}

src/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface Options {
77
layer?: number
88
icon?: boolean
99
output?: string
10+
clipboard?: boolean
1011
}
1112

1213
export interface TreeNode {

0 commit comments

Comments
 (0)