File tree Expand file tree Collapse file tree 7 files changed +229
-0
lines changed
src/Illuminate/Foundation/Console Expand file tree Collapse file tree 7 files changed +229
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Illuminate \Foundation \Console ;
4+
5+ use InvalidArgumentException ;
6+ use Illuminate \Console \Command ;
7+
8+ class PresetCommand extends Command
9+ {
10+ /**
11+ * The console command signature.
12+ *
13+ * @var string
14+ */
15+ protected $ signature = 'preset { type : The preset type (fresh, react) } ' ;
16+
17+ /**
18+ * The console command description.
19+ *
20+ * @var string
21+ */
22+ protected $ description = 'Swap the front-end scaffolding for the application ' ;
23+
24+ /**
25+ * Execute the console command.
26+ *
27+ * @return void
28+ */
29+ public function handle ()
30+ {
31+ if (! in_array ($ this ->argument ('type ' ), ['fresh ' , 'react ' ])) {
32+ throw new InvalidArgumentException ('Invalid preset. ' );
33+ }
34+
35+ return $ this ->{$ this ->argument ('type ' )}();
36+ }
37+
38+ /**
39+ * Install the "fresh" preset.
40+ *
41+ * @return void
42+ */
43+ protected function fresh ()
44+ {
45+ Presets \Fresh::install ();
46+
47+ $ this ->info ('Front-end scaffolding removed successfully. ' );
48+ }
49+
50+ /**
51+ * Install the "react" preset.
52+ *
53+ * @return void
54+ */
55+ public function react ()
56+ {
57+ Presets \React::install ();
58+
59+ $ this ->info ('React scaffolding installed successfully. ' );
60+ $ this ->comment ('Run "npm install && npm run dev" to compile your fresh scaffolding. ' );
61+ }
62+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Illuminate \Foundation \Console \Presets ;
4+
5+ use Illuminate \Filesystem \Filesystem ;
6+
7+ class Fresh
8+ {
9+ /**
10+ * Install the preset.
11+ *
12+ * @return void
13+ */
14+ public static function install ()
15+ {
16+ tap (new Filesystem , function ($ filesystem ) {
17+ $ filesystem ->deleteDirectory (base_path ('node_modules ' ));
18+ $ filesystem ->deleteDirectory (resource_path ('assets ' ));
19+ $ filesystem ->deleteDirectory (public_path ('css ' ));
20+ $ filesystem ->deleteDirectory (public_path ('js ' ));
21+
22+ $ filesystem ->delete (base_path ('webpack.mix.js ' ));
23+ $ filesystem ->delete (base_path ('package.json ' ));
24+ $ filesystem ->delete (base_path ('yarn.lock ' ));
25+ });
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Illuminate \Foundation \Console \Presets ;
4+
5+ use Illuminate \Filesystem \Filesystem ;
6+
7+ class React
8+ {
9+ /**
10+ * Install the preset.
11+ *
12+ * @return void
13+ */
14+ public static function install ()
15+ {
16+ if (file_exists (base_path ('package.json ' ))) {
17+ $ packages = json_decode (file_get_contents (base_path ('package.json ' )), true );
18+
19+ unset($ packages ['devDependencies ' ]['vue ' ]);
20+
21+ $ packages ['devDependencies ' ]['babel-preset-react ' ] = '^6.23.0 ' ;
22+ $ packages ['devDependencies ' ]['react ' ] = '^15.4.2 ' ;
23+ $ packages ['devDependencies ' ]['react-dom ' ] = '^15.4.2 ' ;
24+
25+ ksort ($ packages ['devDependencies ' ]);
26+
27+ file_put_contents (base_path ('package.json ' ), json_encode ($ packages , JSON_PRETTY_PRINT ));
28+ }
29+
30+ copy (__DIR__ .'/react-stubs/app.js ' , resource_path ('assets/js/app.js ' ));
31+ copy (__DIR__ .'/react-stubs/bootstrap.js ' , resource_path ('assets/js/bootstrap.js ' ));
32+
33+ $ filesystem = new Filesystem ;
34+ $ filesystem ->delete (resource_path ('assets/js/components/Example.vue ' ));
35+
36+ copy (__DIR__ .'/react-stubs/Example.js ' , resource_path ('assets/js/components/Example.js ' ));
37+
38+ copy (__DIR__ .'/react-stubs/webpack.mix.js ' , base_path ('webpack.mix.js ' ));
39+
40+ $ filesystem ->deleteDirectory (base_path ('node_modules ' ));
41+ $ filesystem ->delete (base_path ('yarn.lock ' ));
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ import React , { Component } from 'react' ;
2+ import ReactDOM from 'react-dom' ;
3+
4+ export default class Example extends Component {
5+ render ( ) {
6+ return (
7+ < div className = "container" >
8+ < div className = "row" >
9+ < div className = "col-md-8 col-md-offset-2" >
10+ < div className = "panel panel-default" >
11+ < div className = "panel-heading" > Example Component</ div >
12+
13+ < div className = "panel-body" >
14+ I'm an example component!
15+ </ div >
16+ </ div >
17+ </ div >
18+ </ div >
19+ </ div >
20+ ) ;
21+ }
22+ }
23+
24+ if ( document . getElementById ( 'example' ) ) {
25+ ReactDOM . render ( < Example /> , document . getElementById ( 'example' ) ) ;
26+ }
Original file line number Diff line number Diff line change 1+
2+ /**
3+ * First we will load all of this project's JavaScript dependencies which
4+ * includes Vue and other libraries. It is a great starting point when
5+ * building robust, powerful web applications using Vue and Laravel.
6+ */
7+
8+ require ( './bootstrap' ) ;
9+
10+ /**
11+ * Next, we will create a fresh React component instance and attach it to
12+ * the page. Then, you may begin adding components to this application
13+ * or customize the JavaScript scaffolding to fit your unique needs.
14+ */
15+
16+ require ( './components/Example' ) ;
Original file line number Diff line number Diff line change 1+
2+ window . _ = require ( 'lodash' ) ;
3+
4+ /**
5+ * We'll load jQuery and the Bootstrap jQuery plugin which provides support
6+ * for JavaScript based Bootstrap features such as modals and tabs. This
7+ * code may be modified to fit the specific needs of your application.
8+ */
9+
10+ window . $ = window . jQuery = require ( 'jquery' ) ;
11+
12+ require ( 'bootstrap-sass' ) ;
13+
14+ /**
15+ * We'll load the axios HTTP library which allows us to easily issue requests
16+ * to our Laravel back-end. This library automatically handles sending the
17+ * CSRF token as a header based on the value of the "XSRF" token cookie.
18+ */
19+
20+ window . axios = require ( 'axios' ) ;
21+
22+ window . axios . defaults . headers . common = {
23+ 'X-CSRF-TOKEN' : window . Laravel . csrfToken ,
24+ 'X-Requested-With' : 'XMLHttpRequest'
25+ } ;
26+
27+ /**
28+ * Echo exposes an expressive API for subscribing to channels and listening
29+ * for events that are broadcast by Laravel. Echo and event broadcasting
30+ * allows your team to easily build robust real-time web applications.
31+ */
32+
33+ // import Echo from 'laravel-echo'
34+
35+ // window.Pusher = require('pusher-js');
36+
37+ // window.Echo = new Echo({
38+ // broadcaster: 'pusher',
39+ // key: 'your-pusher-key'
40+ // });
Original file line number Diff line number Diff line change 1+ const { mix } = require ( 'laravel-mix' ) ;
2+
3+ /*
4+ |--------------------------------------------------------------------------
5+ | Mix Asset Management
6+ |--------------------------------------------------------------------------
7+ |
8+ | Mix provides a clean, fluent API for defining some Webpack build steps
9+ | for your Laravel application. By default, we are compiling the Sass
10+ | file for the application as well as bundling up all the JS files.
11+ |
12+ */
13+
14+ mix . react ( 'resources/assets/js/app.js' , 'public/js' )
15+ . sass ( 'resources/assets/sass/app.scss' , 'public/css' ) ;
You can’t perform that action at this time.
0 commit comments