66use Swoft \Console \Bean \Annotation \Command ;
77use Swoft \Console \Helper \ConsoleUtil ;
88use Swoft \Console \Input \Input ;
9+ use Swoft \Helper \DirHelper ;
910use Swoft \Helper \ProcessHelper ;
1011
1112/**
@@ -18,12 +19,12 @@ class DevCommand
1819 /**
1920 * @return array
2021 */
21- public function internalConfig (): array
22+ public static function internalConfig (): array
2223 {
2324 return [
2425 'swoft/devtool ' => [
25- '@devtool/web/dist/devtool ' ,
26- '@root/public '
26+ '@devtool/web/dist/devtool/static ' ,
27+ '@root/public/devtool '
2728 ],
2829 ];
2930 }
@@ -34,7 +35,7 @@ public function internalConfig(): array
3435 * srcDir The source assets directory path. eg. `@vendor/some/lib/assets`
3536 * dstDir The defined component name.(default is `@root/public`)
3637 * @Options
37- * -y, --yes BOOL Whether to ask when writing a file . default is: <info>True </info>
38+ * -y, --yes BOOL Do not confirm when execute publish . default is: <info>False </info>
3839 * -f, --force BOOL Force override all exists file.(default: <info>False</info>)
3940 * @Example
4041 * {fullCommand} swoft/devtool
@@ -56,7 +57,7 @@ public function publish(Input $input): int
5657
5758 // first arg is internal component name
5859 if ($ assetDir && !$ targetDir ) {
59- $ config = $ this -> internalConfig ();
60+ $ config = static :: internalConfig ();
6061
6162 if (!isset ($ config [$ assetDir ])) {
6263 \output ()->colored ('missing arguments! ' , 'warning ' );
@@ -68,6 +69,21 @@ public function publish(Input $input): int
6869 $ assetDir = App::getAlias ($ assetDir );
6970 $ targetDir = App::getAlias ($ targetDir );
7071
72+ $ force = \input ()->sameOpt (['f ' , 'force ' ], false );
73+
74+ if ($ force && \is_dir ($ targetDir )) {
75+ \output ()->writeln ("Will delete the old assets: $ targetDir " );
76+
77+ list ($ code , , $ error ) = ProcessHelper::run ("rm -rf $ targetDir " );
78+
79+ if ($ code !== 0 ) {
80+ \output ()->colored ("Delete dir $ targetDir is failed! " , 'error ' );
81+ \output ()->writeln ($ error );
82+
83+ return -2 ;
84+ }
85+ }
86+
7187 $ yes = \input ()->sameOpt (['y ' , 'yes ' ], false );
7288 $ command = "cp -Rf $ assetDir $ targetDir " ;
7389
@@ -79,6 +95,8 @@ public function publish(Input $input): int
7995 return 0 ;
8096 }
8197
98+ DirHelper::mkdir ($ targetDir );
99+
82100 list ($ code , , $ error ) = ProcessHelper::run ($ command , App::getAlias ('@root ' ));
83101
84102 if ($ code !== 0 ) {
0 commit comments