-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAWStats
77 lines (64 loc) · 1.94 KB
/
AWStats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/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 <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)