Skip to content

Commit a625f27

Browse files
committed
fix paths
1 parent e84a570 commit a625f27

12 files changed

+73
-67
lines changed

src/Builder/Concerns/CleansEnvFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function cleanEnvFile(): void
2222
{
2323
$cleanUpKeys = array_merge($this->overrideKeys, config('nativephp.cleanup_env_keys', []));
2424

25-
$envFile = $this->buildPath(app()->environmentFile());
25+
$envFile = $this->buildPath('app/' . app()->environmentFile());
2626

2727
$contents = collect(file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))
2828
// Remove cleanup keys

src/Builder/Concerns/CopiesBundleToBuildDirectory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ public function copyBundleToBuildDirectory(): bool
2323

2424
echo 'Copying secure app bundle to build directory...'.PHP_EOL;
2525
echo 'From: '.realpath(dirname($this->sourcePath(self::$bundlePath))).PHP_EOL;
26-
echo 'To: '.realpath(dirname($this->buildPath(self::$bundlePath))).PHP_EOL;
26+
echo 'To: '.realpath(dirname($this->buildPath('app/'.self::$bundlePath))).PHP_EOL;
2727

2828
// Clean and create build directory
29-
$filesystem->remove($this->buildPath());
30-
$filesystem->mkdir($this->buildPath());
29+
$filesystem->remove($this->buildPath('app'));
30+
$filesystem->mkdir($this->buildPath('app'));
3131

3232
$filesToCopy = [
3333
self::$bundlePath,
3434
// '.env',
3535
];
3636
foreach ($filesToCopy as $file) {
37-
$filesystem->copy($this->sourcePath($file), $this->buildPath($file), true);
37+
$filesystem->copy($this->sourcePath($file), $this->buildPath('app/'.$file), true);
3838
}
3939
$this->keepRequiredDirectories();
4040

src/Builder/Concerns/CopiesCertificateAuthority.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Native\Desktop\Builder\Concerns;
44

5+
use Native\Desktop\Drivers\Electron\ElectronServiceProvider;
56
use Native\Desktop\Support\Composer;
67

