Last active
April 19, 2019 15:03
-
-
Save Skitionek/9db395016195864aa18efac5e312771f to your computer and use it in GitHub Desktop.
Add Github markdown links to tree output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require('child_process'); | |
const args = process.argv.slice(2); | |
const child = spawn('tree',['-f', '--', args[0] || '.']); | |
child.stdout.setEncoding('utf8'); | |
child.stdout.on('data', (chunk) => { | |
const lines = chunk.split(/\n/g).filter(line=>line!==''&&!line.match(/^\d/)); | |
lines.forEach(line=>console.log(line.replace(/([^ \n]*?)([^ /\n]*)$/,'[$2]($1$2)'))); | |
}); | |
/* | |
Replaces this: | |
```bash | |
> tree -- graphql | |
graphql | |
└── src | |
├── constants.js | |
└── index.js | |
2 directories, 2 files | |
``` | |
with this: | |
```bash | |
> node GitMarkdownTree.js graphql | |
[graphql](graphql) | |
└── [src](graphql/src) | |
└── [constants.js](graphql/src/constants.js) | |
└── [index.js](graphql/src/index.js) | |
``` | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Formats with backslashes.