-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* @file clean.js | ||
* @summary prune remote and local branches, then run git garbage collection | ||
*/ | ||
const { execEachRepo } = require('../lib/exec'); | ||
|
||
execEachRepo([ | ||
'git fetch', | ||
'git remote prune origin', | ||
'git gc', | ||
]); | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const matrix = require("../matrix.json"); | ||
const assert = require("assert"); | ||
const { exec } = require("child_process"); | ||
const fs = require("fs"); | ||
|
||
const isStringArray = arr => | ||
Array.isArray(arr) && arr.every(i => typeof i === "string"); | ||
|
||
/** | ||
* Execute a command in each repository | ||
* @param {string | string[]} command the command to run. If an array, it will be joined with `&&`. | ||
*/ | ||
const execEachRepo = async command => { | ||
assert( | ||
typeof command === "string" || isStringArray(command), | ||
"cmd must be a string or array of strings" | ||
); | ||
const cmd = Array.isArray(command) ? command.join(" && ") : command; | ||
|
||
assert( | ||
fs.existsSync("repos"), | ||
"No repositories found, did you forget to run `pnpm clone`?" | ||
); | ||
|
||
for (const item of matrix) { | ||
const command = `cd repos/${item.path} && ${cmd}`; | ||
console.log(command); | ||
|
||
exec(command, function (err) { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
console.log(`Finished: ${item.repository}`); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { execEachRepo }; |
This file contains 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