miridev-cli
Version:
Official CLI tool for deploying static sites to miri.dev - Deploy your websites in seconds
138 lines (119 loc) • 4.62 kB
JavaScript
const { program } = require('commander');
const chalk = require('chalk');
const package = require('../package.json');
const commands = require('../src/commands');
// 명령어들 import
const deployCommand = require('../src/commands/deploy');
const loginCommand = require('../src/commands/login');
const initCommand = require('../src/commands/init');
const statusCommand = require('../src/commands/status');
// 로고를 특정 명령어에서만 표시
function showLogo() {
console.log(chalk.blue.bold(`
███╗ ███╗██╗██████╗ ██╗██████╗ ███████╗██╗ ██╗
████╗ ████║██║██╔══██╗██║██╔══██╗██╔════╝██║ ██║
██╔████╔██║██║██████╔╝██║██║ ██║█████╗ ██║ ██║
██║╚██╔╝██║██║██╔══██╗██║██║ ██║██╔══╝ ╚██╗ ██╔╝
██║ ╚═╝ ██║██║██║ ██║██║██████╔╝███████╗ ╚████╔╝
╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝╚═════╝ ╚══════╝ ╚═══╝
${chalk.gray('✨ Static site deployment made simple')}
`));
}
// 로고가 필요한 명령어에서만 표시
const showLogoCommands = ['help', 'login', 'init', 'status'];
const shouldShowLogo = process.argv.length <= 2 || showLogoCommands.some(cmd => process.argv.includes(cmd)) || process.argv.includes('--help') || process.argv.includes('-h');
if (shouldShowLogo) {
showLogo();
}
program
.name('miridev')
.description('Deploy static sites to miri.dev')
.version(package.version);
// deploy 명령어
program
.command('deploy')
.alias('d')
.description('Deploy current directory to miri.dev')
.option('-d, --dir <directory>', 'Directory to deploy (default: current directory)', '.')
.option('-n, --name <n>', 'Site name')
.option('-s, --site <site>', 'Deploy to existing site (e.g., e7a5d1de.miri.dev)')
.option('-c, --config <file>', 'Config file path', 'miri.config.js')
.option('--skip-build', 'Skip build process')
.option('--open', 'Open deployed site in browser')
.option('--debug', 'Show detailed debug information')
.action(deployCommand);
// login 명령어
program
.command('login')
.description('Login to miri.dev')
.option('-t, --token <token>', 'Login with API token')
.action(loginCommand);
// logout 명령어
program
.command('logout')
.description('Logout from miri.dev')
.action(() => {
const { logout } = require('../src/utils/auth');
logout();
});
// init 명령어
program
.command('init')
.description('Initialize miri.dev configuration')
.option('-f, --force', 'Overwrite existing config')
.action(initCommand);
// status 명령어
program
.command('status')
.alias('st')
.description('Show deployment status and site info')
.action(statusCommand);
// sites 명령어
program
.command('sites')
.alias('ls')
.description('List your deployed sites')
.action(async () => {
const { listSites } = require('../src/commands/sites');
await listSites();
});
// export 명령어
program
.command('export <platform>')
.description('배포 플랫폼별 설정 파일 생성')
.option('-a, --all', '모든 플랫폼 설정 파일 생성')
.action((platform, options) => {
if (options.all) {
commands.export('all');
} else {
commands.export(platform);
}
});
// help 개선
program.on('--help', () => {
console.log('');
console.log(chalk.gray('Examples:'));
console.log(chalk.gray(' $ miridev deploy'));
console.log(chalk.gray(' $ miridev deploy --name my-awesome-site'));
console.log(chalk.gray(' $ miridev deploy --site e7a5d1de.miri.dev'));
console.log(chalk.gray(' $ miridev login'));
console.log(chalk.gray(' $ miridev init'));
console.log('');
console.log(chalk.gray('Documentation: https://www.miri.dev/docs/cli'));
console.log('');
});
// 에러 핸들링
process.on('unhandledRejection', (err) => {
console.error(chalk.red('✗ Unhandled error:'), err.message);
process.exit(1);
});
process.on('uncaughtException', (err) => {
console.error(chalk.red('✗ Uncaught exception:'), err.message);
process.exit(1);
});
program.parse(process.argv);
// 명령어가 주어지지 않은 경우 help 표시
if (!process.argv.slice(2).length) {
program.outputHelp();
}