Skip to content

Commit

Permalink
Add list-files command
Browse files Browse the repository at this point in the history
This is especially useful when piped to grep to find specific filenames
within all projects in the Rush workspace, in order to open those files
in your editor.
  • Loading branch information
Brandon Siegel committed May 8, 2019
1 parent 9ba2049 commit 10bd28a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/config/rush/command-line.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@
"summary": "Reset your workspace - !!DANGER!! unlink dependencies, purge downloaded node_modules, and remove all untracked files and directories",
"safeForSimultaneousRushProcesses": true,
"shellCommand": "rush unlink && echo \"\nStarting \\\"git clean\\\"\" && git clean -dfx && rush purge"
},
{
"commandKind": "global",
"name": "list-files",
"summary": "List files within Rush project directories",
"shellCommand": "node common/scripts/list-files.js"
}
],

Expand Down
35 changes: 35 additions & 0 deletions common/scripts/list-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require("fs");
const path = require("path");

function read(filename) {
const txt = fs
.readFileSync(filename, "utf8")
.replace(/\r/gm, "")
.replace(/\n/gm, "«")
.replace(/\/\*.*?\*\//gm, "")
.replace(/«/gm, "\n")
.replace(/\s+\/\/.*/g, "");
return JSON.parse(txt);
}

function walk(dir) {
var list = fs.readdirSync(dir);
for (const fileName of list) {
const filePath = path.join(dir, fileName);
if (fileName == "node_modules") {
continue;
}

const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
walk(filePath);
} else {
console.log(path.resolve(filePath));
}
}
}

const rush = read(`${__dirname}/../../rush.json`);
for (const each of rush.projects) {
walk(each.projectFolder);
}

0 comments on commit 10bd28a

Please sign in to comment.