-
Currently we can list all available scripts from a workspace by being in it with the command My question: Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I am using this script done in PowerShell through ChatGPT and saved as Here according to ChatGPT what script does:
And here is the script. # Define the output HTML file path
$outputHtml = "scripts_list.html"
# Initialize an array to hold the data
$scriptsData = @()
# Search for all package.json files in the current directory and subdirectories
$packageJsonFiles = Get-ChildItem -Recurse -Filter "package.json"
# Loop through each package.json file
foreach ($file in $packageJsonFiles) {
try {
# Read the JSON content of package.json
$jsonContent = Get-Content -Path $file.FullName | ConvertFrom-Json
# Check if scripts exist in package.json
if ($jsonContent.scripts) {
$scriptsData += [PSCustomObject]@{
Path = $file.DirectoryName
Scripts = $jsonContent.scripts.PSObject.Properties.Name
Commands = $jsonContent.scripts.PSObject.Properties.Name | ForEach-Object { "cd '$($file.DirectoryName)'; pnpm run $_" }
}
}
} catch {
Write-Warning "Could not parse JSON in file: $($file.FullName)"
}
}
# Convert the data to JSON format for filtering
$jsonOutput = $scriptsData | ConvertTo-Json -Depth 3
# Define the HTML template
$htmlContent = @"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scripts List</title>
<style>
body { font-family: Arial, sans-serif; }
input { margin: 20px 0; padding: 5px; width: 100%; font-size: 16px; }
pre { background-color: #f4f4f4; padding: 10px; border-radius: 5px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { padding: 8px 12px; border: 1px solid #ddd; }
th { background-color: #f2f2f2; }
button { padding: 5px 10px; background-color: #4CAF50; color: white; border: none; cursor: pointer; }
button:hover { background-color: #45a049; }
tr.selected { background-color: #e0f7fa; }
</style>
</head>
<body>
<h1>List of All Scripts</h1>
<input type="text" id="searchInput" onkeyup="filterScripts()" placeholder="Search for scripts.." autofocus tabindex="0">
<table tabindex="0">
<thead>
<tr>
<th>Path</th>
<th>Scripts</th>
<th>Run Command</th>
</tr>
</thead>
<tbody id="scriptsTable">
<!-- Rows will be inserted here -->
</tbody>
</table>
<script>
var scriptsData = $jsonOutput;
var selectedRow = -1; // No row selected initially
function populateTable(data) {
var tableBody = document.getElementById("scriptsTable");
tableBody.innerHTML = "";
data.forEach(function(item, rowIndex) {
item.Scripts.forEach(function(script, index) {
var row = document.createElement("tr");
// Path Cell
var pathCell = document.createElement("td");
pathCell.textContent = item.Path;
row.appendChild(pathCell);
// Scripts Cell
var scriptsCell = document.createElement("td");
scriptsCell.textContent = script;
row.appendChild(scriptsCell);
// Command Cell with Copy Button
var commandCell = document.createElement("td");
var command = item.Commands[index];
var button = document.createElement("button");
button.textContent = "Copy Command";
button.onclick = function() { copyToClipboard(command); };
var pre = document.createElement("pre");
pre.textContent = command;
commandCell.appendChild(pre);
commandCell.appendChild(button);
row.appendChild(commandCell);
row.tabIndex = 0; // Allow row to be focusable
row.onclick = function() { copyToClipboard(command); };
row.onkeydown = function(event) {
if (event.key === "Enter") {
copyToClipboard(command);
}
};
tableBody.appendChild(row);
});
});
}
function filterScripts() {
var input = document.getElementById("searchInput");
var filter = input.value.toLowerCase();
var filteredData = scriptsData.filter(function(item) {
return item.Scripts.some(function(script) {
return script.toLowerCase().includes(filter);
});
});
populateTable(filteredData);
selectedRow = -1; // Reset row selection when filter changes
}
function copyToClipboard(content) {
var tempInput = document.createElement("input");
document.body.appendChild(tempInput);
tempInput.value = content;
tempInput.select();
document.execCommand("copy");
document.body.removeChild(tempInput);
alert("Copied to clipboard: " + content);
}
function selectRow(index) {
var rows = document.querySelectorAll("tr");
rows.forEach(function(row, i) {
if (i === index) {
row.classList.add("selected");
} else {
row.classList.remove("selected");
}
});
}
// Keyboard navigation
document.addEventListener("keydown", function(event) {
var rows = document.querySelectorAll("tr");
if (event.key === "Tab") {
// If Tab is pressed, move to the first row after the filter
if (document.activeElement === document.getElementById("searchInput")) {
// Move focus to the first row
if (rows.length > 1) {
rows[1].focus();
}
} else {
selectedRow = (selectedRow + 1) % rows.length;
selectRow(selectedRow);
}
event.preventDefault(); // Prevent default tabbing behavior
} else if (event.key === "Enter") {
var commandCell = rows[selectedRow].querySelector("td button");
if (commandCell) {
commandCell.click(); // Trigger the copy command click event
}
}
});
// Initialize the table with all scripts
populateTable(scriptsData);
// Focus on the search input by default when page loads
document.getElementById("searchInput").focus();
</script>
</body>
</html>
"@
# Save the HTML content to a file
$htmlContent | Out-File -FilePath $outputHtml -Encoding UTF8
# Open the generated HTML file in the default browser
Start-Process $outputHtml
# Wait for a short time to ensure the browser has opened the file
Start-Sleep -Seconds 2
# Remove the HTML file after it's been opened
Remove-Item -Path $outputHtml -Force |
Beta Was this translation helpful? Give feedback.
-
late to the party, but it should be pretty easy if you have $ pnpm m -c exec "cat package.json | jq -r '\"\n--- \(.name) ---\n\(.scripts | keys | join(\"\n\"))\"'"
--- project name 1 ---
build
develop
start-mayhem |
Beta Was this translation helpful? Give feedback.
late to the party, but it should be pretty easy if you have
jq
: