#!/usr/bin/env node
/**
* Check publishing status for NPM and Docker Hub
* Usage: node scripts/check-publish-status.js [version]
*/
import { execSync } from "child_process";
// Use native fetch in Node.js 18+
const PACKAGE_NAME = "mcp-wordpress";
const DOCKER_IMAGE = "docdyhr/mcp-wordpress";
async function checkNPM(version) {
console.log("\nπ¦ Checking NPM Publishing Status...\n");
try {
// Get latest version from NPM
const npmVersion = execSync(`npm view ${PACKAGE_NAME} version`, {
encoding: "utf-8",
}).trim();
console.log(`β
Latest NPM version: ${npmVersion}`);
// Check specific version if provided
if (version) {
try {
execSync(`npm view ${PACKAGE_NAME}@${version} version`, {
encoding: "utf-8",
});
console.log(`β
Version ${version} exists on NPM`);
} catch {
console.log(`β Version ${version} NOT found on NPM`);
return false;
}
}
// Get publish time
const publishTime = execSync(`npm view ${PACKAGE_NAME} time.${version || npmVersion}`, {
encoding: "utf-8",
}).trim();
console.log(`π
Published at: ${new Date(publishTime).toLocaleString()}`);
console.log(`π NPM URL: https://www.npmjs.com/package/${PACKAGE_NAME}`);
return true;
} catch (error) {
console.error("β Failed to check NPM:", error.message);
return false;
}
}
async function checkDockerHub(version) {
console.log("\nπ³ Checking Docker Hub Publishing Status...\n");
try {
// Fetch tags from Docker Hub API
const response = await fetch(`https://hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags?page_size=50`);
const data = await response.json();
if (!data.results) {
throw new Error("No tags found");
}
// Get latest tag info
const latestTag = data.results.find((tag) => tag.name === "latest");
if (latestTag) {
console.log(`β
Latest tag updated: ${new Date(latestTag.last_updated).toLocaleString()}`);
}
// Check specific version if provided
if (version) {
const versionTag = data.results.find((tag) => tag.name === version || tag.name === `v${version}`);
if (versionTag) {
console.log(`β
Version ${versionTag.name} exists on Docker Hub`);
console.log(`π
Published at: ${new Date(versionTag.last_updated).toLocaleString()}`);
} else {
console.log(`β Version ${version} NOT found on Docker Hub`);
return false;
}
}
// List all available tags
console.log("\nπ Available Docker tags:");
data.results.slice(0, 10).forEach((tag) => {
console.log(` - ${tag.name} (${new Date(tag.last_updated).toLocaleDateString()})`);
});
console.log(`\nπ Docker Hub URL: https://hub.docker.com/r/${DOCKER_IMAGE}/tags`);
return true;
} catch (error) {
console.error("β Failed to check Docker Hub:", error.message);
return false;
}
}
async function checkGitHubRelease(version) {
console.log("\nπ Checking GitHub Release Status...\n");
try {
const releases = execSync("gh release list --limit=5", {
encoding: "utf-8",
});
console.log("π Recent GitHub releases:");
console.log(releases);
if (version) {
try {
const releaseInfo = execSync(`gh release view v${version} --json tagName,publishedAt,url`, {
encoding: "utf-8",
});
const release = JSON.parse(releaseInfo);
console.log(`β
GitHub release v${version} exists`);
console.log(`π
Published at: ${new Date(release.publishedAt).toLocaleString()}`);
console.log(`π Release URL: ${release.url}`);
} catch {
console.log(`β GitHub release v${version} NOT found`);
return false;
}
}
return true;
} catch (error) {
console.error("β Failed to check GitHub releases:", error.message);
return false;
}
}
async function main() {
const version = process.argv[2];
console.log("π MCP WordPress Publishing Status Check");
console.log("========================================");
if (version) {
console.log(`\nChecking for version: ${version}`);
}
const npmOk = await checkNPM(version);
const dockerOk = await checkDockerHub(version);
const githubOk = await checkGitHubRelease(version);
console.log("\nπ Summary\n" + "=".repeat(40));
console.log(`NPM Publishing: ${npmOk ? "β
Success" : "β Failed"}`);
console.log(`Docker Hub: ${dockerOk ? "β
Success" : "β Failed"}`);
console.log(`GitHub Release: ${githubOk ? "β
Success" : "β Failed"}`);
if (!npmOk || !dockerOk) {
console.log("\nβ οΈ Some publishing targets failed!");
process.exit(1);
} else {
console.log("\nβ
All publishing targets successful!");
}
}
main().catch(console.error);