Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.

Commit 29faa04

Browse files
author
Kerem
committed
Added webpack helper kit
1 parent adf90ea commit 29faa04

File tree

10 files changed

+150
-18
lines changed

10 files changed

+150
-18
lines changed

src/Commands/ThemeGeneratorCommand.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function handle()
5757
$this->assets($name);
5858
}
5959

60+
if ($this->confirm('Create a webpack helper kit?',true)) {
61+
$this->webpack($name);
62+
}
63+
6064
$this->info("Theme Generator Successful. Now add your default theme from the config/theme settings.");
6165
return;
6266
}
@@ -81,7 +85,7 @@ protected function template($themeName)
8185
$this->config['views_folder']['component'].'.'.$this->config['views_blade']['header'],
8286
$this->config['views_folder']['component'].'.'.$this->config['views_blade']['footer']
8387
],
84-
$this->getStub('layout')
88+
$this->getStub('View','layout')
8589
);
8690

8791
$indexTemplate = str_replace(
@@ -91,7 +95,7 @@ protected function template($themeName)
9195
[
9296
$this->config['views_folder']['layout'].'.'.$this->config['views_blade']['layout'],
9397
],
94-
$this->getStub('index')
98+
$this->getStub('View','index')
9599
);
96100

97101
$this->setFile('resources',$themeName.'/views/'.$this->config['views_folder']['layout'],$this->config['views_blade']['layout'].'.blade.php',$layoutTemplate);
@@ -127,9 +131,35 @@ protected function assets($themeName)
127131

128132
}
129133

130-
protected function getStub($fileName)
134+
protected function webpack($name)
135+
{
136+
$this->setFolder('resources',$name.'/assets');
137+
$this->setFolder('resources',$name.'/assets/'.$this->config['webpack']['folder']['js']);
138+
$this->setFolder('resources',$name.'/assets/'.$this->config['webpack']['folder']['css']);
139+
140+
// Include Js Files
141+
$this->setFile('resources',$name.'/assets/'.$this->config['webpack']['folder']['js'],$this->config['webpack']['file']['js'],$this->getStub('Webpack','js'));
142+
$this->setFile('resources',$name.'/assets/'.$this->config['webpack']['folder']['js'],$this->config['webpack']['file']['bootstrap'],$this->getStub('Webpack','bootstrap'));
143+
144+
// Include Css Files
145+
$this->setFile('resources',$name.'/assets/'.$this->config['webpack']['folder']['css'],$this->config['webpack']['file']['css'],$this->getStub('Webpack','css'));
146+
$this->setFile('resources',$name.'/assets/'.$this->config['webpack']['folder']['css'],$this->config['webpack']['file']['variable'],$this->getStub('Webpack','variable'));
147+
148+
// webpack.mix.js Added
149+
$include_js = 'resources/'.$this->config['resource_path'].'/'.$name.'/assets/'.$this->config['webpack']['folder']['js'].'/'.$this->config['webpack']['file']['js'];
150+
$export_js = 'public/'.$this->config['public_path'].'/'.$name.'/js';
151+
152+
$include_css = 'resources/'.$this->config['resource_path'].'/'.$name.'/assets/'.$this->config['webpack']['folder']['css'].'/'.$this->config['webpack']['file']['css'];
153+
$export_css = 'public/'.$this->config['public_path'].'/'.$name.'/css';
154+
155+
File::append(base_path('webpack.mix.js'), "\n" . implode("\n", ["mix.js('".$include_js."', '".$export_js."').sass('".$include_css."', '".$export_css."').version();"]));
156+
157+
158+
}
159+
160+
protected function getStub($folder,$fileName)
131161
{
132-
return File::get(__DIR__.'/../Template/'.$fileName.'.stub');
162+
return File::get(__DIR__.'/../Template/'.$folder.'/'.$fileName.'.stub');
133163
}
134164

135165
protected function getDirectory($folder,$path = NULL)
@@ -138,18 +168,18 @@ protected function getDirectory($folder,$path = NULL)
138168
{
139169
if ($path === NULL)
140170
{
141-
return resource_path($this->config['theme_path']);
171+
return resource_path($this->config['resource_path']);
142172
}
143-
return resource_path($this->config['theme_path'].'/'.$path);
173+
return resource_path($this->config['resource_path'].'/'.$path);
144174
}
145175

146176
if ($folder === 'public')
147177
{
148178
if ($path === NULL)
149179
{
150-
return public_path($this->config['asset_path']);
180+
return public_path($this->config['public_path']);
151181
}
152-
return public_path($this->config['asset_path'].'/'.$path);
182+
return public_path($this->config['public_path'].'/'.$path);
153183
}
154184

