File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
packages/create-next-stack/src/scripts Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 1- // This script reads each line of stdin and outputs a JSON array of the lines.
2- // This is useful for passing a list of files to a command.
3- // Example usage: `ls | node file-list-to-array.ts`
1+ import { resolve } from "path"
2+
3+ /*
4+ This script reads each line of stdin and outputs a JSON array of the lines.
5+ This is useful for passing a list of files to a command.
6+ Example usage: `ls | node file-list-to-array.ts`
7+ */
8+
49let input = ""
510process . stdin . on ( "data" , ( data ) => {
611 input += data . toString ( )
712} )
813process . stdin . on ( "end" , ( ) => {
914 const filePaths = input . split ( "\n" ) . filter ( Boolean )
1015 const files = filePaths . map ( ( filePath ) => ( {
11- filePath : filePath ,
16+ filePath : filePath . replace ( resolve ( process . cwd ( ) ) + "/" , "" ) ,
1217 fileName : filePath . split ( "/" ) . pop ( ) ?. split ( "." ) [ 0 ] || filePath ,
1318 } ) )
1419 console . log ( JSON . stringify ( files ) )
You can’t perform that action at this time.
0 commit comments