1 | <?php |
||
9 | class ScriptHandler |
||
10 | { |
||
11 | /** |
||
12 | * Create the initial configuration for our project |
||
13 | * |
||
14 | * @param Event $event |
||
15 | */ |
||
16 | public static function createInitialConfig(Event $event) |
||
17 | { |
||
18 | $installer = new Installer(); |
||
19 | $io = $event->getIO(); |
||
20 | |||
21 | // check if parameters.yml exists |
||
22 | $rootDir = realpath(__DIR__ . '/../../../../'); |
||
23 | if (file_exists($rootDir . '/app/config/parameters.yml')) { |
||
24 | $io->write( |
||
25 | $installer->getDecoratedMessage( |
||
26 | 'Skipping creating the initial config as parameters.yml already exists', |
||
27 | 'info', |
||
28 | $io->isDecorated() |
||
29 | ) |
||
30 | ); |
||
31 | } else { |
||
32 | $information = $installer->extractInformationFromPath($rootDir); |
||
33 | |||
34 | // ask all the information we need |
||
35 | $config = array(); |
||
36 | $config['client'] = $installer->ask($io, 'client name', $information['client']); |
||
37 | $config['project'] = $installer->ask($io, 'project name', $information['project']); |
||
38 | |||
39 | $config['database_name'] = substr($config['client'], 0, 8) . '_' . substr($config['project'], 0, 7); |
||
40 | $config['database_user'] = $config['database_name']; |
||
41 | |||
42 | if ($information['is_local']) { |
||
43 | // this is the ip-address of our Vagrantbox |
||
44 | $config['database_host'] = '10.11.12.13'; |
||
45 | $config['database_user'] = 'root'; |
||
46 | $config['database_password'] = 'root'; |
||
47 | } |
||
48 | |||
49 | $config['secret'] = md5(uniqid()); |
||
50 | |||
51 | // create the database if requested |
||
52 | if ($installer->askConfirmation($io, 'Should I create the database?')) { |
||
53 | passthru('mysqladmin create ' . $config['database_name']); |
||
54 | } |
||
55 | |||
56 | // alter the Capfile if requested |
||
57 | $capfilePath = $rootDir . '/Capfile'; |
||
58 | if (file_exists($capfilePath)) { |
||
59 | if ($installer->askConfirmation($io, 'Should I alter the Capfile?')) { |
||
60 | $installer->updateCapfile($capfilePath, $config); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | // alter the dist file if requested |
||
65 | $parameterYmlDistPath = $rootDir . '/app/config/parameters.yml.dist'; |
||
66 | if (file_exists($parameterYmlDistPath)) { |
||
67 | if ($installer->askConfirmation($io, 'Should I alter parameters.yml.dist?')) { |
||
68 | $installer->updateYmlFile($parameterYmlDistPath, $config); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Install NPM |
||
76 | * |
||
77 | * @param Event $event |
||
78 | */ |
||
79 | public static function installNPM(Event $event) |
||
80 | { |
||
81 | static::runCommandOnlyInDevMode('npm install', $event->getIO(), $event->isDevMode()); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Install Bower dependencies |
||
86 | * |
||
87 | * @param Event $event |
||
88 | */ |
||
89 | public static function installBower(Event $event) |
||
90 | { |
||
91 | static::runCommandOnlyInDevMode('bower install', $event->getIO(), $event->isDevMode()); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Run gulp build |
||
96 | * |
||
97 | * @param Event $event |
||
98 | */ |
||
99 | public static function gulpBuild(Event $event) |
||
103 | |||
104 | /** |
||
105 | * Running the given command only when we are in dev-mode |
||
106 | * The output will be send directly to the output buffer |
||
107 | * |
||
108 | * @param string $command |
||
109 | * @param IOInterface $io |
||
110 | * @param boolean $isDevMode |
||
111 | * |
||
112 | */ |
||
113 | 1 | public static function runCommandOnlyInDevMode($command, IOInterface $io, $isDevMode) |
|
140 | } |
||
141 |