-
Notifications
You must be signed in to change notification settings - Fork 0
/
carb
executable file
·115 lines (73 loc) · 2.88 KB
/
carb
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
#!/usr/bin/env php
<?php
require_once 'Console/CommandLine.php';
$parser = new Console_CommandLine();
$parser->description = 'A Fat-Free project generator.';
$parser->version = '0.1.0';
$generateCmd = $parser->addCommand('project', array(
'description' => 'Generate a new project'
));
$generateCmd->addArgument('name', array(
'description' => 'The project name'
));
$controllerCmd = $parser->addCommand('controller', array(
'description' => 'Create a new controller'
));
$controllerCmd->addArgument('name', array(
'description' => 'The controller name'
));
$actionCmd = $parser->addCommand('action', array(
'description' => 'Create a new controller action'
));
$routesCmd = $parser->addCommand('routes', array(
'description' => 'View a list of defined routes'
));
try {
$result = $parser->parse();
// Generate a new project
if ($result->command_name == 'project') {
// TODO: Is Fat Free on PHP's include path?
// Retrieve the project name
$projectName = $result->command->args['name'];
if (file_exists($projectName)) {
printf("The project directory {$projectName} already exists.\n");
} else {
// Create the project name
mkdir($projectName);
// Create the asset directories
mkdir("{$projectName}/css/");
mkdir("{$projectName}/images/");
mkdir("{$projectName}/js/");
// Create the configuration directory
mkdir("{$projectName}/config/");
copy(__DIR__ . '/templates/configuration.cfg', $projectName . '/config/configuration.cfg');
// Create the front controller
copy(__DIR__ . '/templates/index.php', $projectName . '/index.php');
// Create the controller directory
mkdir("{$projectName}/controllers/");
// Create the home and carb controllers
copy(__DIR__ . '/templates/home.php', $projectName . '/controllers/home.php');
copy(__DIR__ . '/templates/carb.php', $projectName . '/controllers/carb.php');
// Create the lib directory for third-party libraries
mkdir("{$projectName}/lib/");
// Create the tests directory
mkdir("{$projectName}/tests/");
// Create the mayo layout and home page
mkdir("{$projectName}/ui/");
copy(__DIR__ . '/templates/layout.html', $projectName . '/ui/layout.html');
copy(__DIR__ . '/templates/home.html', $projectName . '/ui/home.html');
// Create the .htaccess file
copy(__DIR__ . '/templates/.htaccess', $projectName . '/.htaccess');
printf("Your project has been created. talk about adding path to apache here.");
}
// Create a new controller
} else if ($result->command_name == 'controller') {
// Create a new action and optionally an associated view
} else if ($result->command_name == 'action') {
// Search for very last }
// View a list of defined routes
} else if ($result->command_name == 'routes') {
}
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}