Skip to content

Commit 72b29df

Browse files
committed
fix: consistent appData directory
1 parent 5724b18 commit 72b29df

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

src/Commands/BuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function handle(): void
6666

6767
$this->preProcess();
6868

69-
$this->setAppName(slugify: true);
69+
$this->setAppName();
7070

7171
$this->newLine();
7272
intro('Updating Electron dependencies...');

src/Commands/BundleCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function handle(): int
8585

8686
$this->preProcess();
8787

88-
$this->setAppName(slugify: true);
88+
$this->setAppName();
8989
intro('Copying App to build directory...');
9090

9191
// We update composer.json later,

src/Commands/DevelopCommand.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Native\Electron\Traits\Developer;
88
use Native\Electron\Traits\Installer;
99
use Native\Electron\Traits\InstallsAppIcon;
10+
use Native\Electron\Traits\SetsAppName;
1011

1112
use function Laravel\Prompts\intro;
1213
use function Laravel\Prompts\note;
@@ -17,6 +18,7 @@ class DevelopCommand extends Command
1718
use Developer;
1819
use Installer;
1920
use InstallsAppIcon;
21+
use SetsAppName;
2022

2123
protected $signature = 'native:serve {--no-queue} {--D|no-dependencies} {--installer=npm}';
2224

@@ -40,7 +42,7 @@ public function handle(): void
4042
$this->patchPlist();
4143
}
4244

43-
$this->patchPackageJson();
45+
$this->setAppName(developmentMode: true);
4446

4547
$this->installIcon();
4648

@@ -70,14 +72,4 @@ protected function patchPlist(): void
7072

7173
file_put_contents(__DIR__.'/../../resources/js/node_modules/electron/dist/Electron.app/Contents/Info.plist', $pList);
7274
}
73-
74-
protected function patchPackageJson(): void
75-
{
76-
$packageJsonPath = __DIR__.'/../../resources/js/package.json';
77-
$packageJson = json_decode(file_get_contents($packageJsonPath), true);
78-
79-
$packageJson['name'] = config('app.name');
80-
81-
file_put_contents($packageJsonPath, json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
82-
}
8375
}

src/Traits/SetsAppName.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

55
trait SetsAppName
66
{
7-
protected function setAppName(bool $slugify = false): void
7+
protected function setAppName($developmentMode = false): void
88
{
99
$packageJsonPath = __DIR__.'/../../resources/js/package.json';
1010
$packageJson = json_decode(file_get_contents($packageJsonPath), true);
1111

12-
$name = config('app.name');
12+
$name = str(config('app.name'))->slug();
1313

14-
if ($slugify) {
15-
$name = str($name)->lower()->kebab();
14+
/*
15+
* Suffix the app name with '-dev' if it's a development build
16+
* this way, when the developer test his freshly built app,
17+
* configs, migrations won't be mixed up with the production app
18+
*/
19+
if ($developmentMode) {
20+
$name .= '-dev';
1621
}
1722

1823
$packageJson['name'] = $name;

0 commit comments

Comments
 (0)