Skip to content

Commit c553bd5

Browse files
committed
添加创建扩展命令
1 parent 9ae711a commit c553bd5

File tree

13 files changed

+259
-5
lines changed

13 files changed

+259
-5
lines changed

public/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27941,6 +27941,7 @@ var render = function() {
2794127941
_vm._v(" "),
2794227942
_c(
2794327943
"div",
27944+
{ staticClass: "flex-c" },
2794427945
[
2794527946
_c("Actions", {
2794627947
attrs: {

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/app.js": "/app.js?id=002f63ad8c850b9ab4e4",
2+
"/app.js": "/app.js?id=0a3b5ac8e5d7716acd24",
33
"/manifest.js": "/manifest.js?id=d9708e48a6c10ccee4bb",
44
"/vendor.js": "/vendor.js?id=f4679ac178c0e413cb28"
55
}

resources/js/components/grid/Tree.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
/>
7171
</template>
7272
</div>
73-
<div>
73+
<div class="flex-c">
7474
<Actions
7575
:action_list="attrs.actions.data"
7676
:scope="node"

src/AdminServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class AdminServiceProvider extends ServiceProvider
1212

1313
Console\InstallCommand::class,
1414
Console\FormItemCommand::class,
15+
Console\ExtendCommand::class,
1516

1617
];
1718

@@ -78,7 +79,7 @@ protected function registerPublishing()
7879
if ($this->app->runningInConsole()) {
7980
$this->publishes([__DIR__ . '/../config' => config_path()], 'laravel-vue-admin-config');
8081
$this->publishes([__DIR__ . '/../resources/lang' => resource_path('lang')], 'laravel-vue-admin-lang');
81-
$this->publishes([__DIR__.'/../database/migrations' => database_path('migrations')], 'laravel-admin-migrations');
82+
$this->publishes([__DIR__ . '/../database/migrations' => database_path('migrations')], 'laravel-admin-migrations');
8283
$this->publishes([__DIR__ . '/../public' => public_path('vendor/laravel-vue-admin')], 'laravel-vue-admin-assets');
8384
}
8485
}

src/Console/ExtendCommand.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
3+
4+
namespace SmallRuralDog\Admin\Console;
5+
6+
7+
use Illuminate\Console\Command;
8+
use Illuminate\Filesystem\Filesystem;
9+
use Illuminate\Support\Str;
10+
use Symfony\Component\Process\Process;
11+
12+
class ExtendCommand extends Command
13+
{
14+
use AcceptsNameAndVendor;
15+
16+
protected $signature = 'admin:extend {name}';
17+
18+
protected $description = '创建扩展';
19+
20+
public function handle()
21+
{
22+
if (!$this->hasValidNameArgument()) {
23+
return;
24+
}
25+
26+
(new Filesystem)->copyDirectory(
27+
__DIR__ . '/extend-stubs',
28+
$this->extendPath()
29+
);
30+
31+
$this->replace('{{ component }}', $this->extendName(), $this->extendPath() . '/resources/js/extend.js');
32+
33+
34+
$this->replace('{{ namespace }}', $this->extendNamespace(), $this->extendPath() . '/src/ExtendServiceProvider.stub');
35+
$this->replace('{{ component }}', $this->extendName(), $this->extendPath() . '/src/ExtendServiceProvider.stub');
36+
37+
(new Filesystem)->move(
38+
$this->extendPath() . '/src/ExtendServiceProvider.stub',
39+
$this->extendPath() . '/src/ExtendServiceProvider.php'
40+
);
41+
42+
$this->replace('{{ name }}', $this->argument('name'), $this->extendPath() . '/composer.json');
43+
$this->replace('{{ escapedNamespace }}', $this->escapedExtendNamespace(), $this->extendPath() . '/composer.json');
44+
45+
46+
$this->addExtendRepositoryToRootComposer();
47+
$this->addExtendPackageToRootComposer();
48+
$this->addScriptsToNpmPackage();
49+
50+
if ($this->confirm('Would you like to update your Composer packages?', true)) {
51+
$this->composerUpdate();
52+
}
53+
54+
}
55+
56+
protected function composerUpdate()
57+
{
58+
$this->executeCommand('composer update', getcwd());
59+
}
60+
61+
protected function executeCommand($command, $path)
62+
{
63+
$process = (new Process($command, $path))->setTimeout(null);
64+
65+
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
66+
$process->setTty(true);
67+
}
68+
69+
$process->run(function ($type, $line) {
70+
$this->output->write($line);
71+
});
72+
}
73+
74+
protected function addExtendRepositoryToRootComposer()
75+
{
76+
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
77+
78+
$composer['repositories'][] = [
79+
'type' => 'path',
80+
'url' => './' . $this->relativeExtendPath(),
81+
];
82+
83+
file_put_contents(
84+
base_path('composer.json'),
85+
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
86+
);
87+
}
88+
89+
protected function addExtendPackageToRootComposer()
90+
{
91+
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
92+
$composer['require'][$this->argument('name')] = '*';
93+
file_put_contents(
94+
base_path('composer.json'),
95+
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
96+
);
97+
}
98+
99+
protected function addScriptsToNpmPackage()
100+
{
101+
$package = json_decode(file_get_contents(base_path('package.json')), true);
102+
$package['scripts']['build-' . $this->extendName()] = 'cd ' . $this->relativeExtendPath() . ' && npm run dev';
103+
$package['scripts']['build-' . $this->extendName() . '-prod'] = 'cd ' . $this->relativeExtendPath() . ' && npm run prod';
104+
105+
file_put_contents(
106+
base_path('package.json'),
107+
json_encode($package, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
108+
);
109+
}
110+
111+
protected function replace($search, $replace, $path)
112+
{
113+
file_put_contents($path, str_replace($search, $replace, file_get_contents($path)));
114+
}
115+
116+
protected function extendNamespace()
117+
{
118+
return Str::studly($this->extendVendor()) . '\\' . $this->extendClass();
119+
}
120+
121+
protected function extendPath()
122+
{
123+
return config('admin.directory') . '/Extends/' . $this->extendClass();
124+
}
125+
126+
protected function relativeExtendPath()
127+
{
128+
return config('admin.directory') . '/Extends/' . $this->extendClass();
129+
}
130+
131+
protected function escapedExtendNamespace()
132+
{
133+
return str_replace('\\', '\\\\', $this->extendNamespace());
134+
}
135+
136+
protected function extendClass()
137+
{
138+
return Str::studly($this->extendName());
139+
}
140+
141+
protected function extendVendor()
142+
{
143+
return explode('/', $this->argument('name'))[0];
144+
}
145+
146+
147+
protected function extendName()
148+
{
149+
return explode('/', $this->argument('name'))[1];
150+
}
151+
}

src/Console/extend-stubs/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/.idea
2+
/vendor
3+
/node_modules
4+
package-lock.json
5+
composer.phar
6+
composer.lock
7+
phpunit.xml
8+
.phpunit.result.cache
9+
.DS_Store
10+
Thumbs.db
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "{{ name }}",
3+
"description": "A Laravel Vue Admin Extend",
4+
"keywords": [
5+
"laravel",
6+
"vue",
7+
"admin"
8+
],
9+
"license": "MIT",
10+
"require": {
11+
"php": ">=7.1.0"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"{{ escapedNamespace }}\\": "src/"
16+
}
17+
},
18+
"extra": {
19+
"laravel": {
20+
"providers": [
21+
"{{ escapedNamespace }}\\ExtendServiceProvider"
22+
]
23+
}
24+
},
25+
"config": {
26+
"sort-packages": true
27+
},
28+
"minimum-stability": "dev",
29+
"prefer-stable": true
30+
}

src/Console/extend-stubs/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "npm run development",
5+
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
6+
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
7+
"watch-poll": "npm run watch -- --watch-poll",
8+
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
9+
"prod": "npm run production",
10+
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
11+
},
12+
"devDependencies": {
13+
"cross-env": "^5.1",
14+
"laravel-mix": "^4.1.4"
15+
},
16+
"dependencies": {
17+
"vue": "^2.6.11"
18+
}
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VueAdmin.booting((Vue, router, store) => {
2+
3+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//css

0 commit comments

Comments
 (0)