Skip to content

Commit

Permalink
Scaffold new sites by copying a skeleton directory instead of the ugl…
Browse files Browse the repository at this point in the history
…y heredoc strings
  • Loading branch information
adamwathan committed Jan 8, 2016
1 parent faa29fe commit 4247902
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 132 deletions.
3 changes: 3 additions & 0 deletions site/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build_local/
/node_modules/
/vendor/
5 changes: 5 additions & 0 deletions site/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'production' => false,
];
10 changes: 10 additions & 0 deletions site/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var gulp = require('gulp');
var elixir = require('laravel-elixir');

elixir.config.assetsPath = 'source/_assets';
elixir.config.publicPath = 'source/assets';

elixir(function(mix) {
mix.sass('main.scss')
.exec('jigsaw build', ['./source/**/*', '!./source/_assets/**/*']);
});
9 changes: 9 additions & 0 deletions site/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"devDependencies": {
"gulp": "^3.8.8"
},
"dependencies": {
"laravel-elixir": "^4.2.0"
}
}
Empty file.
12 changes: 12 additions & 0 deletions site/source/_layouts/master.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="stylesheet" href="/assets/css/main.css">
</head>
<body>
@yield('body')
</body>
</html>
Empty file added site/source/assets/css/main.css
Empty file.
5 changes: 5 additions & 0 deletions site/source/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@extends('_layouts.master')

@section('body')
<h1>Hello world!</h1>
@endsection
137 changes: 5 additions & 132 deletions src/Console/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class InitCommand extends Command
public function __construct(Filesystem $files)
{
$this->files = $files;
$this->base = getcwd();
parent::__construct();
}

Expand All @@ -31,144 +32,16 @@ protected function configure()
protected function fire()
{
if ($base = $this->input->getArgument('name')) {
$this->base = getcwd() . '/' . $base;
$this->createBaseDirectory();
$this->base .= '/' . $base;
}

$this->createSourceFolder();
$this->createBaseConfig();
$this->createGitIgnore();
$this->createMasterLayout();
$this->createIndexTemplate();
$this->initializeElixir();
$this->createAssetsFolders();
$this->createStylesheets();
$this->scaffoldSite();

$this->info('Site initialized successfully!');
}

private function createBaseDirectory()
private function scaffoldSite()
{
if (! $this->files->isDirectory($this->base)) {
$this->files->makeDirectory($this->base);
}
}

private function createSourceFolder()
{
$this->files->makeDirectory($this->base . '/source');
}

private function createBaseConfig()
{
$this->files->put($this->base . '/config.php', <<<EOT
<?php
return [
'production' => false,
];
EOT
);
}

private function createGitIgnore()
{
$this->files->put($this->base . '/.gitignore', <<<EOT
/build_local/
/node_modules/
/vendor/
EOT
);
}

private function createMasterLayout()
{
$this->files->makeDirectory($this->base . '/source/_layouts');
$this->files->put($this->base . '/source/_layouts/master.blade.php', <<<EOT
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="stylesheet" href="/assets/css/main.css">
</head>
<body>
@yield('body')
</body>
</html>
EOT
);
}

private function createIndexTemplate()
{
$this->files->put($this->base . '/source/index.blade.php', <<<EOT
@extends('_layouts.master')
@section('body')
<h1>Hello world!</h1>
@endsection
EOT
);
}

private function initializeElixir()
{
$this->createPackageJson();
$this->createGulpFile();
}

private function createPackageJson()
{
$this->files->put($this->base . '/package.json', <<<EOT
{
"private": true,
"devDependencies": {
"gulp": "^3.8.8"
},
"dependencies": {
"laravel-elixir": "^4.2.0"
}
}
EOT
);
}

private function createGulpFile()
{
$this->files->put($this->base . '/gulpfile.js', <<<EOT
var gulp = require('gulp');
var elixir = require('laravel-elixir');
elixir.config.assetsPath = 'source/_assets';
elixir.config.publicPath = 'source/assets';
elixir(function(mix) {
mix.sass('main.scss')
.exec('jigsaw build', ['./source/**/*', '!./source/_assets/**/*']);
});
EOT
);
}

private function createAssetsFolders()
{
$this->files->makeDirectory($this->base . '/source/_assets');
$this->files->makeDirectory($this->base . '/source/_assets/sass');
$this->files->makeDirectory($this->base . '/source/assets/');
$this->files->makeDirectory($this->base . '/source/assets/css');
}

private function createStylesheets()
{
$this->files->put($this->base . '/source/_assets/sass/main.scss', '');
$this->files->put($this->base . '/source/assets/css/main.css', '');
$this->files->copyDirectory(__DIR__ . '/../../site', $this->base);
}
}

0 comments on commit 4247902

Please sign in to comment.