#!/usr/bin/env node const program = require('commander') const { existsSync } = require('fs') const { join } = require('path') const pkg = require('../package.json') const init = require('../lib/init') const CWD = process.cwd() const awstatsPath = join(CWD, 'node_modules/awstats/index.js') // 获取 AWStats 版本号 const awstatusPkgPath = join(CWD, 'package.json') let awstatusPkg = '' if (existsSync(awstatusPkgPath)) { const { awstats } = require(awstatusPkgPath) if (awstats && awstats.version) { awstatusPkg = require(awstatusPkgPath).awstats.version awstatusPkg = 'AWStats v' + awstatusPkg require('../utils').SetVersion('') } } const Cliversion = `AWStats-cli v${pkg.version}` // 查看版本号 program.version(`${Cliversion}\n${awstatusPkg}`, '-v, --version') // 初始化 program .command('init [dirname]') .alias('i') .description('Initialize AWStats | 初始化AWStats') .action((dirname) => init(dirname)) // 检测是否已初始化 if (existsSync(awstatsPath)) { const { generate, minify, server, deploy, clean } = require(awstatsPath) // 生成 program .command('generate') .alias('g') .description('Generate static files | 生成静态文件') .action(() => generate()) // 压缩 program .command('minify') .alias('m') .description('Compressed static files | 压缩静态文件') .action(() => minify()) // 本地预览 program .command('server') .alias('s') .option('-p, --port ', 'Reset the port | 重设端口') .description('Start a local service | 启动本地服务') .action((cmd) => server(cmd.port)) // 部署 program .command('deploy') .alias('d') .description('Deploying Static Resources | 部署静态资源') .action(() => deploy()) // 清理 program .command('clean') .alias('c') .description('Cleaning up static files | 清理生成的静态文件') .action(() => clean()) } program.parse(process.argv)