155185
}
@@ -172,17 +202,17 @@ protected function setFolder($directory,$path = null)
172202
{
173203
if ($path == null)
174204
{
175-
return File::makeDirectory(resource_path($this->config['theme_path']));
205+
return File::makeDirectory(resource_path($this->config['resource_path']));
176206
}
177-
return File::makeDirectory(resource_path($this->config['theme_path']).'/'.$path);
207+
return File::makeDirectory(resource_path($this->config['resource_path']).'/'.$path);
178208
}
179209
if ($directory === 'public')
180210
{
181211
if ($path == null)
182212
{
183-
return File::makeDirectory(public_path($this->config['theme_path']));
213+
return File::makeDirectory(public_path($this->config['resource_path']));
184214
}
185-
return File::makeDirectory(public_path($this->config['theme_path']).'/'.$path);
215+
return File::makeDirectory(public_path($this->config['resource_path']).'/'.$path);
186216
}
187217
}
188218
}

src/Config/theme.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,22 @@
1818
'index' => 'index',
1919
'header' => 'header',
2020
'footer' => 'footer',
21-
'layout' => 'main'
21+
'layout' => 'main',
22+
],
23+
/*
24+
* Laravel Default Js & Sass Folder & File Name
25+
*/
26+
'webpack' => [
27+
'folder' => [
28+
'js' => 'js',
29+
'css' => 'sass',
30+
],
31+
'file' => [
32+
'css' => 'app.scss',
33+
'variable' => '_variables.scss',
34+
'js' => 'app.js',
35+
'bootstrap' => 'bootstrap.js',
36+
]
2237
],
2338

2439
/*
@@ -28,9 +43,7 @@
2843
|
2944
|
3045
*/
31-
32-
'theme_path' => 'themes',
33-
34-
'asset_path' => 'themes',
46+
'resource_path' => 'themes',
47+
'public_path' => 'themes',
3548

3649
];
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/Template/layout.stub renamed to src/Template/View/layout.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<link rel="shortcut icon" href="">
1414
<link rel="icon" type="image/png" sizes="192x192" href="">
1515
<link rel="apple-touch-icon" sizes="180x180" href="">
16-
{{ Theme::assetLink('css',''css/app.css', false) }}
16+
{{ Theme::assetLink('css','css/app.css', false) }}
1717

1818
</head>
1919
<body>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
window._ = require('lodash');
2+
3+
/**
4+
* We'll load jQuery and the Bootstrap jQuery plugin which provides support
5+
* for JavaScript based Bootstrap features such as modals and tabs. This
6+
* code may be modified to fit the specific needs of your application.
7+
*/
8+
9+
try {
10+
window.Popper = require('popper.js').default;
11+
window.$ = window.jQuery = require('jquery');
12+
13+
require('bootstrap');
14+
} catch (e) {}
15+
16+
/**
17+
* We'll load the axios HTTP library which allows us to easily issue requests
18+
* to our Laravel back-end. This library automatically handles sending the
19+
* CSRF token as a header based on the value of the "XSRF" token cookie.
20+
*/
21+
22+
window.axios = require('axios');
23+
24+
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
25+
26+
/**
27+
* Next we will register the CSRF Token as a common header with Axios so that
28+
* all outgoing HTTP requests automatically have it attached. This is just
29+
* a simple convenience so we don't have to attach every token manually.
30+
*/
31+
32+
let token = document.head.querySelector('meta[name="csrf-token"]');
33+
34+
if (token) {
35+
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
36+
} else {
37+
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
38+
}
39+
40+
/**
41+
* Echo exposes an expressive API for subscribing to channels and listening
42+
* for events that are broadcast by Laravel. Echo and event broadcasting
43+
* allows your team to easily build robust real-time web applications.
44+
*/
45+
46+
// import Echo from 'laravel-echo';
47+
48+
// window.Pusher = require('pusher-js');
49+
50+
// window.Echo = new Echo({
51+
// broadcaster: 'pusher',
52+
// key: process.env.MIX_PUSHER_APP_KEY,
53+
// cluster: process.env.MIX_PUSHER_APP_CLUSTER,
54+
// encrypted: true
55+
// });

src/Template/Webpack/css.stub

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Fonts
2+
@import url('https://fonts.googleapis.com/css?family=Nunito');
3+
4+
// Variables
5+
@import 'variables';
6+
7+
// Bootstrap
8+
@import '~bootstrap/scss/bootstrap';

src/Template/Webpack/js.stub

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* First we will load all of this project's JavaScript dependencies which
3+
* includes Vue and other libraries. It is a great starting point when
4+
* building robust, powerful web applications using Vue and Laravel.
5+
*/
6+
7+
require('./bootstrap');

src/Template/Webpack/variable.stub

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Body
2+
$body-bg: #f8fafc;
3+
4+
// Typography
5+
$font-family-sans-serif: 'Nunito', sans-serif;
6+
$font-size-base: 0.9rem;
7+
$line-height-base: 1.6;
8+
9+
// Colors
10+
$blue: #3490dc;
11+
$indigo: #6574cd;
12+
$purple: #9561e2;
13+
$pink: #f66d9b;
14+
$red: #e3342f;
15+
$orange: #f6993f;
16+
$yellow: #ffed4a;
17+
$green: #38c172;
18+
$teal: #4dc0b5;
19+
$cyan: #6cb2eb;

0 commit comments

Comments
 (0)