myaidev-method
Version:
Comprehensive development framework with SPARC methodology for AI-assisted software development, multi-platform publishing (WordPress, PayloadCMS, Astro, Docusaurus, Mintlify), and Coolify deployment
206 lines (175 loc) • 5.08 kB
JavaScript
/**
* Mintlify Publishing Script
* Publish markdown content to Mintlify documentation
*/
import { StaticSiteUtils } from '../lib/static-site-utils.js';
const args = process.argv.slice(2);
const options = {
file: null,
projectPath: null,
navSection: null,
branch: 'main',
noPush: false,
commitMessage: null,
json: args.includes('--json'),
verbose: args.includes('--verbose') || args.includes('-v'),
dryRun: args.includes('--dry-run')
};
// Parse arguments
for (let i = 0; i < args.length; i++) {
switch (args[i]) {
case '--file':
case '-f':
options.file = args[++i];
break;
case '--nav-section':
case '-n':
options.navSection = args[++i];
break;
case '--project':
case '-p':
options.projectPath = args[++i];
break;
case '--branch':
case '-b':
options.branch = args[++i];
break;
case '--no-push':
options.noPush = true;
break;
case '--message':
case '-m':
options.commitMessage = args[++i];
break;
case '--help':
case '-h':
printHelp();
process.exit(0);
}
}
// If no file specified, check positional argument
if (!options.file && args.length > 0 && !args[0].startsWith('-')) {
options.file = args[0];
}
function printHelp() {
console.log(`
Mintlify Publishing Script
Usage: mintlify-publish [file] [options]
Arguments:
file Markdown/MDX file to publish (required)
Options:
--nav-section, -n <name> Add to navigation section in mint.json
--project, -p <path> Mintlify project path
--branch, -b <branch> Git branch to push to (default: main)
--no-push Commit but don't push to remote
--message, -m <msg> Custom commit message
--dry-run Validate without committing
--verbose, -v Show detailed progress
--json Output in JSON format
--help, -h Show this help
Examples:
# Publish documentation
mintlify-publish guide.mdx
# Add to specific navigation section
mintlify-publish api-reference.mdx --nav-section "API Reference"
# Custom project path
mintlify-publish article.mdx --project ./docs --branch develop
`);
}
async function publishContent() {
try {
// Validate required options
if (!options.file) {
console.error('Error: Markdown file is required');
console.error('Run with --help for usage information');
process.exit(1);
}
if (options.verbose) {
console.error('Initializing Mintlify publishing...');
}
const site = new StaticSiteUtils({
platform: 'mintlify',
projectPath: options.projectPath
});
if (options.verbose) {
console.error('✓ Mintlify project detected');
}
// Validate project
site.validateProject();
if (options.verbose) {
console.error('✓ Project structure validated');
}
// Dry run - validate only
if (options.dryRun) {
if (options.verbose) {
console.error('✓ Dry run - validation successful');
}
const output = {
success: true,
dryRun: true,
file: options.file,
platform: 'mintlify',
navSection: options.navSection
};
if (options.json) {
console.log(JSON.stringify(output, null, 2));
} else {
console.log('Dry run successful - ready to publish');
}
process.exit(0);
}
// Publish content
const result = await site.publishContent(options.file, {
navSection: options.navSection,
branch: options.branch,
noPush: options.noPush,
commitMessage: options.commitMessage
});
if (options.verbose) {
console.error(`✓ Content published successfully`);
}
// Prepare output
const output = {
success: true,
file: result.file,
platform: result.platform,
git: result.git,
timestamp: new Date().toISOString()
};
if (options.json) {
console.log(JSON.stringify(output, null, 2));
} else {
console.log('\\n' + '='.repeat(60));
console.log('Mintlify Publishing Result');
console.log('='.repeat(60));
console.log(`Status: ✓ Success`);
console.log(`File: ${result.file}`);
console.log(`Committed: ${result.git.committed ? 'Yes' : 'No'}`);
console.log(`Pushed: ${result.git.pushed ? 'Yes' : 'No'}`);
if (result.git.branch) {
console.log(`Branch: ${result.git.branch}`);
}
console.log('='.repeat(60));
}
process.exit(0);
} catch (error) {
if (options.json) {
console.log(JSON.stringify({
success: false,
error: error.message,
timestamp: new Date().toISOString()
}, null, 2));
} else {
console.error(`\\nError: ${error.message}`);
if (options.verbose) {
console.error(`Stack: ${error.stack}`);
}
}
process.exit(1);
}
}
if (import.meta.url === `file://${process.argv[1]}`) {
publishContent();
}
export { publishContent };