-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathBuildCommand.php
More file actions
182 lines (148 loc) · 5.79 KB
/
BuildCommand.php
File metadata and controls
182 lines (148 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
namespace Native\Electron\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Str;
use Native\Electron\Facades\Updater;
use Native\Electron\Traits\CleansEnvFile;
use Native\Electron\Traits\CopiesBundleToBuildDirectory;
use Native\Electron\Traits\CopiesCertificateAuthority;
use Native\Electron\Traits\HasPreAndPostProcessing;
use Native\Electron\Traits\InstallsAppIcon;
use Native\Electron\Traits\LocatesPhpBinary;
use Native\Electron\Traits\OsAndArch;
use Native\Electron\Traits\PatchesPackagesJson;
use Native\Electron\Traits\PrunesVendorDirectory;
use Symfony\Component\Process\Process as SymfonyProcess;
use function Laravel\Prompts\intro;
class BuildCommand extends Command
{
use CleansEnvFile;
use CopiesBundleToBuildDirectory;
use CopiesCertificateAuthority;
use HasPreAndPostProcessing;
use InstallsAppIcon;
use LocatesPhpBinary;
use OsAndArch;
use PatchesPackagesJson;
use PrunesVendorDirectory;
protected $signature = 'native:build
{os? : The operating system to build for (all, linux, mac, win)}
{arch? : The Processor Architecture to build for (x64, x86, arm64)}
{--publish : to publish the app}';
protected array $availableOs = ['win', 'linux', 'mac', 'all'];
private string $buildCommand;
private string $buildOS;
protected function buildPath(string $path = ''): string
{
return __DIR__.'/../../resources/js/resources/app/'.$path;
}
protected function sourcePath(string $path = ''): string
{
return base_path($path);
}
public function handle(): void
{
$this->buildOS = $this->selectOs($this->argument('os'));
$this->buildCommand = 'build';
if ($this->buildOS != 'all') {
$arch = $this->selectArchitectureForOs($this->buildOS, $this->argument('arch'));
$this->buildOS .= $arch != 'all' ? "-{$arch}" : '';
// Should we publish?
if ($this->option('publish')) {
$this->buildCommand = 'publish';
}
}
if ($this->hasBundled()) {
$this->buildBundle();
} else {
$this->warnUnsecureBuild();
$this->buildUnsecure();
}
}
private function buildBundle(): void
{
$this->setAppNameAndVersion();
$this->updateElectronDependencies();
$this->newLine();
intro('Copying Bundle to build directory...');
$this->copyBundleToBuildDirectory();
$this->keepRequiredDirectories();
$this->newLine();
$this->copyCertificateAuthorityCertificate();
$this->newLine();
intro('Copying app icons...');
$this->installIcon();
$this->buildOrPublish();
}
private function buildUnsecure(): void
{
$this->preProcess();
$this->setAppNameAndVersion();
$this->updateElectronDependencies();
$this->newLine();
intro('Copying App to build directory...');
$this->copyToBuildDirectory();
$this->newLine();
$this->copyCertificateAuthorityCertificate();
$this->newLine();
intro('Cleaning .env file...');
$this->cleanEnvFile();
$this->newLine();
intro('Copying app icons...');
$this->installIcon();
$this->newLine();
intro('Pruning vendor directory');
$this->pruneVendorDirectory();
$this->buildOrPublish();
$this->postProcess();
}
protected function getEnvironmentVariables(): array
{
return array_merge(
[
'APP_PATH' => $this->sourcePath(),
'APP_URL' => config('app.url'),
'NATIVEPHP_BUILDING' => true,
'NATIVEPHP_PHP_BINARY_VERSION' => PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION,
'NATIVEPHP_PHP_BINARY_PATH' => $this->sourcePath($this->phpBinaryPath()),
'NATIVEPHP_APP_NAME' => config('app.name'),
'NATIVEPHP_APP_ID' => config('nativephp.app_id'),
'NATIVEPHP_APP_VERSION' => config('nativephp.version'),
'NATIVEPHP_APP_COPYRIGHT' => config('nativephp.copyright'),
'NATIVEPHP_APP_FILENAME' => Str::slug(config('app.name')),
'NATIVEPHP_APP_AUTHOR' => config('nativephp.author'),
'NATIVEPHP_UPDATER_CONFIG' => json_encode(Updater::builderOptions()),
'NATIVEPHP_DEEPLINK_SCHEME' => config('nativephp.deeplink_scheme'),
// Notarization
'NATIVEPHP_APPLE_ID' => config('nativephp-internal.notarization.apple_id'),
'NATIVEPHP_APPLE_ID_PASS' => config('nativephp-internal.notarization.apple_id_pass'),
'NATIVEPHP_APPLE_TEAM_ID' => config('nativephp-internal.notarization.apple_team_id'),
],
Updater::environmentVariables(),
);
}
private function updateElectronDependencies(): void
{
$this->newLine();
intro('Updating Electron dependencies...');
Process::path(__DIR__.'/../../resources/js/')
->env($this->getEnvironmentVariables())
->forever()
->run('npm ci', function (string $type, string $output) {
echo $output;
});
}
private function buildOrPublish(): void
{
$this->newLine();
intro((($this->buildCommand == 'publish') ? 'Publishing' : 'Building')." for {$this->buildOS}");
Process::path(__DIR__.'/../../resources/js/')
->env($this->getEnvironmentVariables())
->forever()
->tty(SymfonyProcess::isTtySupported() && ! $this->option('no-interaction'))
->run("npm run {$this->buildCommand}:{$this->buildOS}", function (string $type, string $output) {
echo $output;
});
}
}