Skip to content

Commit

Permalink
Merge pull request #4 from BRACKETS-by-TRIAD/installer-update
Browse files Browse the repository at this point in the history
Installer update
  • Loading branch information
dejwCake authored Oct 23, 2017
2 parents dc73bd7 + 3b7ba83 commit 2fe3fa2
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 27 deletions.
41 changes: 14 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,9 @@ It uses Laravel 5.5, so it has to meet also all its requirements https://laravel

## Installation ##

[![Craftable installation](https://docs.brackets.sk/assets/craftable-installation-youtube.png)](https://www.youtube.com/watch?v=DBCzLR5gpnw)

To start using Craftable you need to proceed two steps:
1. Adding Craftable
1. Installation

### Adding Craftable ###

You can use your existing Laravel 5.5 application. Or alternatively, you can create new Craftalbe instance (similarily to `laravel new` command.

#### Existing project ####

Start with requiring these two main packagess:
### New Craftable project ###

```bash
composer require brackets/craftable
composer require --dev brackets/admin-generator
```

#### New Craftable project ####
[![Craftable installation](https://docs.brackets.sk/assets/craftable-installation-youtube.png)](https://www.youtube.com/watch?v=DBCzLR5gpnw)

If you want to start on fresh Laravel 5.5, you can use our `brackets/craftable-installer` that do all the tricks for you. Let's install it globally:
```bash
Expand All @@ -90,9 +73,18 @@ Now you can create a new Craftable project:
craftable new my_project
```

### Installation ###
This is going to install all dependencies, publish all important vendor configs, migrate, setup some configs, webpack config and run migrations.

Command is going to generate and **print the password for the default administrator** account. Save this password to your clipboard, we are going to need it soon.

!>Before installation verify, that you have an existing database and database connection environment is correctly set up. Installation wizard is going to generate some code based on your actual database structure (i.e. users table structure) and migrate database so the database connection is obligatory.
### Add Craftable on existing project ###

Or alternatively, you can use your existing Laravel 5.5 application. Start with requiring these two main packages:

```bash
composer require brackets/craftable
composer require --dev brackets/admin-generator
```

To install this package use:
```bash
Expand All @@ -103,11 +95,6 @@ This is going to install all dependencies, publish all important vendor configs,

Command is going to generate and **print the password for the default administrator** account. Save this password to your clipboard, we are going to need it soon.

Once Craftable is installed, don't forget to compile all the assets, so run something like this:
```bash
npm install && npm run dev
```

## Basics ##

Once installed, navigate your browser to `/admin/login`. You should be able to see a login screen.
Expand All @@ -134,4 +121,4 @@ At this point you are ready to start building your administration area. You prob

In case you rather want to create some atypical custom made administration, then you probably want to head over to [Admin UI](admin-ui) package.

Have fun & craft something awesome!
Have fun & craft something awesome!
71 changes: 71 additions & 0 deletions src/Console/Commands/CraftableInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function handle(Filesystem $files)
{
$this->info('Installing Craftable...');

$this->getDbSettings();

$this->publishAllVendors();

$this->generatePasswordAndUpdateMigration();
Expand All @@ -54,6 +56,8 @@ public function handle(Filesystem $files)

$this->call('admin-listing:install');

$this->npm();

$this->comment('Admin password is: ' . $this->password);

$this->info('Craftable installed.');
Expand Down Expand Up @@ -153,4 +157,71 @@ private function scanAndSaveTranslations() {
]);
}

/*
* If default database name in env is present and interaction mode is on,
* asks for database settings. Not provided values will not be overwritten.
*/
private function getDbSettings()
{
if(env('DB_DATABASE') == 'homestead' && $this->input->isInteractive()) {
$dbConnection = $this->choice('What database driver do you use?', ['mysql', 'pgsql'], 1);
if(!empty($dbConnection)) {
$this->strReplaceInFile(base_path('.env'),
'DB_CONNECTION=mysql',
'DB_CONNECTION='.$dbConnection);
}
$dbHost = $this->anticipate('What is your database host?', ['localhost', '127.0.0.1'], '127.0.0.1');
if(!empty($dbHost)) {
$this->strReplaceInFile(base_path('.env'),
'DB_HOST=127.0.0.1',
'DB_HOST='.$dbHost);
}
$dbPort = $this->anticipate('What is your database port?', ['3306', '5432'], env('DB_DATABASE') == 'mysql' ? '3306' : '5432');
if(!empty($dbPort)) {
$this->strReplaceInFile(base_path('.env'),
'DB_PORT=3306',
'DB_PORT='.$dbPort);
}
$DbDatabase = $this->ask('What is your database name?', 'homestead');
if(!empty($DbDatabase)) {
$this->strReplaceInFile(base_path('.env'),
'DB_DATABASE=homestead',
'DB_DATABASE='.$DbDatabase);
}
$dbUsername = $this->ask('What is your database user name?', 'homestead');
if(!empty($dbUsername)) {
$this->strReplaceInFile(base_path('.env'),
'DB_USERNAME=homestead',
'DB_USERNAME='.$dbUsername);
}
$dbPassword = $this->ask('What is your database user password?', 'secret');
if(!empty($dbPassword)) {
$this->strReplaceInFile(base_path('.env'),
'DB_PASSWORD=secret',
'DB_PASSWORD='.$dbPassword);
}
}
}

/*
* Run npm commands if users wishes it.
*/
private function npm()
{
if (!$this->input->isInteractive() || $this->confirm('Do you wish to install npm packages and compile assets?', true)) {
$npmInstallFlag = (env('APP_ENV') === 'production') ? '--production' : '';
$npmRunFlag = (env('APP_ENV') === 'production') ? 'prod' : 'dev';
$noBinLinks = '';
if($this->input->isInteractive() && $this->confirm('Do you need run npm install with --no-bin-links?')) {
$noBinLinks = '--no-bin-links';
}

$this->info('Running npm install '.$npmInstallFlag);
passthru("npm install {$npmInstallFlag} {$noBinLinks}");

$this->info('Running npm run '.$npmRunFlag);
passthru("npm run {$npmRunFlag}");
}
}

}

0 comments on commit 2fe3fa2

Please sign in to comment.