78
use function Laravel\Prompts\error;
@@ -11,20 +12,21 @@ trait CopiesCertificateAuthority
1112
{
1213
abstract public function buildPath(string $path = ''): string;
1314

14-
public function copyCertificateAuthority(string $path): void
15+
public function copyCertificateAuthority(): void
1516
{
1617
try {
17-
$certFilePath = Composer::phpPackagePath('cacert.pem');
18+
$srcPath = Composer::phpPackagePath('cacert.pem');
19+
$destPath = ElectronServiceProvider::buildPath();
1820

19-
if (! file_exists($certFilePath)) {
20-
warning('CA Certificate not found at '.$certFilePath.'. Skipping copy.');
21+
if (! file_exists($srcPath)) {
22+
warning('CA Certificate not found at '.$srcPath.'. Skipping copy.');
2123

2224
return;
2325
}
2426

2527
$copied = copy(
26-
$certFilePath,
27-
"{$path}/cacert.pem"
28+
$srcPath,
29+
"{$destPath}/cacert.pem"
2830
);
2931

3032
if (! $copied) {

src/Builder/Concerns/CopiesToBuildDirectory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ abstract public function sourcePath(string $path = ''): string;
2424
public function copyToBuildDirectory(): bool
2525
{
2626
$sourcePath = $this->sourcePath();
27-
$buildPath = $this->buildPath();
27+
$buildPath = $this->buildPath('app');
28+
2829
$filesystem = new Filesystem;
2930

3031
$patterns = array_merge(
@@ -96,7 +97,7 @@ private function keepRequiredDirectories()
9697
// Electron build removes empty folders, so we have to create dummy files
9798
// dotfiles unfortunately don't work.
9899
$filesystem = new Filesystem;
99-
$buildPath = $this->buildPath();
100+
$buildPath = $this->buildPath('app');
100101

101102
$filesystem->dumpFile("{$buildPath}/storage/framework/cache/_native.json", '{}');
102103
$filesystem->dumpFile("{$buildPath}/storage/framework/sessions/_native.json", '{}');

src/Builder/Concerns/PrunesVendorDirectory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public function pruneVendorDirectory()
1919

2020
$filesystem = new Filesystem;
2121
$filesystem->remove([
22-
$this->buildPath('/vendor/bin'),
23-
$this->buildPath('/vendor/nativephp/php-bin'),
22+
$this->buildPath('app/vendor/bin'),
23+
$this->buildPath('app/vendor/nativephp/php-bin'),
2424
]);
2525

2626
// Remove custom php binary package directory
2727
$binaryPackageDirectory = $this->binaryPackageDirectory();
2828
if (! empty($binaryPackageDirectory) && $filesystem->exists($this->buildPath($binaryPackageDirectory))) {
29-
$filesystem->remove($this->buildPath($binaryPackageDirectory));
29+
$filesystem->remove($this->buildPath('app', $binaryPackageDirectory));
3030
}
3131
}
3232
}

src/Drivers/Electron/Commands/BuildCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private function buildBundle(): void
8080

8181
$this->newLine();
8282
intro('Copying latest CA Certificate...');
83-
$this->builder->copyCertificateAuthority(path: ElectronServiceProvider::buildPath());
83+
$this->builder->copyCertificateAuthority();
8484

8585
$this->newLine();
8686
intro('Copying app icons...');
@@ -105,7 +105,7 @@ private function buildUnsecure(): void
105105

106106
$this->newLine();
107107
intro('Copying latest CA Certificate...');
108-
$this->builder->copyCertificateAuthority(path: ElectronServiceProvider::buildPath());
108+
$this->builder->copyCertificateAuthority();
109109

110110
$this->newLine();
111111
intro('Cleaning .env file...');

src/Drivers/Electron/Commands/DevelopCommand.php

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

5858
$this->installIcon();
5959

60-
$this->builder->copyCertificateAuthority(path: ElectronServiceProvider::buildPath());
60+
$this->builder->copyCertificateAuthority();
6161

6262
$this->runDeveloper(
6363
installer: $this->option('installer'),

src/Drivers/Electron/ElectronServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function packageRegistered(): void
5454

5555
$this->app->bind(Builder::class, function () {
5656
return Builder::make(
57-
buildPath: self::buildPath('app')
57+
buildPath: self::buildPath()
5858
);
5959
});
6060
}

src/Support/Composer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class Composer
1212
{
1313
public static function desktopPackagePath(string $path = '')
1414
{
15-
return self::vendorPath("nativephp/desktop/{$path}");
15+
return Path::join(__DIR__, '../../', $path);
16+
17+
// return self::vendorPath("nativephp/desktop/{$path}");
1618
}
1719

1820
public static function phpPackagePath(string $path = '')
@@ -22,9 +24,9 @@ public static function phpPackagePath(string $path = '')
2224

2325
public static function vendorPath(string $path = '')
2426
{
25-
$vendorPath = realpath(InstalledVersions::getRootPackage()['install_path'].'/vendor');
27+
$rootPath = realpath(InstalledVersions::getRootPackage()['install_path']);
2628

27-
return Path::join($vendorPath, $path);
29+
return Path::join($rootPath, 'vendor', $path);
2830
}
2931

3032
public static function installScripts()

tests/Build/CleanEnvFileTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function buildPath(string $path = ''): string
4646
*/
4747
it('cleans configured keys', function () use ($buildPath, $command) {
4848

49-
(new Filesystem)->dumpFile("{$buildPath}/.env", <<<'TXT'
49+
(new Filesystem)->dumpFile("{$buildPath}/app/.env", <<<'TXT'
5050
FOO=BAR
5151
BAZ=ZAH
5252
TXT);
@@ -57,34 +57,34 @@ public function buildPath(string $path = ''): string
5757

5858
$command->cleanEnvFile();
5959

60-
expect(file_get_contents("{$buildPath}/.env"))
60+
expect(file_get_contents("{$buildPath}/app/.env"))
6161
->not->toContain('FOO')
6262
->toContain('BAZ');
6363
});
6464

6565
it('removes comments', function () use ($buildPath, $command) {
6666

67-
(new Filesystem)->dumpFile("{$buildPath}/.env", <<<'TXT'
67+
(new Filesystem)->dumpFile("{$buildPath}/app/.env", <<<'TXT'
6868
KEEP_ME=hello
6969
# REMOVE_ME=hello
7070
TXT);
7171

7272
$command->cleanEnvFile();
7373

74-
expect(file_get_contents("{$buildPath}/.env"))
74+
expect(file_get_contents("{$buildPath}/app/.env"))
7575
->not->toContain('REMOVE_ME')
7676
->toContain('KEEP_ME');
7777
});
7878

7979
it('injects defaults', function () use ($buildPath, $command) {
80-
(new Filesystem)->dumpFile("{$buildPath}/.env", <<<'TXT'
80+
(new Filesystem)->dumpFile("{$buildPath}/app/.env", <<<'TXT'
8181
LOG_CHANNEL=test
8282
LOG_STACK=test
8383
TXT);
8484

8585
$command->cleanEnvFile();
8686

87-
expect(file_get_contents("{$buildPath}/.env"))
87+
expect(file_get_contents("{$buildPath}/app/.env"))
8888
->not->toContain('LOG_CHANNEL=test')
8989
->not->toContain('LOG_STACK=test')
9090
->toContain('LOG_CHANNEL=stack')
@@ -95,7 +95,7 @@ public function buildPath(string $path = ''): string
9595
it('cleans default cleanup keys', function () use ($buildPath, $command) {
9696

9797
// NOTE: This checks the default cleanup_env_keys are cleaned. So we can sleep at night.
98-
(new Filesystem)->dumpFile("{$buildPath}/.env", <<<'TXT'
98+
(new Filesystem)->dumpFile("{$buildPath}/app/.env", <<<'TXT'
9999
SAFE_VARIABLE=test
100100
AWS_WILDCARD=test
101101
GITHUB_WILDCARD=test
@@ -109,7 +109,7 @@ public function buildPath(string $path = ''): string
109109

110110
$command->cleanEnvFile();
111111

112-
expect(file_get_contents("{$buildPath}/.env"))
112+
expect(file_get_contents("{$buildPath}/app/.env"))
113113
->toContain('SAFE_VARIABLE=test')
114114
->not->toContain('AWS_WILDCARD')
115115
->not->toContain('GITHUB_WILDCARD')

0 commit comments

Comments
 (0)