Skip to content

Commit 599b0cb

Browse files
committed
Adding version control and commands
1 parent cee069b commit 599b0cb

File tree

9 files changed

+1084
-0
lines changed

9 files changed

+1084
-0
lines changed

src/Syntax/Core/CoreServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class CoreServiceProvider extends ServiceProvider {
1111
*/
1212
protected $defer = false;
1313

14+
const version = '1.0.0';
15+
1416
/**
1517
* Bootstrap the application events.
1618
*

src/commands/CleanCommand.php

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
use Illuminate\Console\Command;
4+
use Symfony\Component\Console\Input\InputOption;
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Output\StreamOutput;
7+
8+
class CleanCommand extends Command {
9+
10+
/**
11+
* The console command name.
12+
*
13+
* @var string
14+
*/
15+
protected $name = 'syntax:clean';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Run the final commands to set up the site.';
23+
24+
/**
25+
* An array of available syntax packages
26+
*
27+
* @var string[]
28+
*/
29+
protected $syntaxPackages = ['chat', 'forum'];
30+
31+
/**
32+
* An array of packages that will need a config loaded
33+
*
34+
* @var string[]
35+
*/
36+
protected $syntaxPackagesWithConfig = ['chat'];
37+
38+
/**
39+
* An object containing the core syntax config details
40+
*
41+
* @var string[]
42+
*/
43+
protected $syntaxCoreDetails;
44+
45+
/**
46+
* The output stream for any artisan commands
47+
*
48+
* @var string
49+
*/
50+
protected $stream;
51+
52+
/**
53+
* Create a new command instance.
54+
*
55+
* @return void
56+
*/
57+
public function __construct()
58+
{
59+
parent::__construct();
60+
61+
$this->syntaxCoreDetails = new stdClass();
62+
$this->stream = fopen('php://output', 'w');
63+
}
64+
65+
/**
66+
* Execute the console command.
67+
*
68+
* @return mixed
69+
*/
70+
public function fire()
71+
{
72+
$this->comment('Starting final steps...');
73+
74+
// Run the installation
75+
$this->runArtisan();
76+
77+
// Run gulp commands
78+
$this->runGulp();
79+
80+
// Clean up
81+
$this->cleanUp();
82+
}
83+
84+
/********************************************************************
85+
* Unique Methods
86+
*******************************************************************/
87+
protected function runArtisan()
88+
{
89+
$this->comment('Generating a key...');
90+
Artisan::call('key:generate', array(), new StreamOutput($this->stream));
91+
$this->comment('Adding the migration table...');
92+
Artisan::call('migrate:install', array(), new StreamOutput($this->stream));
93+
Artisan::call('syntax:database', array(), new StreamOutput($this->stream));
94+
Artisan::call('syntax:gulp', array(), new StreamOutput($this->stream));
95+
}
96+
97+
protected function runGulp()
98+
{
99+
$this->comment('Running gulp commands...');
100+
$commands = [
101+
'cd '. base_path(),
102+
'gulp install'
103+
];
104+
105+
SSH::run($commands, function ($line) {
106+
echo $line.PHP_EOL;
107+
});
108+
}
109+
110+
protected function cleanUp()
111+
{
112+
$this->comment('Running clean up commands...');
113+
$commands = [
114+
'cd '. base_path(),
115+
'chmod 755 public',
116+
'chmod 755 public/index.php'
117+
];
118+
119+
SSH::run($commands, function ($line) {
120+
echo $line.PHP_EOL;
121+
});
122+
}
123+
124+
/**
125+
* Get the console command arguments.
126+
*
127+
* @return array
128+
*/
129+
protected function getArguments()
130+
{
131+
return array(
132+
// array('example', InputArgument::REQUIRED, 'An example argument.'),
133+
);
134+
}
135+
136+
/**
137+
* Get the console command options.
138+
*
139+
* @return array
140+
*/
141+
protected function getOptions()
142+
{
143+
return array(
144+
// array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
145+
);
146+
}
147+
148+
}

