@quasarbright/projection
Version:
A static site generator that creates a beautiful, interactive gallery to showcase your coding projects. Features search, filtering, tags, responsive design, and an admin UI.
166 lines (159 loc) • 5.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CLI = void 0;
exports.main = main;
const init_1 = require("./init");
const build_1 = require("./build");
const dev_1 = require("./dev");
const serve_1 = require("./serve");
const admin_1 = require("./admin");
const deploy_1 = require("./deploy");
/**
* CLI class that orchestrates command routing and argument parsing
*/
class CLI {
constructor(version = '1.0.0') {
this.version = version;
this.commands = new Map([
['init', init_1.init],
['build', build_1.build],
['dev', dev_1.dev],
['serve', serve_1.serve],
['admin', admin_1.admin],
['deploy', deploy_1.deploy]
]);
}
/**
* Parse command-line arguments and execute the appropriate command
*/
async run(args) {
// Remove node and script path from args
const [command, ...rest] = args;
// Handle special flags
if (!command || command === '--help' || command === '-h') {
this.showHelp();
return;
}
if (command === '--version' || command === '-v') {
this.showVersion();
return;
}
// Get command handler
const handler = this.commands.get(command);
if (!handler) {
console.error(`\n❌ Unknown command: ${command}\n`);
console.log(`Run 'projection --help' for usage information.\n`);
process.exit(1);
}
// Parse options for the command
const options = this.parseOptions(rest);
// Check if help is requested for this command
if (options.help || options.h) {
options.help = true;
}
// Execute command
try {
await handler(options);
}
catch (error) {
console.error(`\n❌ Command failed: ${error.message}\n`);
process.exit(1);
}
}
/**
* Parse command-line options into an object
*/
parseOptions(args) {
const options = {};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
// Handle flags (--flag or -f)
if (arg.startsWith('--')) {
const key = arg.slice(2);
// Check if next arg is a value or another flag
const nextArg = args[i + 1];
if (nextArg && !nextArg.startsWith('-')) {
// It's a key-value pair
options[this.camelCase(key)] = nextArg;
i++; // Skip next arg since we consumed it
}
else {
// It's a boolean flag
options[this.camelCase(key)] = true;
}
}
else if (arg.startsWith('-') && arg.length === 2) {
// Short flag
const key = arg.slice(1);
const nextArg = args[i + 1];
if (nextArg && !nextArg.startsWith('-')) {
options[key] = nextArg;
i++;
}
else {
options[key] = true;
}
}
}
return options;
}
/**
* Convert kebab-case to camelCase
*/
camelCase(str) {
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
}
/**
* Display help text
*/
showHelp() {
console.log(`
Projection - Static Site Generator for Project Portfolios
USAGE:
projection <command> [options]
COMMANDS:
init Initialize a new Projection project
build Generate the static site from project data
dev Start development server with live reload
serve Serve the generated site with a local HTTP server
admin Start admin interface for managing projects
deploy Deploy the portfolio site to GitHub Pages
OPTIONS:
-h, --help Show this help message
-v, --version Show version number
Run 'projection <command> --help' for detailed information about a command.
EXAMPLES:
projection init # Initialize a new project
projection build # Build the site
projection dev # Start development server
projection admin # Start admin interface
projection deploy # Deploy to GitHub Pages
DOCUMENTATION:
https://github.com/quasarbright/projection
`);
}
/**
* Display version information
*/
showVersion() {
console.log(`projection v${this.version}`);
}
}
exports.CLI = CLI;
/**
* Main entry point for the CLI
*/
async function main(args) {
// Get version from package.json
let version = '1.0.0';
try {
const packageJson = require('../../package.json');
version = packageJson.version;
}
catch (error) {
// Use default version if package.json not found
}
const cli = new CLI(version);
await cli.run(args);
}
//# sourceMappingURL=index.js.map