1 | #!/usr/bin/env node
|
2 |
|
3 | var fs = require('fs');
|
4 | var async = require('async');
|
5 | var path = require('path');
|
6 | var controller = require('../lib/controller');
|
7 | var ProjectManager = require('../lib/aics/project');
|
8 | var PackageManager = require('../lib/aics/package');
|
9 | var Account = require('../lib/aics/account');
|
10 | var commander = require('commander');
|
11 | var argv = require('minimist')(process.argv.slice(2));
|
12 | if (!process.env.AICS_HOST) {
|
13 | process.env.AICS_HOST = 'http://storage.fami2u.com';
|
14 | }
|
15 | // process.env.AICS_HOST = 'http://localhost:8080';
|
16 | var pkg = require('../package.json');
|
17 | process.title = 'aics';
|
18 | commander.version(pkg.version)
|
19 | .description(pkg.description)
|
20 |
|
21 |
|
22 | // const updateNotifier = require('update-notifier');
|
23 | // updateNotifier({pkg}).notify();
|
24 |
|
25 |
|
26 | // commander.on('--help', function() {
|
27 | // console.log(' Basic Examples:');
|
28 | // console.log('');
|
29 | // console.log('');
|
30 | // console.log(' Deployment project:');
|
31 | // console.log('');
|
32 | // console.log(' $ aics deploy appName');
|
33 | // console.log('');
|
34 | // console.log(' Command help:');
|
35 | // console.log('');
|
36 | // console.log(' $ aics deploy -h');
|
37 | // console.log('');
|
38 | // });
|
39 |
|
40 | // 部署到aics
|
41 | commander.command('deploy <project-name> <private-key>')
|
42 | .option('-m, --mobile-settings <mobile-settings.json>', 'Set mobile-settings from json file')
|
43 | .option('-s, --server-only', 'server only')
|
44 | .option('-e, --env <env.json>', 'Set environment variables from json file')
|
45 | .option('-d, --debug', 'debug mode')
|
46 | .description('部署当前项目到 *.fami2x.com')
|
47 | .action(function(argument, privateKey, options) {
|
48 |
|
49 | var pwd = path.resolve('.');
|
50 | var actionsRegistry = new controller(pwd, options);
|
51 | if (actionsRegistry['deploy']) {
|
52 | actionsRegistry['deploy'](argument, privateKey);
|
53 | }
|
54 |
|
55 | }).on('--help', function() {
|
56 | console.log(' Examples:');
|
57 | console.log();
|
58 | console.log(' $ aics deploy appName # Deployment to http://appName.aics.cn ');
|
59 | console.log();
|
60 | console.log(' $ aics deploy appName --env env.json');
|
61 | console.log();
|
62 | });
|
63 |
|
64 | // 配置服务器运行环境
|
65 | commander.command('setup')
|
66 | .description('配置私有服务器运行环境(参见:http://aics.fami2u.com/#setup)')
|
67 | .action(function(options) {
|
68 |
|
69 | var pwd = path.resolve('.');
|
70 |
|
71 | var actionsRegistry = new controller(pwd, options);
|
72 | if (actionsRegistry['setup']) {
|
73 | actionsRegistry['setup']();
|
74 | }
|
75 |
|
76 | }).on('--help', function() {
|
77 | console.log(' Examples:');
|
78 | console.log();
|
79 | console.log(' $ aics setup # configuration your server');
|
80 | console.log();
|
81 | });
|
82 |
|
83 |
|
84 | // 部署到私有的服务器上
|
85 | commander.command('push')
|
86 | .option('-m, --mobile-settings <mobile-settings.json>', 'Set mobile-settings from json file')
|
87 | .option('-s, --server-only', 'server only')
|
88 | .option('-d, --debug', 'debug mode')
|
89 | .option('-b, --verbose', 'verbose mode')
|
90 | .description('部署当前项目到私有服务器')
|
91 | .action(function(options) {
|
92 |
|
93 | var pwd = path.resolve('.');
|
94 | // console.log(options);
|
95 |
|
96 | var actionsRegistry = new controller(pwd, options);
|
97 | if (actionsRegistry['push']) {
|
98 | actionsRegistry['push']();
|
99 | }
|
100 |
|
101 | }).on('--help', function() {
|
102 | console.log(' Examples:');
|
103 | console.log();
|
104 | console.log(' $ aics push # config package.js ');
|
105 | console.log();
|
106 | console.log(' $ aics push');
|
107 | console.log();
|
108 | });
|
109 |
|
110 | // logs
|
111 | commander.command('logs')
|
112 | .option('-l, --lines <lines>', 'output the last N lines, instead of the last 50 by default')
|
113 | .description('打印服务器日志')
|
114 | .action(function(options) {
|
115 |
|
116 | var pwd = path.resolve('.');
|
117 | // console.log(options);
|
118 |
|
119 | var actionsRegistry = new controller(pwd, options);
|
120 | if (actionsRegistry['logs']) {
|
121 | actionsRegistry['logs']();
|
122 | }
|
123 | }).on('--help', function() {
|
124 | console.log(' Examples:');
|
125 | console.log();
|
126 | console.log(' $ aics logs ');
|
127 | console.log();
|
128 | console.log(' $ aics logs -t 100');
|
129 | console.log();
|
130 | });
|
131 | // logs
|
132 | commander.command('mongo')
|
133 | .description('连接远程mongodb数据库')
|
134 | .action(function(options) {
|
135 |
|
136 | var pwd = path.resolve('.');
|
137 | // console.log(options);
|
138 |
|
139 | var actionsRegistry = new controller(pwd, options);
|
140 | if (actionsRegistry['mongo']) {
|
141 | actionsRegistry['mongo']();
|
142 | }
|
143 |
|
144 | }).on('--help', function() {
|
145 | console.log(' Examples:');
|
146 | console.log();
|
147 | console.log(' $ aics mongo');
|
148 | console.log();
|
149 | });
|
150 | //add user
|
151 | commander
|
152 | .command('adduser')
|
153 | .description('登录aics cli')
|
154 | .action(function(env, options) {
|
155 | Account.adduser();
|
156 | }).on('--help', function() {
|
157 | console.log(' Examples:');
|
158 | console.log();
|
159 | console.log(' $ aics adduser # 登录aics cli');
|
160 | console.log();
|
161 | });
|
162 | commander
|
163 | .command('register')
|
164 | .description('创建aics账户')
|
165 | .action(function(env, options) {
|
166 | Account.createUser();
|
167 | })
|
168 | .on('--help', function() {
|
169 | console.log("Examples:")
|
170 | console.log();
|
171 | console.log(" $ aics createuser #create user account")
|
172 | console.log()
|
173 | })
|
174 |
|
175 |
|
176 |
|
177 | //log logind user info
|
178 | commander
|
179 | .command('info')
|
180 | .description('显示 aics cli 登录用户信息')
|
181 | .action(function(env, options) {
|
182 | var user = Account.get();
|
183 | console.log(user.username);
|
184 | }).on('--help', function() {
|
185 | console.log(' Examples:');
|
186 | console.log();
|
187 | console.log(' $ aics whoami # 显示当前登录用户信息');
|
188 | console.log();
|
189 | });
|
190 |
|
191 | // generate aics codedepot conf or aics project conf
|
192 |
|
193 | commander
|
194 | .command('init')
|
195 | .description('生成aics配置文件')
|
196 | .option('-p, --project <name>', 'generate aics project conf')
|
197 | .option('-e, --example <name>', 'generate project from example project conf')
|
198 | .action(function(options) {
|
199 | if (options.project) {
|
200 | ProjectManager.initProject(process.argv);
|
201 | return;
|
202 | }
|
203 | if (options.example) {
|
204 | ProjectManager.initWithSample(options.example);
|
205 | return;
|
206 | }
|
207 | PackageManager.init(process.argv);
|
208 | }).on('--help', function() {
|
209 | console.log(' Examples:');
|
210 | console.log();
|
211 | console.log(' $ aics init -p [name] # 生成一个 名为 name 的 project 项目 ');
|
212 | console.log(' $ aics init -e [name] # 根据 name 生成一个项目');
|
213 | console.log(' $ aics init [name] # 生成一个 名为 name 代码包项目 ');
|
214 | console.log();
|
215 | });
|
216 |
|
217 | commander
|
218 | .command('add [name]')
|
219 | .description('添加 aics 代码包 代码包地址: http://codedepot.fami2u.com/')
|
220 | .action(function(env, options) {
|
221 | ProjectManager.add(env)
|
222 | }).on('--help', function() {
|
223 | console.log(' Examples:');
|
224 | console.log();
|
225 | console.log(' # aics add fami:readme # 添加代码包到project');
|
226 | console.log();
|
227 | });
|
228 |
|
229 | commander
|
230 | .command('update')
|
231 | .description('更新项目依赖')
|
232 | .action(function() {
|
233 | console.log(argv._)
|
234 | if(argv._.length>1){
|
235 | ProjectManager.update(argv._.pop());
|
236 | }else{
|
237 | ProjectManager.updateAll();
|
238 | }
|
239 | }).on('--help', function() {
|
240 | console.log(' Examples:');
|
241 | console.log();
|
242 | console.log(' $ aics update # 更新项目依赖的代码包的版本');
|
243 | console.log(' $ aics update [name] # 更新名为 [name] 的代码包依赖的代码包的版本');
|
244 | console.log();
|
245 | });
|
246 |
|
247 | commander
|
248 | .command('publish')
|
249 | .option('-p, --project <name>', '发布解决方案(项目)')
|
250 | .description('发布aics项目或组件')
|
251 | .action(function(options) {
|
252 | if (options.project) {
|
253 | ProjectManager.publish();
|
254 | return;
|
255 | }
|
256 | PackageManager.publish();
|
257 | }).on('--help', function() {
|
258 | console.log(' Examples:');
|
259 | console.log();
|
260 | console.log(' $ aics publish -p [name] # 发布名为 [name] 的 aics 项目');
|
261 | console.log(' $ aics publish [name] # 发布名为 [name] 的 aics 代码包');
|
262 | console.log();
|
263 | });
|
264 |
|
265 | // commander
|
266 | // .command('remove [packagename]')
|
267 | // .description('删除项目中已经添加的代码包')
|
268 | // .action(function(env, options) {
|
269 | // Account.adduser();
|
270 | // }).on('--help', function() {
|
271 | // console.log(' 说明:');
|
272 | // console.log();
|
273 | // console.log(' 在 *.fami2u.com 注册过的账号可直接登录');
|
274 | // console.log();
|
275 | // });
|
276 |
|
277 | commander
|
278 | .command('addfile')
|
279 | .option('-f, --file <path>', '添加文件到组件')
|
280 | .option('-t, --target <name>', '添加到的组件名称')
|
281 | .description('添加文件到组件')
|
282 | .action(function(options) {
|
283 | PackageManager.addfile(options.target, options.file);
|
284 | }).on('--help', function() {
|
285 | console.log(' Examples:');
|
286 | console.log();
|
287 | console.log(' # aics addfile -f README.md -t depot # 添加文件README.md 到 depot 组件包');
|
288 | console.log();
|
289 | });
|
290 |
|
291 |
|
292 |
|
293 | commander.parse(process.argv);
|