src/commands/ConfigureCommand.php

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<?php
2+
3+
use Illuminate\Console\Command;
4+
use Symfony\Component\Console\Input\InputOption;
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Output\StreamOutput;
7+
8+
class ConfigureCommand extends Command {
9+
10+
/**
11+
* The console command name.
12+
*
13+
* @var string
14+
*/
15+
protected $name = 'syntax:configure';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Set up Laravel configs.';
23+
24+
/**
25+
* An object containing the remote config details
26+
*
27+
* @var string[]
28+
*/
29+
protected $remoteDetails;
30+
31+
/**
32+
* An object containing the database config details
33+
*
34+
* @var string[]
35+
*/
36+
protected $databaseDetails;
37+
38+
/**
39+
* The URL for the this site
40+
*
41+
* @var string
42+
*/
43+
protected $siteUrl;
44+
45+
/**
46+
* The output stream for any artisan commands
47+
*
48+
* @var string
49+
*/
50+
protected $stream;
51+
52+
/**
53+
* Create a new command instance.
54+
*
55+
* @return void
56+
*/
57+
public function __construct()
58+
{
59+
parent::__construct();
60+
61+
$this->remoteDetails = new stdClass();
62+
$this->databaseDetails = new stdClass();
63+
$this->stream = fopen('php://output', 'w');
64+
}
65+
66+
/**
67+
* Execute the console command.
68+
*
69+
* @return mixed
70+
*/
71+
public function fire()
72+
{
73+
$this->comment('Starting Laravel configurations...');
74+
75+
// Set up the configs
76+
$this->setUpRemote();
77+
$this->setUpDatabase();
78+
$this->setUpApp();
79+
80+
$this->comment('Laravel configurations complete!');
81+
}
82+
83+
/********************************************************************
84+
* Unique Methods
85+
*******************************************************************/
86+
protected function confirmConfig($type, $configDetails = null)
87+
{
88+
$this->line('Your '. $type .' configuration will be set to the following.');
89+
90+
switch ($type) {
91+
case 'remote':
92+
$this->line(print_r($this->remoteDetails, 1));
93+
if (!$this->confirm('Do you want to keep this configuration? [yes|no]')) {
94+
return $this->setUpRemote();
95+
} else {
96+
return $this->configureRemote();
97+
}
98+
break;
99+
case 'database':
100+
$this->line(print_r($this->databaseDetails, 1));
101+
if (!$this->confirm('Do you want to keep this configuration? [yes|no]')) {
102+
return $this->setUpDatabase();
103+
} else {
104+
return $this->configureDatabase();
105+
}
106+
break;
107+
}
108+
}
109+
110+
/********************************************************************
111+
* Set Up Methods
112+
*******************************************************************/
113+
protected function setUpRemote()
114+
{
115+
// Set up our remote config
116+
$this->comment('Setting up remote config options...');
117+
$this->remoteDetails->host = $this->ask('What is your remote host? (for ports add :<PORT> to the end)');
118+
$this->remoteDetails->username = $this->ask('What is your remote username?');
119+
$this->remoteDetails->password = $this->secret('What is your remote password?');
120+
$this->remoteDetails->key = $this->ask('Where is your remote rsa key?');
121+
$this->remoteDetails->keyphrase = $this->ask('What is the passphrase?');
122+
$this->remoteDetails->root = $this->ask('Where is your remote root?');
123+
124+
$this->confirmConfig('remote');
125+
}
126+
127+
protected function setUpDatabase()
128+
{
129+
// Set up our database config
130+
$this->comment('Setting up datatabase details...');
131+
$this->databaseDetails->driver = $this->ask('What is your database driver? [Hit enter to use mysql driver]', 'mysql');
132+
$this->databaseDetails->host = $this->ask('What is your database host?');
133+
$this->databaseDetails->database = $this->ask('What is the database name?');
134+
$this->databaseDetails->username = $this->ask('What is your database username?');
135+
$this->databaseDetails->password = $this->secret('What is your database password?');
136+
$this->databaseDetails->charset = $this->ask('What is your database charset? [Hit enter to use utf8]', 'utf8');
137+
$this->databaseDetails->collation = $this->ask('What is your database collation? [Hit enter to use utf8_unicode_ci]', 'utf8_unicode_ci');
138+
$this->databaseDetails->prefix = $this->ask('What is your database prefix?');
139+
140+
$this->confirmConfig('database');
141+
}
142+
143+
protected function setUpApp()
144+
{
145+
// Set up our app config
146+
$this->comment('Setting up app details...');
147+
$this->siteUrl = $this->ask('What is this site\'s url?');
148+
149+
list($path, $contents) = $this->getConfig('app');
150+
151+
$contents = str_replace($this->laravel['config']['app.url'], $this->siteUrl, $contents);
152+
153+
File::put($path, $contents);
154+
}
155+
156+
/********************************************************************
157+
* Configuration Methods
158+
*******************************************************************/
159+
protected function configureRemote()
160+
{
161+
list($path, $contents) = $this->getConfig('remote');
162+
163+
foreach ($this->remoteDetails as $key => $value) {
164+
$contents = str_replace($this->laravel['config']['remote.connections.default.'. $key], $value, $contents);
165+
}
166+
167+
File::put($path, $contents);
168+
}
169+
170+
protected function configureDatabase()
171+
{
172+
list($path, $contents) = $this->getConfig('database');
173+
174+
foreach ($this->databaseDetails as $key => $value) {
175+
$contents = str_replace($this->laravel['config']['database.connections.mysql.'. $key], $value, $contents);
176+
}
177+
178+
File::put($path, $contents);
179+
}
180+
181+
/********************************************************************
182+
* Extra Methods
183+
*******************************************************************/
184+
protected function getConfig($file)
185+
{
186+
$path = $this->laravel['path'].'/config/'. $file .'.php';
187+
188+
$contents = File::get($path);
189+
190+
return array($path, $contents);
191+
}
192+
193+
/**
194+
* Get the console command arguments.
195+
*
196+
* @return array
197+
*/
198+
protected function getArguments()
199+
{
200+
return array(
201+
// array('example', InputArgument::REQUIRED, 'An example argument.'),
202+
);
203+
}
204+
205+
/**
206+
* Get the console command options.
207+
*
208+
* @return array
209+
*/
210+
protected function getOptions()
211+
{
212+
return array(
213+
// array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
214+
);
215+
}
216+
217+
}

0 commit comments

Comments
 (0)