-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·135 lines (112 loc) · 4.58 KB
/
cli.js
File metadata and controls
executable file
·135 lines (112 loc) · 4.58 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env node
const yParser = require('yargs-parser');
const semver = require('semver');
const { existsSync } = require('fs');
const { join } = require('path');
const chalk = require('chalk');
// print version and @local
const args = yParser(process.argv.slice(2));
if (args.v || args.version) {
// eslint-disable-next-line global-require
console.log(require('./package').version);
if (existsSync(join(__dirname, '.local'))) {
console.log(chalk.cyan('@local'));
}
process.exit(0);
}
if (!semver.satisfies(process.version, '>= 8.0.0')) {
console.error(chalk.red('✘ The generator will only work with Node v8.0.0 and up!'));
process.exit(1);
}
const cwd = process.cwd();
const option = args._[0];
const screenshot = async (props) => {
// eslint-disable-next-line global-require
await require('./src/screenshot/index')(props);
process.exit(0);
};
const screenshotDumi = async (props) => {
// eslint-disable-next-line global-require
await require('./src/screenshot/dumi')(props);
process.exit(0);
};
switch (option) {
case 'screenshot':
if (args.dumi) {
screenshotDumi({ cwd, ...args });
} else {
screenshot({ cwd, ...args });
}
break;
case 'i18n-remove':
// eslint-disable-next-line global-require
require('./src/i18n/index')({ cwd, ...args });
break;
case 'fetch-blocks':
// eslint-disable-next-line global-require
require('./src/fetch-blocks/index')({ cwd, ...args });
break;
case 'create':
const name = args._[1] || '';
// eslint-disable-next-line global-require
require('./src/create/index')({ cwd, name, ...args });
break;
case 'pro-components-codemod':
// eslint-disable-next-line global-require
require('./src/pro-components-codemod/index')({ cwd, ...args });
break;
default:
if (args.h || args.help) {
const details = `
Commands:
${chalk.cyan('create')} 创建新的 Ant Design Pro 项目
${chalk.cyan('screenshot ')} 对区块进行截图
${chalk.cyan('i18n-remove')} 从项目中移除国际化
${chalk.cyan('fetch-blocks')} 下载 pro 所有的官方区块
${chalk.cyan('pro-components-codemod')} 自动更新 pro-components 的 import 方式
Options for the ${chalk.cyan('create')} command:
${chalk.green('--list-templates ')} 列出可用的模板
${chalk.green('--template ')} 模板类型(非交互式模式)
${chalk.green('--origin ')} 指定源: github 或 gitee
Options for the ${chalk.cyan('screenshot')} command:
${chalk.green('--path ')} 区块的路径,可以用于只截图一个
${chalk.green('--mobile ')} 使用手机大小的屏幕进行截图
Options for the ${chalk.cyan('i18n-remove')} command:
${chalk.green('--locale ')} 设置语言
${chalk.green('--write ')} 是否写入文件
Options for the ${chalk.cyan('pro-components-codemod')} command:
${chalk.green('--writePkg ')} 是否更新 package.json 中的 dependencies
${chalk.green('--path ')} 更新 pro-components import 的路径
${chalk.green('--cleanup ')} 是否开启 cleanup 模式,多个 import 合并为 单个 import
${chalk.green('--list-versions ')} 列出可用的 pro-components 版本
${chalk.green('--version ')} 指定 pro-components 版本(非交互式模式,可用 latest)
Examples:
${chalk.gray('pro')}
pro -h
${chalk.gray('create (list available templates)')}
pro create --list-templates
${chalk.gray('create (interactive)')}
pro create myapp
${chalk.gray('create (non-interactive)')}
pro create myapp --template simple
pro create myapp --template complete
${chalk.gray('screenshot')}
pro screenshot
pro screenshot --path DashboardWorkplace
${chalk.gray('i18n-remove')}
pro i18n-remove --write
pro i18n-remove --locale en-US --write
${chalk.gray('fetch-blocks')}
pro fetch-blocks
${chalk.gray('pro-components-codemod (interactive)')}
pro pro-components-codemod --writePkg
${chalk.gray('pro-components-codemod (list available versions)')}
pro pro-components-codemod --list-versions
${chalk.gray('pro-components-codemod (non-interactive)')}
pro pro-components-codemod --version latest
pro pro-components-codemod --version 2.6.0 --path src --cleanup
`.trim();
console.log(details);
}
break;
}