-
Notifications
You must be signed in to change notification settings - Fork 30
/
craft
executable file
·87 lines (76 loc) · 2.15 KB
/
craft
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
#!/usr/bin/env php
<?php
/**
* wa-craft/generator-php
*/
$start_time = microtime(true );
/**
* TODO v3.0.0 处理流程
* 定义全局常量
* 装载程序代码
* 处理命令行参数
* 初始化并运行程序
* 增加中间件
* 增加事件
* 修改命令行方式
*/
/* 定义全局常量 */
const ROOT_PATH = __DIR__;
const SRC_PATH = __DIR__ . '/src';
const TAR_ROOT_PATH = __DIR__ . '/deploy';
const VERSION = '3.0.0 alpha1';
const RESOURCE_PATH = __DIR__ . '/resource';
const TEMPLATE_PATH = ROOT_PATH . '/template';
/* 装载程序代码 */
/* 自动运行 composer 下载安装第三方程序 */
if (!file_exists(__DIR__ . "/vendor/autoload.php"))
shell_exec('composer update');
require __DIR__ . "/vendor/autoload.php";
//设置命令
$cmd = new \Commando\Command();
$cmd->option()
->description('A command line toolkit to build MVC scaffold for thinkphp v6.*');
//配置文件
$cmd->option('c')
->aka('config')
->describedAs('define a configuration file, default is : ./config.yaml')
->default(__DIR__ . '/config.yaml')
->map(function ($config) {
return $config;
});
//项目
$cmd->option('p')
->aka('project')
->describedAs('define a project project file')
->default(__DIR__ . '/usecase/fmcs.yaml')
->map(function ($project) {
return $project;
});
//目标路径
$cmd->option('t')
->aka('target')
->describedAs('define a target directory, default is : ' . TAR_ROOT_PATH)
->default(TAR_ROOT_PATH)
->map(function ($target) {
return $target;
});
//目标路径
$cmd->option('e')
->aka('debug')
->describedAs('enable or disable debug information: ')
->default(TRUE)
->map(function ($debug) {
return $debug;
});
//进行创建
$generator = new \generator\Generator([
'config' => $cmd['config'],
'project' => $cmd['project'],
'target' => $cmd['target']
]);
$generator->run();
$end_time = microtime(true );
$period = $end_time - $start_time;
echo "--------------------------------------------------------------------------------".PHP_EOL;
echo "executed in {$period} seconds";
echo " and used ". round(memory_get_usage()/1024) . " KB memory";