From c2b4f4db67c1d34cc833a5a44879b7a412c2417e Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 18 Feb 2025 12:45:46 +0000 Subject: [PATCH 01/11] Implement Pre and Post Processing --- src/Commands/BuildCommand.php | 2 + src/Traits/HasPreAndPostProcessing.php | 92 ++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/Traits/HasPreAndPostProcessing.php diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 98b9b722..a1bad7dd 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -7,11 +7,13 @@ use Illuminate\Support\Str; use Native\Electron\Concerns\LocatesPhpBinary; use Native\Electron\Facades\Updater; +use Native\Electron\Traits\HasPreAndPostProcessing; use Native\Electron\Traits\InstallsAppIcon; use Native\Electron\Traits\OsAndArch; class BuildCommand extends Command { + use HasPreAndPostProcessing; use InstallsAppIcon; use LocatesPhpBinary; use OsAndArch; diff --git a/src/Traits/HasPreAndPostProcessing.php b/src/Traits/HasPreAndPostProcessing.php new file mode 100644 index 00000000..a4d47148 --- /dev/null +++ b/src/Traits/HasPreAndPostProcessing.php @@ -0,0 +1,92 @@ +getConfig($configKey); + + if (! $config instanceof Collection + || empty($config->get('before')) + ) { + return; + } + + intro('Running pre-process commands...'); + + $config->get('before', collect()) + ->each($this->getProcessCallback()); + + outro('Pre-process commands completed.'); + } + + protected function postProcess(string $configKey): void + { + $config = $this->getConfig($configKey); + + if (! $config instanceof Collection + || empty($config->get('after')) + ) { + return; + } + + intro('Running post-process commands...'); + + $config->get('after', collect()) + ->each($this->getProcessCallback()); + + outro('Post-process commands completed.'); + } + + private function formatConfigKey(string $configKey): string + { + return sprintf('nativephp.%s', $configKey); + } + + private function executeCommand(mixed $command): ProcessResult + { + return Process::path(base_path()) + ->timeout(300) + ->tty(\Symfony\Component\Process\Process::isTtySupported() && ! $this->option('no-interaction')) + ->run($command, function (string $type, string $output) { + echo $output; + }); + } + + private function getConfig(string $configKey): mixed + { + $config = config($this->formatConfigKey($configKey)); + + if (is_array($config)) { + return collect($config) + ->map(fn ($value) => is_array($value) ? collect($value) : $value); + } + + return $config; + } + + private function getProcessCallback(): callable + { + return function ($command) { + note("Running command: {$command}"); + $result = $this->executeCommand($command); + + if (! $result->successful()) { + error("Command failed: {$command}"); + return; + } + + note("Command successful: {$command}"); + }; + } +} From 80277dc18007c4d5860df9a07bd4741abc707212 Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 18 Feb 2025 12:49:01 +0000 Subject: [PATCH 02/11] Provide pre and post-process functionality to build command --- src/Commands/BuildCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index a1bad7dd..0f62c54c 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -29,6 +29,8 @@ public function handle(): void { $this->info('Build NativePHP app…'); + $this->preProcess('build'); + Process::path(__DIR__.'/../../resources/js/') ->env($this->getEnvironmentVariables()) ->forever() @@ -66,6 +68,8 @@ public function handle(): void ->run("npm run {$buildCommand}:{$os}", function (string $type, string $output) { echo $output; }); + + $this->postProcess('build'); } protected function getEnvironmentVariables(): array From 1dd1314ae4aac3ffa3479abaad8680828793830d Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 18 Feb 2025 13:04:37 +0000 Subject: [PATCH 03/11] Refactor to align with change to config keys --- src/Traits/HasPreAndPostProcessing.php | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Traits/HasPreAndPostProcessing.php b/src/Traits/HasPreAndPostProcessing.php index a4d47148..7cef6a77 100644 --- a/src/Traits/HasPreAndPostProcessing.php +++ b/src/Traits/HasPreAndPostProcessing.php @@ -12,38 +12,32 @@ trait HasPreAndPostProcessing { - protected function preProcess(string $configKey): void + protected function preProcess(): void { - $config = $this->getConfig($configKey); + $config = $this->getConfig('prebuild'); - if (! $config instanceof Collection - || empty($config->get('before')) - ) { + if (! $config instanceof Collection) { return; } intro('Running pre-process commands...'); - $config->get('before', collect()) - ->each($this->getProcessCallback()); + $config->each($this->getProcessCallback()); outro('Pre-process commands completed.'); } - protected function postProcess(string $configKey): void + protected function postProcess(): void { - $config = $this->getConfig($configKey); + $config = $this->getConfig('postbuild'); - if (! $config instanceof Collection - || empty($config->get('after')) - ) { + if (! $config instanceof Collection) { return; } intro('Running post-process commands...'); - $config->get('after', collect()) - ->each($this->getProcessCallback()); + $config->each($this->getProcessCallback()); outro('Post-process commands completed.'); } @@ -68,8 +62,9 @@ private function getConfig(string $configKey): mixed $config = config($this->formatConfigKey($configKey)); if (is_array($config)) { + // Filter out empty values return collect($config) - ->map(fn ($value) => is_array($value) ? collect($value) : $value); + ->filter(fn ($value) => ! empty($value)); } return $config; @@ -79,6 +74,11 @@ private function getProcessCallback(): callable { return function ($command) { note("Running command: {$command}"); + + if (is_array($command)) { + $command = implode(' && ', $command); + } + $result = $this->executeCommand($command); if (! $result->successful()) { From 05121d206b1e34837ae7c3a8e52c829919d4fc10 Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 18 Feb 2025 13:36:36 +0000 Subject: [PATCH 04/11] Test --- composer.json | 1 + resources/js/yarn.lock | 117 +++++++++++++++--- src/Traits/HasPreAndPostProcessing.php | 12 +- tests/Mocks/HasPreAndPostProcessingMock.php | 11 ++ .../Traits/HasPreAndPostProcessingTest.php | 49 ++++++++ 5 files changed, 167 insertions(+), 23 deletions(-) create mode 100644 tests/Mocks/HasPreAndPostProcessingMock.php create mode 100644 tests/Unit/Traits/HasPreAndPostProcessingTest.php diff --git a/composer.json b/composer.json index 6f404297..eca75b00 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,7 @@ }, "require-dev": { "laravel/pint": "^1.0", + "mockery/mockery": "^1.6", "nunomaduro/collision": "^7.9", "nunomaduro/larastan": "^2.0.1", "orchestra/testbench": "^8.18", diff --git a/resources/js/yarn.lock b/resources/js/yarn.lock index cd99bfca..a2269345 100644 --- a/resources/js/yarn.lock +++ b/resources/js/yarn.lock @@ -1121,10 +1121,10 @@ minimatch "^9.0.3" plist "^3.1.0" -"@esbuild/linux-x64@0.21.5": +"@esbuild/darwin-arm64@0.21.5": version "0.21.5" - resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz" - integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ== + resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz" + integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ== "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.1" @@ -1543,15 +1543,10 @@ resolved "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz" integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA== -"@rollup/rollup-linux-x64-gnu@4.29.1": +"@rollup/rollup-darwin-arm64@4.29.1": version "4.29.1" - resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.29.1.tgz" - integrity sha512-87xYCwb0cPGZFoGiErT1eDcssByaLX4fc0z2nRM6eMtV9njAfEE6OW3UniAoDhX4Iq5xQVpE6qO9aJbCFumKYQ== - -"@rollup/rollup-linux-x64-musl@4.29.1": - version "4.29.1" - resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.29.1.tgz" - integrity sha512-xufkSNppNOdVRCEC4WKvlR1FBDyqCSCpQeMMgv9ZyXqqtKBfkw1yfGMTUTs9Qsl6WQbJnsGboWCp7pJGkeMhKA== + resolved "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.29.1.tgz" + integrity sha512-2ORr7T31Y0Mnk6qNuwtyNmy14MunTAMx06VAPI6/Ju52W10zk1i7i5U3vlDRWjhOI5quBcrvhkCHyF76bI7kEw== "@rushstack/eslint-patch@^1.10.4": version "1.10.4" @@ -1810,6 +1805,14 @@ resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz" integrity sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA== +"@types/plist@^3.0.1": + version "3.0.5" + resolved "https://registry.npmjs.org/@types/plist/-/plist-3.0.5.tgz" + integrity sha512-E6OCaRmAe4WDmWNsL/9RMqdkkzDCY1etutkflWk4c+AcjDU07Pcz1fQwTX0TQz+Pxqn9i4L1TU3UFpjnrcDgxA== + dependencies: + "@types/node" "*" + xmlbuilder ">=11.0.1" + "@types/ps-node@^0.1.3": version "0.1.3" resolved "https://registry.npmjs.org/@types/ps-node/-/ps-node-0.1.3.tgz" @@ -1854,6 +1857,11 @@ resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz" integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw== +"@types/verror@^1.10.3": + version "1.10.10" + resolved "https://registry.npmjs.org/@types/verror/-/verror-1.10.10.tgz" + integrity sha512-l4MM0Jppn18hb9xmM6wwD1uTdShpf9Pn80aXTStnK1C94gtPvJcV2FrDmbOQUAQfJ1cKZHktkQUDwEqaAKXMMg== + "@types/yargs-parser@*": version "21.0.3" resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz" @@ -2048,7 +2056,7 @@ ajv-keywords@^3.4.1: resolved "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz" integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== -ajv@^6.12.0, ajv@^6.12.4, ajv@^6.9.1: +ajv@^6.10.0, ajv@^6.12.0, ajv@^6.12.4, ajv@^6.9.1: version "6.12.6" resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -2263,6 +2271,11 @@ array-union@^2.1.0: resolved "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== +assert-plus@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" + integrity sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw== + astral-regex@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz" @@ -2517,7 +2530,7 @@ buffer-from@^1.0.0: resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -buffer@^5.5.0: +buffer@^5.1.0, buffer@^5.5.0: version "5.7.1" resolved "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz" integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ== @@ -2725,6 +2738,14 @@ cli-spinners@^2.5.0: resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz" integrity sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg== +cli-truncate@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz" + integrity sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg== + dependencies: + slice-ansi "^3.0.0" + string-width "^4.2.0" + cli-truncate@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/cli-truncate/-/cli-truncate-4.0.0.tgz" @@ -2892,7 +2913,7 @@ core-js-compat@^3.38.0, core-js-compat@^3.38.1: dependencies: browserslist "^4.24.2" -core-util-is@~1.0.0: +core-util-is@~1.0.0, core-util-is@1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" integrity sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ== @@ -2912,6 +2933,13 @@ crc-32@^1.2.0: resolved "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz" integrity sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ== +crc@^3.8.0: + version "3.8.0" + resolved "https://registry.npmjs.org/crc/-/crc-3.8.0.tgz" + integrity sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ== + dependencies: + buffer "^5.1.0" + crc32-stream@^4.0.2: version "4.0.3" resolved "https://registry.npmjs.org/crc32-stream/-/crc32-stream-4.0.3.tgz" @@ -3119,6 +3147,20 @@ dmg-builder@25.1.8: optionalDependencies: dmg-license "^1.0.11" +dmg-license@^1.0.11: + version "1.0.11" + resolved "https://registry.npmjs.org/dmg-license/-/dmg-license-1.0.11.tgz" + integrity sha512-ZdzmqwKmECOWJpqefloC5OJy1+WZBBse5+MR88z9g9Zn4VY+WYUkAyojmhzJckH5YbbZGcYIuGAkY5/Ys5OM2Q== + dependencies: + "@types/plist" "^3.0.1" + "@types/verror" "^1.10.3" + ajv "^6.10.0" + crc "^3.8.0" + iconv-corefoundation "^1.1.7" + plist "^3.0.4" + smart-buffer "^4.0.2" + verror "^1.10.0" + dot-prop@^9.0.0: version "9.0.0" resolved "https://registry.npmjs.org/dot-prop/-/dot-prop-9.0.0.tgz" @@ -3720,6 +3762,11 @@ extract-zip@^2.0.0, extract-zip@^2.0.1: optionalDependencies: "@types/yauzl" "^2.9.1" +extsprintf@^1.2.0: + version "1.4.1" + resolved "https://registry.npmjs.org/extsprintf/-/extsprintf-1.4.1.tgz" + integrity sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA== + fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz" @@ -3973,6 +4020,11 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3: + version "2.3.3" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" @@ -4345,6 +4397,14 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" +iconv-corefoundation@^1.1.7: + version "1.1.7" + resolved "https://registry.npmjs.org/iconv-corefoundation/-/iconv-corefoundation-1.1.7.tgz" + integrity sha512-T10qvkw0zz4wnm560lOEg0PovVqUXuOFhhHAkixw8/sycy7TJt7v/RrkEKEQnAw2viPSJu6iAkErxnzR0g8PpQ== + dependencies: + cli-truncate "^2.1.0" + node-addon-api "^1.6.3" + iconv-lite@^0.6.2: version "0.6.3" resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz" @@ -5663,6 +5723,11 @@ node-abi@^3.45.0: dependencies: semver "^7.3.5" +node-addon-api@^1.6.3: + version "1.7.2" + resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz" + integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg== + node-api-version@^0.2.0: version "0.2.0" resolved "https://registry.npmjs.org/node-api-version/-/node-api-version-0.2.0.tgz" @@ -5987,7 +6052,7 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" -plist@^3.0.5, plist@^3.1.0: +plist@^3.0.4, plist@^3.0.5, plist@^3.1.0: version "3.1.0" resolved "https://registry.npmjs.org/plist/-/plist-3.1.0.tgz" integrity sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ== @@ -6687,6 +6752,15 @@ slash@^3.0.0: resolved "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== +slice-ansi@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz" + integrity sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ== + dependencies: + ansi-styles "^4.0.0" + astral-regex "^2.0.0" + is-fullwidth-code-point "^3.0.0" + slice-ansi@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz" @@ -6704,7 +6778,7 @@ slice-ansi@^5.0.0: ansi-styles "^6.0.0" is-fullwidth-code-point "^4.0.0" -smart-buffer@^4.2.0: +smart-buffer@^4.0.2, smart-buffer@^4.2.0: version "4.2.0" resolved "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz" integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg== @@ -7451,6 +7525,15 @@ vary@~1.1.2: resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz" integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg== +verror@^1.10.0: + version "1.10.1" + resolved "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz" + integrity sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg== + dependencies: + assert-plus "^1.0.0" + core-util-is "1.0.2" + extsprintf "^1.2.0" + "vite@^4.0.0 || ^5.0.0", vite@^5.0.0: version "5.4.11" resolved "https://registry.npmjs.org/vite/-/vite-5.4.11.tgz" @@ -7573,7 +7656,7 @@ xml-name-validator@^4.0.0: resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz" integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw== -xmlbuilder@^15.1.1: +xmlbuilder@^15.1.1, xmlbuilder@>=11.0.1: version "15.1.1" resolved "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz" integrity sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg== diff --git a/src/Traits/HasPreAndPostProcessing.php b/src/Traits/HasPreAndPostProcessing.php index 7cef6a77..ca58cfe4 100644 --- a/src/Traits/HasPreAndPostProcessing.php +++ b/src/Traits/HasPreAndPostProcessing.php @@ -12,9 +12,9 @@ trait HasPreAndPostProcessing { - protected function preProcess(): void + public function preProcess(): void { - $config = $this->getConfig('prebuild'); + $config = $this->getPrePostBuildConfig('prebuild'); if (! $config instanceof Collection) { return; @@ -27,9 +27,9 @@ protected function preProcess(): void outro('Pre-process commands completed.'); } - protected function postProcess(): void + public function postProcess(): void { - $config = $this->getConfig('postbuild'); + $config = $this->getPrePostBuildConfig('postbuild'); if (! $config instanceof Collection) { return; @@ -51,13 +51,13 @@ private function executeCommand(mixed $command): ProcessResult { return Process::path(base_path()) ->timeout(300) - ->tty(\Symfony\Component\Process\Process::isTtySupported() && ! $this->option('no-interaction')) + ->tty(\Symfony\Component\Process\Process::isTtySupported()) ->run($command, function (string $type, string $output) { echo $output; }); } - private function getConfig(string $configKey): mixed + protected function getPrePostBuildConfig(string $configKey): mixed { $config = config($this->formatConfigKey($configKey)); diff --git a/tests/Mocks/HasPreAndPostProcessingMock.php b/tests/Mocks/HasPreAndPostProcessingMock.php new file mode 100644 index 00000000..e4b51805 --- /dev/null +++ b/tests/Mocks/HasPreAndPostProcessingMock.php @@ -0,0 +1,11 @@ +makePartial(); + + $mock->shouldAllowMockingProtectedMethods(); + $mock->shouldReceive('getPrePostBuildConfig') + ->with('prebuild') + ->andReturn(collect(Config::get('nativephp.prebuild'))); + + $mock->shouldReceive('getPrePostBuildConfig') + ->with('postbuild') + ->andReturn(collect(Config::get('nativephp.postbuild'))); + + // Verify those files were created in preProcess + $mock->preProcess(); + + expect(file_exists($tmpDir . '/prebuild1'))->toBeTrue(); + expect(file_exists($tmpDir . '/prebuild2'))->toBeTrue(); + + // Verify those files were created in postProcess + $mock->postProcess(); + expect(file_exists($tmpDir . '/postbuild1'))->toBeTrue(); + expect(file_exists($tmpDir . '/postbuild2'))->toBeTrue(); + + // Cleanup + unlink($tmpDir . '/prebuild1'); + unlink($tmpDir . '/prebuild2'); + unlink($tmpDir . '/postbuild1'); + unlink($tmpDir . '/postbuild2'); +}); From 1be0d7770e01d6ec8c30e487c1378ba8ec16b220 Mon Sep 17 00:00:00 2001 From: PeteBishwhip <9081809+PeteBishwhip@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:37:51 +0000 Subject: [PATCH 05/11] Fix styling --- src/Traits/HasPreAndPostProcessing.php | 2 ++ .../Traits/HasPreAndPostProcessingTest.php | 24 +++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Traits/HasPreAndPostProcessing.php b/src/Traits/HasPreAndPostProcessing.php index ca58cfe4..bada5007 100644 --- a/src/Traits/HasPreAndPostProcessing.php +++ b/src/Traits/HasPreAndPostProcessing.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Process\ProcessResult; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Process; + use function Laravel\Prompts\error; use function Laravel\Prompts\intro; use function Laravel\Prompts\note; @@ -83,6 +84,7 @@ private function getProcessCallback(): callable if (! $result->successful()) { error("Command failed: {$command}"); + return; } diff --git a/tests/Unit/Traits/HasPreAndPostProcessingTest.php b/tests/Unit/Traits/HasPreAndPostProcessingTest.php index f6bcc458..7fc2064e 100644 --- a/tests/Unit/Traits/HasPreAndPostProcessingTest.php +++ b/tests/Unit/Traits/HasPreAndPostProcessingTest.php @@ -9,13 +9,13 @@ $tmpDir = sys_get_temp_dir(); Config::set('nativephp.prebuild', [ - 'touch ' . $tmpDir . '/prebuild1', - 'touch ' . $tmpDir . '/prebuild2', + 'touch '.$tmpDir.'/prebuild1', + 'touch '.$tmpDir.'/prebuild2', ]); Config::set('nativephp.postbuild', [ - 'touch ' . $tmpDir . '/postbuild1', - 'touch ' . $tmpDir . '/postbuild2', + 'touch '.$tmpDir.'/postbuild1', + 'touch '.$tmpDir.'/postbuild2', ]); $mock = \Mockery::mock(HasPreAndPostProcessingMock::class) @@ -33,17 +33,17 @@ // Verify those files were created in preProcess $mock->preProcess(); - expect(file_exists($tmpDir . '/prebuild1'))->toBeTrue(); - expect(file_exists($tmpDir . '/prebuild2'))->toBeTrue(); + expect(file_exists($tmpDir.'/prebuild1'))->toBeTrue(); + expect(file_exists($tmpDir.'/prebuild2'))->toBeTrue(); // Verify those files were created in postProcess $mock->postProcess(); - expect(file_exists($tmpDir . '/postbuild1'))->toBeTrue(); - expect(file_exists($tmpDir . '/postbuild2'))->toBeTrue(); + expect(file_exists($tmpDir.'/postbuild1'))->toBeTrue(); + expect(file_exists($tmpDir.'/postbuild2'))->toBeTrue(); // Cleanup - unlink($tmpDir . '/prebuild1'); - unlink($tmpDir . '/prebuild2'); - unlink($tmpDir . '/postbuild1'); - unlink($tmpDir . '/postbuild2'); + unlink($tmpDir.'/prebuild1'); + unlink($tmpDir.'/prebuild2'); + unlink($tmpDir.'/postbuild1'); + unlink($tmpDir.'/postbuild2'); }); From 4fda3f8f9086d3cc7606ad63dc31f7a7febde572 Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 18 Feb 2025 13:39:26 +0000 Subject: [PATCH 06/11] Rmeove changes to yarn.lock --- resources/js/yarn.lock | 117 ++++++----------------------------------- 1 file changed, 17 insertions(+), 100 deletions(-) diff --git a/resources/js/yarn.lock b/resources/js/yarn.lock index a2269345..cd99bfca 100644 --- a/resources/js/yarn.lock +++ b/resources/js/yarn.lock @@ -1121,10 +1121,10 @@ minimatch "^9.0.3" plist "^3.1.0" -"@esbuild/darwin-arm64@0.21.5": +"@esbuild/linux-x64@0.21.5": version "0.21.5" - resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz" - integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ== + resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz" + integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ== "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.1" @@ -1543,10 +1543,15 @@ resolved "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz" integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA== -"@rollup/rollup-darwin-arm64@4.29.1": +"@rollup/rollup-linux-x64-gnu@4.29.1": version "4.29.1" - resolved "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.29.1.tgz" - integrity sha512-2ORr7T31Y0Mnk6qNuwtyNmy14MunTAMx06VAPI6/Ju52W10zk1i7i5U3vlDRWjhOI5quBcrvhkCHyF76bI7kEw== + resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.29.1.tgz" + integrity sha512-87xYCwb0cPGZFoGiErT1eDcssByaLX4fc0z2nRM6eMtV9njAfEE6OW3UniAoDhX4Iq5xQVpE6qO9aJbCFumKYQ== + +"@rollup/rollup-linux-x64-musl@4.29.1": + version "4.29.1" + resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.29.1.tgz" + integrity sha512-xufkSNppNOdVRCEC4WKvlR1FBDyqCSCpQeMMgv9ZyXqqtKBfkw1yfGMTUTs9Qsl6WQbJnsGboWCp7pJGkeMhKA== "@rushstack/eslint-patch@^1.10.4": version "1.10.4" @@ -1805,14 +1810,6 @@ resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz" integrity sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA== -"@types/plist@^3.0.1": - version "3.0.5" - resolved "https://registry.npmjs.org/@types/plist/-/plist-3.0.5.tgz" - integrity sha512-E6OCaRmAe4WDmWNsL/9RMqdkkzDCY1etutkflWk4c+AcjDU07Pcz1fQwTX0TQz+Pxqn9i4L1TU3UFpjnrcDgxA== - dependencies: - "@types/node" "*" - xmlbuilder ">=11.0.1" - "@types/ps-node@^0.1.3": version "0.1.3" resolved "https://registry.npmjs.org/@types/ps-node/-/ps-node-0.1.3.tgz" @@ -1857,11 +1854,6 @@ resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz" integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw== -"@types/verror@^1.10.3": - version "1.10.10" - resolved "https://registry.npmjs.org/@types/verror/-/verror-1.10.10.tgz" - integrity sha512-l4MM0Jppn18hb9xmM6wwD1uTdShpf9Pn80aXTStnK1C94gtPvJcV2FrDmbOQUAQfJ1cKZHktkQUDwEqaAKXMMg== - "@types/yargs-parser@*": version "21.0.3" resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz" @@ -2056,7 +2048,7 @@ ajv-keywords@^3.4.1: resolved "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz" integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== -ajv@^6.10.0, ajv@^6.12.0, ajv@^6.12.4, ajv@^6.9.1: +ajv@^6.12.0, ajv@^6.12.4, ajv@^6.9.1: version "6.12.6" resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -2271,11 +2263,6 @@ array-union@^2.1.0: resolved "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== -assert-plus@^1.0.0: - version "1.0.0" - resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" - integrity sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw== - astral-regex@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz" @@ -2530,7 +2517,7 @@ buffer-from@^1.0.0: resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -buffer@^5.1.0, buffer@^5.5.0: +buffer@^5.5.0: version "5.7.1" resolved "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz" integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ== @@ -2738,14 +2725,6 @@ cli-spinners@^2.5.0: resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz" integrity sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg== -cli-truncate@^2.1.0: - version "2.1.0" - resolved "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz" - integrity sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg== - dependencies: - slice-ansi "^3.0.0" - string-width "^4.2.0" - cli-truncate@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/cli-truncate/-/cli-truncate-4.0.0.tgz" @@ -2913,7 +2892,7 @@ core-js-compat@^3.38.0, core-js-compat@^3.38.1: dependencies: browserslist "^4.24.2" -core-util-is@~1.0.0, core-util-is@1.0.2: +core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" integrity sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ== @@ -2933,13 +2912,6 @@ crc-32@^1.2.0: resolved "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz" integrity sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ== -crc@^3.8.0: - version "3.8.0" - resolved "https://registry.npmjs.org/crc/-/crc-3.8.0.tgz" - integrity sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ== - dependencies: - buffer "^5.1.0" - crc32-stream@^4.0.2: version "4.0.3" resolved "https://registry.npmjs.org/crc32-stream/-/crc32-stream-4.0.3.tgz" @@ -3147,20 +3119,6 @@ dmg-builder@25.1.8: optionalDependencies: dmg-license "^1.0.11" -dmg-license@^1.0.11: - version "1.0.11" - resolved "https://registry.npmjs.org/dmg-license/-/dmg-license-1.0.11.tgz" - integrity sha512-ZdzmqwKmECOWJpqefloC5OJy1+WZBBse5+MR88z9g9Zn4VY+WYUkAyojmhzJckH5YbbZGcYIuGAkY5/Ys5OM2Q== - dependencies: - "@types/plist" "^3.0.1" - "@types/verror" "^1.10.3" - ajv "^6.10.0" - crc "^3.8.0" - iconv-corefoundation "^1.1.7" - plist "^3.0.4" - smart-buffer "^4.0.2" - verror "^1.10.0" - dot-prop@^9.0.0: version "9.0.0" resolved "https://registry.npmjs.org/dot-prop/-/dot-prop-9.0.0.tgz" @@ -3762,11 +3720,6 @@ extract-zip@^2.0.0, extract-zip@^2.0.1: optionalDependencies: "@types/yauzl" "^2.9.1" -extsprintf@^1.2.0: - version "1.4.1" - resolved "https://registry.npmjs.org/extsprintf/-/extsprintf-1.4.1.tgz" - integrity sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA== - fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz" @@ -4020,11 +3973,6 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3: - version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" - integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== - function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" @@ -4397,14 +4345,6 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" -iconv-corefoundation@^1.1.7: - version "1.1.7" - resolved "https://registry.npmjs.org/iconv-corefoundation/-/iconv-corefoundation-1.1.7.tgz" - integrity sha512-T10qvkw0zz4wnm560lOEg0PovVqUXuOFhhHAkixw8/sycy7TJt7v/RrkEKEQnAw2viPSJu6iAkErxnzR0g8PpQ== - dependencies: - cli-truncate "^2.1.0" - node-addon-api "^1.6.3" - iconv-lite@^0.6.2: version "0.6.3" resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz" @@ -5723,11 +5663,6 @@ node-abi@^3.45.0: dependencies: semver "^7.3.5" -node-addon-api@^1.6.3: - version "1.7.2" - resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz" - integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg== - node-api-version@^0.2.0: version "0.2.0" resolved "https://registry.npmjs.org/node-api-version/-/node-api-version-0.2.0.tgz" @@ -6052,7 +5987,7 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" -plist@^3.0.4, plist@^3.0.5, plist@^3.1.0: +plist@^3.0.5, plist@^3.1.0: version "3.1.0" resolved "https://registry.npmjs.org/plist/-/plist-3.1.0.tgz" integrity sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ== @@ -6752,15 +6687,6 @@ slash@^3.0.0: resolved "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -slice-ansi@^3.0.0: - version "3.0.0" - resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz" - integrity sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ== - dependencies: - ansi-styles "^4.0.0" - astral-regex "^2.0.0" - is-fullwidth-code-point "^3.0.0" - slice-ansi@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz" @@ -6778,7 +6704,7 @@ slice-ansi@^5.0.0: ansi-styles "^6.0.0" is-fullwidth-code-point "^4.0.0" -smart-buffer@^4.0.2, smart-buffer@^4.2.0: +smart-buffer@^4.2.0: version "4.2.0" resolved "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz" integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg== @@ -7525,15 +7451,6 @@ vary@~1.1.2: resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz" integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg== -verror@^1.10.0: - version "1.10.1" - resolved "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz" - integrity sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg== - dependencies: - assert-plus "^1.0.0" - core-util-is "1.0.2" - extsprintf "^1.2.0" - "vite@^4.0.0 || ^5.0.0", vite@^5.0.0: version "5.4.11" resolved "https://registry.npmjs.org/vite/-/vite-5.4.11.tgz" @@ -7656,7 +7573,7 @@ xml-name-validator@^4.0.0: resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz" integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw== -xmlbuilder@^15.1.1, xmlbuilder@>=11.0.1: +xmlbuilder@^15.1.1: version "15.1.1" resolved "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz" integrity sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg== From ec176cdd4660581d2e554b9de79cbffb8566bfef Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 18 Feb 2025 14:05:44 +0000 Subject: [PATCH 07/11] Remove no-longer necessary keys --- src/Commands/BuildCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 0f62c54c..d2878161 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -29,7 +29,7 @@ public function handle(): void { $this->info('Build NativePHP app…'); - $this->preProcess('build'); + $this->preProcess(); Process::path(__DIR__.'/../../resources/js/') ->env($this->getEnvironmentVariables()) @@ -69,7 +69,7 @@ public function handle(): void echo $output; }); - $this->postProcess('build'); + $this->postProcess(); } protected function getEnvironmentVariables(): array From 66af0b0a04fccd2ff85629c4382cd65f0d1dac27 Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 18 Feb 2025 14:12:25 +0000 Subject: [PATCH 08/11] Allow dynamic properties on mock class --- tests/Mocks/HasPreAndPostProcessingMock.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Mocks/HasPreAndPostProcessingMock.php b/tests/Mocks/HasPreAndPostProcessingMock.php index e4b51805..541160f1 100644 --- a/tests/Mocks/HasPreAndPostProcessingMock.php +++ b/tests/Mocks/HasPreAndPostProcessingMock.php @@ -5,6 +5,7 @@ use Illuminate\Console\Command; use Native\Electron\Traits\HasPreAndPostProcessing; +#[\AllowDynamicProperties] class HasPreAndPostProcessingMock extends Command { use HasPreAndPostProcessing; From 391fef347fc5c4cf16d9ddfd54c7381076e6134c Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Fri, 21 Feb 2025 07:08:16 +0000 Subject: [PATCH 09/11] Reduce complexity, remove Mockery, update test --- composer.json | 1 - src/Traits/HasPreAndPostProcessing.php | 54 ++++++------------- tests/Mocks/HasPreAndPostProcessingMock.php | 12 ----- .../Traits/HasPreAndPostProcessingTest.php | 24 ++++----- 4 files changed, 24 insertions(+), 67 deletions(-) delete mode 100644 tests/Mocks/HasPreAndPostProcessingMock.php diff --git a/composer.json b/composer.json index eca75b00..6f404297 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,6 @@ }, "require-dev": { "laravel/pint": "^1.0", - "mockery/mockery": "^1.6", "nunomaduro/collision": "^7.9", "nunomaduro/larastan": "^2.0.1", "orchestra/testbench": "^8.18", diff --git a/src/Traits/HasPreAndPostProcessing.php b/src/Traits/HasPreAndPostProcessing.php index bada5007..61c81f4d 100644 --- a/src/Traits/HasPreAndPostProcessing.php +++ b/src/Traits/HasPreAndPostProcessing.php @@ -2,7 +2,6 @@ namespace Native\Electron\Traits; -use Illuminate\Contracts\Process\ProcessResult; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Process; @@ -15,72 +14,49 @@ trait HasPreAndPostProcessing { public function preProcess(): void { - $config = $this->getPrePostBuildConfig('prebuild'); + $config = collect(config('nativephp.prebuild')); - if (! $config instanceof Collection) { + if ($config->isEmpty()) { return; } intro('Running pre-process commands...'); - $config->each($this->getProcessCallback()); + $this->runProcess($config); outro('Pre-process commands completed.'); } public function postProcess(): void { - $config = $this->getPrePostBuildConfig('postbuild'); + $config = collect(config('nativephp.postbuild')); - if (! $config instanceof Collection) { + if ($config->isEmpty()) { return; } intro('Running post-process commands...'); - $config->each($this->getProcessCallback()); + $this->runProcess($config); outro('Post-process commands completed.'); } - private function formatConfigKey(string $configKey): string + private function runProcess(Collection $configCommands): void { - return sprintf('nativephp.%s', $configKey); - } - - private function executeCommand(mixed $command): ProcessResult - { - return Process::path(base_path()) - ->timeout(300) - ->tty(\Symfony\Component\Process\Process::isTtySupported()) - ->run($command, function (string $type, string $output) { - echo $output; - }); - } - - protected function getPrePostBuildConfig(string $configKey): mixed - { - $config = config($this->formatConfigKey($configKey)); - - if (is_array($config)) { - // Filter out empty values - return collect($config) - ->filter(fn ($value) => ! empty($value)); - } - - return $config; - } - - private function getProcessCallback(): callable - { - return function ($command) { + $configCommands->each(function ($command) { note("Running command: {$command}"); if (is_array($command)) { $command = implode(' && ', $command); } - $result = $this->executeCommand($command); + $result = Process::path(base_path()) + ->timeout(300) + ->tty(\Symfony\Component\Process\Process::isTtySupported()) + ->run($command, function (string $type, string $output) { + echo $output; + }); if (! $result->successful()) { error("Command failed: {$command}"); @@ -89,6 +65,6 @@ private function getProcessCallback(): callable } note("Command successful: {$command}"); - }; + }); } } diff --git a/tests/Mocks/HasPreAndPostProcessingMock.php b/tests/Mocks/HasPreAndPostProcessingMock.php deleted file mode 100644 index 541160f1..00000000 --- a/tests/Mocks/HasPreAndPostProcessingMock.php +++ /dev/null @@ -1,12 +0,0 @@ -makePartial(); - - $mock->shouldAllowMockingProtectedMethods(); - $mock->shouldReceive('getPrePostBuildConfig') - ->with('prebuild') - ->andReturn(collect(Config::get('nativephp.prebuild'))); - - $mock->shouldReceive('getPrePostBuildConfig') - ->with('postbuild') - ->andReturn(collect(Config::get('nativephp.postbuild'))); - // Verify those files were created in preProcess $mock->preProcess(); @@ -46,4 +34,10 @@ unlink($tmpDir.'/prebuild2'); unlink($tmpDir.'/postbuild1'); unlink($tmpDir.'/postbuild2'); -}); +}) + ->with([ + // Empty class with the HasPreAndPostProcessing trait + new class { + use HasPreAndPostProcessing; + } + ]); From 8ad121a41bbf00eaee24466ed0c39db7360719a7 Mon Sep 17 00:00:00 2001 From: PeteBishwhip <9081809+PeteBishwhip@users.noreply.github.com> Date: Fri, 21 Feb 2025 07:08:41 +0000 Subject: [PATCH 10/11] Fix styling --- tests/Unit/Traits/HasPreAndPostProcessingTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Traits/HasPreAndPostProcessingTest.php b/tests/Unit/Traits/HasPreAndPostProcessingTest.php index 6dba08dc..e9ec01b0 100644 --- a/tests/Unit/Traits/HasPreAndPostProcessingTest.php +++ b/tests/Unit/Traits/HasPreAndPostProcessingTest.php @@ -37,7 +37,8 @@ }) ->with([ // Empty class with the HasPreAndPostProcessing trait - new class { + new class + { use HasPreAndPostProcessing; - } + }, ]); From 4d3af32380c7c8ad553d911189361c9132e8af69 Mon Sep 17 00:00:00 2001 From: SRWieZ <1408020+SRWieZ@users.noreply.github.com> Date: Fri, 21 Feb 2025 19:57:16 +0000 Subject: [PATCH 11/11] Fix styling --- src/Commands/BuildCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index fa09e09a..cba960d6 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -6,9 +6,9 @@ use Illuminate\Support\Facades\Process; use Illuminate\Support\Str; use Native\Electron\Facades\Updater; -use Native\Electron\Traits\HasPreAndPostProcessing; use Native\Electron\Traits\CleansEnvFile; use Native\Electron\Traits\CopiesToBuildDirectory; +use Native\Electron\Traits\HasPreAndPostProcessing; use Native\Electron\Traits\InstallsAppIcon; use Native\Electron\Traits\LocatesPhpBinary; use Native\Electron\Traits\OsAndArch; @@ -20,9 +20,9 @@ class BuildCommand extends Command { - use HasPreAndPostProcessing; use CleansEnvFile; use CopiesToBuildDirectory; + use HasPreAndPostProcessing; use InstallsAppIcon; use LocatesPhpBinary; use OsAndArch; @@ -61,7 +61,7 @@ public function handle(): void $buildCommand = 'publish'; } } - + $this->preProcess(); $this->setAppName(slugify: true);