Skip to content

Commit

Permalink
feat: add clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Oct 15, 2024
1 parent b3bf096 commit 0f219b8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bin/clean.js
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',
]);

39 changes: 39 additions & 0 deletions lib/exec.js
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 };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test:default": "RUST_BACKTRACE=1 node bin/test.js $(which oxlint)",
"update": "node bin/update.js",
"reset": "node bin/reset.js",
"clean": "node bin/clean.js",
"lint": "npx oxlint@latest ."
}
}

0 comments on commit 0f219b8

Please sign in to comment.